123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- using System.Collections;
- using UnityEngine;
- public class SoundGameController : MonoBehaviour
- {
- SoundTrackManager soundTrackManager = new();
- GameObject notePrefabSwipe, notePrefabTap;
- // Start is called once before the first execution of Update after the MonoBehaviour is created
- void Start()
- {
- TextAsset soundTrackJson = Resources.Load<TextAsset>("WalkDogs/SoundTrack/track_1");
- if (soundTrackJson != null)
- {
- string soundTrackString = soundTrackJson.text;
- soundTrackManager.ImportFromJson(soundTrackString);
- }
- notePrefabSwipe = Resources.Load<GameObject>("WalkDogs/Note/NoteSwipe");
- notePrefabTap = Resources.Load<GameObject>("WalkDogs/Note/NoteTap");
- StartCoroutine(PlaySoundGame());
- }
- // Update is called once per frame
- void Update()
- {
- }
- IEnumerator PlaySoundGame()
- {
- float startTime = Time.time;
- float endTime = startTime + soundTrackManager.length;
- while (Time.time < endTime)
- {
- foreach (var note in soundTrackManager.soundAction)
- {
- if (!note.isActive && Time.time >= startTime - GameData.noteStartLeadTime)
- {
- note.isActive = true;
- CreateNote(note.time, note.action);
- continue;
- }
- }
- }
- return null;
- }
- private void CreateNote(float hitTime, string action)
- {
- GameObject note;
- if (action == "tap")
- {
- note = Instantiate(notePrefabTap);
- }
- else
- {
- note = Instantiate(notePrefabSwipe);
- }
- NoteController noteController = note.GetComponent<NoteController>();
- noteController.speed = soundTrackManager.speed;
- noteController.hitTime = hitTime;
- noteController.action = action;
- }
- }
|