private GameObject[,] ResizeMatrix(GameObject[,] matrix, int newCols, int newRows) { GameObject[,] newMatrix = new GameObject[newCols, newRows]; int currentCols = matrix.GetLength(0); int currentRows = matrix.GetLength(1); int maxCols = Mathf.Max(newCols, currentCols); int maxRow = Mathf.Max(newRows, currentRows); for (int i = 0; i < maxCols; i++) { for (int j = 0; j < maxRow; j++) { if (newMatrix.GetLength(0) <= i) { continue; } if (newMatrix.GetLength(1) <= j) { continue; } if (matrix.GetLength(0) <= i) { continue; } if (matrix.GetLength(1) <= j) { continue; } newMatrix[i, j] = matrix[i, j]; } } return(newMatrix); }
GameObject[,] CreateGrid(int x, int y, float distBetweenTiles) { GameObject[,] gridArray = new GameObject[x, y]; int gridX = gridArray.GetLength(0); int gridY = gridArray.GetLength(1); //float cornerCenterX = 0.0f; //float cornerCenterY = 0.0f; float xOffset = 0.0f; float yOffset = 0.0f; for (int i = 0; i < gridY; i++) { xOffset = 0.0f; for (int j = 0; j < gridX; j++) { GameObject newTile = Instantiate(tilePrefab, new Vector3(transform.position.x + xOffset, transform.position.y + yOffset, transform.position.z), transform.rotation) as GameObject; newTile.transform.parent = gameObject.transform; gridArray[j, i] = newTile; xOffset += distBetweenTiles; } yOffset -= distBetweenTiles; } return(gridArray); }
//spawn new grid of gameobjects, each having a single sprite private GameObject SpawnGridFrom(List <Sprite> tiles, Sprite tileContainer) { Vector2 sizeParent = UnityUtils.GetDimensionInPX(tileContainer); Vector2 size = UnityUtils.GetDimensionInPX(tiles[0]); GameObject gridContainer = new GameObject("Grid"); gridContainer.transform.position = this.transform.position; gridContainer.transform.parent = this.transform; int count = 0; GameObject[,] grid = new GameObject[columns, rows]; //TODO: still magic, TBD... for (int y = 0; y < grid.GetLength(1); y++) { for (int x = 0; x < grid.GetLength(0); x++) { string cellName = transform.name + "Cell_" + count + "_[" + x + "," + y + "]"; GameObject cell = SpawnCell(cellName); Vector3 cellPosition = new Vector3(-sizeParent.x / 2 + x * size.x + size.x / 2, sizeParent.y / 2 - (y * size.y + size.y / 2), 0); cell.transform.position = transform.position + (cellPosition * transform.localScale.x); cell.transform.parent = gridContainer.transform; grid[x, y] = cell; SpriteRenderer sr = cell.AddComponent <SpriteRenderer>(); sr.sprite = tiles[count]; sr.sortingLayerName = this.sr.sortingLayerName; sr.sortingOrder += 1; count++; } } return(gridContainer); }
// Sets the map for pathing, must be called before running the pathing. // map: array of tiles // easiestRoute: should the easiest route be located (as little climbing as possible) // heights: list of height values for the cells, in order public void SetMap(GameObject[,] map, bool easiestRoute, List<int> heights) { this.easiestRoute = easiestRoute; resetNodes = new List<Node>(); nextNodes = new List<Node>(); this.width = map.GetLength(0); this.height = map.GetLength(1); this.nodes = new Node[this.width, this.height]; if (easiestRoute) //save heights to nodes for easiest route { for (int y = 0; y < this.height; y++) { for (int x = 0; x < this.width; x++) { nodes[x, y] = new Node(x, y, heights[x + 1 * y + 1]); } } } else { for (int y = 0; y < this.height; y++) { for (int x = 0; x < this.width; x++) { this.nodes[x, y] = new Node(x, y, true); // TRUE = Walkable for all tiles } } } }
// Use this for initialization void Start() { //Should work solely in local space PolygonCollider2D collider = GetComponent <PolygonCollider2D>(); Bounds bounds = collider.bounds; float spacing = 4; float halfSpacing = spacing / 2; Vector2 curPos = new Vector2(bounds.min.x + halfSpacing, bounds.min.y + halfSpacing); GameObject[,] circles = new GameObject[(int)Mathf.Ceil(bounds.size.x) + 1, (int)Mathf.Ceil(bounds.size.y) + 1]; int xIndex = 0; int yIndex = 0; while (curPos.y < bounds.max.y) { curPos.x = bounds.min.x + halfSpacing; xIndex = 0; while (curPos.x < bounds.max.x) { if (collider.OverlapPoint(curPos)) { GameObject circle = GameObject.Instantiate(circleTemplate); //circle.transform.parent = this.transform; circle.transform.position = curPos; circle.transform.localScale = new Vector2(.25f, .25f); circles[xIndex, yIndex] = circle; } curPos.x += spacing; xIndex++; } curPos.y += spacing; yIndex++; } for (int curX = 0; curX < circles.GetLength(0) - 1; curX++) { for (int curY = 0; curY < circles.GetLength(1) - 1; curY++) { if (circles[curX, curY] != null) { GameObject source = circles[curX, curY]; createJoint(source, circles[curX + 1, curY]); createJoint(source, circles[curX + 1, curY + 1]); createJoint(source, circles[curX, curY + 1]); if (curY > 0) { createJoint(source, circles[curX + 1, curY - 1]); } } } } }
// Runs only once at the time of the game initialization public void Awake() { RowCount = 4; ColCount = 4; Scale = Utility.Component.GetScale(RowCount, ColCount); cornerParentTransform = cornerParent.GetComponent <Transform>(); hEdgeParentTransform = hEdgeParent.GetComponent <Transform>(); vEdgeParentTransform = vEdgeParent.GetComponent <Transform>(); boxParentTransform = boxParent.GetComponent <Transform>(); Corner = new GameObject[RowCount + 1, ColCount + 1]; HEdge = new GameObject[RowCount + 1, ColCount]; VEdge = new GameObject[RowCount, ColCount + 1]; Box = new GameObject[RowCount, ColCount]; for (int row = 0; row < Corner.GetLength(0); row++) { for (int col = 0; col < Corner.GetLength(1); col++) { Corner[row, col] = InstantiateCorner(row, col); } } for (int row = 0; row < HEdge.GetLength(0); row++) { for (int col = 0; col < HEdge.GetLength(1); col++) { HEdge[row, col] = InstantiateHEdge(row, col); } } for (int row = 0; row < VEdge.GetLength(0); row++) { for (int col = 0; col < VEdge.GetLength(1); col++) { VEdge[row, col] = InstantiateVEdge(row, col); } } for (int row = 0; row < Box.GetLength(0); row++) { for (int col = 0; col < Box.GetLength(1); col++) { Box[row, col] = InstantiateBox(row, col); } } CompleteBoxCount = 0; transform.position += App.GridPosition.Offset; GameLogic.Setup(this); }
private GameObject[,] MirrorMatrixOnY(GameObject[,] oldMatrix) { GameObject[,] newMatrix = new GameObject[oldMatrix.GetLength(0), oldMatrix.GetLength(1)]; for (int i = 0; i < newMatrix.GetLength(0); i++) { for (int j = 0; j < newMatrix.GetLength(1); j++) { newMatrix[i, j] = oldMatrix[i, oldMatrix.GetLength(1) - j - 1]; } } return(newMatrix); }
public static sCell[,] getSerArray(GameObject[,] cellArray) { sCell[,] ser = new sCell[cellArray.GetLength(0), cellArray.GetLength(1)]; for (int x = 0; x < ser.GetLength(0); x++) { for (int y = 0; y < ser.GetLength(1); y++) { ser[x, y] = new sCell(cellArray[x, y]); } } return ser; }
static GameObject[,] CopierTableau(GameObject[,] tableauACopie) { GameObject[,] TableauCopie = new GameObject[tableauACopie.GetLength(0), tableauACopie.GetLength(1)]; for (int i = 0; i < TableauCopie.GetLength(0); i++) { for (int j = 0; j < TableauCopie.GetLength(1); j++) { TableauCopie[i, j] = tableauACopie[i, j]; } } return(TableauCopie); }
// Start is called before the first frame update void Start() { Graph mazeGraph = new Graph(5, 5); //create a graph that represents the maze we're making Graph.Node[,] maze = mazeGraph.makeUST(); /*//for debug below * Graph.Node[,] maze = new Graph.Node[5,5]; * for(int i=0;i<5; i++) * { * for (int j=0;j<5;j++) * { * maze[i, j] = new Graph.Node(i, j); * if(i!=4) maze[i, j].rightEdge = true; * if(j!=4) maze[i, j].upEdge = true; * } * } * * //for debug above*/ GameObject[,] tiles = new GameObject[maze.GetLength(0), maze.GetLength(1)]; //make an array of maze tiles, their indeices correponding to the maze matrix. for (int i = 0; i < maze.GetLength(0); i++) //create the maze, initializing only the heart { float tilePosX = mazeLeftLimit + i * (completeTileSideLength + gapBetweenTile) + (0.5f) * completeTileSideLength; for (int j = 0; j < maze.GetLength(1); j++) { float tilePosZ = mazeSouthLimit + j * (completeTileSideLength + gapBetweenTile) + (0.5f) * completeTileSideLength; Vector3 location = new Vector3(tilePosX, yOffset, tilePosZ); tiles[i, j] = Instantiate(completeTile, location, completeTile.transform.rotation); } } for (int i = 0; i < tiles.GetLength(0); i++) { for (int j = 0; j < tiles.GetLength(1); j++) { GameObject thisTile = tiles[i, j]; //thisTile and thisNode are corresponding Graph.Node thisNode = maze[i, j]; if (thisNode.rightEdge) //if this node has a right edge { thisTile.transform.GetChild((int)TileChildren.EAST).gameObject.SetActive(true); //activate the right extension of this tile tiles[i + 1, j].transform.GetChild((int)TileChildren.WEST).gameObject.SetActive(true); //activate the left extension of the game object on the right side } if (thisNode.upEdge) //if this node has an up (north) edge { thisTile.transform.GetChild((int)TileChildren.NORTH).gameObject.SetActive(true); //activate the up extension of this tile tiles[i, j + 1].transform.GetChild((int)TileChildren.SOUTH).gameObject.SetActive(true); //activate the south extension of the tile to the north //this would not cause out of bound since there wouldn't be an edge in that direction to start with } } } mazeController.GetComponent <MazeControl>().initialize(tiles); //initialize the maze controller who will keep track of whether the maze is still solvable }
GameObject[,] OrganizaGOs(GameObject[] Gs) { Vector3 T = Gs[0].transform.position; int xMax = (int)T.x; int xMin = (int)T.x; int zMax = (int)T.z; int zMin = (int)T.z; for (int i = 0; i < Gs.Length; i++) { T = Gs[i].transform.position; if (T.x > xMax) { xMax = (int)T.x; } if (T.x < xMin) { xMin = (int)T.x; } if (T.z > zMax) { zMax = (int)T.z; } if (T.z < zMin) { zMin = (int)T.z; } } GameObject[,] meusGs = new GameObject[(xMax - xMin) / 10 + 1, (zMax - zMin) / 10 + 1]; Debug.Log("o tamanho é " + meusGs.GetLength(0) + " : " + meusGs.GetLength(1)); for (int i = 0; i < Gs.Length; i++) { if (Gs[i].transform.localScale == new Vector3(10, 10, 10)) { T = Gs[i].transform.position; Debug.Log((((int)T.x - xMin) / 10) + " :" + (((int)T.z - zMin) / 10)); meusGs[((int)T.x - xMin) / 10, ((int)T.z - zMin) / 10] = Gs[i]; } } return(meusGs); }
public override void Initialise() { board = new GameObject[6, 7]; //Each child of this transform contains a column of counter gameobjects for (int x = 0; x < board.GetLength(1); x++) { for (int y = 0; y < board.GetLength(0); y++) { board[y, x] = transform.GetChild(x).GetChild(y).gameObject; board[y, x].SetActive(false); } } //Set the board to represent a new Connect 4 game state SetBoard(new C4Board()); }
void InspectArray(GameObject[,] gos) { int columns = gos.GetLength(0); Debug.Log("Columns: " + columns); int rows = gos.GetLength(1); Debug.Log("Rows: " + rows); for (int c = 0; c < columns; c++) { for (int r = 0; r < rows; r++) { Debug.Log(gos [c, r].name); } } }
//protected string[,] blueprint; //public string[,] getBlueprint() //{ // initBlueprint(); // return BoardUtilities.flipStringTableCoord(blueprint); //} //protected virtual void initBlueprint() //{ // blueprint = new string[,] { // { ___, ___, ___, ___, ___, ___ }, // { ___, ___, ___, ___, ___, ___ }, // { ___, ___, ___, ___, ___, ___ }, // { ___, ___, ___, ___, ___, ___ }, // { ___, ___, ___, ___, ___, ___ }, // { ___, ___, ___, ___, ___, ___ }, // { ___, ___, ___, ___, ___, ___ } // }; //} protected GameObject[,] FlipTableCoord(GameObject[,] originalT) { /*flip the inner and outer array, so the table has same coord as the gameboard*/ /*flip y axis to match unity coord*/ GameObject[,] targetT = new GameObject[originalT.GetLength(1), originalT.GetLength(0)]; int column = targetT.GetLength(0); int row = targetT.GetLength(1); for (int c = 0; c < column; c++) { for (int r = 0; r < row; r++) { targetT[c, r] = originalT[row - 1 - r, c]; } } return(targetT); }
IEnumerator shuffle() { //shuffle board warning.SetTrigger("ShowWarning"); yield return(new WaitForSeconds(0.5f)); // Create a second array GameObject[,] board2 = new GameObject[(int)BoardSize.x, (int)BoardSize.y * 2]; // in this array store the new tiles at random for (int x = 0; x < board.GetLength(0); x++) { for (int y = 0; y < (board.GetLength(1) / 2); y++) { do { int newX = Random.Range(0, board2.GetLength(0)); int newY = Random.Range(0, board2.GetLength(1) / 2); if (board2[newX, newY] == null) { board2[newX, newY] = board[x, y]; board2[newX, newY].GetComponent <TileController>().location = new Vector2(newX, newY); break; } }while(true); } } for (int x = 0; x < board.GetLength(0); x++) { for (int y = 0; y < (board.GetLength(1) / 2); y++) { board2[x, y].GetComponent <TileController>().updateTilePosition(); } } // assign the main array as this array board = board2; DoneShuffeling = true; moveTilesIntoPos(); StartCoroutine(ScanBoard()); }
public GameObject[,] GetBoardLayoutBg() { GameObject[,] targetT = new GameObject[layout.GetLength(0), layout.GetLength(1)]; int column = targetT.GetLength(0); int row = targetT.GetLength(1); for (int c = 0; c < column; c++) { for (int r = 0; r < row; r++) { //mark empty unit as XXX, otherwise kept null as default if (layout[c, r] == XXX) { targetT[c, r] = XXX; } } } return(FlipTableCoord(targetT)); }
public void Start() { //Creates 3D array of gameobjects GameObject[,,] GameObjectArray3D = new GameObject[100, 1, 100]; //Loop through all the array indexes and instantiate a simple Cube for (int x = 0; x < GameObjectArray3D.GetLength(0); x++) { for (int y = 0; y < GameObjectArray3D.GetLength(1); y++) { for (int z = 0; z < GameObjectArray3D.GetLength(2); z++) { //Cubes are placed to create a grid to work on GameObjectArray3D[x, y, z] = GameObject.CreatePrimitive(PrimitiveType.Cube); //Sets the positon of the new object to the x,y,z of the current array index GameObjectArray3D[x, y, z].transform.position = new Vector3(x, y, z); } } } }
public void PerformCheck(GameObject[,] List) { for (int i = 0; i < List.GetLength(0); i++) { List<GameObject> toDelete = new List<GameObject>(); for (int j = 0; j < List.GetLength(1); j++) { if ((j + 1 < List.GetLength(1) && List[i, j].tag == List[i, j + 1].tag) || (toDelete.Count > 0 && toDelete[toDelete.Count-1].tag == List[i,j].tag)) { toDelete.Add(List[i, j]); //Debug.Log("Got match at " + AllTilesY[k, l] + " and " + AllTilesY[k, l + 1]); } else if (toDelete.Count >= 3) { Debug.Log("Got a chain of " + toDelete.Count); Found(toDelete); } else toDelete = new List<GameObject>(); } } }
/// <summary> /// Instances terrain tiles to display, from terrain data in pre-loaded chunks, based on the tilemap's focus coordinates on the world map. /// </summary> /// <param name="offset">Can instance tiles offset from the focus coordinates by the given offset vector. Vector2.zero would be no offset. Probably not required /// in the current tile map implementation.</param> private void Refresh(Vector2 offset) { GameObject tileInstance; Vector2 tilePos = Vector2.zero; Vector2 focusPos = screenManager.GetScreenPositionAt(Focus); GameObject[,] buffer = new GameObject[viewableTileDimensions.X, viewableTileDimensions.Y]; for (int i = 0; i < buffer.GetLength(0); i++) { for (int j = 0; j < buffer.GetLength(1); j++) { //The position to place the tile is the lower left corner (0,0) plus the indices in units tilePos = focusPos + offset - new Vector2(viewableTileDimensions.I / 2 - i, viewableTileDimensions.J / 2 - j); tileInstance = Instantiate(worldManager.GetTilePrefab(GetCoordinates(new IntegerPair(i, j))), tilePos, Quaternion.identity, tileCollection.transform); buffer[i, j] = tileInstance; } } DestroyTileArray(); tileMap.tileArray = buffer; }
public void InstantiateWeapons() { if (entity.IsOwner) { WeaponsAvailable = 4; CurrentWeaponNumber = 0; GameObject[] WeaponsToInstantiate = new GameObject[4]; WeaponsToInstantiate[0] = loadoutManager.Loadouts[loadoutManager.LoadoutChosen].Primary; WeaponsToInstantiate[1] = loadoutManager.Loadouts[loadoutManager.LoadoutChosen].Secondary; WeaponsToInstantiate[2] = loadoutManager.Loadouts[loadoutManager.LoadoutChosen].Lethal; WeaponsToInstantiate[3] = loadoutManager.Loadouts[loadoutManager.LoadoutChosen].NonLethal; for (int i = 0; i < WeaponsToInstantiate.GetLength(0); i++) { Weapons[i] = Instantiate(WeaponsToInstantiate[i], WeaponStruct.transform.position, Quaternion.identity); Weapons[i].transform.SetParent(WeaponStruct.transform); Weapons[i].transform.rotation = Quaternion.Euler(WeaponsToInstantiate[i].GetComponent <Weapon>().CorrectRotation); Weapons[i].transform.localRotation = Quaternion.Euler(WeaponsToInstantiate[i].GetComponent <Weapon>().CorrectRotation); Weapons[i].layer = LayerMask.NameToLayer("Weapon"); for (int j = 0; j < Weapons[i].transform.childCount; j++) { Transform Child = Weapons[i].transform.GetChild(j); Child.gameObject.layer = LayerMask.NameToLayer("Weapon"); for (int k = 0; k < Child.childCount; k++) { Child.GetChild(k).gameObject.layer = LayerMask.NameToLayer("Weapon"); } } Weapons[i].transform.localPosition = Weapons[i].GetComponent <Weapon>().HipPosition; Weapons[i].SetActive(false); } Weapons[0].SetActive(true); CurrentWeapon = Weapons[0].GetComponent <Weapon>(); } }
//窗口控件初始化 protected override void InitWidget() { this.ClearWindowData(); mPopupListBtn = mRoot.Find("SelectKind/PopupList").GetComponent <UIButton>(); mScroll = mRoot.Find("RuneScrollView").GetComponent <UIScrollView>(); mGrid = mRoot.Find("RuneScrollView/OptionItems").GetComponent <UIGrid>(); m_PopList_Label = mRoot.Find("SelectKind/PopupList/Label").GetComponent <UILabel>(); EventDelegate.Add(mPopupListBtn.onClick, OnShowLevel); if (!mScroll.gameObject.activeInHierarchy) { mScroll.gameObject.SetActive(true); } m_RuneLevelGo = mRoot.Find("SelectKind/RuneLevel").gameObject; mResident = true; m_LevelLabelArray = new GameObject[GameDefine.GameConstDefine.MaxRuneLevel]; string resFile = "SelectKind/RuneLevel/Level"; for (int i = 0; i < m_LevelLabelArray.GetLength(0); ++i) { string indexStr = Convert.ToString(i); string filename = resFile + indexStr; GameObject levelGo = mRoot.Find(filename).gameObject; levelGo.name = indexStr; UIEventListener.Get(levelGo).onClick += onClickLevel; m_LevelLabelArray[i] = levelGo; } LoadRunes(); }
//----------------------------------------- Para el manejo del nivel ----------------------------------------------- private void ShuffleInPlace(GameObject[] source) { //Shuffle dentro de un array for (int inx = source.GetLength(0)-1; inx > 0; --inx) { int position = UnityEngine.Random.Range(0, source.GetLength(0)-1); GameObject temp = source[inx]; source[inx] = source[position]; source[position] = temp; } }
void Start() { GameObject[] paredes = GameObject.FindGameObjectsWithTag("Simulation"); GameObject[,] cubos_suelo = new GameObject[0, 0]; GameObject initPath = new GameObject(); int randomInits = Random.Range(3, 7); // Numero de caminos Debug.Log(randomInits); Vector3[] init_pathes = new Vector3[randomInits]; for (int i = 0; i < paredes.Length; i++) { if (paredes[i].transform.eulerAngles == Vector3.zero) { cubos_suelo = paredes[i].GetComponent <Game_Grid>().cubos_matrix; Debug.Log(paredes[i].gameObject.name); Debug.Log(cubos_suelo[3, 3].transform.eulerAngles); } } int filasB = Random.Range(0, cubos_suelo.GetLength(0)); int columnasB = Random.Range(0, cubos_suelo.GetLength(1)); Instantiate(flag, cubos_suelo[filasB, columnasB].transform.position, Quaternion.identity); for (int i = 0; i < init_pathes.Length; i++) { //int filas = Random.Range(0, cubos_suelo.GetLength(0)); //int columnas = Random.Range(0, cubos_suelo.GetLength(1)); int filas = Random.Range(0, cubos_suelo.GetLength(0)); int columnas = Random.Range(0, cubos_suelo.GetLength(1)); //init_pathes[0] = cubos_suelo[filas, columnas].transform.position; cubos_suelo[filas, columnas].GetComponent <Renderer>().material.color = Color.blue; //init_pathes[i] = cubos_suelo[filas, columnas].transform.position; //cubos_suelo[filas, columnas].GetComponent<Renderer>().material.color = Color.blue; int counter = 0; while (!((filas == filasB) && (columnas == columnasB))) { int random1 = Random.Range(0, 10); int random2 = Random.Range(0, 10); int random3 = Random.Range(0, 10); //No ejecutar random3 más de una vez seguida if ((filasB - filas) > 0 && random1 > 5) { filas++; } else if ((filasB - filas) < 0 && random1 > 5) { filas--; } if ((columnasB - columnas) > 0 && random2 > 5) { columnas++; } else if ((columnasB - columnas) < 0 && random2 > 5) { columnas--; } if (((filas == filasB) && (columnas == columnasB))) { break; } //path.Add(cubos_suelo[filas, columnas]); //path[counter].GetComponent<Renderer>().material.color = Color.magenta; //if(random3 > 7) // cubos_suelo[filas, columnas].GetComponent<Renderer>().material.color = Color.yellow; if (random3 < 7) { cubos_suelo[filas, columnas].GetComponent <Renderer>().material.color = Color.magenta; //path[counter].transform.localScale = new Vector3(path[counter].transform.localScale.x, // 3.0f * counter, path[counter].transform.localScale.z); cubos_suelo[filas, columnas].transform.localScale = new Vector3(cubos_suelo[filas, columnas].transform.localScale.x, 3.0f * counter, cubos_suelo[filas, columnas].transform.localScale.z); counter++; //cubos_suelo[filas, columnas].GetComponent<Renderer>().material.color = Color.magenta; } //else //{ // cubos_suelo[filas, columnas].GetComponent<Renderer>().material.color = Color.yellow; // counter++; //} } } //int filas = Random.Range(0, cubos_suelo.GetLength(0)); //int columnas = Random.Range(0, cubos_suelo.GetLength(1)); //int filasB = Random.Range(0, cubos_suelo.GetLength(0)); //int columnasB = Random.Range(0, cubos_suelo.GetLength(1)); //Instantiate(flag, cubos_suelo[filasB, columnasB].transform.position, Quaternion.identity); ////init_pathes[0] = cubos_suelo[filas, columnas].transform.position; //cubos_suelo[filas, columnas].GetComponent<Renderer>().material.color = Color.blue; //List<GameObject> path = new List<GameObject>(); //path.Add(cubos_suelo[filas, columnas]); //int counter = 0; //while (!((filas == filasB) && (columnas == columnasB))) //{ // int random1 = Random.Range(0, 10); // int random2 = Random.Range(0, 10); // int random3 = Random.Range(0, 10); // if ((filasB - filas) > 0 && random1 > 5) // { // filas++; // } // else if((filasB - filas) < 0 && random1 > 5) // { // filas--; // } // if ((columnasB - columnas) > 0 && random2 > 5) // { // columnas++; // } // else if((columnasB - columnas) < 0 && random2 > 5) // { // columnas--; // } // if(((filas == filasB) && (columnas == columnasB))) // { // break; // } // //path.Add(cubos_suelo[filas, columnas]); // //path[counter].GetComponent<Renderer>().material.color = Color.magenta; // if(random3 < 7) // { // cubos_suelo[filas, columnas].GetComponent<Renderer>().material.color = Color.magenta; // //path[counter].transform.localScale = new Vector3(path[counter].transform.localScale.x, // // 3.0f * counter, path[counter].transform.localScale.z); // cubos_suelo[filas, columnas].transform.localScale = new Vector3(cubos_suelo[filas, columnas].transform.localScale.x, // 3.0f * counter, cubos_suelo[filas, columnas].transform.localScale.z); // counter++; // //cubos_suelo[filas, columnas].GetComponent<Renderer>().material.color = Color.magenta; // } // else // { // cubos_suelo[filas, columnas].GetComponent<Renderer>().material.color = Color.yellow; // counter++; // } //} //for (int i = 0; i < path.Capacity; i++) //{ // path[i].GetComponent<Renderer>().material.color = Color.magenta; // path[i].transform.localScale += new Vector3(0, // 3.0f * i, 0); // Debug.Log("HELLO"); //} }
public void Bake() { //Clean previous entity List <Entity> tmpEntities = FindObjectsOfType <Entity>().ToList(); List <GameObject> entities = new List <GameObject>(); foreach (Entity entity in tmpEntities) { if (!entities.Contains(entity.gameObject)) { entities.Add(entity.gameObject); } } List <GameObject> previousEntities = new List <GameObject>(); foreach (GameObject e in entities) { if (e.GetComponent <GraphNodeComponent>()) { previousEntities.Add(e); } } foreach (GameObject e in previousEntities) { DestroyImmediate(e); } //Get bounds int graphWidth = Mathf.Abs(tilemap.cellBounds.xMin - tilemap.cellBounds.xMax); int graphHeight = Mathf.Abs(tilemap.cellBounds.yMin - tilemap.cellBounds.yMax); tilemap.CompressBounds(); //Build graph //Create new graph GameObject[,] graph = new GameObject[graphWidth, graphHeight]; int indexX = 0; int indexY = 0; foreach (Vector3Int pos in tilemap.cellBounds.allPositionsWithin) { Vector3Int localPlace = new Vector3Int(pos.x, pos.y, pos.z); Vector3 place = tilemap.CellToWorld(localPlace); if (tilemap.HasTile(localPlace) && !buildingTilemap.HasTile(localPlace)) { if (!solidTiles.Contains(tilemap.GetTile(localPlace))) { GameObject tmp = new GameObject { name = "Node[" + indexX + "." + indexY + "]" }; tmp.AddComponent <GraphNodeComponent>(); int cost = 0; foreach (TileCost costTile in costTiles) { if (costTile.tileBase == tilemap.GetTile(localPlace)) { cost = costTile.cost; } } tmp.GetComponent <GraphNodeComponent>().cost = cost; tmp.GetComponent <GraphNodeComponent>().neighbors = new List <GameObject>(); tmp.AddComponent <Entity>(); tmp.transform.position = tilemap.GetCellCenterWorld(localPlace); tmp.GetComponent <GraphNodeComponent>().position = tmp.transform; graph[indexX, indexY] = tmp; tmp.transform.SetParent(transform); } } indexX++; if (indexX >= graph.GetLength((0))) { indexX = 0; indexY++; } } BoundsInt bounds = new BoundsInt(-1, -1, 0, 3, 3, 1); //Get All neighbors for (int x = 0; x < graphWidth; x++) { for (int y = 0; y < graphHeight; y++) { //If is a walkable tile => Add neighbors if (graph[x, y] == null) { continue; } foreach (Vector3Int b in bounds.allPositionsWithin) { //Check that b is not himself as a node if (b.x == 0 && b.y == 0) { continue; } //Check if b is inside bounds of graph if (b.x + x < 0 || b.x + x >= graphWidth || b.y + y < 0 || b.y + y >= graphHeight) { continue; } //Check if neighbors node is walkable if (graph[x + b.x, y + b.y] == null) { continue; } //Add cross without check if (b.x == 0 || b.y == 0) { graph[x, y].GetComponent <GraphNodeComponent>().neighbors.Add(graph[x + b.x, y + b.y]); } else //Else add only if both corner are free { if (graph[x, y + b.y] != null && graph[x + b.x, y] != null) { graph[x, y].GetComponent <GraphNodeComponent>().neighbors.Add(graph[x + b.x, y + b.y]); } } } } } }
public GameObject[,] genLip(GameObject[,] world, GameObject tarTile, GameObject replaceTile, GameObject neighborTile) { GameObject[,] returnWorld = world; Debug.Log ("Lip Generating"); for (int x = 0; x < world.GetLength (0); x++) { for (int y = 0; y < world.GetLength (1); y++) { Debug.Log ("X:" + x + ", Y:" + y); GameObject tile = world [x, y]; if (tile.CompareTag(tarTile.tag)) { if (y - 1 >= 0 && neighborTile.CompareTag(world[x,y-1].tag) ) { Debug.Log ("Replacing... Y-1"); Destroy(world[x,y]); returnWorld [x, y] = Instantiate (replaceTile); } else if (x - 1 >= 0 && neighborTile.CompareTag(world[x-1,y].tag) ) { Debug.Log ("Replacing... X-1"); Destroy(world[x,y]); returnWorld [x, y] = Instantiate (replaceTile); } else if (x + 1 < world.GetLength(0) && neighborTile.CompareTag(world[x+1,y].tag) ) { Debug.Log ("Replacing... X+1"); Destroy(world[x,y]); returnWorld [x, y] = Instantiate (replaceTile); } else if (y + 1 < world.GetLength(1) && neighborTile.CompareTag(world[x,y+1].tag) ) { Debug.Log ("Replacing... Y+1"); Destroy(world[x,y]); returnWorld [x, y] = Instantiate (replaceTile); } } } } return returnWorld; }
GameObject random_building(GameObject[] gameoblist) { int total=gameoblist.GetLength(0); int pick=(int)(total*Random.value); return gameoblist[pick]; }
//判定 public void hantei(GameObject[,] haiti, int hakosu, int combosu, GameObject[,] deshako, string koname) { //hakosu int[] kanri = new int[30]; GameObject[,] haitiko = new GameObject[haiti.GetLength(0), haiti.GetLength(1)]; for (int i = 0; i < haiti.GetLength(0); i++) { for (int j = 0; j < haiti.GetLength(1); j++) { foreach (Transform child in haiti[i, j].transform) { koname = child.name; } haitiko[i, j] = haiti[i, j].transform.FindChild(koname).gameObject; } } //haiti[i,j] 動かしたところ //deshakoの配列の長 hakosu = 0; combosu = 0; //縦にそろってた時 for (int j = 0; j < haitiko.GetLength(1); j++) { bool itido = false; for (int i = 0; i < haitiko.GetLength(0); i++) { if (itido == false) { int suu = 0; int c = i + 1; bool sw = false; //縦探索 if (i == 0 || i == 1 || i == 2) { while (sw == false && c < haiti.GetLength(0)) { if (haitiko[i, j].tag == haitiko[c, j].tag) { suu++; if (suu > 1) { if (itido == false) { deshako[combosu, hakosu] = haitiko[i, j]; hakosu++; deshako[combosu, hakosu] = haitiko[i + 1, j]; hakosu++; //コンボが++; //コンボが決まっているので列は探索しない itido = true; } deshako[combosu, hakosu] = haitiko[c, j]; hakosu++; } } else { //脱出 sw = true; } c++; } } } } if (itido == true) { //はこの長さを格納 kanri[combosu] = hakosu; combosu++; //箱の要素数リセット hakosu = 0; } } //ただの横探索。 for (int i = 0; i < haiti.GetLength(0); i++) { bool itido = false; for (int j = 0; j < haiti.GetLength(1); j++) { if (itido == false) { int c = j + 1; bool sw = false; //3個以上並ぶとなので int suu = 0; switch (j) { case 0: //とりあえず case 1: case 2: case 3: while (sw == false && c < haiti.GetLength(1)) { if (haitiko[i, j].tag == haitiko[i, c].tag) { suu++; if (suu > 1) { if (itido == false) { deshako[combosu, hakosu] = haitiko[i, j]; hakosu++; deshako[combosu, hakosu] = haitiko[i, j + 1]; hakosu++; //コンボが++; //コンボが決まっているので列は探索しない itido = true; } deshako[combosu, hakosu] = haitiko[i, c]; hakosu++; } } else { sw = true; } c++; } break; } } } if (itido == true) { //はこの長さを格納 kanri[combosu] = hakosu; combosu++; //箱の要素数リセット hakosu = 0; } } //オブジェクトを消す bool otosw = false; for (int a = 0; a < combosu; a++) { bool sw = false; for (int b = 0; b < kanri[a]; b++) { //一回だけ if (sw == false) { //0のところがnullじゃないやつ if (deshako[a, b] != null) { //コンボ数を数える //これが実際に表示される奴 GameObject[] se = new GameObject[2]; Text te; se[0] = (GameObject)Instantiate(comboobj, deshako[a, b + 1].transform.position, deshako[a, b + 1].transform.rotation); //このゲームオブジェクトの中身を調べ、そこのテキストにbusを代入 se[1] = se[0].transform.FindChild("coT").gameObject; te = se[1].GetComponent <Text>(); te.text = (bsu + 1) + "combo"; bsu++; //消したよというのをお知らせ seisei.kesu = true; //コンボの表示 //初回だけ音 if (otosw == false) { aud.SEo1(); otosw = true; } } sw = true; } if (deshako[a, b] != null) { //それぞれタグごとに攻撃力に加算してから Kou.tagcheckkou(deshako[a, b]); Instantiate(pat, new Vector2((deshako[a, b].transform.position.x + 0.5f), (deshako[a, b].transform.position.y - 0.5f)), deshako[a, b].transform.rotation); //消す Destroy(deshako[a, b]); } } } botanstate = 0; }
public void ParseLevel() { foreach (var go in m_objects) { Destroy(go); } m_objects = new List <GameObject>(); m_text.text = string.Empty; string path = m_input.text; if (!path.EndsWith(".pac")) { path = path + ".pac"; } m_input.text = path; path = Path.Combine(@"Assets\levels", path); if (!File.Exists(path)) { m_text.text += "file not available!" + Environment.NewLine; return; } Tile[,] tiles = new Tile[0, 0]; //int[] characterPositions = new int[10]; List <Vector3> charpos; m_text.text += "parsing started:" + Environment.NewLine; string level, figures; if (Parser.IsValidLevel(path, out level, out figures, ref m_text)) { m_text.text += Environment.NewLine + "start building" + Environment.NewLine; tiles = Parser.ParseValidLevel(level, ref m_text); //characterPositions = Parser.getCharacterPositions(figures); charpos = Parser.GetCharPositions(); m_text.text += " got positions" + Environment.NewLine; m_text.text += level + Environment.NewLine; } else { m_input.text = "level structure not valid" + Environment.NewLine; return; } GameObject[,] objs = new GameObject[tiles.GetLength(0), tiles.GetLength(1)]; // build prefabs for (int r = 0; r < tiles.GetLength(0); r++) { for (int c = 0; c < tiles.GetLength(1); c++) { Vector3 pos = new Vector3(c, 0f, -r); Quaternion rot = Quaternion.Euler(0f, tiles[r, c].Rotation, 0f); GameObject go = null; #region switch switch (tiles[r, c].Type) { case Tile.Element.Block: go = Block; break; case Tile.Element.Corner: go = Corner; break; case Tile.Element.Corridor: go = Corridor; break; case Tile.Element.Cross: go = Cross; break; case Tile.Element.Deadend: go = DeadEnd; break; case Tile.Element.TCross: go = TCross; break; default: break; } #endregion var inst = Instantiate(go, pos, rot); m_objects.Add(inst); objs[r, c] = inst; } } m_text.text += "level building finished w/success" + Environment.NewLine; for (int r = 0; r < tiles.GetLength(0); r++) { for (int c = 0; c < tiles.GetLength(1); c++) { if (tiles[r, c].ltrb_open[0]) { objs[r, c].GetComponent <WayPoint>().leftWaypoint = objs[r, c - 1].GetComponent <WayPoint>(); } if (tiles[r, c].ltrb_open[1]) { objs[r, c].GetComponent <WayPoint>().upWaypoint = objs[r - 1, c].GetComponent <WayPoint>(); } if (tiles[r, c].ltrb_open[2]) { objs[r, c].GetComponent <WayPoint>().rightWaypoint = objs[r, c + 1].GetComponent <WayPoint>(); } if (tiles[r, c].ltrb_open[3]) { objs[r, c].GetComponent <WayPoint>().downWaypoint = objs[r + 1, c].GetComponent <WayPoint>(); } } } m_text.text += "added waypoints to GameObjects" + Environment.NewLine; for (int i = 0; i < charpos.Count; i++) { m_text.text += " char pos fig " + (i + 1) + ": " + charpos [i].x + " " + charpos [i].y + " " + charpos [i].z + objs[(int)charpos[0].x, -(int)charpos[0].z].GetComponent <WayPoint>() + Environment.NewLine; } m_text.text += "" + objs.GetLength(0) + " - " + objs.GetLength(1) + " / " + objs.Length; transform.position = new Vector3((tiles.GetLength(1) - 1) / 2f, 10, -(tiles.GetLength(0) - 1) / 2f); Pacman = Instantiate(Pacman, charpos[0], qempty); Blinky = Instantiate(Blinky, charpos[1], qempty); Inky = Instantiate(Inky, charpos[2], qempty); Pinky = Instantiate(Pinky, charpos[3], qempty); Clyde = Instantiate(Clyde, charpos[4], qempty); Pacman.transform.position = charpos[0]; Blinky.transform.position = charpos[1]; Inky.transform.position = charpos[2]; Pinky.transform.position = charpos[3]; Clyde.transform.position = charpos[4]; m_objects.Add(Pacman); m_objects.Add(Blinky); m_objects.Add(Inky); m_objects.Add(Pinky); m_objects.Add(Clyde); //Pacman = Instantiate(Pacman, new Vector3(characterPositions[0], 0, -characterPositions[1]), new Quaternion(0, 0, 0, 0)); //Blinky = Instantiate(Blinky, new Vector3(characterPositions[2], 0, -characterPositions[3]), new Quaternion(0, 0, 0, 0)); //Inky = Instantiate(Inky, new Vector3(characterPositions[4], 0, -characterPositions[5]), new Quaternion(0, 0, 0, 0)); //Pinky = Instantiate(Pinky, new Vector3(characterPositions[6], 0, -characterPositions[7]), new Quaternion(0, 0, 0, 0)); //Clyde = Instantiate(Clyde, new Vector3(characterPositions[8], 0, -characterPositions[9]), new Quaternion(0, 0, 0, 0)); //Pacman.GetComponent<PlayerControlScript>().currentWaypoint = m_obj[characterPositions[0], characterPositions[1]].GetComponent<WayPoint>(); //Blinky.GetComponent<EnemyBehaviourScript>().currentWaypoint = m_obj[characterPositions[2], characterPositions[3]].GetComponent<WayPoint>(); //Inky.GetComponent<EnemyBehaviourScript>().currentWaypoint = m_obj[characterPositions[4], characterPositions[5]].GetComponent<WayPoint>(); //Pinky.GetComponent<EnemyBehaviourScript>().currentWaypoint = m_obj[characterPositions[6], characterPositions[7]].GetComponent<WayPoint>(); //Clyde.GetComponent<EnemyBehaviourScript>().currentWaypoint = m_obj[characterPositions[8], characterPositions[9]].GetComponent<WayPoint>(); Pacman.GetComponent <PlayerControlScript>().currentWaypoint = objs[-(int)charpos[0].z, (int)charpos[0].x].GetComponent <WayPoint>(); Blinky.GetComponent <EnemyBehaviourScript>().currentWaypoint = objs[-(int)charpos[1].z, (int)charpos[1].x].GetComponent <WayPoint>(); Inky.GetComponent <EnemyBehaviourScript>().currentWaypoint = objs[-(int)charpos[2].z, (int)charpos[2].x].GetComponent <WayPoint>(); Pinky.GetComponent <EnemyBehaviourScript>().currentWaypoint = objs[-(int)charpos[3].z, (int)charpos[3].x].GetComponent <WayPoint>(); Clyde.GetComponent <EnemyBehaviourScript>().currentWaypoint = objs[-(int)charpos[4].z, (int)charpos[4].x].GetComponent <WayPoint>(); m_text.text += "instanziated characters" + Environment.NewLine; }
public void replaceOnEllipse(GameObject[,] world, GameObject tile, int tarX, int tarY, int length, int height, GameObject targetTile) { //Debug.Log ("Generating ellipse at x:"+tarX+", y:"+tarY+" of length:"+length+" and height:"+height); for (int x = tarX - length; x <= tarX + length; x++) { for (int y = tarY - height; y <= tarY + height; y++) { float theta = Mathf.Atan2 ((y - tarY), (x - tarX)); float radius = Mathf.Sqrt (Mathf.Pow (height / 2, 2) * Mathf.Pow (Mathf.Cos (theta), 2) + Mathf.Pow (length / 2, 2) * Mathf.Pow (Mathf.Sin (theta), 2)); float distance = getDistance (tarX, tarY, x, y); if (distance <= radius) { if (x >= 0 && x < world.GetLength (0) && y >= 0 && y < world.GetLength (1)) { GameObject wTile = world[x,y]; if (wTile.CompareTag(targetTile.tag)) { Destroy(world[x,y]); world[x,y] = Instantiate(tile); } } } } } }
void CreateHighway() { // Using Prim's algoritm, finds the shortest minimal spanning tree (MST) // It finds the shortest distance between to connect all cities with eachother // It determines which cities are linked with a highway // Links keeps track which city is connected with another GameObject[,] links = new GameObject[cities.Count - 1, 2]; // Available cities are not yet in the MST List <GameObject> cityAvailable = new List <GameObject>(); for (int i = 0; i < cities.Count; i++) { cityAvailable.Add(cities[i]); } // Cities which are already part of the MST List <GameObject> MSTset = new List <GameObject>(); MSTset.Add(cities[0]); cityAvailable.Remove(cities[0]); for (int h = 0; h < cities.Count - 1; h++) { float distMin = (float)surfaceArea; for (int i = 0; i < MSTset.Count; i++) { for (int j = 0; j < cityAvailable.Count; j++) { int startXCor = MSTset[i].GetComponent <CityProperties>().xCor; int startZCor = MSTset[i].GetComponent <CityProperties>().zCor; int cityXCor = cityAvailable[j].GetComponent <CityProperties>().xCor; int cityZCor = cityAvailable[j].GetComponent <CityProperties>().zCor; int dx = Mathf.Abs(startXCor - cityXCor); int dz = Mathf.Abs(startZCor - cityZCor); int dist = dz + dx; if (dist < distMin) { distMin = dist; links[h, 0] = MSTset[i]; links[h, 1] = cityAvailable[j]; } } } cityAvailable.Remove(links[h, 1]); MSTset.Add(links[h, 1]); } // If there is only one city and thus no link, place a Asphalt in the middle to start PlaceIntersect() if (cities.Count == 1) { int x0 = cities[0].GetComponent <CityProperties>().xCor; int z0 = cities[0].GetComponent <CityProperties>().zCor; if (gridObjects[x0, z0].tag == "Water") { gridObjects[x0, z0].GetComponent <General>().AddPiece(Bridge); gridObjects[x0, z0].tag = "Bridge"; gridObjects[x0, z0].AddComponent <Asphalt>(); } else if (gridObjects[x0, z0].tag == "Grass") { gridObjects[x0, z0].GetComponent <General>().AddPiece(Asphalt_default); gridObjects[x0, z0].tag = "Asphalt"; gridObjects[x0, z0].GetComponent <General>().RemovePiece("Grass"); Destroy(gridObjects[x0, z0].GetComponent <Grass>()); } } // Places the road from city0 to city1 for (int i = 0; i < links.GetLength(0); i++) { int x0 = links[i, 0].GetComponent <CityProperties>().xCor; int z0 = links[i, 0].GetComponent <CityProperties>().zCor; int x1 = links[i, 1].GetComponent <CityProperties>().xCor; int z1 = links[i, 1].GetComponent <CityProperties>().zCor; RoadLine(x0, x1, z0, true); RoadLine(z0, z1, x1, false); } // All corners can't have an intersection within two tiles GameObject[] asphalts = GameObject.FindGameObjectsWithTag("Asphalt"); foreach (GameObject asphalt in asphalts) { int xCor = asphalt.GetComponent <General>().xCor; int zCor = asphalt.GetComponent <General>().zCor; if ((gridObjects[xCor - 1, zCor].tag == "Asphalt" || gridObjects[xCor + 1, zCor].tag == "Asphalt") && (gridObjects[xCor, zCor - 1].tag == "Asphalt" || gridObjects[xCor, zCor + 1].tag == "Asphalt")) { List <GameObject> surround = Utility.SurroundingObjects(xCor, zCor, 2); foreach (GameObject obj in surround) { obj.GetComponent <General>().intersectPossible = false; } } } buildState += 1; }
//Used when loading a game. Replaces the current cellArray with the new one public void setParentForCells(GameObject[,] cells) { //Destroy any current children foreach (Transform child in transform) { Destroy(child.gameObject); } CellHandler.cellArray = cells; for (int x = 0; x < cells.GetLength(0); x++) { for (int y = 0; y < cells.GetLength(1); y++) { if (cells[x, y] != null) cells[x, y].transform.SetParent(this.transform); } } }
private GameObject[,] Create(int length, int width) { var map = new GameObject[length, width]; var mapBlueprint = new GameObject[length, width]; // generating blueprint map for (var x = 0; x < length; x++) { for (var z = 0; z < width; z++) { mapBlueprint[x, z] = GameManager.Instance.BuildingsFactory.GetPrefab(x, z); } } // generating spacings in blueprint map for (var x = 1; x < mapBlueprint.GetLength(0); x += 2) { for (var z = 0; z < mapBlueprint.GetLength(1); z += 1) { mapBlueprint[x, z] = null; } } for (var z = 1; z < mapBlueprint.GetLength(1); z += 2) { for (var x = 0; x < mapBlueprint.GetLength(0); x += 1) { mapBlueprint[x, z] = null; } } // generating map based on map blueprint for (var x = 0; x < mapBlueprint.GetLength(0); x++) { for (var z = 0; z < mapBlueprint.GetLength(1); z++) { // its empty cell - nothing to do with it - skip it here if (mapBlueprint[x, z] == null) { continue; } var instance = GameManager.Instance.BuildingsFactory.Create(mapBlueprint[x, z]); instance.transform.parent = GameManager.Instance.GameObjectsManager.gameObject.transform; var spawnPositionX = x; var spawnPositionZ = z; var positionX = spawnPositionX; var positionY = instance.gameObject.transform.lossyScale.y / 2; // height var positionZ = spawnPositionZ; instance.transform.localPosition = new Vector3(positionX, positionY, positionZ); map[x, z] = instance; } } // generating humans on map based on map blueprint for (var x = 0; x < mapBlueprint.GetLength(0); x++) { for (var z = 0; z < mapBlueprint.GetLength(1); z++) { // its busy cell - nothing to do with it - skip it here if (mapBlueprint[x, z] != null) { continue; } // TODO: copy/paste from above - refactor this in future var instance = GameManager.Instance.HumansFactory.Create(); // human was not spawned at all - nothing to do with it - skip it here if (instance == null) { continue; } instance.transform.parent = GameManager.Instance.GameObjectsManager.gameObject.transform; var spawnPositionX = x; var spawnPositionZ = z; var positionX = spawnPositionX; var positionY = instance.gameObject.transform.lossyScale.y / 2; // height var positionZ = spawnPositionZ; instance.transform.localPosition = new Vector3(positionX, positionY, positionZ); map[x, z] = instance; } } return(map); }
public void genEllipse(GameObject[,] world, GameObject tile, int tarX, int tarY, int length, int height) { //Debug.Log ("Generating ellipse at x:"+tarX+", y:"+tarY+" of length:"+length+" and height:"+height); for (int x = tarX - length; x <= tarX + length; x++) { for (int y = tarY - height; y <= tarY + height; y++) { float theta = Mathf.Atan2 ((y - tarY), (x - tarX)); float radius = Mathf.Sqrt (Mathf.Pow (height / 2, 2) * Mathf.Pow (Mathf.Cos (theta), 2) + Mathf.Pow (length / 2, 2) * Mathf.Pow (Mathf.Sin (theta), 2)); float distance = getDistance (tarX, tarY, x, y); if (distance <= radius) { if (x >= 0 && x < world.GetLength (0) && y >= 0 && y < world.GetLength (1)) { GameObject tarTile = world [x, y]; if (!tarTile.GetComponent<SpriteRenderer> ().sprite.Equals (tile.GetComponent<SpriteRenderer> ().sprite)) { Destroy (tarTile); world [x, y] = Instantiate (tile); } else { //Debug.Log ("Was equal, not replacing"); } } } } } }
//窗口控件初始化 protected override void InitWidget() { var userLevel = GameUserModel.Instance.UserLevel; var unlockSlotNum = userLevel / 3; m_CloseBtn = mRoot.Find("CloseBtn").GetComponent <UIButton>(); EventDelegate.Add(m_CloseBtn.onClick, OnCloseInterface); mPopupListBtn = mRoot.Find("RuneSelect/PopupList").GetComponent <UIButton>(); EventDelegate.Add(mPopupListBtn.onClick, OnShowLevel); m_RuneLevelGo = mRoot.Find("RuneSelect/RuneLevel").gameObject; m_PopList_Label = mRoot.Find("RuneSelect/PopupList/Label").GetComponent <UILabel>(); mScroll = mRoot.Find("Package").GetComponent <UIScrollView>(); mGrid = mRoot.Find("Package/Grid").GetComponent <UIGrid>(); m_StatusLabel = mRoot.Find("InfoWindow/Staus").GetComponent <UILabel>(); m_StatusLabel.text = ""; m_LevelLabelArray = new GameObject[GameDefine.GameConstDefine.MaxRuneLevel]; string resFile = "RuneSelect/RuneLevel/Level"; for (int i = 0; i < m_LevelLabelArray.GetLength(0); ++i) { string indexStr = Convert.ToString(i); string filename = resFile + indexStr; GameObject levelGo = mRoot.Find(filename).gameObject; levelGo.name = indexStr; UIEventListener.Get(levelGo).onClick += onClickLevel; m_LevelLabelArray[i] = levelGo; } m_Page1Btn = mRoot.Find("PagesList/Grid/RunePages").GetComponent <UIButton>(); EventDelegate.Add(m_Page1Btn.onClick, onClickPage); m_AddPageBtn = mRoot.Find("PagesList/AddButton").GetComponent <UIButton>(); EventDelegate.Add(m_AddPageBtn.onClick, onAddPageClick); string slotFilePre = "EquipBlank/Slot"; for (int i = 0; i < GameDefine.GameConstDefine.MaxRuneSlot; ++i) { string indexName = Convert.ToString(i + 1); string slotColliderFile = slotFilePre + indexName; GameObject slotGo = mRoot.Find(slotColliderFile).gameObject; UIEventListener.Get(slotGo).onClick += onClickSlot; string curFileStr = slotColliderFile + "/Icon"; m_Slot_Sprite_Array[i] = new SlotInfo(); m_Slot_Sprite_Array[i].sprite = new UISprite(); m_Slot_Sprite_Array[i].runeid = new uint(); var tempSprite = mRoot.Find(curFileStr).GetComponent <UISprite>(); m_Slot_Sprite_Array[i].sprite = tempSprite; m_Slot_Sprite_Array[i].sprite.name = indexName; m_Slot_Sprite_Array[i].sprite.spriteName = ""; m_Slot_Sprite_Array[i].lockGO = mRoot.Find(slotColliderFile + "/Lock").gameObject; if (i < unlockSlotNum) { m_Slot_Sprite_Array[i].lockGO.SetActive(false); m_Slot_Sprite_Array[i].ifCanEquip = true; } slotGo.name = Convert.ToString(i); } m_CombineBtn = mRoot.Find("CombineBtn").GetComponent <UIButton>(); EventDelegate.Add(m_CombineBtn.onClick, onClickCombine); m_WashBtn = mRoot.Find("WashBtn").GetComponent <UIButton>(); EventDelegate.Add(m_WashBtn.onClick, onClickWash); m_CurPageNum = 0; ifFirstLoad = true; LoadRunes(); LoadEquip(); }
public GameObject[,] CalculateNextState(GameObject[,] originalGrid) { Debug.Log("Stating, baby!"); var nextState = new GameObject[originalGrid.GetLength(0), originalGrid.GetLength(1)]; for (int x = 0; x < nextState.GetLength(1); x++) { for (int y = 0; y < nextState.GetLength(0); y++) { var cur = originalGrid[y, x]; GetNeighbors(originalGrid, x, y, out int treeCount, out int houseCount, out int powerHousecount); //Debug.Log($"cur.name counts: t: {treeCount}, h {houseCount}, ph {powerHousecount}"); if (IsEmpty(cur)) { // Generate new stuff. //if (treeCount - houseCount*1.5 >= 0 && treeCount >=2) //{ // nextState[y, x] = Instantiate(housePrefab, new Vector3(x, y, 0f), Quaternion.identity); //} //else if (treeCount >= 2 || UnityEngine.Random.Range(0f, 1f) > 0.95f) { nextState[y, x] = Instantiate(treePrefab, new Vector3(x, y, 0f), Quaternion.identity); } else { nextState[y, x] = Instantiate(floorPrefab, new Vector3(x, y, 0f), Quaternion.identity); }; } //// Potentially kill things. else if (IsTree(cur)) { if (houseCount >= 3 || treeCount >= 7 || powerHousecount >= 1) { nextState[y, x] = Instantiate(floorPrefab, new Vector3(x, y, 0f), Quaternion.identity); } else { nextState[y, x] = Instantiate(treePrefab, new Vector3(x, y, 0f), Quaternion.identity); } } else if (IsHouse(cur)) { // Houses die when if (treeCount == 0) { nextState[y, x] = Instantiate(floorPrefab, new Vector3(x, y, 0f), Quaternion.identity); } else { nextState[y, x] = Instantiate(housePrefab, new Vector3(x, y, 0f), Quaternion.identity); } } else if (IsPower(cur)) { nextState[y, x] = Instantiate(powerPrefab, new Vector3(x, y, 0f), Quaternion.identity); } else { nextState[y, x] = Instantiate(floorPrefab, new Vector3(x, y, 0f), Quaternion.identity); } nextState[y, x].GetComponent <PlayableBase>().X = x; nextState[y, x].GetComponent <PlayableBase>().Y = y; } } return(nextState); }