private void OnTriggerEnter(Collider other) { if (other.gameObject.GetComponent <BoardHolder>() != null) { currentHolder = other.gameObject.GetComponent <BoardHolder>(); } }
//private Transform boardHolder; //A variable to store a reference to the transform of our Board object. //private List <Vector3> gridPositions = new List <Vector3> (); //A list of possible locations to place tiles. //Clears our list gridPositions and prepares it to generate a new board. // void InitialiseList () //{ // //Clear our list gridPositions. // gridPositions.Clear (); // //Loop through x axis (columns). // for(int x = 1; x < columns-1; x++) // { // //Within each column, loop through y axis (rows). // for(int y = 1; y < rows-1; y++) // { // //At each index add a new Vector3 to our list with the x and y coordinates of that position. // gridPositions.Add (new Vector3(x, y, 0f)); // } // } //} //Sets up the outer walls and floor (background) of the game board. void BoardSetup() { //Instantiate Board and set boardHolder to its transform. //boardHolder = new GameObject ("Board").transform; //Loop along x axis, starting from -1 (to fill corner) with floor or outerwall edge tiles. GameObject toInstantiate = floorTiles[Random.Range(0, floorTiles.Length)]; for (int x = 0; x < columns + 1; x++) { //gridPositionsList.Add(new List<GameObject>()); BoardHolder.AddNewRow(); //Loop along y axis, starting from -1 to place floor or outerwall tiles. for (int y = 0; y < rows + 1; y++) { //Field f; //print("gyuyugyu"); //Choose a random tile from our array of floor tile prefabs and prepare to instantiate it. toInstantiate = floorTiles[Random.Range(0, floorTiles.Length)]; //f = new Field(floorTiles[Random.Range(0, floorTiles.Length)]); //Check if we current position is at board edge, if so choose a random outer wall prefab from our array of outer wall tiles. if (x == -1 || x == columns || y == -1 || y == rows) { toInstantiate = outerWallTiles [Random.Range(0, outerWallTiles.Length)]; } //f = new Field(outerWallTiles[Random.Range(0, outerWallTiles.Length)]); //print(x + " " + y); BoardHolder.AddAtTheEnd(toInstantiate, x); //Instantiate the GameObject instance using the prefab chosen for toInstantiate at the Vector3 corresponding to current grid position in loop, cast it to GameObject. //GameObject instance = // Instantiate(toInstantiate, new Vector3(x, y, 0f), Quaternion.identity) as GameObject; //gridPositionsList[x].Add(instance); //Set the parent of our newly instantiated object instance to boardHolder, this is just organizational to avoid cluttering hierarchy. //instance.transform.SetParent (boardHolder); } } BoardHolder.ChangeFieldOn(outerWallTiles[Random.Range(0, outerWallTiles.Length)], 3, 3); }
/* * private void PutTile(int iX, int iY, int iZ) * { * GameObject tile = TPrefabMgr.Instance("Tile1", "Tile1", iX, iY, iZ); * Vector3 objectScl = Vector3.Scale(tile.transform.localScale, new Vector3(c_fTileScale, c_fTileScale, 1.0f)); * tile.transform.localScale = objectScl; * } */ public void BoardInit() { xSize = ySize = 9; // map size _map = new BoardHolder[xSize, ySize]; //_map init for (int i = 0; i < ySize; i++) { for (int j = 0; j < xSize; j++) { _map[i, j] = new BoardHolder(); } } //tile set up bool isLight = true; for (int i = 0; i < ySize; i++) { if (ySize % 2 == 0) { if (isLight == true) { isLight = false; } else { isLight = true; } } for (int j = 0; j < xSize; j++) { if (isLight == true) { _grassLight.transform.position = new Vector3(j * c_nTileLength, 0, i * c_nTileLength); _map[i, j].objList.Add(GameObject.Instantiate(_grassLight)); isLight = false; } else { _grassDark.transform.position = new Vector3(j * c_nTileLength, 0, i * c_nTileLength); _map[i, j].objList.Add(GameObject.Instantiate(_grassDark)); isLight = true; } } } // for statement //int iX = 0; int iY = 0; int iZ = 10; TextAsset data = Resources.Load("stage1", typeof(TextAsset)) as TextAsset; StringReader sr = new StringReader(data.text); // 먼저 한줄을 읽는다. string source = sr.ReadLine(); string[] values; // 쉼표로 구분된 데이터들을 저장할 배열 (values[0]이면 첫번째 데이터 ) while (source != null) { values = source.Split(','); // 쉼표로 구분한다. 저장시에 쉼표로 구분하여 저장하였다. if (values.Length == 0) { sr.Close(); return; } for (int i = 0; i < values.Length; i++) { //0: outer wall, 1:tree, 2:emptyspace, 3:climber, 4:fire, 5:fireman string objname = ""; if (values[i].Equals("0")) { //objname = "OuterWall1"; continue; } else if (values[i].Equals("1")) { //PutTile(iX + i, iY, iZ); objname = "Tree1"; } else if (values[i].Equals("2")) { //PutTile(iX + i, iY, iZ); continue; } else if (values[i].Equals("3")) { //PutTile(iX + i, iY, iZ); objname = "Climber"; } else if (values[i].Equals("4")) { //PutTile(iX + i, iY, iZ); //objname = "Fire"; continue; } else if (values[i].Equals("5")) { //PutTile(iX + i, iY, iZ); objname = "Fireman"; } GameObject obj = TPrefabMgr.Instance(objname, objname, ((i - 1) * c_nTileLength) - (c_nTileLength / 2), iY, (iZ * c_nTileLength) - (c_nTileLength / 2)); Vector3 objectScale = Vector3.Scale(obj.transform.localScale, new Vector3(c_fTileScale, c_fTileScale, c_fTileScale)); obj.transform.localScale = objectScale; } source = sr.ReadLine(); // 한줄 읽는다. iZ--; } /* * xSize = ySize = 8; // map size * _map = new BoardHolder[xSize, ySize]; * * //_map init * for (int i = 0; i < ySize; i++) * for (int j = 0; j < xSize; j++) * _map[i,j] = new BoardHolder (); * * //tile set up * bool isLight = true; * for (int i = 0; i < ySize; i++) { * if (ySize % 2 == 0) { * if (isLight == true) * isLight = false; * else * isLight = true; * } * * for (int j = 0; j < xSize; j++) { * * * if (isLight == true) { * _grassLight.transform.position = new Vector3 (j * 14, 0, i * 14); * _map[i,j].objList.Add(GameObject.Instantiate (_grassLight)); * isLight = false; * } else { * _grassDark.transform.position = new Vector3 (j * 14, 0, i * 14); * _map[i,j].objList.Add(GameObject.Instantiate (_grassDark)); * isLight = true; * } * } * * } // for statement * * * // Determining firefighter's starting point. * List<int> charPositionNumbers = new List<int>(); * charPositionNumbers = GetRandomNumbers(0, xSize, _character._fireMans.Length, null); * charPositionNumbers.Sort (); * * int cnt=0; * charPositionNumbers.ForEach (item => { * * _character._charTextures[cnt].transform.position = new Vector3( item * 14 -7, 0, 7); * _character._charTextures[cnt].transform.localScale = new Vector3( 4,4,4); * _character._fireMans[cnt] = GameObject.Instantiate(_character._charTextures[cnt]); * cnt++; * }); * * * //tree random set up * List<int> treePositionNumbers = new List<int>(); * int mapArea = xSize * ySize - 1; * treePositionNumbers = GetRandomNumbers(0, mapArea, mapArea / 2, charPositionNumbers); * treePositionNumbers.Sort (); * * * treePositionNumbers.ForEach (item => { * int x = item % xSize; * int y = item / xSize; * int ranNum = UnityEngine.Random.Range(0,3); * _tree[ranNum].transform.position = new Vector3( (x)*14-7, 0, (y)*14 + 7); * _tree[ranNum].transform.localScale = new Vector3( 2,2,2); * _map[x, y].objList.Add(GameObject.Instantiate(_tree[ranNum])); * }); * * */ } // BoardInit