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.
74 lines
2.6 KiB
74 lines
2.6 KiB
using System.Collections.Generic;
|
|
using Entitas;
|
|
using GAS.Runtime;
|
|
using UnityEngine;
|
|
|
|
namespace CoreGame.Render
|
|
{
|
|
// 只对LocalPlayer起效
|
|
public class MovementSys : IExecuteSystem, ICleanupSystem
|
|
{
|
|
private readonly IGroup<CombatEntity> m_MoveGroup;
|
|
private readonly List<CombatEntity> m_CacheEntities = new List<CombatEntity>();
|
|
|
|
public MovementSys(CombatContext contexts)
|
|
{
|
|
var matcher = (Matcher<CombatEntity>)Matcher<CombatEntity>.AllOf(CombatComponentsLookup.Movement, CombatComponentsLookup.NavAgentProxy)
|
|
.NoneOf(CombatComponentsLookup.Dead, CombatComponentsLookup.ForceNav);
|
|
m_MoveGroup = contexts.GetGroup(matcher);
|
|
RealTimeChart.Instance.AddTrack("MovementSysX", Color.green);
|
|
RealTimeChart.Instance.AddTrack("MovementSysY", Color.red);
|
|
}
|
|
|
|
public void Execute(float deltaTime)
|
|
{
|
|
m_MoveGroup.GetEntities(m_CacheEntities);
|
|
if (m_CacheEntities.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < m_CacheEntities.Count; i++)
|
|
{
|
|
var combatEntity = m_CacheEntities[i];
|
|
if (combatEntity.TagCountContainer.HasAnyTags(GTagLib.State_Death, GTagLib.State_Stun, GTagLib.State_ForceMove))
|
|
continue;
|
|
|
|
var movementCmpt = combatEntity.movement;
|
|
var trans = combatEntity.transformProxy;
|
|
trans.SetRenderSpeed(0);
|
|
var navAgentProxy = combatEntity.navAgentProxy;
|
|
if (movementCmpt.joySpeed <= 0.001)
|
|
{
|
|
navAgentProxy.StopNav();
|
|
continue;
|
|
}
|
|
|
|
var property = combatEntity.property;
|
|
var speed = property.MoveSpeed;
|
|
speed *= movementCmpt.joySpeed;
|
|
|
|
var dir = new Vector2(Mathf.Cos(movementCmpt.direction * Mathf.Deg2Rad),
|
|
Mathf.Sin(movementCmpt.direction * Mathf.Deg2Rad));
|
|
|
|
|
|
if (combatEntity.TagCountContainer.HasTag(GTagLib.State_Bound))
|
|
{
|
|
dir = Vector2.zero;
|
|
speed = 0;
|
|
}
|
|
|
|
trans.SetRenderSpeed(speed.AsFloat);
|
|
navAgentProxy.SetDestination(trans.position + dir, speed);
|
|
}
|
|
}
|
|
|
|
public void Cleanup()
|
|
{
|
|
for (int i = 0; i < m_CacheEntities.Count; i++)
|
|
{
|
|
m_CacheEntities[i].RemoveMovement();
|
|
}
|
|
}
|
|
}
|
|
}
|