[MenuItem("Assets/Create/Song")] //允許從 unity 中直接建立外掛功能,不重要 public static void CreateNewSongAsset() { SonataSongData asset = ScriptableObject.CreateInstance <SonataSongData>(); AssetDatabase.CreateAsset(asset, "Assets/NewSong.asset"); EditorUtility.FocusProjectWindow(); Selection.activeObject = asset; }
public void SetSong(SonataSongData song) { Song = song; gameObject.GetComponent <AudioSource>().time = 0; //從第幾秒開始播放 gameObject.GetComponent <AudioSource>().clip = Song.BackgroundTrack; //抓歌曲 gameObject.GetComponent <AudioSource>().pitch = 1; //會改變音高,超過1會加速而且變尖銳,小數值會變慢變低音,畫面會回溯很可怕 SmoothAudioTime = MyMath.BeatsToSeconds(-Song.AudioStartBeatOffset, Song.BeatsPerMinute); //開頭播放前的節拍數轉為秒數取負值,功能未知 }
public override void OnInspectorGUI() { DrawInspector(); //Check for mouse events if (Event.current.isMouse) { if (Event.current.type == EventType.MouseDown) { OnMouseDown(Event.current); //按進度條區域 } else if (Event.current.type == EventType.MouseUp) { OnMouseUp(Event.current); //按主要編輯區域 } } //Check for key input events if (Event.current.isKey) { if (Event.current.type == EventType.KeyDown) { OnKeyDown(Event.current); //上下左右CTL來操控主要編輯區域 } } if (Event.current.type == EventType.ValidateCommand) { switch (Event.current.commandName) { case "UndoRedoPerformed": RedrawProgressViewTexture(); //每次新增刪除音符時,進度條同步更新. break; } } if (GUI.changed) { SonataSongData targetData = target as SonataSongData; if (targetData.BackgroundTrack != null && SonataPlayer.Song != targetData) { SonataPlayer.SetSong(targetData); //可以用拖曳的方式新增和變換歌曲 } } UpdateMetronome(); //節拍器 RepaintGui(); }
public void SetSong(SonataSongData song) { Song = song; SmoothAudioTime = MyMath.BeatsToSeconds(-Song.AudioStartBeatOffset, Song.BeatsPerMinute); //開頭播放前的節拍數轉為秒數取負值,功能未知 }