Added a new static class `AssetsPath` for asset management. Added a new icon file (`icon-256.ico`) for UI representation. Added new package references to enhance functionality. Added internals visibility attributes for better testing. Added a new `EngineEditorViewModel` class for MVVM support. Added a new `GameObject` class for component management. Added a new `BitSet` class for efficient bit manipulation. Added various utility classes to support the new entity system. Changed the `ID` property in `ProjectInfo` to internal. Changed the `AddProjectAsync` method to return the created `ProjectInfo`. Changed the connection string retrieval method to use the new `Command` constant. Changed the `DataPath` class to use `readonly` fields for folder paths. Changed the `ActivationHandler` class to use new `DataPath` constants. Changed the `OpenProjectPage` layout and interaction for better UI. Updated the target framework to a newer version for compatibility. Updated the `ProjectService` to use new constants from `DataPath`. Updated the `World` class to improve entity management. Refactored the `ProjectRepository` class to encapsulate SQL commands. Refactored the `Transform` class to use properties for better encapsulation.
96 lines
1.8 KiB
C#
96 lines
1.8 KiB
C#
using Ghost.Engine.Components;
|
|
using Ghost.Engine.Services;
|
|
using System.Collections.ObjectModel;
|
|
|
|
namespace Ghost.Engine;
|
|
|
|
public class GameObject
|
|
{
|
|
private readonly ObservableCollection<Component> _components = new();
|
|
|
|
public string name = string.Empty;
|
|
public bool isActive = true;
|
|
|
|
public Transform Transform { get; } = new();
|
|
|
|
private GameObject()
|
|
{
|
|
AddComponent(Transform);
|
|
}
|
|
|
|
public static GameObject Create(string name = "")
|
|
{
|
|
var gameObject = new GameObject
|
|
{
|
|
name = name
|
|
};
|
|
|
|
GameLoopService.RegisterGameObject(gameObject);
|
|
return gameObject;
|
|
}
|
|
|
|
public void AddComponent(Component component)
|
|
{
|
|
_components.Add(component);
|
|
}
|
|
|
|
public void RemoveComponent(Component component)
|
|
{
|
|
_components.Remove(component);
|
|
}
|
|
|
|
public T? GetComponent<T>() where T : Component
|
|
{
|
|
foreach (var component in _components)
|
|
{
|
|
if (component is T t)
|
|
{
|
|
return t;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
internal void Start()
|
|
{
|
|
foreach (var component in _components)
|
|
{
|
|
component.Start();
|
|
}
|
|
}
|
|
|
|
internal void Update()
|
|
{
|
|
foreach (var component in _components)
|
|
{
|
|
component.Update();
|
|
}
|
|
}
|
|
|
|
internal void LateUpdate()
|
|
{
|
|
foreach (var component in _components)
|
|
{
|
|
component.LateUpdate();
|
|
}
|
|
}
|
|
|
|
internal void FixedUpdate()
|
|
{
|
|
foreach (var component in _components)
|
|
{
|
|
component.FixedUpdate();
|
|
}
|
|
}
|
|
|
|
public void Destroy()
|
|
{
|
|
foreach (var component in _components)
|
|
{
|
|
component.OnDestroy();
|
|
}
|
|
|
|
GameLoopService.UnregisterGameObject(this);
|
|
}
|
|
} |