private void InitInputController() { RuntimeInputConfiguration inputConfig = inputController.GetRuntimeInputConfig(); InputBinding horizontalBinding = inputConfig.GetBinding(InputBindingName.GAMEPLAY_HORIZONTAL); InputBinding verticalBinding = inputConfig.GetBinding(InputBindingName.GAMEPLAY_VERTICAL); InputBinding interactBinding = inputConfig.GetBinding(InputBindingName.GAMEPLAY_INTERACT); InputBinding attackBinding = inputConfig.GetBinding(InputBindingName.GAMEPLAY_ATTACK); InputBinding primarySkillBinding = inputConfig.GetBinding(InputBindingName.GAMEPLAY_PRIMARY_SKILL); InputBinding secondarySkillBinding = inputConfig.GetBinding(InputBindingName.GAMEPLAY_SECONDARY_SKILL); InputBinding toggleTargetingBinding = inputConfig.GetBinding(InputBindingName.GAMEPLAY_TOGGLE_TARGETING); InputBinding nextTargetBinding = inputConfig.GetBinding(InputBindingName.GAMEPLAY_NEXT_TARGET); horizontalBinding.Action.Start = () => { blackboard.Set <float>(BlackboardKey.Horizontal, horizontalBinding.Value); }; verticalBinding.Action.Start = () => { blackboard.Set <float>(BlackboardKey.Vertical, verticalBinding.Value); }; interactBinding.Action.Start = () => interactor.Interact(); attackBinding.Action.Start = () => { bool attackFlag = blackboard.Get <bool>(BlackboardKey.AttackingFlag); if (attackFlag) { blackboard.Set <bool>(BlackboardKey.NextAttackFlag, true); } else { blackboard.Set <bool>(BlackboardKey.AttackingFlag, true); } }; primarySkillBinding.Action.Start = () => { bool skillFlag = blackboard.Get <bool>(BlackboardKey.SkillFlag); skillController.SetCurrentSkill(0); if (!skillFlag && skillController.CanUseCurrentSkill()) { EntitySkillInfo skill = skillController.CurrentSkill.SkillInfo; blackboard.Set <string>(BlackboardKey.AnimTrigger, skill.MetaData.AnimTrigger); blackboard.Set <bool>(BlackboardKey.SkillFlag, true); } }; secondarySkillBinding.Action.Start = () => { bool skillFlag = blackboard.Get <bool>(BlackboardKey.SkillFlag); skillController.SetCurrentSkill(1); if (!skillFlag && skillController.CanUseCurrentSkill()) { EntitySkillInfo skill = skillController.CurrentSkill.SkillInfo; blackboard.Set <string>(BlackboardKey.AnimTrigger, skill.MetaData.AnimTrigger); blackboard.Set <bool>(BlackboardKey.SkillFlag, true); } }; toggleTargetingBinding.Action.Start = () => { ToggleTargeting(); }; nextTargetBinding.Action.Start = () => { GetNextTarget(); }; }
private void InitStateMachine() { blackboard = new StateBlackboard(); blackboard.Add(BlackboardKey.AttackingFlag, false); blackboard.Add(BlackboardKey.NextAttackFlag, false); blackboard.Add(BlackboardKey.SkillFlag, false); blackboard.Add(BlackboardKey.DamageFlag, false); blackboard.Add(BlackboardKey.RepeatDamageFlag, false); blackboard.Add(BlackboardKey.AnimTrigger, string.Empty); blackboard.Add <Transform>(BlackboardKey.Target, null); blackboard.Add <Vector3>(BlackboardKey.MoveDirection, Vector3.zero); SetAnimTriggerAction setIdleTriggerAction = new SetAnimTriggerAction(blackboard, animator, "Idle"); LookAtTargetAction lookAtAction = new LookAtTargetAction(blackboard, transform); PlayerIdleState idleState = new PlayerIdleState(blackboard, setIdleTriggerAction, lookAtAction); StateNode idleNode = new StateNode(idleState, new Condition(() => { return(true); })); SetAnimTriggerAction setRunTriggerAction = new SetAnimTriggerAction(blackboard, animator, "Move"); SetMoveDirectionAction setMoveDirAction = new SetMoveDirectionAction(blackboard, transform, Camera.main.transform); MoveControllerAction moveControllerAction = new MoveControllerAction(blackboard, GetComponent <CharacterController>(), runSpeed); PlayerMoveState moveState = new PlayerMoveState(blackboard, setRunTriggerAction, setMoveDirAction, moveControllerAction, 100); StateNode moveNode = new StateNode(moveState, new Condition(() => { float horizontal = inputController.GetRuntimeInputConfig().GetBinding(InputBindingName.GAMEPLAY_HORIZONTAL).Value; float vertical = inputController.GetRuntimeInputConfig().GetBinding(InputBindingName.GAMEPLAY_VERTICAL).Value; return(Mathf.Abs(horizontal) > InputConstants.INPUT_DEAD_ZONE || Mathf.Abs(vertical) > InputConstants.INPUT_DEAD_ZONE); })); SetAnimTriggerAction setAttackTrigger = new SetAnimTriggerAction(blackboard, animator, "Attack", true); SetAnimTriggerAction setNextAttackTrigger = new SetAnimTriggerAction(blackboard, animator, "NextAttack", true); PlayerAttackState attackState = new PlayerAttackState(blackboard, setAttackTrigger, setNextAttackTrigger, lookAtAction, 500); StateNode attackNode = new StateNode(attackState, new Condition(() => { return(blackboard.Get <bool>(BlackboardKey.AttackingFlag) == true); })); SetAnimTriggerAction setSkillTrigger = new SetAnimTriggerAction(blackboard, animator, BlackboardKey.AnimTrigger, true); PlayerSkillState skillState = new PlayerSkillState(blackboard, setSkillTrigger, 400); StateNode skillNode = new StateNode(skillState, new Condition(() => { return(blackboard.Get <bool>(BlackboardKey.SkillFlag) == true); })); SetAnimTriggerAction damageAction = new SetAnimTriggerAction(blackboard, animator, "Damage", true); DamageState damageState = new DamageState(blackboard, damageAction, 600); Condition damageCondition = new Condition(() => { return(blackboard.Get <bool>(BlackboardKey.DamageFlag)); }); StateNode damageNode = new StateNode(damageState, damageCondition); DeathState deathState = DeathState.Create(blackboard, animator, "Die", int.MaxValue); StateNode deathNode = new StateNode(deathState, new Condition(() => { return(!self.IsAlive); })); List <StateNode> nodes = new List <StateNode>(); nodes.Add(idleNode); nodes.Add(moveNode); nodes.Add(attackNode); nodes.Add(skillNode); nodes.Add(damageNode); nodes.Add(deathNode); stateMachine = new StateMachine(blackboard, nodes, idleState); }
private void InitStateMachine() { blackboard = new StateBlackboard(); blackboard.Add <bool>(BlackboardKey.DamageFlag, false); blackboard.Add <bool>(BlackboardKey.RepeatDamageFlag, false); blackboard.Add <Transform>(BlackboardKey.Transform, transform); blackboard.Add <float>(BlackboardKey.AttackRange, 0f); EnemyIdleState idleState = EnemyIdleState.Create(blackboard, animator, "Idle", 0); StateNode idleNode = new StateNode(idleState, new Condition(() => { return(true); })); SetAnimTriggerAction walkAction = new SetAnimTriggerAction(blackboard, animator, "Run"); MeleeAttackState meleeAttackState = MeleeAttackState.Create(blackboard, animator, navAgent, attackValidator.MeleeAttacks, transform, BlackboardKey.AttackRange, BlackboardKey.AnimTrigger, walkAction, 300); StateNode attackNode = new StateNode(meleeAttackState, new Condition(() => { return(target != null); })); DamageState damageState = DamageState.Create(blackboard, animator, "Damage", 500); StateNode damageNode = new StateNode(damageState, new Condition(() => { return(blackboard.Get <bool>(BlackboardKey.DamageFlag)); })); DeathState deathState = DeathState.Create(blackboard, animator, "Death", int.MaxValue); StateNode deathNode = new StateNode(deathState, new Condition(() => { return(!self.IsAlive); })); List <StateNode> nodes = new List <StateNode>(); nodes.Add(idleNode); nodes.Add(attackNode); nodes.Add(damageNode); nodes.Add(deathNode); stateMachine = new StateMachine(blackboard, nodes, idleState); }
private void InitStateMachine() { blackboard = new StateBlackboard(); blackboard.Add <bool>(BlackboardKey.DamageFlag, false); blackboard.Add <bool>(BlackboardKey.RepeatDamageFlag, false); blackboard.Add <Transform>(BlackboardKey.Transform, transform); blackboard.Add <float>(BlackboardKey.RunRange, 3f); EnemyIdleState idleState = EnemyIdleState.Create(blackboard, animator, "Idle", 0); StateNode idleNode = new StateNode(idleState, new Condition(() => { return(true); })); SetAnimTriggerAction idleAction = new SetAnimTriggerAction(blackboard, animator, "Idle"); SetAnimTriggerAction runAction = new SetAnimTriggerAction(blackboard, animator, "Run"); TimerAction timerAction = new TimerAction(blackboard, 0.5f, 1.5f); SetRandomDestinationAction destinationAction = new SetRandomDestinationAction(blackboard, transform.position, 6f); MoveToDestinationAction moveToAction = new MoveToDestinationAction(blackboard, navAgent); SetSkillAction setSkillAction = new SetSkillAction(blackboard, skillController); LookAtTargetAction lookAtAction = new LookAtTargetAction(blackboard, transform); SetAnimTriggerAction attackAction = new SetAnimTriggerAction(blackboard, animator, BlackboardKey.AnimTrigger, true); RangedAttackState attackState = new RangedAttackState(blackboard, idleAction, timerAction, destinationAction, runAction, moveToAction, setSkillAction, lookAtAction, attackAction, 300); StateNode attackNode = new StateNode(attackState, new Condition(() => target != null)); DamageState damageState = DamageState.Create(blackboard, animator, "Damage", 500); StateNode damageNode = new StateNode(damageState, new Condition(() => { return(blackboard.Get <bool>(BlackboardKey.DamageFlag)); })); DeathState deathState = DeathState.Create(blackboard, animator, "Death", int.MaxValue); StateNode deathNode = new StateNode(deathState, new Condition(() => { return(!self.IsAlive); })); List <StateNode> nodes = new List <StateNode>(); nodes.Add(idleNode); nodes.Add(attackNode); nodes.Add(damageNode); nodes.Add(deathNode); stateMachine = new StateMachine(blackboard, nodes, idleState); }