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.
 
 
 
 
 
 

41 lines
1.3 KiB

using CoreGame;
using Entitas;
namespace CoreGame.Render
{
public class TransformSyncSystem: IExecuteSystem
{
private readonly CombatContext m_Contexts;
public TransformSyncSystem(CombatContext contexts)
{
m_Contexts = contexts;
}
public void Execute(float deltaTime)
{
m_Contexts.GetGroup(MatcherExt.s_MovementMatcher).GetEntities(Contexts.s_CacheEntities);
for (int i = 0; i < Contexts.s_CacheEntities.Count; i++)
{
var re = Contexts.s_CacheEntities[i];
var transform = re.transformProxy;
var cacheRender = transform.GetRenderPosition();
transform.RenderSync(deltaTime);
var renderPosition = transform.GetRenderPosition();
if (re.hasAnimationProxy)
{
// 时间减缓
var speedSqr = (cacheRender - renderPosition).sqrMagnitude / (deltaTime * deltaTime);
if (speedSqr > 0.04)
{
re.animationProxy.Play(FNameLookup.Move);
}
else if (speedSqr < 0.01)
{
re.animationProxy.Play(FNameLookup.Idle);
}
}
}
}
}
}