private void InitMetaData()
    {
        var       rootText  = Resources.Load <TextAsset>("meta/root" + SceneManager.GetActiveScene().name);
        var       docStream = new StringReader(rootText.text);
        RootGraph root      = RootGraph.Construct(docStream);

        foreach (var clip in root.Clips)
        {
            //load clip
            var      clipText      = Resources.Load <TextAsset>("meta/" + clip.Path);
            var      clipDocStream = new StringReader(clipText.text);
            ClipTree clipGraph     = ClipTree.Construct(clipDocStream);
            var      ser           = new YamlDotNet.Serialization.Serializer();

            clipGraphs.Add(clip.Name, clipGraph);
            var midiFile = Resources.Load <TextAsset>("clips/" + clipGraph.Midi);
            Debug.Log(clipGraph.Midi);

            AudioSource audioSource = AddAudioSourceToScene(clipGraph.Audio);

            //parse midi
            Midi midi = new MidiParser().Parse(midiFile.bytes);
            //debug
            Debug.Log(midi.Tracks[2].Bpm);
            foreach (var msg in midi.Tracks[2].Messages)
            {
                Debug.Log(msg);
            }
            Debug.Log(ser.Serialize(clipGraph));
            clips.Add(clip.Name, new Assets.Core.Clip(audioSource, midi));
        }
        foreach (var graph in root.Scriptgraphs)
        {
            var graphText = Resources.Load <TextAsset>("meta/" + graph.Path);
            Debug.Log(graphText);
            var        graphDocStream = new StringReader(graphText.text);
            ScriptTree scriptGraph    = ScriptTree.Construct(graphDocStream);
            var        ser            = new YamlDotNet.Serialization.Serializer();

            scriptGraphs.Add(graph.Name, scriptGraph);
            Debug.Log("Constructed a script graph : " + graph.Name);
            Debug.Log(ser.Serialize(scriptGraph));
        }
    }
Beispiel #2
0
        // Use only in editor mode
        public static void SaveScripts(string name, ScriptTree tree)
        {
            var       rootText    = Resources.Load <TextAsset>("meta/root");
            var       docStream   = new StringReader(rootText.text);
            RootGraph root        = RootGraph.Construct(docStream);
            var       scriptGraph = root.Scriptgraphs.Find(sg => sg.Name == name);
            string    fullPath    = path + scriptGraph.Path + ".yaml";
            var       sr          = new YamlDotNet.Serialization.SerializerBuilder()
                                    .WithNamingConvention(new YamlDotNet.Serialization.NamingConventions.CamelCaseNamingConvention())
                                    .Build();

            using (FileStream fs = new FileStream(fullPath, FileMode.Create))
            {
                using (StreamWriter writer = new StreamWriter(fs))
                {
                    writer.Write(sr.Serialize(tree));
                }
            }
            UnityEditor.AssetDatabase.Refresh();
        }