資源簡介
基于Unity2017.3.0f3的音樂(節(jié)拍)demo,可更換音樂快速搭建游戲原型。
代碼片段和文件信息
using?UnityEngine;
using?UnityEditor;
using?System.Collections;
using?System.Collections.Generic;
[CustomEditor(?typeof(?SongData?)?)]
public?class?SongDataEditor?:?Editor
{
//Needed?to?draw?2D?lines?and?rectangles
private?static?Texture2D?_coloredLineTexture;
private?static?Color?_coloredLineColor;
private?Gameobject?Guitarobject;
private?AudioSource?MetronomeSource;
private?SongPlayer?SongPlayer;
private?AudioClip?LastAudioClip;
//Dimensions?of?the?editor
//Song?View?is?the?one?with?the?black?background?where?you?can?add?notes?etc.
//ProgressBar?or?Progress?View?is?the?small?preview?on?the?right?where?you?can?navigate?through?the?song
private?Rect?SongViewRect;
private?float?SongViewProgressBarWidth?=?20f;
private?float?SongViewHeight?=?400f;
//Metronome?Vars
private?static?bool?UseMetronome;
private?float?LastMetronomeBeat?=?Mathf.NegativeInfinity;
//Helper?vars?to?handle?mouse?clicks
private?Vector2?MouseUpPosition?=?Vector2.zero;
private?bool?LastClickWasRightMouseButton;
//Currently?selected?note?index
private?int?SelectedNote?=?-1;
//Song?overview?texture?(the?one?on?the?right?which?you?can?use?to?navigate)
private?Texture2D?ProgressViewTexture;
//Timer?to?calculate?editor?performance
Timer?PerformanceTimer?=?new?Timer();
[MenuItem(?“Assets/Create/Song“?)]
public?static?void?CreateNewSongAsset()
{
SongData?asset?=?scriptableobject.CreateInstance();
AssetDatabase.CreateAsset(?asset?“Assets/NewSong.asset“?);
EditorUtility.FocusProjectWindow();
Selection.activeobject?=?asset;
}
protected?void?OnEnable()
{
//Setup?object?references
Guitarobject?=?Gameobject.Find(?“Guitar“?);
if(?Guitarobject?==?null?)
{
return;
}
SongPlayer?=?Guitarobject.GetComponentyer>();
MetronomeSource?=?Gameobject.Find(?“Metronome“?).GetComponent();
LastAudioClip?=?SongPlayer.Song.BackgroundTrack;
//Prepare?playback
SongPlayer.SetSong(?(SongData)target?);
LastMetronomeBeat?=?-Mathf.Ceil(?SongPlayer.Song.AudioStartBeatOffset?);
RedrawProgressViewTexture();
}
protected?void?RedrawProgressViewTexture()
{
int?width?=?(int)SongViewProgressBarWidth;
int?height?=?(int)SongViewHeight;
if(?!ProgressViewTexture?)
{
//Create?empty?texture?if?it?doesn‘t?exist
ProgressViewTexture?=?new?Texture2D(?width?height?);
ProgressViewTexture.wrapMode?=?TextureWrapMode.Clamp;
}
//Draw?Background?Color
Color[]?BackgroundColor?=?new?Color[?width?*?height?];
for(?int?i?=?0;?i? {
BackgroundColor[?i?]?=?new?Color(?0.13f?0.1f?0.26f?);
}
ProgressViewTexture.SetPixels(?0?0?width?height?BackgroundColor?);
//Calculate?the?scale?in?which?the?notes?are?drawn?so?they?all?fit?into?the?progress?view
float?totalBeats?=?SongPlayer.Song.GetLengthInBeats();
float?heightOfOneBeat?=?1f?/?totalBeats?*?(float)height;
//Dr
- 上一篇:精餾塔資料
- 下一篇:R語言Igraph軟件包0.7.1
評(píng)論
共有 條評(píng)論