Class GameElement
Represents a game element
public abstract class GameElement : IIdentifier, IPropertyTable, ISerialization
- Inheritance
-
GameElement
- Implements
- Derived
- Inherited Members
Constructors
GameElement()
Creates a new game element
protected GameElement()
Properties
AABB
The axis-aligned bounding box (AABB) of the game element.
public AABB AABB { get; set; }
Property Value
Behaviors
The behaviors of the game element
public List<IGameBehavior> Behaviors { get; set; }
Property Value
CastShadows
Determines if the game element casts shadows
public virtual bool CastShadows { get; set; }
Property Value
Children
The children of the game element
public IReadOnlyList<GameElement> Children { get; }
Property Value
Enabled
Determines if the game element is enabled
public virtual bool Enabled { get; set; }
Property Value
HasTransparency
Determines if the game element has transparency.
public abstract bool HasTransparency { get; }
Property Value
ID
The ID of the game element
public Guid ID { get; set; }
Property Value
Name
The name of the game element
public string Name { get; set; }
Property Value
Parent
The parent of the game element
public GameElement Parent { get; set; }
Property Value
Properties
Gets a collection of custom properties associated with the current instance.
public Dictionary<string, object> Properties { get; }
Property Value
Remarks
Use this dictionary to store and retrieve additional metadata or user-defined values related to the instance. Property names are case-sensitive. Modifying the collection affects only the current instance.
Tags
A set of tags associated with the game element, used for categorization or filtering.
public HashSet<string> Tags { get; }
Property Value
Transform
The transform of the game element
public virtual Transform Transform { get; set; }
Property Value
Visible
Determines if the game element is visible
public virtual bool Visible { get; set; }
Property Value
WorldAABB
Gets the world axis-aligned bounding box (AABB) of the game element.
public AABB WorldAABB { get; }
Property Value
Methods
AddBehavior<T>(T)
Adds a behavior to the game element
public T AddBehavior<T>(T behavior) where T : IGameBehavior
Parameters
behaviorT
Returns
- T
Type Parameters
T
AddChild(GameElement)
Adds a child to the game element
public void AddChild(GameElement child)
Parameters
childGameElement
AddTag(string)
Adds a tag to the game element.
public void AddTag(string tag)
Parameters
tagstring
Collide(Collision)
Collides the game element
public virtual void Collide(Collision collision)
Parameters
collisionCollision
ComputeAABB()
Computes the axis-aligned bounding box (AABB) of the game element.
public abstract void ComputeAABB()
Deserialize(JObject, SerializationContext, Func<JObject, bool>)
Deserializes the JSON representation into the current object and its hierarchy.
public virtual void Deserialize(JObject obj, SerializationContext serializationContext, Func<JObject, bool> callback = null)
Parameters
objJObjectserializationContextSerializationContextcallbackFunc<JObject, bool>
Exceptions
Dispose(BaseScene, IRenderDevice)
Disposes the game element
public virtual void Dispose(BaseScene scene, IRenderDevice renderer)
Parameters
sceneBaseScenerendererIRenderDevice
FindChild<T>()
Searches the immediate child elements and returns the first child of the specified type.
public T FindChild<T>() where T : GameElement
Returns
- T
The first child element of type T if found; otherwise, null.
Type Parameters
TThe type of child element to search for. Must derive from GameElement.
Remarks
Only immediate children are considered in the search. If multiple children of type T exist, only the first is returned.
FindChild<T>(string)
Searches for a child element of the specified type with the given name.
public T FindChild<T>(string name) where T : GameElement
Parameters
namestringThe name of the child element to locate. The comparison is case-sensitive.
Returns
- T
The first child element of type T with the specified name, or null if no matching element is found.
Type Parameters
TThe type of child element to search for. Must derive from GameElement.
Remarks
If multiple child elements of type T share the same name, only the first one encountered is returned. The search is limited to immediate children and does not include nested descendants.
FindChildren<T>()
Returns an array containing all child elements of the specified type.
public T[] FindChildren<T>() where T : GameElement
Returns
- T[]
An array of elements of type T that are children of this instance. The array is empty if no matching children are found.
Type Parameters
TThe type of child elements to search for. Must derive from GameElement.
FindChildren<T>(string)
Finds all child elements of the specified type that have the given name.
public T[] FindChildren<T>(string name) where T : GameElement
Parameters
namestringThe name of the child elements to find. The comparison is case-sensitive.
Returns
- T[]
An array containing all child elements of type T whose Name property matches the specified name. The array will be empty if no matching elements are found.
Type Parameters
TThe type of child elements to search for. Must derive from GameElement.
GetBehavior<T>()
Gets a behavior from the game element
public T GetBehavior<T>() where T : IGameBehavior
Returns
- T
Type Parameters
T
GetMeshes()
Returns the meshes and materials of the game element
public virtual Mesh[]? GetMeshes()
Returns
- Mesh[]
GetWorldAABB()
Gets the world axis-aligned bounding box (AABB) of the game element by transforming its local AABB using its world transform.
public AABB GetWorldAABB()
Returns
GetWorldTransform()
Gets the world transform of the game element by recursively combining its local transform with its parent's world transform.
public Transform GetWorldTransform()
Returns
HasTag(string)
Checks if the game element has a specific tag.
public bool HasTag(string tag)
Parameters
tagstring
Returns
Init(BaseScene, Viewport, IRenderDevice)
Initializes the game element
public virtual void Init(BaseScene scene, Viewport viewport, IRenderDevice renderer)
Parameters
sceneBaseSceneviewportViewportrendererIRenderDevice
RemoveTag(string)
Removes a tag from the game element.
public void RemoveTag(string tag)
Parameters
tagstring
Render(BaseScene, Viewport, IRenderDevice, Camera)
Renders the game element
public virtual void Render(BaseScene scene, Viewport viewport, IRenderDevice renderer, Camera camera)
Parameters
sceneBaseSceneviewportViewportrendererIRenderDevicecameraCamera
RenderShadow(BaseScene, Viewport, IRenderDevice)
Renders the shadow of the game element
public virtual void RenderShadow(BaseScene scene, Viewport viewport, IRenderDevice renderer)
Parameters
sceneBaseSceneviewportViewportrendererIRenderDevice
Serialize(JsonWriter, SerializationContext, Action<JsonWriter>)
Serializes the current object and its hierarchy into a JSON representation.
public virtual void Serialize(JsonWriter writer, SerializationContext serializationContext, Action<JsonWriter> callback = null)
Parameters
writerJsonWriterserializationContextSerializationContextThe context that provides serialization settings and state information used during the serialization process.
callbackAction<JsonWriter>
Remarks
The returned JSON object includes information about the object's type, identifier, name, transform, visibility, enabled state, shadow casting, parent, tags, axis-aligned bounding boxes, children, and custom properties. Behaviors are not currently serialized and are represented as an empty array.
Update(BaseScene, float)
Updates the game element
public virtual void Update(BaseScene scene, float dt)