API Entity - shmellyorc/Box GitHub Wiki
Namespace: Box.Entities
Represents the foundational game object type, encapsulating hierarchy (parent/child), positioning, visibility, layering, naming, coroutines, signal connections, and timer management. Entities drive per-frame logic via Update
, lifecycle hooks (OnEnter
, OnExit
), and integrate with core systems (rendering, input, assets) through the engine.
public Entity()
Creates an entity with default state: position (0,0)
, size (0,0)
, visible, not exiting, and ready for child management, coroutines, signals, and timers.
Property | Description |
---|---|
IEnumerable<Entity> Children |
Enumerates active child entities, skipping null or exiting ones. |
bool IsExiting |
Indicates whether the entity is in the process of being removed. |
Entity Parent |
Reference to the parent entity, if any. |
bool IsParent |
True if this entity has no parent. |
bool IsChild |
True if this entity is a child of another entity. |
Screen Screen |
The screen context this entity belongs to. |
Camera Camera |
The camera for the current screen. |
int ChildCount |
Number of direct child entities. |
Vect2 Center |
Half of the Size , representing the entity’s center point. |
int ChildIndex |
Index position within parent’s child list, or -1 if none. |
Rect2 LocalBounds |
Bounding rectangle based on the entity’s own position and size. |
Rect2 Bounds |
Shorthand for GlobalBounds . |
Rect2 GlobalBounds |
Bounding rectangle taking into account parent offsets. |
string Name |
Entity identifier; setting enforces uniqueness among siblings and emits EntityNameChanged signal. |
bool Visible |
Whether the entity and its children should be rendered; toggling emits a ScreenDirty signal. |
bool KeepAlive |
When false and not visible, entity may be culled; toggling emits ScreenDirty . |
int Layer |
Drawing order layer; children offset by parent’s layer; toggling emits ScreenDirty . |
Vect2 LocalPosition |
Position relative to parent. |
Vect2 Position |
Alias for GlobalPosition . |
Vect2 GlobalPosition |
World-space position; changing emits ScreenDirty . |
float Width |
Alias for Size.X . |
float Height |
Alias for Size.Y . |
Vect2 Size |
Width and height; changing emits ScreenDirty . |
Method Signature | Description | Returns |
---|---|---|
Vect2 GetGlobalPosition(Entity entity) |
Computes the world position of the specified entity, incorporating parent offsets. | Vect2 |
Vect2 GetGlobalPosition(Vect2 position) |
Computes world position for a given local vector. | Vect2 |
Vect2 GetLocalPosition(Entity entity) |
Retrieves the local position vector of the specified entity. | Vect2 |
Vect2 GetLocalPosition(Vect2 position) |
Converts a world-space vector to local space. | Vect2 |
bool AnyParentOfType<T>(out T result) |
Searches up the hierarchy for a parent of type T . |
bool |
IEnumerable<T> GetParents<T>() |
Enumerates all ancestor entities matching type T . |
IEnumerable<T> |
IEnumerable<T> ChildrenAs<T>() |
Casts children to type T or throws if invalid. |
IEnumerable<T> |
void AddChild(params Entity[] entities) |
Attaches one or more child entities, delaying until screen is assigned. | void |
T AddChild<T>(params Entity[] entities) where T : Entity |
Increments layer for each, adds children, and returns this as T . |
T |
void InsertChild(int index, Entity entity) |
Inserts a single child at the specified index. | void |
T GetChild<T>(int index) where T : Entity |
Retrieves the child at index , or default if out of range. |
T |
bool HasChild<T>() where T : Entity |
Checks if any child of type T exists. |
bool |
bool HasChild(Entity entity) |
Checks if the given entity is a direct child. | bool |
bool RemoveChild(Entity entity) |
Removes and deregisters the specified child; returns success. | bool |
bool RemoveChild(params Entity[] entities) |
Removes multiple children; returns true if all were removed. | bool |
void ClearChildren() |
Removes and deregisters all child entities. | void |
void Destroy() |
Marks this entity for exit and removes it from its parent/screen. | void |
CoroutineHandle StartRoutineDelayed(float delay, IEnumerator routine) |
Begins a coroutine after a delay, unless exiting. | CoroutineHandle |
CoroutineHandle StartRoutine(IEnumerator routine) |
Begins a coroutine immediately, unless exiting. | CoroutineHandle |
bool HasRoutine(CoroutineHandle handle) |
Checks if a coroutine handle is active. | bool |
bool HasRoutine(IEnumerator enumerator) |
Checks if a coroutine enumerator is active. | bool |
bool StopRoutine(CoroutineHandle handle) |
Stops the specified coroutine by handle. | bool |
bool StopRoutine(IEnumerator handle) |
Stops the specified coroutine by enumerator. | bool |
void ClearRoutines() |
Stops and removes all coroutines associated with this entity. | void |
void Connect(string name, Action<SignalHandle> handle) |
Subscribes to a named signal; stores handler for future disconnect. | void |
void Connect(Enum name, Action<SignalHandle> handle) |
Subscribes to an enum-named signal. | void |
void Emit(string name, params object[] data) |
Emits a named signal with optional data. | void |
void Emit(Enum name, params object[] data) |
Emits an enum-named signal with optional data. | void |
void EmitDelayed(float delay, string name, params object[] data) |
Emits a named signal after a delay. | void |
void EmitDelayed(float delay, Enum name, params object[] data) |
Emits an enum-named signal after a delay. | void |
bool HasSignal(string name) |
Returns true if handlers are connected for the named signal. | bool |
bool HasSignal(Enum name) |
Returns true if handlers are connected for the enum-named signal. | bool |
bool Disconnect(string name) |
Unsubscribes all handlers from the named signal; returns true if any removed. | bool |
bool Disconnect(Enum name) |
Unsubscribes all handlers from the enum-named signal. | bool |
void ClearSignals() |
Disconnects and removes all signal handlers for this entity. | void |
void StartTimer(string name, float delay, bool repeat, Action action) |
Creates a named timer that invokes action after delay ; repeats if set. |
void |
void StartTimer(Enum name, float delay, bool repeat, Action action) |
Creates an enum-named timer. | void |
void StartTimer(float delay, bool repeat, Action action) |
Creates an auto-named timer. | void |
bool TimerExists(string name) |
Checks for an existing named timer. | bool |
bool TimerExists(Enum name) |
Checks for an existing enum-named timer. | bool |
bool StopTimer(string name) |
Stops and removes the named timer. | bool |
bool StopTimer(Enum name) |
Stops and removes the enum-named timer. | bool |
void ClearTimers() |
Removes all timers associated with this entity. | void |
// Create a parent and child entity
tvar parent = new Entity();
var child = new Entity();
parent.AddChild(child);
// Start a routine on the child
child.StartRoutineDelayed(1f, RoutineExample());
IEnumerator RoutineExample()
{
yield return new WaitForSeconds(0.5f);
child.Emit("CustomSignal", child);
}