68 lines
2.0 KiB
C#
68 lines
2.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Ichni.RhythmGame;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
namespace Ichni.Editor
|
|
{
|
|
public class MusicPlayer : MonoBehaviour
|
|
{
|
|
public bool isDebugging;
|
|
public bool isPlaying;
|
|
public AudioSource audioSource;
|
|
private float DspTime => (float)AudioSettings.dspTime;
|
|
private void Update()
|
|
{
|
|
if (isDebugging)
|
|
{
|
|
EditorManager.instance.songInformation.songTime += Time.deltaTime;
|
|
return;
|
|
}
|
|
|
|
if (isPlaying)
|
|
{
|
|
EditorManager.instance.songInformation.songTime = EditorManager.instance.musicPlayer.audioSource.time;
|
|
}
|
|
}
|
|
|
|
public void PlayMusic()
|
|
{
|
|
|
|
isPlaying = !isPlaying;
|
|
|
|
EditorManager.instance.songInformation.songTime = audioSource.time;
|
|
if (isPlaying)
|
|
{
|
|
Trail.FreezeAllTrails(!isPlaying);
|
|
audioSource.Play();
|
|
}
|
|
else PauseMusic();
|
|
}
|
|
public IEnumerator PlayBackMusic()
|
|
{
|
|
float startt = audioSource.time;
|
|
PlayMusic();
|
|
yield return new WaitUntil(() => Keyboard.current.rightAltKey.wasReleasedThisFrame);
|
|
audioSource.time = startt;
|
|
PauseMusic();
|
|
|
|
}
|
|
public void PauseMusic()
|
|
{
|
|
isPlaying = false;
|
|
EditorManager.instance.songInformation.songTime = audioSource.time;
|
|
audioSource.Pause();
|
|
Trail.FreezeAllTrails(!isPlaying);
|
|
}
|
|
|
|
public void StopMusic()
|
|
{
|
|
isPlaying = false;
|
|
EditorManager.instance.songInformation.songTime = 0;
|
|
audioSource.Stop();
|
|
EditorManager.instance.uiManager.timeline.timePointerModule.SetRange(0);
|
|
}
|
|
}
|
|
} |