private void MapGeneration() { MapGenerationStart.Invoke(); UnityEngine.Random.InitState(_mapStatus.Seed); for (int i = 0; i < BlockGrid.y; i++) { float x = -((float)BlockGrid.x / 2f); float y = 0; for (int j = 0; j < BlockGrid.x; j++) { int index = UnityEngine.Random.Range(0, Blocks.Count); Vector2 size = Blocks[index].Size; if (size.y > y) { y = size.y; } GameObject instance = Instantiate(Blocks[index].gameObject); instance.transform.SetParent(this.transform); GeneratedBlocks.Add(instance.GetComponent <Block>()); instance.transform.position = new Vector3(x, (y * i) + _yOffset, 0); x += size.x; } } MapGenerated.Invoke(); }
public void ClearMap() { for (int i = 0; i < GeneratedBlocks.Count; i++) { Destroy(GeneratedBlocks[i].gameObject); } GeneratedBlocks.Clear(); }
public void BlockDisabled(GameObject blockGameObject) { Block block = blockGameObject.GetComponent <Block>(); if (block == null || _mapStatus == null) { return; } int index = GeneratedBlocks.IndexOf(block); _mapStatus.BlockStatus[index] = block.gameObject.activeSelf; if (AllBlocksDisabled()) { AllBlocksDisabledCallback.Invoke(); } }