using System;
using XGame.Framework.Interfaces;
namespace XGame.Framework.Components
{
///
/// 逻辑行为组件基类
///
///
public abstract class Component : IComponent, IReference, IActiveable, IDisposable
{
public TContext Context { get; private set; }
public virtual int Order => 0;
void IComponent.Bind(object handle)
{
Context = (TContext)handle;
}
public bool Active { get; private set; }
void IActiveable.Enable(object intent)
{
if (Active) return;
Active = true;
OnEnable(intent);
}
void IActiveable.Disable()
{
if (!Active) return;
Active = false;
OnDisable();
}
void IReference.Clear()
{
OnDispose();
}
void IDisposable.Dispose()
{
OnDispose();
Context = default;
}
protected virtual void OnEnable(object intent)
{
}
protected virtual void OnDisable()
{
}
///
/// 销毁事件回调
/// 缓存池回收也会触发OnDispose,但不真正销毁
///
protected abstract void OnDispose();
}
}