void EnterFollowState(fsm.State _from, fsm.State _to, fsm.Event _event) { GameSys.Log("NPC开始跟随"); if (moveFSM != null) { moveFSM.UnLockMoving(); } int count = curTarget.positionSlots.Count; bool foundSlot = false; for (int i = 0; i < count; i++) { if (curTarget.positionSlots[i].occupyObj == null) { foundSlot = true; followSlot = i; } } if (!foundSlot) { followSlot = curTarget.AddPositionSlot(); } curTarget.positionSlots[followSlot].occupyObj = this.gameObject; MoveTo(curTarget.positionSlots[followSlot].obj.transform.position); }
void EnterBackonState(fsm.State _from, fsm.State _to, fsm.Event _event) { GameSys.Log("NPC进入招手状态"); timer = 0; if (animFSM != null) { animFSM.BeckOn(); } }
void EnterCowerState(fsm.State _from, fsm.State _to, fsm.Event _event) { GameSys.Log("NPC感到害怕"); if (animFSM != null) { animFSM.Cower(); } timer = 1; }
void EnterIdleState(fsm.State _from, fsm.State _to, fsm.Event _event) { GameSys.Log("NPC停下来思考"); StopMovingTo(); FaceToPlayer(); if (animFSM != null) { animFSM.Idle(); } }
void EnterFinishedState(fsm.State _from, fsm.State _to, fsm.Event _event) { GameSys.Log("任务完成"); stateMachine.Stop(); StopMovingTo(); if (animFSM != null) { animFSM.Idle(); } if (finishedCallback != null) { finishedCallback(actorInfo.ServerInstanceID); } }
/// <summary> /// 加载协同 /// </summary> IEnumerator DoLoad(LoadingTask kCurrentTask) { WWW www = new WWW(kCurrentTask.kAssetPath); yield return(www); if (www.isDone) { //检查报错 if (www.error != null) { GameSys.Log(www.error); www = null; yield break; } AssetBundle bundle = www.assetBundle; if (bundle != null) { kCurrentTask.OnLoaded(bundle.mainAsset, true); this.m_kLoadedAsset.Add(kCurrentTask.kAssetPath, bundle.mainAsset); } else { AudioClip audioClip = www.audioClip; if (audioClip != null) { kCurrentTask.OnLoaded(audioClip, true); this.m_kLoadedAsset.Add(kCurrentTask.kAssetPath, audioClip); } } } else { GameSys.Log("声音加载错误"); } //加载完毕从执行序列中移除 if (this.m_kExecQueue.Contains(kCurrentTask)) { this.m_kExecQueue.Remove(kCurrentTask); } }
/// <summary> /// 移动到指定终点 by吴江 /// </summary> /// <param name="_pos"></param> /// <param name="_maxDistance"></param> /// <param name="_noStop"></param> public override void MoveTo(Vector3 _pos, float _maxDistance = 10.0f, bool _noStop = false) { if (moveFSM != null) { Vector3[] path = GameStageUtility.StartPath(transform.position, _pos); if (path == null) { return; } moveFSM.path = path; if (moveFSM.path == null) { GameSys.Log("NPC's path not found! Target: " + _pos); moveFSM.destPos = moveFSM.transform.position; moveFSM.StopMovingTo(); return; } MoveTo(moveFSM.path); } }
public override bool Exec(Actor _actor) { if (GameCenter.curGameStage == null || !GameCenter.sceneMng.EnterSucceed) { return(false); } //如果目标在使用技能,返回false ,等他用完 by吴江 SmartActor sa = _actor as SmartActor; if (sa.isRigidity) //如果在僵直 { return(false); } if (sa != null && (sa.isCasting || sa.isCastingAttackEffect)) //如果在使用技能 { sa.CancelAbility(); } if (path == null) { path = GameStageUtility.StartPath(_actor.transform.position, destPos); if (path == null) { GameSys.Log("寻路失败!"); _actor.StopMovingTo(); MainPlayer player = _actor as MainPlayer; if (player != null) { if (player.CannotMoveTo != null) { player.CannotMoveTo(); } } return(true); } else { destPos = path[path.Length - 1]; } } //检查是否超出最远距离 by吴江 if (maxDistance > 0.0f) { Vector3 delta = destPos - _actor.transform.position; if (ignoreY) { delta.y = 0.0f; } if (delta.sqrMagnitude <= (maxDistance * maxDistance)) { _actor.StopMovingTo(); return(true); } } if (firstTime) { if (_actor.isMoveLocked == false) { // firstTimeTick = Time.realtimeSinceStartup; firstTime = false; _actor.MoveTo(path, maxDistance, false); } return(false); } if (maxDistance <= 0.0f) { Vector3 delta = destPos - _actor.transform.position; if (ignoreY) { delta.y = 0.0f; } if (delta.sqrMagnitude < (0.1 * _actor.CurRealSpeed * 0.1 * _actor.CurRealSpeed)) { var player = _actor as SmartActor; if (player != null) { _actor.StopMovingTo(); } return(true); } } if (_actor.IsMoving) { return(false); } else { path = GameStageUtility.StartPath(_actor.transform.position, destPos); _actor.MoveTo(path, maxDistance, false); if (path == null || path.Length == 0) { return(true); } } return(false); }
void ExitBackonState(fsm.State _from, fsm.State _to, fsm.Event _event) { GameSys.Log("NPC离开招手状态"); }
void ExitCowerState(fsm.State _from, fsm.State _to, fsm.Event _event) { GameSys.Log("NPC不再感到害怕"); //结束动画 }
void ExitFollowState(fsm.State _from, fsm.State _to, fsm.Event _event) { GameSys.Log("NPC停止跟随"); StopMovingTo(); }
void ExitIdleState(fsm.State _from, fsm.State _to, fsm.Event _event) { GameSys.Log("NPC结束思考"); }
void ExitLedState(fsm.State _from, fsm.State _to, fsm.Event _event) { GameSys.Log("停止带领"); StopMovingTo(); }
void EnterLedState(fsm.State _from, fsm.State _to, fsm.Event _event) { GameSys.Log("开始带领玩家走向任务终点"); MoveTo(curNPCActionRef.targetPos); checkTime = Time.time; }