The logo now bops to the beat

This commit is contained in:
Rapandrasmus 2023-05-19 00:25:57 +02:00
parent 5ca54ba7b7
commit 8e35e4280e
4 changed files with 48 additions and 5 deletions

View file

@ -2268,7 +2268,7 @@ AnimationClip:
m_Level: 0 m_Level: 0
m_CycleOffset: 0 m_CycleOffset: 0
m_HasAdditiveReferencePose: 0 m_HasAdditiveReferencePose: 0
m_LoopTime: 1 m_LoopTime: 0
m_LoopBlend: 0 m_LoopBlend: 0
m_LoopBlendOrientation: 0 m_LoopBlendOrientation: 0
m_LoopBlendPositionY: 0 m_LoopBlendPositionY: 0

View file

@ -2588,7 +2588,7 @@ AnimationClip:
m_Level: 0 m_Level: 0
m_CycleOffset: 0 m_CycleOffset: 0
m_HasAdditiveReferencePose: 0 m_HasAdditiveReferencePose: 0
m_LoopTime: 1 m_LoopTime: 0
m_LoopBlend: 0 m_LoopBlend: 0
m_LoopBlendOrientation: 0 m_LoopBlendOrientation: 0
m_LoopBlendPositionY: 0 m_LoopBlendPositionY: 0

View file

@ -2821,7 +2821,8 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
createButton: {fileID: 2094622677} createButton: {fileID: 2094622677}
Bpm: 114 logoAnim: {fileID: 869323824}
bpm: 114
--- !u!82 &1811344143 --- !u!82 &1811344143
AudioSource: AudioSource:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -2833,7 +2834,7 @@ AudioSource:
serializedVersion: 4 serializedVersion: 4
OutputAudioMixerGroup: {fileID: -7454359775428337364, guid: e76f74363e1893a42bd3ebe9643b7d12, type: 2} OutputAudioMixerGroup: {fileID: -7454359775428337364, guid: e76f74363e1893a42bd3ebe9643b7d12, type: 2}
m_audioClip: {fileID: 8300000, guid: db628a16ac450d442970008255720d2d, type: 3} m_audioClip: {fileID: 8300000, guid: db628a16ac450d442970008255720d2d, type: 3}
m_PlayOnAwake: 1 m_PlayOnAwake: 0
m_Volume: 1 m_Volume: 1
m_Pitch: 1 m_Pitch: 1
Loop: 1 Loop: 1

View file

@ -10,10 +10,52 @@ namespace HeavenStudio
{ {
[SerializeField] private Button createButton; [SerializeField] private Button createButton;
[SerializeField] private float Bpm = 114f; [SerializeField] private Animator logoAnim;
[SerializeField] private float bpm = 114f;
private AudioSource musicSource;
private double songPosBeat;
private double songPos;
private double time;
private double targetBopBeat;
private double lastAbsTime;
private void Start() private void Start()
{ {
musicSource = GetComponent<AudioSource>();
createButton.onClick.AddListener(delegate { GlobalGameManager.LoadScene("Editor"); Jukebox.PlayOneShot("ui/UIEnter"); }); createButton.onClick.AddListener(delegate { GlobalGameManager.LoadScene("Editor"); Jukebox.PlayOneShot("ui/UIEnter"); });
musicSource.Play();
}
private void Update()
{
if (songPos >= musicSource.clip.length)
{
time = 0;
targetBopBeat = 0;
}
double absTime = Time.realtimeSinceStartup;
double dt = absTime - lastAbsTime;
lastAbsTime = absTime;
time += dt;
songPos = time;
songPosBeat = SecsToBeats(songPos);
if (songPosBeat >= targetBopBeat)
{
logoAnim.Play("LogoBop", 0, 0);
targetBopBeat += 1;
}
}
public double SecsToBeats(double s)
{
return s / 60f * bpm;
} }
} }
} }