示例#1
0
文件: Board.cs 项目: Lotti/ggj2018
    private void PopulateCells()
    {
        // populate path cells
        int prevRandom = -1;
        int random;

        for (int i = 0; i < cells.Count; i++)
        {
            do
            {
                random = UnityEngine.Random.Range(0, cells[i].Count);
            } while (prevRandom != -1 && Mathf.Abs(random - prevRandom) <= 2);
            prevRandom = random;

            GameObject c = cells[i][random];
            ISector    s = LocalMap[0];
            alreadyPopulatedCells.Add(i + "-" + random, true);

            GameObject g = (GameObject)Instantiate(Resources.Load(prefabPath + s.prefabName()), Vector3.zero, Quaternion.identity, c.transform);
            g.transform.localPosition = Vector3.zero;
            shipObjectives.Add(g);
            LocalMap.RemoveAt(0);
        }

        // populate other cells
        for (int i = 0; i < cells.Count; i++)
        {
            for (int y = 0; y < cells[i].Count; y++)
            {
                int rand = UnityEngine.Random.Range(0, 3);

                if (!alreadyPopulatedCells.ContainsKey(i + "-" + y) && rand == 0)
                {
                    GameObject c = cells[i][y];
                    ISector    s = GameManager.MapSpawner()[UnityEngine.Random.Range(0, GameManager.MapSpawner().Length)];
                    GameObject g = (GameObject)Instantiate(Resources.Load(prefabPath + s.prefabName()), Vector3.zero, Quaternion.identity, c.transform);
                    g.transform.localPosition = Vector3.zero;
                }
            }
        }
    }