override public void OnDeactivate() { AnimEngine[AnimName].speed = 1; Action.SetSuccess(); Action = null; Owner.BlackBoard.Speed = 0; base.OnDeactivate(); // Time.timeScale = 1; }
protected override void Initialize(ActionBase action) { base.Initialize(action); Action = action as ActionGoTo; Vector3 dir; if (Owner.BlackBoard.LookType == E_LookType.TrackTarget && Owner.BlackBoard.DesiredTarget != null) { dir = Owner.BlackBoard.DesiredTarget.Position - Owner.Transform.position; dir.y = 0; dir.Normalize(); } else { dir = Action.FinalPosition - Owner.Transform.position; dir.y = 0; dir.Normalize(); } StartRotation = Owner.Transform.rotation; if (dir != Vector3.zero) { FinalRotation.SetLookRotation(dir); } Owner.BlackBoard.MotionType = GetMotionType(); if (Action.Motion == E_MotionType.Sprint) { MaxSpeed = Owner.BlackBoard.MaxSprintSpeed; } else if (Action.Motion == E_MotionType.Run) { MaxSpeed = Owner.BlackBoard.MaxRunSpeed; } else { MaxSpeed = Owner.BlackBoard.MaxWalkSpeed; } RotationProgress = 0; }
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); }