書名:《Unityで作るリズムゲーム》
作者:長崎大学マルチメディア研究会
Note生成測試
由於目前還沒有進行譜面的撰寫和讀取,因此先通過手動添加Notes和BPM段落作為測試
在PlayerController中,在數據加到beatMap.noteDatas以及beatMap.tempoChangeDatas中,然後將note生成出來
Single Note
生成後的預想概念圖
//Note GameObject Prefab
[SerializeField] GameObject prefabSingleNote;
private void Awake()
{
currentSec = 0f;
currentBeat = 0f;
//Test
beatMap = new BeatMap();
//Reading Note Data
beatMap.noteDatas = new List<NoteProperty>()
{
new NoteProperty(0, 0, 0, NoteType.Single),
new NoteProperty(1, 1, 1, NoteType.Single),
new NoteProperty(2, 2, 2, NoteType.Single),
new NoteProperty(3, 3, 1, NoteType.Single),
new NoteProperty(4, 4, 0, NoteType.Single),
new NoteProperty(4, 4, 4, NoteType.Single),
new NoteProperty(5, 5, 3, NoteType.Single),
new NoteProperty(6, 6, 2, NoteType.Single),
new NoteProperty(7, 7, 3, NoteType.Single),
new NoteProperty(8, 8, 4, NoteType.Single),
};
//BPM Stage
beatMap.tempoChangeDatas = new List<TempoChange>()
{
new TempoChange(0, 60f),
new TempoChange(2, 120f),
new TempoChange(4, 60f),
new TempoChange(6, 120f)
};
//Spawning Notes
foreach (NoteProperty noteProperty in beatMap.noteDatas)
{
Instantiate(prefabSingleNote)
.GetComponent<NoteControllerBase>()
.noteProperty = noteProperty;
}
}
在Unity編輯器:
將SingleNoteController附在SingleNote預製體中
- 創建一個空物體「Player」,將PlayerController附在上面,然後把SingleNote預製體賦值到Single Note Prefab中
- 最後點撃播放,就能看到一個譜面出現在我們眼前(這裡我對相機的視角進行了微調)
Long Note生成測試
生成後的預想概念圖
//Note GameObject Prefab
[SerializeField] GameObject singleNotePrefab = null;
[SerializeField] GameObject longNotePrefab = null;
private void Awake()
{
currentSec = 0f;
currentBeat = 0f;
//Test
beatMap = new BeatMap();
//Reading Note Data
beatMap.noteDatas = new List<NoteProperty>()
{
new NoteProperty(0, 0, 0, NoteType.Single),
new NoteProperty(1, 1, 1, NoteType.Single),
new NoteProperty(2, 3, 2, NoteType.Long),
new NoteProperty(3, 4, 1, NoteType.Long),
new NoteProperty(4, 8, 0, NoteType.Long),
new NoteProperty(4, 5, 4, NoteType.Long),
new NoteProperty(5, 6, 3, NoteType.Long),
new NoteProperty(6, 7, 2, NoteType.Single),
new NoteProperty(7, 8, 3, NoteType.Single),
new NoteProperty(8, 9, 4, NoteType.Single),
};
//BPM Stage
beatMap.tempoChangeDatas = new List<TempoChange>()
{
new TempoChange(0, 60f),
new TempoChange(2, 120f),
new TempoChange(4, 60f),
new TempoChange(6, 120f)
};
//Spawning Notes
foreach (NoteProperty noteProperty in beatMap.noteDatas)
{
Instantiate(noteProperty.noteType == NoteType.Single ?
singleNotePrefab : longNotePrefab)
.GetComponent<NoteControllerBase>()
.noteProperty = noteProperty;
}
}
在Unity編輯器
將LongNoteController附在LongNote預製體中
- 然後把LongNote的預製體也賦值給PlayerController的Long Note Prefab中Single Note
- 點撃播放