public void CalculateGrid() { Transform generatedGrid = transform.GetChild(0); GameGridGenerator generator = GetComponent <GameGridGenerator>(); int rowSize = (int)generator.gridWorldSize.x; int colSize = (int)generator.gridWorldSize.y; grid = new Node[rowSize, colSize]; if (generatedGrid != null && (rowSize * colSize == generatedGrid.childCount)) { int index = 0; for (int y = 0; y < colSize; y++) { for (int x = 0; x < rowSize; x++) { Node node = generatedGrid.GetChild(index).GetComponent <Node>(); grid[x, y] = node; node.gridPosition = new int[] { x, y }; index++; } } } }
void Start() { Skillz_tookTurn = false; GameGridGenerator gen = FindObjectOfType <GameGridGenerator>(); //If we're in a Skillz turn-based tournament, some special logic for block generation is needed. if (SkillzSDK.Api.IsTournamentInProgress) { CurrentPlayerUIText.text = "Your turn"; //If starting a new tournament, randomize the block layout. if (Skillz_GameData.Blocks == null) { gen.Seed = SkillzSDK.Api.GetRandomNumber(); } //Otherwise, just set up the generator to create the right number of blocks. else { TurnsLeft = Skillz_GameData.TurnsLeft; gen.NBlocksX = Skillz_GameData.Blocks.GetLength(0); gen.NBlocksY = Skillz_GameData.Blocks.GetLength(1); IsPlayer1Turn = true; } } gen.GenerateBlocks(true); //Now that the blocks have been generated, fill them in with the correct colors // if we're continuing a Skillz tournament. if (SkillzSDK.Api.IsTournamentInProgress && Skillz_GameData.Blocks != null) { for (int x = 0; x < gen.NBlocksX; ++x) { for (int y = 0; y < gen.NBlocksY; ++y) { Vector2i loc = new Vector2i(x, y); if (GameGrid.Instance.GetBlock(new Vector2i(x, y)) != null) { if (Skillz_GameData.Blocks[x, y] >= 0) { GameGrid.Instance.GetBlock(loc).ColorID = Skillz_GameData.Blocks[x, y]; } else { GameGrid.Instance.DestroyBlock(loc); } } } } //Set up player scores. PlayerOneScore = Skillz_GameData.GetScore(PlayerUniqueID); PlayerTwoScore = Skillz_GameData.GetOtherScore(PlayerUniqueID); } }