public void Update() { uint sceneId = SceneHelp.Instance.CurSceneID; uint lineId = SceneHelp.Instance.CurLine; Actor player = Game.GetInstance().GetLocalPlayer(); if (player == null) { return; } if (mPathWalker == null) { mPathWalker = new AIActorPathWalker(player); } bool needReturn = false; // 调整了mRunningTargetPathNode和mPathWalker更新的顺序,先更新mRunningTargetPathNode再更新mPathWalker if (RunningTargetPathNode != null) { // 要导航的点非当前场景的点,移除先 if (RunningTargetPathNode.SceneId != sceneId || (RunningTargetPathNode.LineId != 0 && RunningTargetPathNode.LineId != lineId)) { mTargetPathNodes.Remove(RunningTargetPathNode); RunningTargetPathNode = null; } else { bool walkRet = false; if (RunningTargetPathNode.IsRunning == false) { walkRet = RunningTargetPathNode.WalkToTarget(); } if (walkRet == true) { needReturn = true; } } } if (mPathWalker != null) { // 切换场景后,本地玩家重新创建 if (mPathWalker.TargetActor == null) { mPathWalker.TargetActor = player; } mPathWalker.Update(); } if (needReturn) { return; } if (mTargetPathNodes.Count <= 0) { mPathWalker.Reset(); return; } foreach (var item in mTargetPathNodes) { if (item.SceneId == sceneId && (item.LineId == 0 || item.LineId == lineId)) { if (RunningTargetPathNode == item) { return; } Vector3 targetPos = Vector3.zero; if (item.TargetNpcId != 0) { //NpcPlayer targetNpc = NpcManager.Instance.GetNpcByNpcId(item.TargetNpcId); //if (targetNpc != null) //{ // targetPos = targetNpc.transform.position; // NpcManager.Instance.NavigatingNpcId = item.TargetNpcId; // RunningTargetPathNode = item; // return; //} if (NpcManager.GetNpcPos(item.TargetNpcId, ref targetPos)) { NpcManager.Instance.NavigatingNpcId = item.TargetNpcId; RunningTargetPathNode = item; return; } // // Spartan.NpcInfo npcInfo = Spartan.NpcInfoManager.Instance.GetNpcInfo((int)item.TargetNpcId); // // if (npcInfo != null) // { // targetPos = npcInfo.Position; // // //LocalPlayerWalkToDestination(targetPos); // // RunningTargetPathNode = item; // return; // } } else if (item.TargetTriggerId != 0) { //TriggerCollider trigger = TriggerManager.Instance.GetTrigger((int)item.TargetTriggerId); //if (trigger != null) //{ // //targetPos = trigger.transform.position; // //LocalPlayerWalkToDestination(targetPos); // RunningTargetPathNode = item; // return; //} } else if (item.WantEnterMapId != 0) { //TriggerCollider targetTrigger = TriggerManager.Instance.GetShortestPortalTrigger(item.WantEnterMapId); //uint triggerId = 0; //if (targetTrigger == null) //{ // targetTrigger = TriggerManager.Instance.GetShortestPortalTrigger(0); // if(targetTrigger != null) // { // triggerId = (uint)targetTrigger.TriggerInfo.Id; // } // else // { // triggerId = TriggerManager.Instance.GetShortestPortalTriggerId(item.WantEnterMapId); // if(triggerId == 0) // { // triggerId = TriggerManager.Instance.GetShortestPortalTriggerId(0); // } // } //} //RunningTargetPathNode = item; //RunningTargetPathNode.TargetTriggerId = triggerId; // foreach (var triggerItem in TriggerManager.Instance.Triggers) // { // if (triggerItem.Value.TriggerInfo.NeedNavigation == false) // { // continue; // } // // if (triggerItem.Value.TriggerInfo.Info == Spartan.TriggerInfo.InfoType.PORTAL && triggerItem.Value.TriggerInfo.PortalTargetMapID == item.WantEnterMapId) // { // // targetPos = triggerItem.Value.transform.position; // // //LocalPlayerWalkToDestination(targetPos); // // RunningTargetPathNode = item; // mRunningTargetPathNode.TargetTriggerId = (uint)triggerItem.Value.TriggerInfo.Id; // // return; // } // } } else if (item.TargetMonsterId != 0) { List <Vector3> monsterPositions = xc.Dungeon.LevelObjectHelper.GetMonsterPositionsByActorId(item.TargetMonsterId); if (monsterPositions.Count > 0) { // targetPos = groupInfo.Position; //targetPos = InstanceHelper.ClampInWalkableRange(targetPos); //LocalPlayerWalkToDestination(targetPos); RunningTargetPathNode = item; return; } } else if (item.TargetTagId != 0) { Neptune.Tag tagInfo = Neptune.DataManager.Instance.Data.GetNode <Neptune.Tag>((int)item.TargetTagId); if (tagInfo != null) { RunningTargetPathNode = item; return; } } else if (item.TargetConstPos.Equals(Vector3.zero) == false) { RunningTargetPathNode = item; } } } }