51 lines
1.0 KiB
C#
51 lines
1.0 KiB
C#
using System;
|
|
|
|
using Syntriax.Engine.Core.Abstract;
|
|
|
|
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;
|
|
|
|
private bool _enabled = true;
|
|
private IEntity _entity = null!;
|
|
|
|
public IEntity Entity => _entity;
|
|
|
|
public bool Enabled
|
|
{
|
|
get => _enabled;
|
|
set
|
|
{
|
|
if (value == _enabled)
|
|
return;
|
|
|
|
_enabled = value;
|
|
OnEnabledChanged?.Invoke(this);
|
|
}
|
|
}
|
|
|
|
public bool Assign(IEntity entity)
|
|
{
|
|
if (_entity.Initialized)
|
|
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;
|
|
}
|
|
}
|