コード例 #1
0
    public static void SpawnNewCandy(GridManager.CellContents candyType, Vector2Int gridPosition)
    {
        if (candyType == GridManager.CellContents.empty || candyType == GridManager.CellContents.hole)
        {
            Debug.LogError("GridDisplayer.cs : Couldn't spawn new candy because given CellContents value is not a candy.");
            return;
        }

        GameObject newCandy = null;

        switch (candyType)
        {
        case GridManager.CellContents.candy_blue:
            newCandy = S.blueCandyPool.TakeFromPool(true, S.gridElementContainer);
            break;

        case GridManager.CellContents.candy_red:
            newCandy = S.redCandyPool.TakeFromPool(true, S.gridElementContainer);
            break;

        case GridManager.CellContents.candy_green:
            newCandy = S.greenCandyPool.TakeFromPool(true, S.gridElementContainer);
            break;

        case GridManager.CellContents.candy_orange:
            newCandy = S.orangeCandyPool.TakeFromPool(true, S.gridElementContainer);
            break;

        case GridManager.CellContents.candy_yellow:
            newCandy = S.yellowCandyPool.TakeFromPool(true, S.gridElementContainer);
            break;
        }


        newCandy.transform.position   = GridToWorld(gridPosition);
        newCandy.transform.rotation   = Quaternion.identity;
        newCandy.transform.localScale = new Vector3(S.cellSize * S.candySize, S.cellSize * S.candySize, S.cellSize * S.candySize);

        GridElement_Candy gridElementComponent = newCandy.GetComponent <GridElement_Candy>();

        // wire the GridElement methods to the GridCell delegates
        gridElementComponent.RegisterMethodsOnCell(gridPosition);

        gridElementComponent.x = gridPosition.x;
        gridElementComponent.y = gridPosition.y;
    }
コード例 #2
0
    /// <summary>
    /// Returns an allowed random color, that is a color that hasn't been preset in the level editor, as a CellContents enum value.
    /// </summary>
    /// <returns></returns>
    public GridManager.CellContents GetRandomColor()
    {
        GridManager.CellContents val = 0;


        // if all the colors are preset we just return a random value because the loop below would be infinite
        // we also return a basic random number is there are not preset colors
        if (presetColors.Length >= 5 || presetColors.Length == 0)
        {
            return((GridManager.CellContents)Random.Range(1, 6));
        }

        do
        {
            val = (GridManager.CellContents)Random.Range(1, 6);
        }while (presetColors.Contains(val));



        return(val);
    }