Beispiel #1
0
        public static TileWrapper CreateTileWrapper(string cardId, int count, GameObject holderGameObject, int position)
        {
            var newTileObj    = new GameObject("MyDeckTileVisual");
            var newTileVisual = newTileObj.AddComponent <DeckTrayDeckTileVisual>();

            Logger.AppendLine("Creating card based on new instance");
            newTileVisual.MarkAsUsed();
            newTileVisual.Show();
            CollectionDeckSlot deckSlot = new CollectionDeckSlot
            {
                CardID        = cardId,
                Count         = count,
                Index         = 0,
                OnSlotEmptied = slot => { },
                Premium       = TAG_PREMIUM.GOLDEN
            };

            newTileVisual.SetSlot(deckSlot, false);
            newTileObj.transform.SetParent(holderGameObject.transform);
            newTileObj.transform.localScale    = new Vector3(Scale, Scale, Scale);
            newTileObj.transform.localPosition = new Vector3(0f, 0f, position * HeightDistance);
            var tileWrapper = new TileWrapper {
                Tile = newTileVisual, Count = count
            };

            return(tileWrapper);
        }
Beispiel #2
0
 public void Load(string fileName)
 {
     fileName = Application.persistentDataPath + "/saves/" + fileName;
     if (System.IO.File.Exists(fileName))
     {
         string      json    = System.IO.File.ReadAllText(fileName);
         TileWrapper wrapper = JsonUtility.FromJson <TileWrapper>(json);
         if (wrapper.tiles != null && wrapper.tiles.Length > 0)
         {
             foreach (TileData tileData in wrapper.tiles)
             {
                 Debug.Log(tileData.position);
                 tilemap.SetTile(tileData.position, tileData.tile);
             }
         }
         if (wrapper.spikes != null && wrapper.spikes.Length > 0)
         {
             foreach (TileData tileData in wrapper.spikes)
             {
                 spikes.SetTile(tileData.position, tileData.tile);
             }
         }
     }
     else
     {
         Debug.LogWarning($"File {fileName} doesn't exist.");
     }
 }
Beispiel #3
0
    public void Save()
    {
        List <TileData> tiles = new List <TileData>();

        foreach (Vector3Int pos in tilemap.cellBounds.allPositionsWithin)
        {
            if (!tilemap.HasTile(pos))
            {
                continue;
            }
            var tile     = tilemap.GetTile(pos);
            var tileData = new TileData
            {
                position    = pos,
                tile        = tile,
                tilemapName = tilemap.name
            };
            tiles.Add(tileData);
        }

        List <TileData> spikesList = new List <TileData>();

        foreach (Vector3Int pos in spikes.cellBounds.allPositionsWithin)
        {
            if (!spikes.HasTile(pos))
            {
                continue;
            }
            var tile     = spikes.GetTile(pos);
            var tileData = new TileData
            {
                position    = pos,
                tile        = tile,
                tilemapName = spikes.name
            };
            spikesList.Add(tileData);
        }

        TileWrapper wrapper = new TileWrapper
        {
            tiles  = tiles.ToArray(),
            spikes = spikesList.ToArray()
        };
        string json = JsonUtility.ToJson(wrapper);

        if (fileName.text.Equals(""))
        {
            fileName.text = GenerateFileName();
        }
        fileName.text = fileName.text.Replace(".", "_").Replace(":", "_");
        System.IO.FileInfo file = new System.IO.FileInfo(Application.persistentDataPath + "/saves/" + fileName.text + ".json");
        file.Directory.Create();
        System.IO.File.WriteAllText(file.FullName, json);
        Debug.Log(file.FullName);
    }
Beispiel #4
0
    private void OnLevelEnter()
    {
        for (int x = 0; x < GameState.CurrentLevel.Map.Width; x++)
        {
            for (int y = 0; y < GameState.CurrentLevel.Map.Height; y++)
            {
                TileWrapper t = Instantiate(TilePrefab, new Vector3(x, y, 0), Quaternion.identity, transform);
                t.GridPosition = new Vector2Int(x, y);
                t.UpdateTile();
            }
        }

        //Instantiates the player
        PlayerWrapper p = Instantiate(PlayerPrefab, new Vector3(GameState.CurrentLevel.Player.Position.x, GameState.CurrentLevel.Player.Position.y, 0), Quaternion.identity, transform);

        p.Player = GameState.CurrentLevel.Player;
        p.PlayerAnimationName = "Player1";

        UIManager.SetTitles("Level %l".Replace("%l", GameState.History.Level.ToString()), "Go!", Color.blue, Color.blue);
    }