Пример #1
0
    public void changeState(string stateName)
    {
        HexGridState newState = State(stateName);

        if (newState == null)
        {
            return;
        }

        state.OnExit(this);
        state = newState;
        state.OnEnter(this);
    }
Пример #2
0
    public override void Awake()
    {
        base.Awake();
        neighbors = new List <HexGrid>();

        //initialize states
        stateList = new List <HexGridState>();
        stateList.Add(new HexGridState());
        stateList.Add(new TokenGridState());
        stateList.Add(new ReachGridState());
        stateList.Add(new EnemyGridState());

        state = State("default");

        //detect grid neighbors
        Vector3 point1 = this.transform.position + Vector3.up * radarHeight;
        Vector3 point2 = this.transform.position + Vector3.down * radarHeight;

        Collider[] detected = Physics.OverlapCapsule(point1, point2, radarRadius, gridLayer);
        foreach (Collider c in detected)
        {
            RaycastCollider collider = c.GetComponent <RaycastCollider>();
            if (collider != null && collider.target is HexGrid && collider.target != this)
            {
                neighbors.Add((HexGrid)collider.target);
            }
        }

        //detect token on top
        detected = Physics.OverlapSphere(this.transform.position, 0.05f, tokenLayer);
        foreach (Collider c in detected)
        {
            Token t = c.transform.GetComponent <Token>();
            token = t;
            if (t != null)
            {
                state   = State("token");
                t.place = this;
                t.transform.position = this.transform.position;
                break;
            }
        }

        state.OnEnter(this);
    }