private void Awake()
    {
        receiver = GetComponent<ControllerWheels>();
        sphereCollider = this.GetComponent<SphereCollider>();
        //Debug.LogWarning("HARDCODED");
        sphereCollider.isTrigger = true;
        sphereCollider.radius = 20f;

        receiverColliders = GetComponents<Collider>().ToList();
        receiverColliders = GetComponentsInChildren<Collider>().ToList();
        receiverColliders.ForEach(hC => Physics.IgnoreCollision(sphereCollider, hC));

        m_hRigidbody = this.GetComponent<Rigidbody>();

        //FSM
        idle = new StateIdle(this);
        patrol = new StatePatrol(this);
        onAir = new StateOnAir(this);
        wait = new StateWait(this);

        patrol.Idle = idle;
        patrol.OnAir = onAir;
        onAir.Wait = wait;
        wait.Patrol = patrol;

        currentState = idle;
        currentState.OnStateEnter();
    }
Example #2
0
    /// <summary>
    /// Initialize the character
    /// </summary>
    new public virtual void Start()
    {
        moveStick      = new ControlStick();
        jumpAlarm      = ScriptableObject.CreateInstance <Alarm>();
        hitLagAlarm    = ScriptableObject.CreateInstance <Alarm>();
        spriteRenderer = this.gameObject.GetComponentInChildren <SpriteRenderer>();

        timer     = 0;
        velocity  = new Vector3(0f, 0f, 0f);
        position  = new Vector2(0f, 0f);
        knockback = new Vector3(0f, 0f, 0f);
        jumpCount = 0;

        // Pool the states
        currentState = new StateIdle(this);
        stateAttack  = new StateAttack(this);
        stateCrouch  = new StateCrouch(this);
        stateIdle    = new StateIdle(this);
        stateDash    = new StateDash(this);
        stateJump    = new StateJump(this);
        stateRun     = new StateRun(this);
        stateHurt    = new StateHurt(this);
        stateFall    = new StateFall(this);
        playerContactFilter.layerMask = playerMask;

        timerSpeed = 1;

        canJump   = true;
        canAttack = true;
    }
Example #3
0
    void Start()
    {
        _type     = UnitType.Enemy;
        _isMoving = false;
        InitAbility();

        _players       = new List <PlayerBehaviour>();
        _playerObjects = GameObject.FindGameObjectsWithTag("Player");
        foreach (var player in _playerObjects)
        {
            _players.Add(player.GetComponent <PlayerBehaviour>());
        }

        _animator = GetComponent <Animator>();

        _stateProcessor = new StateProcessor();
        StateIdle       = new StateIdle();      //待機状態
        StateSelect     = new StateSelect();    //選択状態
        StateMove       = new StateMove();      //移動状態
        StateAttack     = new StateAttack();    //攻撃状態
        StateIntercept  = new StateIntercept(); //傍受状態

        _stateProcessor.State       = StateIdle;
        StateIdle.execDelegate      = IdleUpdate;
        StateSelect.execDelegate    = SelectUpdate;
        StateMove.execDelegate      = MoveUpdate;
        StateAttack.execDelegate    = AttackUpdate;
        StateIntercept.execDelegate = InterceptUpdate;
    }
Example #4
0
 public Reptiloid(string name, int attack, int defence, int health, int healthMaximum, double skill)
     : base(name, attack, defence, health, healthMaximum)
 {
     sightRadius      = (int)(10 + 20 * skill);
     panicHealthLimit = healthMaximum / 10;
     state            = new StateIdle(this);
 }
    private void Awake()
    {
        m_hWeapon = this.GetComponent<Weapon>();
        Owner = GetComponent<Actor>();
        m_hIdle             = new StateIdle(this);
        m_hPatrol           = new StatePatrol(this);

        switch ((int)AimMode)
        {
            case 1:
                m_hPatrol.Next = new StateAimBallistic(this); 
                break;
            case 2:
                m_hPatrol.Next = new StateAimDirect(this); 
                break;
        }


        m_hPatrol.Next.Next = m_hPatrol;

        m_hCurrent          = m_hPatrol;
        m_hCurrent.OnStateEnter();

        
    }
Example #6
0
 public RuntimeStateMachine()
 {
     _runtimeState = (int)RuntimeState.NotAvailable;
     _stateActions = new Dictionary <RuntimeState, Action>(10)
     {
         {
             RuntimeState.Idle, () => { StateIdle?.Invoke(); }
         },
         {
             RuntimeState.Running, () => { StateRunning?.Invoke(); }
         },
         {
             RuntimeState.Error, () => { StateError?.Invoke(); }
         },
         {
             RuntimeState.Over, () => { StateOver?.Invoke(); }
         },
         {
             RuntimeState.AbortRequested, () => { StateAbortRequested?.Invoke(); }
         },
         {
             RuntimeState.Abort, () => { StateAbort?.Invoke(); }
         },
         {
             RuntimeState.Collapsed, () => { StateCollapsed?.Invoke(); }
         },
         {
             RuntimeState.Timeout, () => { TimeOut?.Invoke(); }
         }
     };
 }
Example #7
0
    public override StateBase <Hero> update(Hero hero)
    {
        StateBase <Hero> next = this;

        if (hero.want == Hero.wantAction.JUMP)
        {
            hero.jump();
            hero.animCtrl.SetBool("isJumping", true);
            next = new StateJump();
            hero.fire();
            return(next);
        }

        bool ran = hero.move();

        if (!ran)
        {
            hero.animCtrl.SetBool("isRunning", false);
            next = new StateIdle();
        }

        if (hero.want == Hero.wantAction.ATTACK)
        {
            hero.attack();
        }

        return(next);
    }
Example #8
0
    public void Awake()
    {
        if (!Mathf.Approximately(Spawns.Sum(hS => hS.Chance), 1f))
            throw new UnityException(this.gameObject.name + ": Sum of chances must be == 1");

        animator = GetComponent<Animator>();
        units = new List<GameObject>();

        idle = new StateIdle(this);
        ready = new StateReady(this);
        wait = new StateWait(this);
        spawn = new StateSpawn(this);
        open = new StateOpen(this);
        push = new StatePush(this);
        close = new StateClose(this);

        ready.Wait = wait;
        wait.Spawn = spawn;
        spawn.Open = open;
        open.Push = push;
        push.Close = close;
        close.Ready = ready;

        currentState = ready;
        ready.OnStateEnter();
    }
Example #9
0
    private StateIdle()
    {
        if (_instance != null)
        {
            return;
        }

        _instance = this;
    }
Example #10
0
        public override void Configure()
        {
            entity   = GetComponent <Entity>();
            rigid    = GetComponent <Rigidbody2D>();
            collider = GetComponentInChildren <CapsuleCollider2D>();

            ChangeState(stateIdle = new StateIdle());
            stateWalking          = new StateWalking();

            AddOverseer(new AppearanceOverseer());
        }
Example #11
0
    private StateAttack _stateAttack;//自动追击
    //private _stateBack;

    public void Init(Creature owner)
    {
        _machine   = new StateMachine();
        _owner     = owner;
        _stateIdle = new StateIdle();
        _stateIdle.Init(_owner, _machine);
        _stateAttack = new StateAttack();
        _stateAttack.Init(_owner, _machine);

        _machine.RegisterState(IDLE_NAME, _stateIdle);
        _machine.RegisterState(ATTACK_NAME, _stateAttack);
        _machine.SetDefaultState(IDLE_NAME);
    }
Example #12
0
    // Update is called once per frame
    void Update()
    {
        if (personBubble == null)
        {
            return;
        }
        Vector2 localPoint = StaticData.ManorWorldPointToUICameraAnchorPos(transPersonPointBubble.position);

        personBubble.GetComponent <RectTransform>().anchoredPosition = localPoint;
        if (isBeginAnimByTime)
        {
            currAnimTimeBegin += Time.unscaledDeltaTime;
        }
        //设置对话状态
        if (currAnimTimeBegin >= StaticData.configExcel.GetVertical().ManorTimePlayAnimTimeInterval)
        {
            currAnimTimeBegin = 0f;
            //开始播放
            personBubble.gameObject.SetActive(true);
            //设置内容
            string content = string.Empty;
            //先取针对性的
            int idLocal = -1;
            if (TipsPertinence.Count > 0)
            {
                idLocal = TipsPertinence[TipsPertinence.Count - 1];
                content = StaticData.GetMultilingual(idLocal);
            }
            if (string.IsNullOrEmpty(content))
            {
                //随机
                int randomValue = randomTips.Next(0, maxRandom);
                idLocal = TipsRandom[randomValue];
                content = StaticData.GetMultilingual(idLocal);
            }
            personBubble.SetContent(content, scaleRadio: 1f);
            //播放角色动作
            stateIdle = (StateIdle)randomTips.Next(1, 3 + 1);//1-5
            animatorIdle.Play(stateIdle.ToString());
            isBubbleShow = true;
        }

        if (isBubbleShow)
        {
            currBubbleShowTime += Time.unscaledDeltaTime;
            if (currBubbleShowTime >= StaticData.configExcel.GetVertical().ManorTimeShowBubble)
            {
                CloseBubble();
            }
        }
    }
Example #13
0
    void Start()
    {
        if (m_fsm != null)
        {
            StateMove stateMove = new StateMove();
            StateIdle stateIdle = new StateIdle();
            stateIdle.AddTransition(FSMTransition.MOVE, FSMStateId.STATE_MOVE);
            stateMove.AddTransition(FSMTransition.STOP_MOVE, FSMStateId.STATE_IDLE);
            m_fsm.AddState(stateIdle);
            m_fsm.AddState(stateMove);
            m_fsm.CurrentState = stateIdle;
        }

        m_spatial = gameObject.GetComponent <Spatial>();
        m_fighter = gameObject.GetComponent <Fightable>();
    }
Example #14
0
    void Start()
    {
        if (m_fsm != null)
        {
            StateMove stateMove = new StateMove();
            StateIdle stateIdle = new StateIdle();
            stateIdle.AddTransition(FSMTransition.MOVE, FSMStateId.STATE_MOVE);
            stateMove.AddTransition(FSMTransition.STOP_MOVE, FSMStateId.STATE_IDLE);
            m_fsm.AddState(stateIdle);
            m_fsm.AddState(stateMove);
            m_fsm.CurrentState = stateIdle;
        }

        m_spatial = gameObject.GetComponent<Spatial>();
        m_fighter = gameObject.GetComponent<Fightable>();
    }
	void Awake()
	{
		helicopter		= this.GetComponent<ControllerPlayerHeli>();
		
		idle			= new StateIdle(this);
		lift			= new StateLift(this);
		patrol			= new StatePatrol(this);
		landing			= new StateLanding(this);

		lift.Patrol		= patrol;
		patrol.Landing	= landing;
		patrol.Idle		= idle;
		landing.Idle	= idle;

		currentState = idle;
		idle.OnStateEnter();
	}
Example #16
0
    public override StateBase <Hero> update(Hero hero)
    {
        StateBase <Hero> next = this;

        hero.move();
        if (hero.isLanding)
        {
            next = new StateIdle();
            hero.animCtrl.SetBool("isJumping", false);
        }

        if (hero.want == Hero.wantAction.ATTACK)
        {
            hero.attack();
        }

        return(next);
    }
Example #17
0
        public Enemy()
        {
            sightRadius = 100f;

            //Init states
            idle   = new StateIdle(this);
            chase  = new StateChase(this);
            attack = new StateAttack(this);

            //Linking states NB: questo è brutto
            idle.Chase   = chase;
            chase.Idle   = idle;
            chase.Attack = attack;
            attack.Idle  = idle;
            attack.Chase = chase;

            //Turn on the FSM and set currentstate to idle
            idle.OnStateEnter();
            currentState = idle;
        }
Example #18
0
    public override void Update()
    {
        // start chasing the player
        agent.SetDestination(player.position);

        // check if AI character has finished setting a path to player
        if (agent.hasPath)
        {
            // check if AI is within attack range of player, then move to Attack state
            if (CanAttackPlayer())
            {
                nextState = new StateAttack(npc, agent, anim, player);
                stage     = EVENT.EXIT;
            }
            // if AI lost sight of the player, then exit pursue stat and go Idle
            else if (!CanSeePlayer())
            {
                nextState = new StateIdle(npc, agent, anim, player);
                stage     = EVENT.EXIT;
            }
        }
    }
Example #19
0
    // Use this for initialization
    void Start () {
#if UNITY_EDITOR || UNITY_STANDALONE
        InputPlayer = IsInputPlayer; // Inspector -> Property
#else //SERVER SIDE
        InputPlayer = false;
#endif


        State state = new StateIdle();
        state.Event_OnEnter = StateEvent_OnEnter;
        _dicStates.Add((int)eState.E_IDLE, state);

        state = new StateRun();
        state.Event_OnEnter = StateEvent_OnEnter;
        _dicStates.Add((int)eState.E_RUN, state);

        state = new StateRun();
        state.Event_OnEnter = StateEvent_OnEnter;
        _dicStates.Add((int)eState.E_ATTACK, state);

        SetStateIdle();
    }
Example #20
0
    // Use this for initialization
    void Start()
    {
#if UNITY_EDITOR || UNITY_STANDALONE
        InputPlayer = IsInputPlayer; // Inspector -> Property
#else //SERVER SIDE
        InputPlayer = false;
#endif


        State state = new StateIdle();
        state.Event_OnEnter = StateEvent_OnEnter;
        _dicStates.Add((int)eState.E_IDLE, state);

        state = new StateRun();
        state.Event_OnEnter = StateEvent_OnEnter;
        _dicStates.Add((int)eState.E_RUN, state);

        state = new StateRun();
        state.Event_OnEnter = StateEvent_OnEnter;
        _dicStates.Add((int)eState.E_ATTACK, state);

        SetStateIdle();
    }
Example #21
0
    void Start()
    {
        _type = UnitType.Player;

        _animator  = GetComponent <Animator>();
        _menuPanel = GameObject.FindGameObjectWithTag("Panel");
        _menuFlag  = false;

        InitAbility();

        _stateProcessor = new StateProcessor();
        StateIdle       = new StateIdle();      //待機状態
        StateSelect     = new StateSelect();    //選択状態
        StateMove       = new StateMove();      //移動状態
        StateAttack     = new StateAttack();    //攻撃状態
        StateIntercept  = new StateIntercept(); //傍受状態

        _stateProcessor.State       = StateIdle;
        StateIdle.execDelegate      = IdleUpdate;
        StateSelect.execDelegate    = SelectUpdate;
        StateMove.execDelegate      = MoveUpdate;
        StateAttack.execDelegate    = AttackUpdate;
        StateIntercept.execDelegate = InterceptUpdate;
    }
Example #22
0
    public override void Update()
    {
        // get the directional vector between AI and player
        Vector3 direction = player.position - npc.transform.position;

        // remove vertical component value to avoid tilting AI character
        direction.y = 0;

        // rotate AI character to face player while shooting
        npc.transform.rotation = Quaternion.Slerp(npc.transform.rotation, Quaternion.LookRotation(direction), rotationSpeed * Time.deltaTime);

        // if player is out of AI's attack range but AI can still see them, then move to chasing state
        if (!CanAttackPlayer() && CanSeePlayer())
        {
            nextState = new StatePursue(npc, agent, anim, player);
            stage     = EVENT.EXIT;
        }
        // if AI lost sight of the player, then exit state and go idle
        else if (!CanSeePlayer())
        {
            nextState = new StateIdle(npc, agent, anim, player);
            stage     = EVENT.EXIT;
        }
    }