Class Stage
Core system that handles entity spawning and despawning logic
Fields
SETTING_SET_VIEW_H
ID for remote setting between engine and rigged game
Declaration
public const int SETTING_SET_VIEW_H = 921736238
SETTING_SET_VIEW_X
ID for remote setting between engine and rigged game
Declaration
public const int SETTING_SET_VIEW_X = 921736235
SETTING_SET_VIEW_Y
ID for remote setting between engine and rigged game
Declaration
public const int SETTING_SET_VIEW_Y = 921736236
SETTING_SET_VIEW_Z
ID for remote setting between engine and rigged game
Declaration
public const int SETTING_SET_VIEW_Z = 921736237
Properties
AntiSpawnRect
Rect in global space that determine where a despawned entity should not respawn from map
Declaration
public static IRect AntiSpawnRect { get; }
Enable
True is the system is required for the game
Declaration
public static bool Enable { get; }
Entities
Current spawned entity instances for each layer
Declaration
public static Entity[][] Entities { get; }
EntityCounts
Current spawned entity count for each layers
Declaration
public static int[] EntityCounts { get; }
IsReady
True if the system is ready to use
Declaration
public static bool IsReady { get; }
SpawnRect
Rect in global space that determine where the entities need to be spawn from map
Declaration
public static IRect SpawnRect { get; }
ViewRect
Rect in global space that represents player view. Ascpect ratio of this rect keeps the same when user adjust application window size, so the actual rect range for rendering is Renderer.CameraRect.
Declaration
public static IRect ViewRect { get; }
ViewZ
Current position Z value
Declaration
public static int ViewZ { get; }
Methods
DespawnAllEntitiesOfType<E>(int)
Declaration
public static void DespawnAllEntitiesOfType<E>(int targetLayer = -1) where E : Entity
Parameters
Type | Name | Description |
---|---|---|
int | targetLayer | Set to -1 to apply on all layers |
DespawnAllNonUiEntities(bool)
Declaration
public static void DespawnAllNonUiEntities(bool refreshImmediately = false)
Parameters
Type | Name | Description |
---|---|---|
bool | refreshImmediately | True if refresh the active state inside this function |
FindEntity(int)
Get instance of an spawned entity which have given type ID
Declaration
public static Entity FindEntity(int typeID)
FindEntity<T>()
Get instance of an spawned entity with type of T
Declaration
public static T FindEntity<T>() where T : Entity
ForAllActiveEntities<E>(int)
Iterate through all active entities inside given layer
Declaration
public static IEnumerable<E> ForAllActiveEntities<E>(int entityLayer = -1) where E : Entity
Parameters
Type | Name | Description |
---|---|---|
int | entityLayer | Use EntityLayer.XXX to get this value. Set to -1 to target all layers |
Type Parameters
Name | Description |
---|---|
E | Type of target entity |
GetCameraCullingPadding()
Get current expand padding for camera rect in global space
Declaration
public static Int4 GetCameraCullingPadding()
GetEntityCapacity(int)
Get max size limitation of target entity inside it's entity layer
Declaration
public static int GetEntityCapacity(int typeID)
GetEntityType(int)
Get System.Type for given type ID. Null if ID is invalid
Declaration
public static Type GetEntityType(int id)
GetOrSpawnEntity(int, int, int)
Get instance of an entity from stage first, if not found, spawn a new one.
Declaration
public static Entity GetOrSpawnEntity(int typeID, int x, int y)
Initial position in global space when spawn a new one
Initial position in global space when spawn a new one
Returns
Type | Description |
---|---|
Entity | The entity instance. Null if not found |
GetOrSpawnEntity<T>(int, int)
Get instance of an entity from stage first, if not found, spawn a new one.
Declaration
public static T GetOrSpawnEntity<T>(int x, int y) where T : Entity
Parameters
Type | Name | Description |
---|---|---|
int | x | Initial position in global space when spawn a new one |
int | y | Initial position in global space when spawn a new one |
Returns
Type | Description |
---|---|
T | The entity instance. Null if not found |
GetSpawnedEntityCount(int)
Get how many entities of given type is on stage currently
Declaration
public static int GetSpawnedEntityCount(int id)
Parameters
Type | Name | Description |
---|---|---|
int | id | ID of the entity. Can be cached by typeof(YourEntity).AngeHash() |
IsEntityRequireDrawBehind(int)
True if entity with given type ID should draw inside behind map layer
Declaration
public static bool IsEntityRequireDrawBehind(int id)
IsEntityRequireReposition(int)
True if the target entity keep it's position when out of range. This is done by setting the map block data.
Declaration
public static bool IsEntityRequireReposition(int typeID)
IsValidEntityID(int)
True if the given ID is a valid entity type ID in internal pool
Declaration
public static bool IsValidEntityID(int id)
PeekOrGetEntity(int)
Get instance of an unspawned entity from pool first, if not found, get a spawned one from the stage
Declaration
public static Entity PeekOrGetEntity(int typeID)
Returns
Type | Description |
---|---|
Entity | The entity instance. Null if not found |
PeekOrGetEntity<T>()
Get instance of an unspawned entity from pool first, if not found, get a spawned one from the stage
Declaration
public static T PeekOrGetEntity<T>() where T : Entity
Returns
Type | Description |
---|---|
T | True if the instance is founded |
RemoveStagedEntity(Int3)
Remove entity with given instance ID from StagedEntityPool
Declaration
public static void RemoveStagedEntity(Int3 instanceID)
SetViewPositionDelay(int, int, int, int)
Set view rect position at the end of current frame
Declaration
public static void SetViewPositionDelay(int x, int y, int lerp = 1000, int priority = -2147483648)
Smooth amount (0 means no motion applys. 1000 means immediately applys)
SetViewRectImmediately(IRect, bool, bool)
Set view rect position in global space
Declaration
public static void SetViewRectImmediately(IRect newRect, bool remapAllRenderingCells = false, bool resetDelay = true)
True if change position and size for all existing rendering cells
True if ignore all existing delay operation of view rect position/size
SetViewSizeDelay(int, int, int, bool)
Set view rect height at the end of current frame
Declaration
public static void SetViewSizeDelay(int height, int lerp = 1000, int priority = -2147483648, bool centralized = false)
SetViewXDelay(int, int, int)
Set view rect X at the end of current frame
Declaration
public static void SetViewXDelay(int x, int lerp = 1000, int priority = -2147483648)
Smooth amount (0 means no motion applys. 1000 means immediately applys)
SetViewYDelay(int, int, int)
Set view rect Y at the end of current frame
Declaration
public static void SetViewYDelay(int y, int lerp = 1000, int priority = -2147483648)
Smooth amount (0 means no motion applys. 1000 means immediately applys)
SetViewZ(int, bool)
Set current position Z
Declaration
public static void SetViewZ(int newZ, bool immediately = false)
True if the internal data is immediately change instead of change in the end of the frame
SpawnEntity(int, int, int)
Find an entity with given ID from internal pool and make it into the stage
Declaration
public static Entity SpawnEntity(int typeID, int x, int y)
Parameters
Type | Name | Description |
---|---|---|
int | typeID | ID of the entity. Can be cached by typeof(YourEntity).AngeHash() |
int | x | Initial position in global space |
int | y | Initial position in global space |
Returns
Type | Description |
---|---|
Entity | Instance of the entity. Null when failed |
SpawnEntityFromWorld(int, int, int, int, int, int, bool)
Find an entity with given ID from internal pool and make it into the stage. This function will make it an entity from map
Declaration
public static Entity SpawnEntityFromWorld(int typeID, int x, int y, int z, int reposDeltaX = 0, int reposDeltaY = 0, bool forceSpawn = false)
Parameters
Type | Name | Description |
---|---|---|
int | typeID | ID of the entity. Can be cached by typeof(YourEntity).AngeHash() |
int | x | Initial position in global space |
int | y | Initial position in global space |
int | z | Z of the map position |
int | reposDeltaX | Offset in global space for entity reposition |
int | reposDeltaY | Offset in global space for entity reposition |
bool | forceSpawn | True if ignore the StagedEntityPool check and AntiSpawnRect check |
Returns
Type | Description |
---|---|
Entity | Instance of the entity. Null when failed |
SpawnEntity<T>(int, int)
Find an entity with given ID from internal pool and make it into the stage
Declaration
public static T SpawnEntity<T>(int x, int y) where T : Entity
Parameters
Type | Name | Description |
---|---|---|
int | x | Initial position in global space |
int | y | Initial position in global space |
Returns
Type | Description |
---|---|
T | Instance of the entity. Null when failed |
Type Parameters
Name | Description |
---|---|
T | Type of the entity |
TryFindEntity(int, out Entity)
Get instance of an spawned entity which have given type ID
Declaration
public static bool TryFindEntity(int typeID, out Entity result)
Returns
Type | Description |
---|---|
bool | True if the entity founded |
TryFindEntityNearby<E>(Int2, out E, Func<E, bool>)
Get nearest instance of an spawned entity from given position with type of E
Declaration
public static bool TryFindEntityNearby<E>(Int2 pos, out E finalTarget, Func<E, bool> condition = null)
Parameters
Type | Name | Description |
---|---|---|
Int2 | pos | (in global space) |
Func<E, bool> | condition | Only include the entity target when this function return true. Set to null to not having extra checking |
Returns
Type | Description |
---|---|
bool | True if entity founded |
TryFindEntity<E>(out E)
Get instance of an spawned entity with type of E
Declaration
public static bool TryFindEntity<E>(out E result) where E : Entity
Returns
Type | Description |
---|---|
bool | True if the entity founded |
TryGetEntities(int, out ReadOnlySpan<Entity>, out int)
Get all entities inside given layer. The result array referenced by the span is cached. No heap pressure.
Declaration
public static bool TryGetEntities(int layer, out ReadOnlySpan<Entity> entities, out int count)
Parameters
Type | Name | Description |
---|---|---|
int | layer | Use EntityLayer.XXX to get this value |
ReadOnlySpan<Entity> | entities | Result span |
int | count | How many entities are inside the result |
Returns
Type | Description |
---|---|
bool | True if the result is founded |
TryGetStagedEntity(Int3, out Entity)
Get instance of an staged entity by instanceID from StagedEntityPool
Declaration
public static bool TryGetStagedEntity(Int3 instanceID, out Entity instance)
Parameters
Type | Name | Description |
---|---|---|
Int3 | instanceID | Get this from Entity.InstanceID |
Returns
Type | Description |
---|---|
bool | True if the result is founded |
TryRepositionEntity(Entity, bool)
Perform reposition logic of the entity instance.
Declaration
public static void TryRepositionEntity(Entity entity, bool carryThoughZ = false)
True if the entity is being keep into other map z-layer
TrySpawnEntity(int, int, int, out Entity)
Find an entity with given ID from internal pool and make it into the stage
Declaration
public static bool TrySpawnEntity(int typeID, int x, int y, out Entity entity)
Parameters
Type | Name | Description |
---|---|---|
int | typeID | ID of the entity. Can be cached by typeof(YourEntity).AngeHash() |
int | x | Initial position in global space |
int | y | Initial position in global space |
Entity | entity | Instance of the entity |
Returns
Type | Description |
---|---|
bool | True if the entity is spawned |
TrySpawnEntity<T>(int, int, out T)
Find an entity with given ID from internal pool and make it into the stage
Declaration
public static bool TrySpawnEntity<T>(int x, int y, out T entity) where T : Entity
Parameters
Type | Name | Description |
---|---|---|
int | x | Initial position in global space |
int | y | Initial position in global space |
T | entity | Instance of the entity |
Returns
Type | Description |
---|---|
bool | True if the entity is spawned |
Type Parameters
Name | Description |
---|---|
T | Type of the entity |