示例#1
0
    private void SwapTilesAndDeepCpy(Vector2Int tappedTile, Vector2Int toCheckTile)
    {
        GameTileDisplay toCheckTileDisplay = tilesDictionary[toCheckTile].GetComponent <GameTileDisplay>();
        GameTileDisplay movingTileDisplay  = tilesDictionary[tappedTile].GetComponent <GameTileDisplay>();

        GameTile copy = ScriptableObject.CreateInstance <GameTile>();

        copy.CopyFrom(movingTileDisplay.myTile);
        copy.originalX      = movingTileDisplay.myTile.originalX;
        copy.originalY      = movingTileDisplay.myTile.originalY;
        copy.originalUVRect = movingTileDisplay.myTile.originalUVRect;
        copy.disabledColour = movingTileDisplay.myTile.disabledColour;
        copy.enabledColour  = movingTileDisplay.myTile.enabledColour;
        copy.SetIsEmpty(movingTileDisplay.myTile.GetIsEmpty());

        // set the moving tile to the empty tile stats
        movingTileDisplay.myTile.CopyFrom(toCheckTileDisplay.myTile);
        movingTileDisplay.SetIsEmpty(toCheckTileDisplay.myTile.GetIsEmpty()); // true if swapping with empty cell
        movingTileDisplay.SetImageRect();

        // set the empty tile stats to the copied tile
        toCheckTileDisplay.myTile.CopyFrom(copy);
        toCheckTileDisplay.SetIsEmpty(copy.GetIsEmpty()); // false
        toCheckTileDisplay.SetImageRect();
    }
示例#2
0
    // x1, y1 cell for the moving tile
    private void SwapTiles(int x1, int y1, int x2, int y2)
    {
        GameTileDisplay toCheckTile = tilesDictionary[new Vector2Int(x2, y2)].GetComponent <GameTileDisplay>();
        GameTileDisplay movingTile  = tilesDictionary[new Vector2Int(x1, y1)].GetComponent <GameTileDisplay>();

        GameTile copy = ScriptableObject.CreateInstance <GameTile>();

        copy.CopyFrom(movingTile.myTile); // save the moving tile

        // set the moving tile to the empty tile stats
        movingTile.myTile.CopyFrom(toCheckTile.myTile);
        movingTile.SetIsEmpty(toCheckTile.myTile.GetIsEmpty()); // true if swapping with empty cell

        // set the empty tile stats to the copied tile
        toCheckTile.myTile.CopyFrom(copy);
        toCheckTile.SetIsEmpty(copy.GetIsEmpty()); // false
        toCheckTile.SetImageRect();

        Destroy(copy);
    }