namespace Sandbox;
public partial class GameObject
{
///
/// Add a component to this GameObject
///
public T AddComponent( bool startEnabled = true ) where T : Component, new() => Components.Create( startEnabled );
///
/// Add a component to this GameObject
///
public T GetOrAddComponent( bool startEnabled = true ) where T : Component, new()
{
var t = GetComponent( true );
if ( t is not null ) return t;
t = AddComponent( startEnabled );
return t;
}
///
/// Get a component on this GameObject
///
public T GetComponent( bool includeDisabled = false ) => Components.Get( includeDisabled );
///
/// Get components on this GameObject
///
public IEnumerable GetComponents( bool includeDisabled = false ) => Components.GetAll( includeDisabled ? (FindMode.InSelf | FindMode.Enabled | FindMode.Disabled) : FindMode.InSelf | FindMode.Enabled );
///
/// Get components on this GameObject and on descendant GameObjects
///
public IEnumerable GetComponentsInChildren( bool includeDisabled = false, bool includeSelf = true ) => Components.GetAll( includeDisabled ? ((includeSelf ? FindMode.InSelf : default) | FindMode.InDescendants | FindMode.Enabled | FindMode.Disabled) : (includeSelf ? FindMode.InSelf : default) | FindMode.InDescendants | FindMode.Enabled );
///
/// Get component on this GameObject or on descendant GameObjects
///
public T GetComponentInChildren( bool includeDisabled = false, bool includeSelf = true ) => Components.Get( includeDisabled ? ((includeSelf ? FindMode.InSelf : default) | FindMode.InDescendants | FindMode.Enabled | FindMode.Disabled) : (includeSelf ? FindMode.InSelf : default) | FindMode.InDescendants | FindMode.Enabled );
///
/// Get components on this GameObject and on ancestor GameObjects
///
public IEnumerable GetComponentsInParent( bool includeDisabled = false, bool includeSelf = true ) => Components.GetAll( includeDisabled ? ((includeSelf ? FindMode.InSelf : default) | FindMode.InAncestors | FindMode.Enabled | FindMode.Disabled) : (includeSelf ? FindMode.InSelf : default) | FindMode.InAncestors | FindMode.Enabled );
///
/// Get component on this GameObject and on ancestor GameObjects
///
public T GetComponentInParent( bool includeDisabled = false, bool includeSelf = true ) => Components.Get( includeDisabled ? ((includeSelf ? FindMode.InSelf : default) | FindMode.InAncestors | FindMode.Enabled | FindMode.Disabled) : (includeSelf ? FindMode.InSelf : default) | FindMode.InAncestors | FindMode.Enabled );
}