Beispiel #1
0
    // Public Functions
    // Advance(): Advance to the next state, which is defined by _enumState
    public bool Advance(SCState _enumState)
    {
        if (_enumState.Equals(m_currentEnumState))
        {
            Debug.LogWarning(this.name + ".SquadChildFSM.Advance(): Tried to advance to same state! m_currentEnumState = SC.State." + m_currentEnumState.ToString());
            return(false);
        }

        // State Changing
        m_currentState.Exit();

        m_currentEnumState = _enumState;
        m_currentState     = dict_States[m_currentEnumState];

        m_currentState.Enter();
        return(true);
    }
Beispiel #2
0
    // Start(): Use this for initialisation
    void Start()
    {
        // Initialisation of Dictionary
        dict_States = new Dictionary <SCState, ISCState>();
        dict_States.Add(SCState.Dead, new SC_DeadState(this));
        dict_States.Add(SCState.Idle, new SC_IdleState(this));
        dict_States.Add(SCState.Attack, new SC_AttackState(this));
        dict_States.Add(SCState.Defend, new SC_DefendState(this));
        dict_States.Add(SCState.Produce, new SC_ProduceState(this));
        dict_States.Add(SCState.FindResource, new SC_FindResourceState(this));
        dict_States.Add(SCState.Avoid, new SC_AvoidState(this));

        // Initialisation
        playerPosition   = PlayerMain.Instance.transform.position;
        m_strafingVector = Vector3.up;
        mAnimate         = new Animate(transform);

        fStrafingRadius      = PlayerSquadFSM.Instance.StrafingRadius;
        fStrafingSpeed       = PlayerSquadFSM.Instance.StrafingSpeed;
        fDefenceAngle        = PlayerSquadFSM.Instance.DefenceAngle;
        fDefenceRadius       = PlayerSquadFSM.Instance.DefenceRadius;
        fDefenceSpeed        = PlayerSquadFSM.Instance.DefenceSpeed;
        fDefenceRigidity     = PlayerSquadFSM.Instance.DefenceRigidity;
        nDefenceMinimumCount = PlayerSquadFSM.Instance.DefenceMinimumCount;
        fAttackSpeed         = PlayerSquadFSM.Instance.AttackSpeed;

        mainDefenceVector = Quaternion.Euler(0f, 0f, (fDefenceAngle / 2.0f)) * Vector2.up * fDefenceRadius;

        if (s_list_EnemyLandmine == null)
        {
            s_list_EnemyLandmine = ECTracker.Instance.LandmineCells;
        }

        // Initialisation of first state
        m_currentEnumState = SCState.Dead;
        m_currentState     = dict_States[m_currentEnumState];
        m_currentState.Enter();
    }