Esempio n. 1
0
    public void CompositionFileLoad(string nameOfComposition)
    {
        char[] separatorText           = " ".ToCharArray();
        CompositionSaveData loadetData = new CompositionSaveData();
        string tempCompositionRead     = File.ReadAllText(Application.dataPath + "/Compositions/" + nameOfComposition + ".json");

        loadetData = JsonUtility.FromJson <CompositionSaveData>(tempCompositionRead);
        width      = loadetData.savedWidth;
        hight      = loadetData.savedHight;
        string[] tempArrayInString = loadetData.copositionInString.Split(separatorText);
        int      i = 0;

        for (int y = 0; y < hight; y++)
        {
            for (int x = 0; x < width; x++)
            {
                i = (width * y) + x;
                levelComposition[x, y] = int.Parse(tempArrayInString[i]);
                Debug.Log(levelComposition[x, y]);
            }
        }

        if (SceneManager.GetActiveScene().name == "Editor")
        {
            CearLevel();
            misplacedObjectsCount = 0;
            LevelConstruction();
        }
    }
Esempio n. 2
0
////////////
//Save system.....
    public void CompositionFileSave(string nameOfComposition)
    {
        CompositionSaveData compositionToSave = new CompositionSaveData();

        compositionToSave.savedWidth = width;
        compositionToSave.savedHight = hight;
//twodimentiona array have to be flatted , using string with separator to flaten, then knowing width we can put it back together.
        string joinedData = null;

        for (int y = 0; y < hight; y++)
        {
            for (int x = 0; x < width; x++)
            {
                joinedData += levelComposition[x, y].ToString() + " ";
            }
        }
        compositionToSave.copositionInString = joinedData;


        string json = JsonUtility.ToJson(compositionToSave);

        Debug.Log(json);
        File.WriteAllText(Application.dataPath + "/Compositions/" + nameOfComposition + ".json", json);
    }