Ejemplo n.º 1
0
 private void Match3_OnGemGridPositionDestroyed(object sender, System.EventArgs e)
 {
     Match3.GemGridPosition gemGridPosition = sender as Match3.GemGridPosition;
     if (gemGridPosition != null && gemGridPosition.GetGemGrid() != null)
     {
         gemGridDictionary.Remove(gemGridPosition.GetGemGrid());
     }
 }
Ejemplo n.º 2
0
    public void Setup(Match3 match3, Grid <Match3.GemGridPosition> grid)
    {
        this.match3 = match3;
        this.grid   = grid;

        float cameraYOffset = 1f;

        cameraTransform.position = new Vector3(grid.GetWidth() * .5f, grid.GetHeight() * .5f + cameraYOffset, cameraTransform.position.z);

        match3.OnGemGridPositionDestroyed += Match3_OnGemGridPositionDestroyed;
        match3.OnNewGemGridSpawned        += Match3_OnNewGemGridSpawned;

        // Initialize Visual
        gemGridDictionary   = new Dictionary <Match3.GemGrid, GemGridVisual>();
        glassGridDictionary = new Dictionary <Match3.GemGridPosition, GlassGridVisual>();

        for (int x = 0; x < grid.GetWidth(); x++)
        {
            for (int y = 0; y < grid.GetHeight(); y++)
            {
                Match3.GemGridPosition gemGridPosition = grid.GetGridObject(x, y);
                Match3.GemGrid         gemGrid         = gemGridPosition.GetGemGrid();

                Vector3 position = grid.GetWorldPosition(x, y);
                position = new Vector3(position.x, 12);

                // Visual Transform
                Transform gemGridVisualTransform = Instantiate(pfGemGridVisual, position, Quaternion.identity);
                gemGridVisualTransform.Find("sprite").GetComponent <SpriteRenderer>().sprite = gemGrid.GetGem().sprite;

                GemGridVisual gemGridVisual = new GemGridVisual(gemGridVisualTransform, gemGrid);

                gemGridDictionary[gemGrid] = gemGridVisual;

                // Glass Visual Transform
                Transform glassGridVisualTransform = Instantiate(pfGlassGridVisual, grid.GetWorldPosition(x, y), Quaternion.identity);

                GlassGridVisual glassGridVisual = new GlassGridVisual(glassGridVisualTransform, gemGridPosition);

                glassGridDictionary[gemGridPosition] = glassGridVisual;

                // Background Grid Visual
                Instantiate(pfBackgroundGridVisual, grid.GetWorldPosition(x, y), Quaternion.identity);
            }
        }

        SetBusyState(.5f, () => SetState(State.TryFindMatches));

        isSetup = true;
    }