Ejemplo n.º 1
0
    public Data.MapStructure LoadMap(string fileName)
    {
        Data.MapStructure mapStructure = new Data.MapStructure();

        FilePath = Application.dataPath + "/SaveData" + fileName + ".json";
        Debug.Log("FilePath: " + FilePath);

        DirectoryInfo dir = new DirectoryInfo(FilePath);

        if (File.Exists(FilePath))
        {
            string json = File.ReadAllText(FilePath);

            var temp_mapStructure = JsonUtility.FromJson <Data.MapStructure>(json);
            mapStructure.ground_layer    = temp_mapStructure.ground_layer;
            mapStructure.furniture_layer = temp_mapStructure.furniture_layer;

            if (temp_mapStructure != null)
            {
                Debug.Log("Loading json, Success");
            }
            else
            {
                Debug.LogError("Loading json, Failed");
            }
        }
        else
        {
            Debug.LogError("Not exists file: " + fileName);
        }


        return(mapStructure);
    }
Ejemplo n.º 2
0
    public void Set(string json)
    {
        if (json == null)
        {
            mapStructure = new Data.MapStructure();
        }
        else
        {
            mapStructure = JsonConvert.DeserializeObject <Data.MapStructure>(json);
        }

        set = true;
    }
Ejemplo n.º 3
0
    public void SaveMap(string fileName, Data.MapStructure mapStructure)
    {
        FileOut = Application.dataPath + "/SaveData";

        if (!Directory.Exists(FileOut))
        {
            Debug.Log("Create folder " + FileOut);
            Directory.CreateDirectory(FileOut);
        }

        FileOut = Application.dataPath + "/SaveData/" + fileName + ".json";

        string json = JsonUtility.ToJson(mapStructure);

        File.WriteAllText(FileOut, json);

        Debug.Log("FileOut: " + FileOut);
    }