override public void OnDeactivate() { // Time.timeScale = 1; //AnimEngine.Stop(AnimName); Action.SetSuccess(); Action = null; base.OnDeactivate(); }
void Update() { if (Owner.BlackBoard.Health <= 0) { if (!isDeath) { StartCoroutine(PlayTeleport()); isDeath = true; } return; } else { Owner.CharacterController.SimpleMove(Vector3.zero); } // 只有当在警觉状态下,才会进行警戒计时 if (Alert() && Owner.Status == E_CurrentStatus.E_Idle) { alertStartTime += Time.deltaTime; ActionRotate actionRotate = ActionFactory.Create(ActionFactory.E_Type.E_Rotate) as ActionRotate; actionRotate.Direction = targetDir; animComponent.HandleAction(actionRotate); Owner.BlackBoard.WeaponState = E_WeaponState.Ready; } else { ActionIdle actionIdle = ActionFactory.Create(ActionFactory.E_Type.E_IDLE) as ActionIdle; animComponent.HandleAction(actionIdle); alertStartTime = 0; Owner.BlackBoard.WeaponState = E_WeaponState.NotInHands; } // 当超过警觉时间,切换为移动状态 if (alertStartTime > alertTime) { Owner.Status = E_CurrentStatus.E_Move; alertStartTime = 0; } if (Owner.Status == E_CurrentStatus.E_Move) { // 当进入移动状态时,判断敌人是否在视野范围内,如果是追击敌人,如果不在,返回到Idl状态,接着之前的行为 if (InView()) { ActionGoTo actionGoto = ActionFactory.Create(ActionFactory.E_Type.E_GOTO) as ActionGoTo; Owner.BlackBoard.MoveDir = targetDir.normalized; // 更新移动方向 Owner.BlackBoard.WeaponState = E_WeaponState.Ready; actionGoto.FinalPosition = targetPos; actionGoto.MoveType = E_MoveType.Forward; actionGoto.Motion = E_MotionType.Sprint; animComponent.HandleAction(actionGoto); } else { Owner.Status = E_CurrentStatus.E_Idle; Owner.BlackBoard.WeaponState = E_WeaponState.NotInHands; } } // 只要在攻击距离内,就直接切换到攻击状态 if (InAttackView() && Owner.Status == E_CurrentStatus.E_Move) { ActionAttack actionAttack = ActionFactory.Create(ActionFactory.E_Type.E_ATTACK) as ActionAttack; actionAttack.Target = Player.Instance.Agent; actionAttack.AttackDir = Player.Instance.transform.position - transform.position; animComponent.HandleAction(actionAttack); Owner.WorldState.SetWSProperty(E_PropKey.E_IDLING, false); Owner.Status = E_CurrentStatus.E_Attack; } if (Owner.Status == E_CurrentStatus.E_Attack && Owner.WorldState.GetWSProperty(E_PropKey.E_IDLING).GetBool()) { // Owner.Status = E_CurrentStatus.E_Idle; Owner.Status = E_CurrentStatus.E_Injury; } // 如果在受伤或者格挡状态,隔0.3s回Idle if (Owner.Status == E_CurrentStatus.E_Injury || Owner.Status == E_CurrentStatus.E_Block) { injuryStartTime += Time.deltaTime; } if (injuryStartTime > injuryTime) { Owner.Status = E_CurrentStatus.E_Idle; injuryStartTime = 0; } }
// 生成动作 static public ActionBase Create(E_Type type) { int index = (int)type; ActionBase a; if (m_UnusedActions[index].Count > 0) { a = m_UnusedActions[index].Dequeue(); } else { switch (type) { case E_Type.E_IDLE: a = new ActionIdle(); break; case E_Type.E_MOVE: a = new ActionMove(); break; case E_Type.E_GOTO: a = new ActionGoTo(); break; case E_Type.E_COMBAT_MOVE: a = new ActionCombatMove(); break; case E_Type.E_ATTACK: a = new ActionAttack(); break; case E_Type.E_ATTACK_ROLL: a = new ActionAttackRoll(); break; case E_Type.E_ATTACK_WHIRL: a = new ActionAttackWhirl(); break; case E_Type.E_INJURY: a = new ActionInjury(); break; case E_Type.E_DAMAGE_BLOCKED: a = new ActionDamageBlocked(); break; case E_Type.E_BLOCK: a = new ActionBlock(); break; case E_Type.E_ROLL: a = new ActionRoll(); break; case E_Type.E_INCOMMING_ATTACK: a = new ActionIncommingAttack(); break; case E_Type.E_WEAPON_SHOW: a = new ActionWeaponShow(); break; case E_Type.E_Rotate: a = new ActionRotate(); break; case E_Type.E_USE_LEVER: a = new ActionUseLever(); break; case E_Type.E_PLAY_ANIM: a = new ActionPlayAnim(); break; case E_Type.E_PLAY_IDLE_ANIM: a = new ActionPlayIdleAnim(); break; case E_Type.E_DEATH: a = new ActionDeath(); break; case E_Type.E_KNOCKDOWN: a = new ActionKnockdown(); break; case E_Type.E_Teleport: a = new ActionTeleport(); break; default: Debug.LogError("no Action to create"); return(null); } } a.Reset(); a.SetActive(); m_ActionsInAction.Add(a); return(a); }
protected override void Initialize(ActionBase action) { base.Initialize(action); Action = action as ActionRotate; CurrentRotationTime = 0; StartRotation = Transform.rotation; Vector3 finalDir; if (Action.Target != null) { finalDir = (Action.Target.Position + (Action.Target.BlackBoard.MoveDir * Action.Target.BlackBoard.Speed * 0.5f)) - Transform.position; finalDir.Normalize(); } else if (Action.Direction != Vector3.zero) { finalDir = Action.Direction; } else { finalDir = Transform.forward; } if (Vector3.Dot(finalDir, Transform.right) > 0) { AnimName = Owner.AnimSet.GetRotateAnim(Owner.BlackBoard.MotionType, E_RotationType.Right); } else { AnimName = Owner.AnimSet.GetRotateAnim(Owner.BlackBoard.MotionType, E_RotationType.Left); } CrossFade(AnimName, 0.02f); //if (Owner.BlackBoard.WeaponState == E_WeaponState.NotInHands) //{ // AnimEngine.CrossFade(Owner.AnimSet.GetShowWeaponAnim(Owner.BlackBoard.WeaponSelected), 0.02f); // AnimEngine.CrossFadeQueued(AnimName); //} //else //{ // AnimEngine.CrossFade(Owner.AnimSet.GetHideWeaponAnim(Owner.BlackBoard.WeaponSelected), 0.02f); // AnimEngine.CrossFadeQueued(AnimName); //} FinalRotation.SetLookRotation(finalDir); RotationTime = Vector3.Angle(Transform.forward, finalDir) / (360.0f * Owner.BlackBoard.RotationSmooth); if (RotationTime == 0) { Release(); } float animLen = AnimEngine[AnimName].length; int steps = Mathf.CeilToInt(RotationTime / animLen); EndOfStateTime = AnimEngine[AnimName].length * steps + Time.timeSinceLevelLoad; //Debug.Log(steps + " " + RotationTime + " " + AnimEngine[AnimName].length); }