using System.Collections.Generic; using Entitas; using GAS.Runtime; using UnityEngine; namespace CoreGame.Render { public class NavSys : IExecuteSystem { private readonly IGroup m_NavGroup; private readonly List m_CacheEntities = new List(); public NavSys(CombatContext contexts) { var navMatcher = (Matcher)Matcher.AllOf(CombatComponentsLookup.NavAgentProxy) .NoneOf(CombatComponentsLookup.Dead); m_NavGroup = contexts.GetGroup(navMatcher); } public void Execute(float deltaTime) { m_NavGroup.GetEntities(m_CacheEntities); if (m_CacheEntities.Count == 0) return; for (int i = 0; i < m_CacheEntities.Count; i++) { var ent = m_CacheEntities[i]; if (ent.HasComponent(CombatComponentsLookup.NavState) == false) continue; var navAgentProxy = ent.navAgentProxy; navAgentProxy.ChangeSpeedParam(deltaTime <= BattleConst.Epsilon ? 0 : 1); if (ent.TagCountContainer.HasAnyTags(GTagLib.State_Death, GTagLib.State_ForceMove)) continue; if (ent.TagCountContainer.HasTag(GTagLib.State_Stun)) { navAgentProxy.StopNav(); ent.RemoveNavState(); continue; } if (navAgentProxy.IsArrived()) { navAgentProxy.StopNav(); ent.RemoveNavState(); continue; } var logicPos = navAgentProxy.GetLogicPos(); var transformProxy = ent.transformProxy; // 抖动 水平速度小于0.4f时,不转向 float dis = deltaTime * 0.4f; if (Mathf.Abs(logicPos.x - transformProxy.position.x) > dis) { transformProxy.SetDirection((logicPos - transformProxy.position).normalized); } transformProxy.SetPosition(logicPos); } } } }