public void Initialize(BlocGrid grid, Vector2 offsetPosition) { this.blocGrid = grid; if (this.tileSize == 0) { Debug.LogError("The tile size is incorect."); return; } this.tileMarginOffset = (float)this.tileMarginSize / (float)this.tileSize; // Initialize sprites. this.sprites = new Sprite[this.spriteDescriptions.Length]; for (int index = 0; index < this.spriteDescriptions.Length; index++) { BlocSpriteDescription spriteDescription = this.spriteDescriptions[index]; if (spriteDescription.Sprite == null) { Debug.LogError("The sprite of the bloc " + spriteDescription.Color + " is null."); } this.sprites[(int)spriteDescription.Color] = spriteDescription.Sprite; } // Initialize blocRenderers. int rowCount = this.blocGrid.Height; int columnCount = this.blocGrid.Width; this.blocRenderers = new BlocRenderer[columnCount, rowCount]; for (int y = 0; y < rowCount; ++y) { for (int x = 0; x < columnCount; ++x) { GameObject gameObject = GameObject.Instantiate(this.blocPrefab) as GameObject; gameObject.transform.position = new Vector3(offsetPosition.x + x - (x * this.tileMarginOffset), offsetPosition.y + y - (y * this.tileMarginOffset)); gameObject.transform.parent = this.gameObject.transform; BlocRenderer blocRenderer = gameObject.GetComponent<BlocRenderer>(); blocRenderer.Initialize(this.sprites); this.blocRenderers[x, y] = blocRenderer; } } // Compute the renderer's area. float width = columnCount - ((float)this.tileMarginSize / (float)this.tileSize * (columnCount - 1)); float height = rowCount - ((float)this.tileMarginSize / (float)this.tileSize * (rowCount - 1)); this.RendererRect = new Rect(-0.5f, -0.5f, width, height); this.initialized = true; }
public IEnumerator Start() { this.preview = new BlocGrid(6, 4); GameObject rendererObject = Instantiate(this.rendererPrefab) as GameObject; rendererObject.transform.parent = this.transform; rendererObject.transform.localPosition = Vector3.zero; this.previewRenderer = rendererObject.GetComponent<BlocGridRenderer>(); this.previewRenderer.OverrideBlocSpriteDescription(new BlocSpriteDescription(BlocSpriteDescription.BlocColor.Black, this.backgroundTexture)); this.previewRenderer.Initialize(this.preview, Vector2.zero); while (Application.Instance == null || Application.Instance.Game == null) { yield return null; } Application.Instance.Game.CurrentTetrominoChange += this.Game_CurrentTetrominoChange; }