forked from Misaki/GhostEngine
Refactor entity-component system and related classes
Changed the `Component` class to an interface `IComponentData` to support a data-oriented design. Changed the `Transform` class from a class to a struct, implementing `IComponentData` and updating properties. Changed the `GameObject` class to use a dictionary for components and added properties for state management. Changed the `PlayerLoopService` class to `GameLoopService` and updated methods to integrate with the new `SceneManager`. Changed the `World` class to manage multiple worlds and enhance entity management with new querying methods. Added the `Scene` class to manage root game objects and their lifecycle. Added new utility classes like `ComponentMask`, `Box<T>`, and `TypeHandle<T>` for better component management. Added the `ScriptComponent` class to allow for modular scriptable components attached to entities. Added the `QueryEnumerable` class to facilitate flexible querying of entities with specific components. Updated the `Test` class in `Program.cs` to demonstrate the new entity and component management system. Updated project files to include new references and settings supporting the changes made in the codebase.
This commit is contained in:
78
Ghost.Entities/ScriptComponent.cs
Normal file
78
Ghost.Entities/ScriptComponent.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
namespace Ghost.Entities;
|
||||
|
||||
public abstract class ScriptComponent : IComponentData
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this script component is enabled.
|
||||
/// </summary>
|
||||
public bool Enable
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the entity that owns this script component.
|
||||
/// </summary>
|
||||
public Entity Owner
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the priority of the script component.
|
||||
/// Change this during runtime does not affect the execution order.
|
||||
/// </summary>
|
||||
public virtual int ExecutionOrder => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Called when the script component is enabled.
|
||||
/// </summary>
|
||||
public virtual void OnEnable()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the script component is disabled.
|
||||
/// </summary>
|
||||
public virtual void OnDisable()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the script component is started.
|
||||
/// </summary>
|
||||
public virtual void Start()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called every frame.
|
||||
/// </summary>
|
||||
public virtual void Update()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called every frame after all Update methods have been called.
|
||||
/// </summary>
|
||||
public virtual void LateUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called at a fixed interval.
|
||||
/// This method is called at a fixed time step, independent of the frame rate.
|
||||
/// </summary>
|
||||
public virtual void FixedUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the script component is destroyed.
|
||||
/// </summary>
|
||||
public virtual void OnDestroy()
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user