Exemplo n.º 1
0
    public void Init(LevelData data = null, Line linePrefab = null)
    {
        if (data)
        {
            InitGrid(data?.Seed);
            //towers
            foreach (TowerData td in data.Towers)
            {
                if (td.IsSwitch)
                {
                    Switch.CreateInstance().CreateFromData(td, this);
                }
                else
                {
                    Tower.CreateInstance().CreateFromData(td, this);
                }
            }
            //lines
            foreach (LineData ld in data.Lines)
            {
                Line l = Instantiate(linePrefab);
                l.CreateFromData(ld, this);
            }
        }
        else
        {
            InitGrid(null);
        }

        GridGenerated?.Invoke(this, this);
    }
Exemplo n.º 2
0
        public void GenerateTiles(Vector2 Start, float tileSpacing)
        {
            LevelManager.Instance.SelectedLevel = LevelManager.Instance.GetNextLevel();

            string[] pattern = LevelManager.Instance.SelectedLevel.Pattern;

            int rows    = pattern.Length;
            int columns = pattern[0].Length;

            var YPositions = new float[rows];
            var XPositions = new float[columns];
            var pieces     = new List <ISquarePiece>(rows * columns);

            for (int x = 0; x < columns; x++)
            {
                for (int y = 0; y < rows; y++)
                {
                    float xPos = Start.x + (x * tileSpacing);
                    float yPos = Start.y - (y * tileSpacing);

                    YPositions[y] = yPos;
                    XPositions[x] = xPos;

                    string     row  = pattern[y];
                    PieceTypes type = (PieceTypes)row[x];

                    if (type == PieceTypes.Empty)
                    {
                        continue;
                    }

                    var piece = GenerateTile(type, xPos, yPos, x, y, true);

                    piece.transform.parent = GridParent;

                    pieces.Add(piece.GetComponent <SquarePiece>());
                }
            }
            PieceManager.Instance.Setup(pieces, XPositions, YPositions);

            GridGenerated?.Invoke();
        }