Exemple #1
0
    public void Setup(Vector2Int _position, e_squareType _type, e_teams _team)
    {
        position   = _position;
        squareType = _type;
        team       = _team;

        Colorisation();
    }
    public void GenerateMap()
    {
        foreach (Square s in squaresList)
        {
            DestroyImmediate(s.gameObject);
        }

        squaresList.Clear();

        if (map != null)
        {
            mapSize = map.MapSize;
        }
        int current = 0;

        float spriteSize = squarePrefab.GetComponentInChildren <SpriteRenderer>().sprite.bounds.size.x / 2;

        Vector2 mapSpace = new Vector2(sideSpace - spriteSize, sideSpace - spriteSize);

        float step = mapSpace.x * 2 / (mapSize.x - 1);

        startingPoint = new Vector2(-mapSpace.x, step / 2 * (mapSize.y - 1));


        for (int i = 0; i < mapSize.x; i++)
        {
            for (int j = 0; j < mapSize.y; j++)
            {
                GameObject inst = Instantiate(squarePrefab, transform);
                inst.transform.localPosition = new Vector2(startingPoint.x + step * i, startingPoint.y - step * j);

                Square square = inst.GetComponent <Square>();

                e_squareType type = map != null ? map.SquaresList[current].Type : (e_squareType)Random.Range(1, (int)e_squareType.Obstacle + 1);
                e_teams      team = map != null ? map.SquaresList[current].Team : e_teams.Default;

                square.Setup(new Vector2Int(i, j), type, team);
                current++;

                squaresList.Add(square);
            }
        }
    }