You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.5 KiB
63 lines
2.5 KiB
using CoreGame;
|
|
using Entitas;
|
|
using UnityEngine;
|
|
|
|
namespace CoreGame.Render
|
|
{
|
|
public class LocationSyncSystem : IExecuteSystem
|
|
{
|
|
private readonly Contexts m_Contexts;
|
|
private readonly Matcher<CombatEntity> m_PosMatcher;
|
|
private static readonly object s_EntityNoMove = new object();
|
|
|
|
public LocationSyncSystem(Contexts contexts)
|
|
{
|
|
m_Contexts = contexts;
|
|
m_PosMatcher = (Matcher<CombatEntity>)Matcher<CombatEntity>.AllOf(CombatComponentsLookup.TransformProxy).
|
|
NoneOf(CombatComponentsLookup.JoystickProxy,
|
|
CombatComponentsLookup.VirtualCameraProxy,
|
|
CombatComponentsLookup.Dead);
|
|
m_PosMatcher.componentNames = CombatComponentsLookup.componentNames;
|
|
|
|
RealTimeChart.Instance.AddTrack("LocationSyncSystemX", UnityEngine.Color.yellow);
|
|
RealTimeChart.Instance.AddTrack("LocationSyncSystemY", UnityEngine.Color.blue);
|
|
}
|
|
|
|
public void Execute(float deltaTime)
|
|
{
|
|
if (deltaTime < BattleConst.Epsilon)
|
|
return;
|
|
|
|
var ces = m_Contexts.combat.GetGroup(MatcherExt.s_MovementMatcher).GetEntities(Contexts.s_CacheEntities);
|
|
var dtRevese = 1.0f / (deltaTime * deltaTime);
|
|
var cesCount = ces.Count;
|
|
for (int i = 0; i < cesCount; i++)
|
|
{
|
|
var re = ces[i];
|
|
var transform = (TransformProxy)re.GetComponent(CombatComponentsLookup.TransformProxy);
|
|
var speedSqr = (transform.position - transform.lastPosition).sqrMagnitude * dtRevese;
|
|
re.DispatchEvent(ClientEvent.NoMovementTime, speedSqr > 0.04f ? null : s_EntityNoMove);
|
|
|
|
// todo : 如果变换的多的话,需要加响应系统同步
|
|
// if (BattleModule.Instance.worldType != WorldType.Battle)
|
|
{
|
|
var animProxy = (AnimationProxy)re.GetComponent(CombatComponentsLookup.AnimationProxy);
|
|
if (animProxy != null)
|
|
{
|
|
// 时间减缓
|
|
if (speedSqr > 0.04)
|
|
{
|
|
animProxy.Play(FNameLookup.Move);
|
|
}
|
|
else if (speedSqr < 0.01)
|
|
{
|
|
animProxy.Play(FNameLookup.Idle);
|
|
}
|
|
}
|
|
transform.Sync();
|
|
transform.Flush();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|