private void Start() { fsm = new FSM("AITest FSM Two"); MoveForwardState = fsm.AddState("MoveForwardState"); IdleState = fsm.AddState("MoveRightState"); TurnState = fsm.AddState("TurnState"); MoveForwardAction = new MoveAction(MoveForwardState); IdleAction = new MoveAction(IdleState); TurnAction = new TurnAction(TurnState); MoveForwardState.AddAction(MoveForwardAction); IdleState.AddAction(IdleAction); TurnState.AddAction(TurnAction); MoveForwardState.AddTransition("ToTurn", TurnState); TurnState.AddTransition("ToIdle", IdleState); TurnState.AddTransition("ToTurn", TurnState); IdleState.AddTransition("ToForward", MoveForwardState); IdleState.AddTransition("ToTurn", TurnState); MoveForwardAction.Init(this.transform, .1f, 2.0f, "ToTurn"); TurnAction.Init(this.transform, 2.0f, "ToIdle"); IdleAction.Init(this.transform, 0, 2.0f, "ToForward"); fsm.Start("MoveForwardState"); }
// Use this for initialization void Start() { fsm = new FSM("AITest FSM Two"); MoveLeftState = fsm.AddState("MoveLeftState"); MoveRightState = fsm.AddState("MoveRightState"); MoveLeftAction = new MoveAction(MoveLeftState); MoveRightAction = new MoveAction(MoveRightState); MoveLeftTextAction = new TextAction(MoveLeftState); MoveRightTextAction = new TextAction(MoveRightState); //This adds the actions to the state and add state to it's transition map MoveLeftState.AddAction(MoveLeftTextAction); MoveLeftState.AddAction(MoveLeftAction); MoveRightState.AddAction(MoveRightTextAction); MoveRightState.AddAction(MoveRightAction); MoveLeftState.AddTransition("ToRight", MoveRightState); MoveRightState.AddTransition("ToLeft", MoveLeftState); //this initializes the actions MoveLeftTextAction.Init("AI Moving Left", 1f, ""); MoveRightTextAction.Init("AI Moving Right", 1f, ""); MoveLeftAction.Init(this.transform, new Vector3(1, 0, 0), new Vector3(-1, 0, 0), 1.0f, "ToRight"); MoveRightAction.Init(this.transform, new Vector3(-1, 0, 0), new Vector3(1, 0, 0), 1.0f, "ToLeft"); //Starts the FSM fsm.Start("MoveLeftState"); }
// Update is called once per frame void Update() { if (MatchSystem.instance.GetActivePlayer() == _creatureStat && MatchSystem.instance.CanAction) { List <CreatureStats> enemies = MatchSystem.instance.GetAllPlayers() .Where(x => x != _creatureStat) .Where(x => x.team != _creatureStat.team).ToList(); //Debug.LogFormat("AI нашел {0} врагов", enemies.Count); if (enemies.Count > 0) { AIPriority enemy = checkPrority(enemies); if (enemy == null) { return; } if (enemy.isAttack) { //AttackAction action = new AttackAction(_creatureStat, enemy.enemy); AttackAction action = GetComponent <AttackAction>(); action.Init(enemy.enemy); MatchSystem.instance.RunAction(action); } else { //MoveAction action = new MoveAction(_creatureStat, enemy.tail); MoveAction action = GetComponent <MoveAction>(); action.Init(enemy.tail); MatchSystem.instance.RunAction(action); } } } }
private void Tail_OnClick(Tail tail) { /*if (!SingleSystemManager.instance.CheckOn(GetType())) return;*/ //MoveAction action = new MoveAction(MatchSystem.instance.GetActivePlayer(), tail); MoveAction action = MatchSystem.instance.GetActivePlayer().GetComponent <MoveAction>(); action.Init(tail); MatchSystem.instance.RunAction(action); }
public override void Start() { base.Start(); m_HitPoints = HitPoints; objectScanner = new ObjectScanner(this, onObjectFound); //Initialise all actions idleAction.Init(Animator, "ToFollow"); followMoveAction.Init(transform, Animator, MovementTypes.MOVE_RUN, "ToIdle", unit); patrolMoveAction.Init(transform, Animator, MovementTypes.MOVE_WALK, "ToIdle", unit); patrolAction.Init(transform, Animator, "ToIdle"); attackAction.Init(Animator); fsm.Start(CharacterStates.STATE_IDLE); }
// 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"); }
public override void OnClick(Tail obj) { if (obj.TailType == Tail.TailTypes.Ground) { MoveAction action = MatchSystem.instance.GetActivePlayer().GetComponent <MoveAction>(); action.Init(obj); MatchSystem.instance.RunAction(action); } else if (obj.TailType == Tail.TailTypes.Treasure) { PickTreasureAction action = MatchSystem.instance.GetActivePlayer().GetComponent <PickTreasureAction>(); action.Init(obj.Treasure); MatchSystem.instance.RunAction(action); //MatchSystem.instance.RunAction(new PickTreasureAction(null, obj.Treasure)); } else if (obj.TailType == Tail.TailTypes.Character) { AttackAction action = MatchSystem.instance.GetActivePlayer().GetComponent <AttackAction>(); action.Init(obj.Creature); MatchSystem.instance.RunAction(action); } }