Ejemplo n.º 1
0
        IEnumerable <GameObject> IFactory <int, int, Object, IEnumerable <GameObject> > .Create(int row, int column, Object prefab)
        {
            var parentGO = new GameObject("Walls");

            var wallRow    = row + 2;
            var wallColumn = column + 2;
            var gridCalc   = new GridPositionCalculator(wallRow, wallColumn);
            var wallList   = new List <GameObject>();

            for (int i = 0; i < wallRow; i++)
            {
                if (IsFirstOrLastRow(i, gridCalc.lastRow))
                {
                    for (int j = 0; j < wallColumn; j++)
                    {
                        var wallGO = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
                        Debug.Assert(wallGO.IsValid());

                        wallGO.transform.localPosition = gridCalc.Calc(i, j);
                        wallGO.transform.parent        = parentGO.transform;
                        wallList.Add(wallGO);
                    }
                }
                else
                {
                    var firstColumnWallGO = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
                    Debug.Assert(firstColumnWallGO.IsValid());

                    firstColumnWallGO.transform.localPosition = gridCalc.Calc(i, 0);
                    firstColumnWallGO.transform.parent        = parentGO.transform;
                    wallList.Add(firstColumnWallGO);

                    var lastColumnWallGO = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
                    Debug.Assert(lastColumnWallGO.IsValid());

                    lastColumnWallGO.transform.localPosition = gridCalc.Calc(i, gridCalc.lastColumn);
                    lastColumnWallGO.transform.parent        = parentGO.transform;
                    wallList.Add(lastColumnWallGO);
                }
            }

            return(wallList);
        }
Ejemplo n.º 2
0
        IEnumerable <GameObject> IFactory <int, int, Object, IEnumerable <GameObject> > .Create(int row, int column, Object prefab)
        {
            var parentGO  = new GameObject("Floors");
            var gridCalc  = new GridPositionCalculator(row, column);
            var floorList = new List <GameObject>();

            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < column; j++)
                {
                    var floorGO = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
                    Debug.Assert(floorGO.IsValid());

                    floorGO.transform.localPosition = gridCalc.Calc(i, j);
                    floorGO.transform.parent        = parentGO.transform;
                    floorList.Add(floorGO);
                }
            }

            return(floorList);
        }