using System; using System.Collections.Generic; namespace Awperative; public sealed partial class Body { public Component GetComponent() where Generic : Component => GetComponents()[0]; public Component[] GetComponents() where Generic : Component { List 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() 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() where Generic : Component { foreach (Component __component in _components) if (__component.GetType() == typeof(Generic)) if (__component.EnforceSingleton) return true; else return false; return false; } }