using System; using internal GlitchyEngine.World; namespace GlitchyEngine.World { public struct Entity { private EcsEntity _entity = .InvalidEntity; private Scene _scene = null; public EcsEntity Handle => _entity; public Scene Scene => _scene; public this() { } public this(EcsEntity entity, Scene scene) { _entity = entity; _scene = scene; } public bool IsValid => _entity.IsValid; public T* AddComponent(T value = T()) where T: struct, new { Log.EngineLogger.AssertDebug(!HasComponent(), scope $"Entity already has component."); return _scene._ecsWorld.AssignComponent(_entity, value); } public T* GetComponent() where T: struct, new { Log.EngineLogger.AssertDebug(HasComponent(), "Entity doesn't have component!"); return _scene._ecsWorld.GetComponent(_entity); } public bool HasComponent() where T: struct, new { return _scene._ecsWorld.HasComponent(_entity); } public void RemoveComponent() where T: struct, new { Log.EngineLogger.AssertDebug(HasComponent(), "Entity doesn't have component!"); _scene._ecsWorld.RemoveComponent(_entity); } } }