// Start is called before the first frame update void Start() { music = new EightBitSoundGenerator.Music(); MemoryStream stream = new MemoryStream(musicFile.bytes); BinaryReader reader = new BinaryReader(stream); music.Load(reader); }
void ToolsLine() { EditorGUI.DrawRect(new Rect(0, 0, position.width, 60), new Color(0, 0, 0, 1)); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("New")) { music = new Music(); currentPart = music.GetPart(0); noteSpeed = music.Speed; } if (GUILayout.Button("Load")) { string fn = EditorUtility.OpenFilePanel("open file", Application.dataPath, "bytes"); if (!string.IsNullOrEmpty(fn)) { using (FileStream stream = new FileStream(fn, FileMode.Open)) { BinaryReader reader = new BinaryReader(stream); music = new Music(); music.Load(reader); noteSpeed = music.Speed; currentPart = music.GetPart(0); } } } if (music != null) { if (GUILayout.Button("Save")) { string fn = EditorUtility.SaveFilePanel("save file", Application.dataPath, "new music", "bytes"); if (!string.IsNullOrEmpty(fn)) { using (FileStream stream = new FileStream(fn, FileMode.Create)) { BinaryWriter writer = new BinaryWriter(stream); music.Save(writer); } } } } GUILayout.Space(10); string[] girdSize = { "1\\8", "1\\4", "1\\2", "1\\3", "1" }; float[] girds = { 0.125f, 0.25f, 0.5f, 0.33333f, 1.0f }; sizeGird = EditorGUILayout.Popup(sizeGird, girdSize); sizeA = girds[sizeGird]; string newns = GUILayout.TextArea(noteSpeed.ToString()); int spd = int.Parse(newns); noteSpeed = spd; if (spd > 50 && spd < 200) { music.Speed = noteSpeed; } if (GUILayout.Button("Play")) { if (!testObj) { testObj = new GameObject(); testObj.name = "Editor Audio Object"; } music.Play(testObj); music.Time = 0; } if (GUILayout.Button("Pause/Resume")) { if (music.IsPlaying) { playTime = music.Time; music.Stop(); } else { if (!testObj) { testObj = new GameObject(); testObj.name = "Editor Audio Object"; } music.Play(testObj); music.Time = playTime; } } if (GUILayout.Button("Stop")) { music.Stop(); playTime = 0; } EditorGUILayout.EndHorizontal(); if (Event.current.type == EventType.KeyUp) { if (Event.current.control) { if (Event.current.keyCode == KeyCode.C) { Copy(); } else if (Event.current.keyCode == KeyCode.X) { Copy(); currentPart.RemoveSelected(); currentPart.CleanSelected(); music.UpdateParts(); } else if (Event.current.keyCode == KeyCode.V) { Paste(); } } } //if(Event.current.type == EventType.MouseDown) //{ // if (music.IsPlaying) // { // music.Stop(); // } //} }