Пример #1
0
    private void CreateToken(int gridX, int gridY, bool avoidMatches, bool withMove)
    {
        Vector3 newPos;

        if (withMove)
        {
            bool isDown = (collapseDirection == MoveDirection.Down);

            float columnsVerticalOffset = -Mathf.Abs(gridX - gridSize.x / 2) *
                                          tokenSize.y * generationTokensRelativeDistance;

            newPos = GridToWorldPosition(
                gridX,
                gridY + (isDown ? -1 : 1) * (gridSize.y))
                     + Vector3.up * (isDown ? -1 : 1) * columnsVerticalOffset;
        }
        else
        {
            newPos = GridToWorldPosition(gridX, gridY);
        }

        GameObject tokenObj = Instantiate(Settings.main.tokens.prefab,
                                          newPos, Quaternion.identity, transform);
        MaskToken token = tokenObj.GetComponent <MaskToken>();

        token.previousGridPosition = new Vector2Int(-1, -1);
        SetTokenInGrid(token, gridX, gridY);
        UpdateTokenPosition(token, Settings.main.tokens.collapseTime);
        token.wasMoved = false;

        if (avoidMatches)
        {
            List <int> unwantedElements = new List <int>();
            if (gridY > 1)
            {
                if (tokens[gridY - 1, gridX].elementId == tokens[gridY - 2, gridX].elementId)
                {
                    unwantedElements.Add(tokens[gridY - 1, gridX].elementId);
                }
            }

            if (gridX > 1)
            {
                if (tokens[gridY, gridX - 1].elementId == tokens[gridY, gridX - 2].elementId)
                {
                    unwantedElements.Add(tokens[gridY, gridX - 1].elementId);
                }
            }
            token.SetRandomElement(unwantedElements.ToArray());
        }
        else
        {
            token.SetRandomElement();
        }
        token.UpdateSpriteImmediate();
        tokenObj.name = Settings.main.elements[token.elementId].name + "(" + gridX + ", " + gridY + ")";
    }
Пример #2
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            if (GUILayout.Button("Update Sprite"))
            {
                MaskToken token = target as MaskToken;
                token.UpdateSpriteImmediate();
            }
        }