public void stop() { currentAction.destory = true; currentAction = IdleAction.GetIdleAction(-1f, ani); this.runAction(this.gameObject, currentAction, this); // 永久站立 }
public bool AskToListenTo(GameObject who) { var desireToTalk = metrics.Value("desire_to_talk", who); var willTalk = actor.curAction == null ? true : actor.curAction.Action.Utility() < desireToTalk; if (willTalk) { var idle = new IdleAction() { WaitDelegate = WaitFunction }; idle.Stopped += HadToStopTalking; actor.Act(idle); TalksTo = who; hookedSpeaker = false; StartCoroutine(CheckHookedSpeaker()); } else { var e = EventsManager.Instance.GetEvent <DialogRejected>(); e.Root = gameObject; e.Initiator = who; EventsManager.Instance.FireEvent(e); } return(willTalk); }
private void Jitting() { SetupAction?.Invoke(); MainAction.Invoke(1); IdleAction.Invoke(1); CleanupAction?.Invoke(); }
public void Jitting() { // first signal about jitting is raised from auto-generated Program.cs, look at BenchmarkProgram.txt MainAction.Invoke(1); IdleAction.Invoke(1); isJitted = true; }
private void Start() { fsm = new FiniteStateMachine("AITest FSM"); IdleState = fsm.AddState("IdleState"); ScanState = fsm.AddState("ScanState"); PatrolState = fsm.AddState("WanderState"); PatrolAction = new WanderAction(PatrolState); IdleAction = new IdleAction(IdleState); ScanAction = new ScanningAction(ScanState); deathState = fsm.AddState("DeathState"); DeathAction = new DeathState(deathState); //This adds the actions to the state and add state to it's transition map PatrolState.AddAction(PatrolAction); IdleState.AddAction(IdleAction); PatrolState.AddTransition("ToIdle", IdleState); IdleState.AddTransition("ToPatrol", PatrolState); ScanState.AddTransition("ToScanning", ScanState); deathState.AddTransition("ToDeath", deathState); PatrolAction.Init(target, 3.0f, gameObject.GetComponent <EnemyAstar>(), "ToIdle"); IdleAction.Init(target, "AI on Idle", 3.0f, gameObject.GetComponent <EnemyAstar>(), "ToPatrol"); DeathAction.Init(3.0f, gameObject.GetComponent <EnemyAstar>()); ScanAction.Init(3.0f); fsm.StartMachine("IdleState"); }
public GameStateController() { gameFsm = new FSM("GameFSM"); preStartState = gameFsm.AddState((byte)GameState.PreStart); idleState = gameFsm.AddState((byte)GameState.Idle); playState = gameFsm.AddState((byte)GameState.Play); pauseState = gameFsm.AddState((byte)GameState.Pause); gameOverState = gameFsm.AddState((byte)GameState.GameOver); preStartAction = new PreStartAction(preStartState); playingAction = new PlayAction(playState); pauseAction = new PauseAction(pauseState); gameOverAction = new GameOverAction(gameOverState); idleAction = new IdleAction(idleState); preStartState.AddTransition((byte)FSMTransition.ToIdle, idleState); idleState.AddTransition((byte)FSMTransition.ToPlay, playState); playState.AddTransition((byte)FSMTransition.ToPause, pauseState); playState.AddTransition((byte)FSMTransition.ToGameOver, gameOverState); gameOverState.AddTransition((byte)FSMTransition.ToIdle, idleState); preStartAction.Init(); idleAction.Init(); playingAction.Init(); pauseAction.Init(); gameOverAction.Init(); }
public void AfterAddAction_HasAction_Test() { Action action = new Think(); Action idleAction = new IdleAction(); action.AddAction(idleAction); Assert.True(action.CurrentAction().Equals(idleAction)); }
public static IdleAction GetIdleAction(float time, Animator ani) { IdleAction currentAction = ScriptableObject.CreateInstance <IdleAction>(); currentAction.time = time; currentAction.ani = ani; return(currentAction); }
public void RemoveAction_OnListWithOneAction_Test() { Action action = new Think(); Action idleAction = new IdleAction(); action.AddAction(idleAction); action.RemoveAction(); Assert.Equal(0, action.ActionListCount()); }
public void AfterAddTwoActions_HasTwoInList_Test() { Action action = new Think(); Action idleAction = new IdleAction(); Action wanderAction = new WanderAction(); action.AddAction(idleAction); action.AddAction(wanderAction); Assert.Equal(2, action.ActionListCount()); }
public void AfterAddTwoActions_NextActionIs_FirstAddedAction_Test() { Action action = new Think(); Action idleAction = new IdleAction(); Action wanderAction = new WanderAction(); action.AddAction(idleAction); action.AddAction(wanderAction); Assert.True(action.NextAction().Equals(idleAction)); }
public void RemoveAction_OnListWithTwoActions_CurrentActionIsFirstAddedAction_Test() { Action action = new Think(); Action idleAction = new IdleAction(); Action wanderAction = new WanderAction(); action.AddAction(idleAction); action.AddAction(wanderAction); action.RemoveAction(); Assert.True(action.CurrentAction().Equals(idleAction)); }
IEnumerator InitActions() { yield return(new WaitForSeconds(0.01f)); IdleInitAction = new IdleAction(this, "Idle", NV, mr, colliders, Ani); AttackAction = new NormalAttack(this, new string[] { "劈砍1", "劈砍3" }, 0.44f, NV, Ani); BackAction = new TakeBack(this, "", NV, transform); InjuredAction = new InjuredAction(this, "GetHit", 1, NV, Ani); RunAction = new RunAction(this, "Run", NV, Ani); DieAction = new DieAction(this, "Die", mr, NV, transform, colliders, Ani, 0.2f); }
public void AddTwoActionsByList_Test() { Action action = new Think(); List <Action> list = new List <Action>(); Action idleAction = new IdleAction(); Action wanderAction = new WanderAction(); list.Add(idleAction); list.Add(wanderAction); action.AddActions(list); Assert.Equal(2, action.ActionListCount()); }
public void AddTwoActionsByList_LastAddedIsCurrentAction_Test() { Action action = new Think(); List <Action> list = new List <Action>(); Action idleAction = new IdleAction(); Action wanderAction = new WanderAction(); list.Add(idleAction); list.Add(wanderAction); action.AddActions(list); Assert.True(action.CurrentAction().Equals(wanderAction)); }
public static void doDone(IdleAction actionObject) { //Debuger.Log(processor.renderTimeElasped + " SetState Idle " + actionObject.physicalFrameNumber); var actor = SceneViews.instance.getCurFBScene().getActor(actionObject.objectID); if (actor.animator != null) { actor.animator.SetInteger("state", (int)ActorAnimatorState.Idle); actor.resetAnimtorSpeed(); actor.hideRunEffect(); } }
public override void Awake() { base.Awake(); IdleInitAction = new IdleAction(this, "Idle", NV, mr, colliders, Ani); AttackAction = new NormalAttack(this, new string[] { "attack1", "attack2" }, 0.44f, NV, Ani); BackAction = new TakeBack(this, "", NV, transform); InjuredAction = new InjuredAction(this, "GetHit", 1, NV, Ani); RunAction = new RunAction(this, "Run", NV, Ani); DieAction = new DieAction(this, "Die", mr, NV, transform, colliders, Ani, 0.2f); //技能节点初始化(skill1Action是AI中需要cd和weight控制的技能,而skill1Action是根据相应的触发条件触发的) skill1Action = new SYSkillAction(this, "skill1", 0.7f, 0.7f, NV, 10, Ani); skill2Action = new JumpAction(this, "skill2", 1.4f, 3f, NV, 3, Ani, 1.65f); //将通过冷却和权值的技能添加到总技能列表中(所以仅将skill1Action进行CD和Weight的封装并添加,而skill2Action在update中根据条件来单独控制技能的触发) SkillList.Add(new SkillCDAndWeight_New(skill1Action, 10, 20)); }
// Use this for initialization void Start() { base.Initialize(); // Load Action Func으로 뺴세요 if (MoveAction == null) { MoveAction = GetComponent <MoveAction>(); } if (IdleAction == null) { IdleAction = GetComponent <IdleAction>(); } if (RollAction == null) { RollAction = GetComponent <RollAction>(); } if (AttackAction == null) { AttackAction = GetComponent <AttackAction>(); } if (KnockBackAction == null) { KnockBackAction = GetComponent <KnockBackAction>(); } if (BackStepAction == null) { BackStepAction = GetComponent <BackStepAction>(); } if (BlockAction == null) { BlockAction = GetComponent <BlockAction>(); } var mainCamera = Camera.main.GetComponent <TargetCamera>(); MoveAction.OnMoveEndCallBack += mainCamera.OnUpdateCamera; RollAction.OnMoveEndCallBack += mainCamera.OnUpdateCamera; mainCamera.SetTarget(this); }
private void BuildIdleState(State inTargetState, NpcController inNpcController, NpcDataHolder inNpcData, State inPatrolState, State inAttackState, State inDieState) { // -------------------------------------------------------------------------------- // 1- Setup Actions // -------------------------------------------------------------------------------- var idleAction = new IdleAction(inNpcController, inNpcData.idleDuration); // -------------------------------------------------------------------------------- // 2- Setup decisions // -------------------------------------------------------------------------------- var attackDecision = new AttackDecision(inNpcController); var idleToPatrolDecision = new IdleToPatrolDecision(idleAction); var dieDecision = new DieDecision(inNpcController.gameView as IDestructible); // -------------------------------------------------------------------------------- // 3- Setup Transitions // -------------------------------------------------------------------------------- var transitionToAttack = new Transition() { hasFalseState = false, decision = attackDecision, trueState = inAttackState }; var transitionToPatrol = new Transition() { hasFalseState = false, decision = idleToPatrolDecision, trueState = inPatrolState }; var transitionToDie = new Transition() { hasFalseState = false, decision = dieDecision, trueState = inDieState }; // -------------------------------------------------------------------------------- // 4- Define State // -------------------------------------------------------------------------------- inTargetState.Define( Color.green, new Action[] { idleAction }, new [] { transitionToAttack, transitionToDie, transitionToPatrol } ); }
/// <summary> /// Owner的动态标记发生变化, 通知每个Action, 从而得知这些Action哪些需要被终止. /// </summary> /// <param name="flagName">动态标记标识</param> public void OnActiveFlagsStateChanged(ActiveFlagsDef flagName, bool increased) { for (ActionTypeDef type = ActionTypeDef.ActionTypeIdle; type < ActionTypeDef.ActionTypeCount; ++type) { Action action = GetActionByType(type); if (action == null) { continue; } if (!action.OnActiveFlagsStateChanged(flagName, increased)) { action.Stop(false); } } if (flagName == ActiveFlagsDef.IsDead) { IdleAction.SetActive(Owner.isAlive()); } }
// Use this for initialization void Start() { // Load Action Func으로 뺴세요 if (MoveAction == null) { MoveAction = GetComponent <MoveAction>(); } if (IdleAction == null) { IdleAction = GetComponent <IdleAction>(); } if (AttackAction == null) { AttackAction = GetComponent <AttackAction>(); } base.Initialize(); StartCoroutine(MoveCorutine()); }
// Use this for initialization void Start() { fsm = new Core.FSM.FSM("PlayerFSM"); moveState = fsm.AddState("MoveState"); idleState = fsm.AddState("IdleState"); moveAction = new MoveAction(moveState); idleAction = new IdleAction(idleState); moveState.AddAction(moveAction); idleState.AddAction(idleAction); PlayerRB = gameObject.GetComponent <Rigidbody>(); playerObj = GameObject.Find("Player"); moveAction.Init(gameObject.transform, PlayerRB, velocity, sprintVelocity, jumpSpeed, "ToIdle"); idleAction.Init(); idleState.AddTransition("ToMove", moveState); moveState.AddTransition("ToIdle", idleState); fsm.Start("IdleState"); }
private void Awake() { Animator = GetComponent <Animator>(); unit = GetComponent <Unit>(); //Create the Finite State Machine fsm = new FSM("AI Controller FSM"); //Create the states and actions idleState = fsm.AddState(CharacterStates.STATE_IDLE); followState = fsm.AddState(CharacterStates.STATE_FOLLOW); attackState = fsm.AddState(CharacterStates.STATE_ATTACK); patrolState = fsm.AddState(CharacterStates.STATE_PATROL); idleAction = new IdleAction(idleState, this); followMoveAction = new MoveAction(followState, this); patrolMoveAction = new MoveAction(patrolState, this); patrolAction = new PatrolAction(patrolState, this); attackAction = new AttackAction(attackState, this); //Add actions to the states idleState.AddAction(idleAction); followState.AddAction(followMoveAction); attackState.AddAction(attackAction); patrolState.AddAction(patrolAction); patrolState.AddAction(patrolMoveAction); //Add transitions to the states idleState.AddTransition("ToFollow", followState); followState.AddTransition("ToIdle", idleState); followState.AddTransition("ToAttack", attackState); attackState.AddTransition("ToIdle", idleState); attackState.AddTransition("ToFollow", followState); patrolState.AddTransition("ToIdle", idleState); patrolState.AddTransition("ToFollow", followState); //ScanForObjects(gameObject.transform.position, m_DetectionRadius); }
private void Awake() { actionsQueue = new List <AbstractAction>(); currentAction = new IdleAction(EActionType.Idle, this); originalScaleX = transform.localScale.x; }
public void idle() { currentAction = IdleAction.GetIdleAction(Random.Range(1, 1.5f), ani); this.runAction(this.gameObject, currentAction, this); }
public void stop() { action.destroy = true; action = IdleAction.GetIdleAction(-1f, animator); this.RunAction(this.gameObject, action, this); }
public IdleToPatrolDecision(IdleAction inIdle) { _idleAction = inIdle ?? throw new Exception($"IdleAction must be not null"); }
private void Start() { player = GameObject.FindGameObjectWithTag(Tags.Player).GetComponent <UserSoldier>(); gameManager = GameObject.FindGameObjectWithTag(Tags.GameController).GetComponent <GameManager>(); npc = GetComponent <NPCSoldier>(); npc.Damaged += Damaged; nextRadius = gameManager.nextRadius; SetCoverPos(transform.position); var notInSafeZoneCond = new ConditionNode(IsInSafeZone, false); var haveEnemyCond = new ConditionNode(HaveEnemyInSight, true); var beingShootCond = new ConditionNode(BeingShoot, true); var haveWeaponCond = new ConditionNode(HaveWeapon, true); var seekWeaponCond = new ConditionNode(SeekWeapon, true); var equipAction = new SetEquipmentAction(npc, true); var notEquipAction = new SetEquipmentAction(npc, false); var crouchAction = new SetCrouchAction(npc, true); var notCrouchAction = new SetCrouchAction(npc, false); var toSafeZoneAction = new MoveAction(npc, blackBoard, safeZoneKey); var goCoverAction = new MoveAction(npc, blackBoard, coverPosKey); var FallBackAction = new MoveAction(npc, blackBoard, fallBackPosKey); var goWeaponAction = new MoveAction(npc, blackBoard, weaponPosKey); var pickUpWeaponAction = new PickUpWeaponAction(npc, blackBoard, weaponKey); var shootAction = new ShootAction(npc, blackBoard, enemyPosKey); var turnToShooterAction = new TurnAction(npc, blackBoard, shooterPosKey); var idleAction = new IdleAction(npc); var combat = new SequenceNode(); combat.AddCondition(haveWeaponCond); combat.AddNode(equipAction); combat.AddNode(shootAction); var fallBack = new SequenceNode(); fallBack.AddNode(FallBackAction); haveEnemy = new SelectionNode(); haveEnemy.AddCondition(haveEnemyCond); haveEnemy.AddNode(combat); haveEnemy.AddNode(fallBack); var counter = new SequenceNode(); counter.AddCondition(haveWeaponCond); counter.AddNode(turnToShooterAction); beingShoot = new SelectionNode(); beingShoot.AddCondition(beingShootCond); beingShoot.AddNode(counter); beingShoot.AddNode(fallBack); toSafeZone = new SequenceNode(); toSafeZone.AddCondition(notInSafeZoneCond); toSafeZone.AddNode(notCrouchAction); toSafeZone.AddNode(notEquipAction); toSafeZone.AddNode(toSafeZoneAction); stayInCover = new SequenceNode(); stayInCover.AddCondition(haveWeaponCond); stayInCover.AddNode(goCoverAction); stayInCover.AddNode(crouchAction); stayInCover.AddNode(idleAction); seekWeapon = new SequenceNode(); seekWeapon.AddCondition(seekWeaponCond); seekWeapon.AddNode(goWeaponAction); seekWeapon.AddNode(pickUpWeaponAction); idle = new SelectionNode(); idle.AddNode(stayInCover); idle.AddNode(seekWeapon); root.AddNode(haveEnemy); root.AddNode(beingShoot); root.AddNode(toSafeZone); root.AddNode(idle); }
public void stop() { baseAction.destory = true; baseAction = IdleAction.GetIdleAction(-1f, animator); this.runAction(this.gameObject, baseAction, this); }
public void idle() { baseAction = IdleAction.GetIdleAction(Random.Range(1, 1.5f), animator); this.runAction(this.gameObject, baseAction, this); }