Exemplo n.º 1
0
    public void Save()
    {
        JsonTestClass.MusicalFile musicFile = new JsonTestClass.MusicalFile();
        musicFile.numberNote  = partition.Count;
        musicFile.musicalNote = new JsonTestClass.MusicalNote[partition.Count];


        for (int i = 0; i < partition.Count; i++)
        {
            if (partition [i].NoteToPlay)
            {
                musicFile.musicalNote[i] = new JsonTestClass.MusicalNote(partition [i].NoteToPlay.getNoteName(), partition [i].NoteToPlay.Octave - 1, partition [i].nbFourth * 0.25f);
            }
            else
            {
                musicFile.musicalNote[i] = new JsonTestClass.MusicalNote(0, 10, partition [i].nbFourth * 0.25f);
            }
        }



        String        ressourcePath = Path.Combine(Application.dataPath, "Resources");                   // Get Path to game resources folder
        DirectoryInfo di            = new DirectoryInfo(Path.Combine(ressourcePath, "StreamingAssets")); // Get Path to Streaming assets

        int numberFiles = CreateFiles.DirCount(di) / 2;

        String filePath = Path.Combine("StreamingAssets", "Comp" + numberFiles + ".json"); // Get Path to file in resources folder
        String realPath = Path.Combine(ressourcePath, filePath);                           // Get Real Path

        JsonTestClass.SaveJSONToFile(JsonTestClass.MapToJSON(musicFile), realPath);
    }
Exemplo n.º 2
0
    void Start()
    {
        GameObject gameState = GameObject.Find("GameState");
        GameState  gs        = gameState.GetComponent <GameState>();

        fileName = gs.fileName;

        String newPath     = Path.Combine("StreamingAssets", fileName);     // Get Path to file in resources folder without .json !
        String savedString = JsonTestClass.LoadJSONFromFile(newPath);       // Load Json from file

        musicFile = new JsonTestClass.MusicalFile();
        musicFile = JsonTestClass.JSONToObject(savedString);          // Create Object from Json

        numberNote = musicFile.numberNote;

        partition = new List <KeyValuePair <NoteScript, float> >();
        for (int i = 0; i < numberNote; i++)
        {
            int   clipIndex    = musicFile.musicalNote[i].noteName + 12 * musicFile.musicalNote[i].noteOctave;
            float clipDuration = musicFile.musicalNote[i].noteTempo;
            if (clipIndex < 84)
            {
                partition.Add(new KeyValuePair <NoteScript, float> (notes [clipIndex].GetComponent <NoteScript> (), clipDuration));
            }
            else
            {
                partition.Add(new KeyValuePair <NoteScript, float> (null, clipDuration));
            }
        }


        //  Play();
    }