ProjectDDD/Packages/SLUnity/SLUI/SLUIOnOffTransition.cs

90 lines
2.0 KiB
C#
Raw Normal View History

using System;
namespace Superlazy.UI
{
public abstract class SLUIOnOffTransition : SLUIComponent
{
protected bool currentState = false;
private Action<bool> enableAction;
private bool changing;
internal void InitState(SLUIObjectOnOff bindParent)
{
if (this.bindParent == null)
{
OnInit();
}
currentState = false;
}
public void StartChange(bool toOn, SLUIEntity uiEntity, Action<bool> updateEnabledAction)
{
if (changing) return;
changing = true;
currentState = toOn;
enableAction = updateEnabledAction;
if (bindParent)
{
if (OnUpdate(true))
{
EndChange();
return;
}
}
{
if (currentState)
{
enableAction.Invoke(true);
}
}
}
protected override void Enable()
{
}
protected override void Disable()
{
if (changing == false) return;
// 언어변경등으로 강제 체인지 된 경우는 메서드 호출을 보장해준다
ForceDisable();
currentState = false;
EndChange();
}
private void Update()
{
if (changing)
{
if (OnUpdate())
{
EndChange();
}
}
}
protected abstract void ForceDisable();
protected abstract bool OnUpdate(bool forceUpdate = false);
private void EndChange()
{
if (changing == false) return;
changing = false;
if (currentState)
{
enableAction.Invoke(true);
}
else
{
enableAction.Invoke(false);
}
}
}
}