Files
test/Assets/PerfectWorld/Scripts/Players/CECActionSwitcher.cs
T
2025-11-07 18:01:47 +07:00

100 lines
3.4 KiB
C#

using BrewMonster.Assets.PerfectWorld.Scripts.Players;
using UnityEngine;
namespace BrewMonster
{
public class CECActionSwitcher : CECActionSwitcherBase
{
private System.Collections.Generic.List<CECActionContext> m_actionContexts =
new System.Collections.Generic.List<CECActionContext>();
public CECActionSwitcher(CECHostPlayer pHost) : base(pHost)
{
}
public void Tick(float deltaTime)
{
ProcessMessage();
// Convert DWORD to uint for milliseconds (Unity deltaTime is in seconds)
uint dt = (uint)(deltaTime * 1000f);
// Iterate backwards to safely remove items during iteration
for (int i = m_actionContexts.Count - 1; i >= 0; i--)
{
CECActionContext pContext = m_actionContexts[i];
if (pContext != null)
{
/*pContext.Update(dt);
if (pContext.NeedBeRemoved())
{
// In C#, we just remove from list - GC handles cleanup
m_actionContexts.RemoveAt(i);
}*/
}
else
{
m_actionContexts.RemoveAt(i);
}
}
}
public void ProcessMessage()
{
for (int i = 0; i < m_msgs.Count; i++)
{
EMsgActionSwitcher eMsg = (EMsgActionSwitcher)m_msgs[i];
switch (eMsg)
{
/* case EMsgActionSwitcher.MSG_FLY:
{
OnFly();
}
break;
case EMsgActionSwitcher.MSG_MOUNTPET:
{
OnRide();
}
break;*/
case EMsgActionSwitcher.MSG_CASTSKILL:
{
OnCastSkill();
}
break;
}
}
m_msgs.Clear();
}
public void OnCastSkill()
{
RemoveRideFlyRelatedContext();
}
public void RemoveRideFlyRelatedContext()
{
// Iterate backwards to safely remove items while iterating
for (int i = m_actionContexts.Count - 1; i >= 0; i--)
{
CECActionContext context = m_actionContexts[i];
if (context != null)
{
bool isRelated = context.IsContext(ActionContextType.AC_FLYTORIDE)
|| context.IsContext(ActionContextType.AC_RIDETOSKILL)
|| context.IsContext(ActionContextType.AC_RIDETOFLY)
|| context.IsContext(ActionContextType.AC_RIDETOUSETARGETITEM);
if (isRelated)
{
// In C#, we don't need explicit delete - GC will handle it
// But if context implements IDisposable, call Dispose() here
if (context is System.IDisposable disposable)
{
disposable.Dispose();
}
m_actionContexts.RemoveAt(i);
}
}
}
}
}
}