public bool WalkToTarget() { if (Reached) { return(true); } if (!NeedWork) { return(true); } Actor player = Game.GetInstance().GetLocalPlayer(); // 此时资源还未加载完成 if (player == null || player.IsResLoaded == false) { return(false); } if (Game.GetInstance().GetLoadAsyncOp() != null && Game.GetInstance().GetLoadAsyncOp().isDone == false) { return(false); } if (GameInput.Instance.GetEnableInput() == false) { return(false); } Vector3 targetPos = Vector3.zero; if (TargetNpcId != 0) { if (NpcManager.GetNpcPos(TargetNpcId, ref targetPos)) { IsRunning = true; TargetPathManager.Instance.LocalPlayerWalkToDestination(targetPos, RelateTask); return(true); } } else if (TargetTriggerId != 0) { //TriggerCollider trigger = TriggerManager.Instance.GetTrigger((int)TargetTriggerId); //if (trigger != null) //{ // targetPos = trigger.transform.position; // TargetPathManager.Instance.LocalPlayerWalkToDestination(targetPos); // return true; //} } else if (WantEnterMapId != 0) { //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 == WantEnterMapId) // { // targetPos = triggerItem.Value.transform.position; // TargetPathManager.Instance.LocalPlayerWalkToDestination(targetPos); // TargetTriggerId = (uint)triggerItem.Value.TriggerInfo.Id; // return true; // } //} } else if (TargetMonsterId != 0) { Vector3 monsterPosition = xc.Dungeon.LevelObjectHelper.GetNearestMonsterPositionByActorId(TargetMonsterId); if (monsterPosition.Equals(Vector3.zero) == false) { targetPos = monsterPosition; targetPos = InstanceHelper.ClampInWalkableRange(targetPos); IsRunning = true; TargetPathManager.Instance.LocalPlayerWalkToDestination(targetPos, RelateTask); return(true); } } else if (TargetTagId != 0) { Neptune.Tag tagInfo = Neptune.DataManager.Instance.Data.GetNode <Neptune.Tag>((int)TargetTagId); if (tagInfo != null) { Vector3 tagPosition = tagInfo.Position; float radius = tagInfo.SphereRadius; if (tagPosition.Equals(Vector3.zero) == false) { targetPos = tagPosition; targetPos.x = tagPosition.x + UnityEngine.Random.Range(-radius, radius); targetPos.z = Mathf.Sqrt(radius * radius - (targetPos.x - tagPosition.x) * (targetPos.x - tagPosition.x)) + tagPosition.z; targetPos = InstanceHelper.ClampInWalkableRange(targetPos); IsRunning = true; TargetPathManager.Instance.LocalPlayerWalkToDestination(targetPos, RelateTask); return(true); } } } else if (Vector3.zero.Equals(TargetConstPos) == false) { if (IsReachConstTargetPos()) { TargetPathManager.Instance.NotifyLastPathNodeReached(); return(true); } IsRunning = true; TargetPathManager.Instance.LocalPlayerWalkToDestination(TargetConstPos, RelateTask); return(true); } return(false); }
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; } } } }