Files
AwperativeKernel/Awperative/Kernel/Entities/Bodies/Components/Location.cs
2026-02-08 15:31:07 -05:00

45 lines
1.5 KiB
C#

using System;
using System.Collections.Generic;
namespace Awperative;
public sealed partial class Body
{
public Component GetComponent<Generic>() where Generic : Component => GetComponents<Generic>()[0];
public Component[] GetComponents<Generic>() where Generic : Component {
List<Component> returnValue = [];
foreach (Component component in _components)
if (component is Generic) returnValue.Add(component);
if(returnValue.Count == 0) { Debug.LogWarning("Scene has no components of this type"); return null; }
return returnValue.ToArray();
}
public Component FindSingleton<Generic>() where Generic : Component {
foreach (Component component in _components)
if (component.GetType() == typeof(Generic))
if(component.EnforceSingleton)
return component;
else {
Debug.LogError("Component is not a singleton");
return null;
}
Debug.LogError("Scene does not contain a component of this type");
return null;
}
public bool SingletonExists<Generic>() where Generic : Component
{
foreach (Component __component in _components)
if (__component.GetType() == typeof(Generic))
if (__component.EnforceSingleton)
return true;
else
return false;
return false;
}
}