feat: Added IAssignable.Unassign()

This commit is contained in:
2023-11-24 17:03:21 +03:00
parent 6f68e29fb8
commit 5a01b01215
6 changed files with 79 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ namespace Syntriax.Engine.Core;
public class StateEnable : IStateEnable
{
public Action<IAssignable>? OnUnassigned { get; set; } = null;
public Action<IAssignableEntity>? OnEntityAssigned { get; set; } = null;
public Action<IStateEnable>? OnEnabledChanged { get; set; } = null;
@@ -29,11 +30,21 @@ public class StateEnable : IStateEnable
public bool Assign(IEntity entity)
{
if (_entity is not null) // TODO: IInitialize Maybe?
if (_entity is not null) // TODO: Add IInitialize to IAssignable or IEntity maybe?
return false;
_entity = entity;
OnEntityAssigned?.Invoke(this);
return true;
}
public bool Unassign()
{
if (_entity is null)
return false;
_entity = null!;
OnUnassigned?.Invoke(this);
return true;
}
}