2023-05-29 20:09:34 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using HeavenStudio.Util;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace HeavenStudio.Games.Scripts_Rockers
|
|
|
|
{
|
|
|
|
public class RockersRocker : MonoBehaviour
|
|
|
|
{
|
|
|
|
private Sound[] stringSounds = new Sound[6];
|
|
|
|
private Sound chordSound;
|
|
|
|
private Animator anim;
|
|
|
|
public int[] lastPitches = new int[6];
|
|
|
|
public int lastBendPitch;
|
|
|
|
|
|
|
|
[SerializeField] private GameObject strumEffect;
|
|
|
|
|
|
|
|
[SerializeField] private bool JJ;
|
|
|
|
|
|
|
|
[NonSerialized] public bool muted;
|
|
|
|
private bool strumming;
|
|
|
|
private bool bending;
|
|
|
|
[NonSerialized] public bool together;
|
|
|
|
|
|
|
|
[SerializeField] List<Sprite> bluSprites = new List<Sprite>();
|
|
|
|
[SerializeField] List<Sprite> yelSprites = new List<Sprite>();
|
|
|
|
[SerializeField] List<Sprite> normalSprites = new List<Sprite>();
|
|
|
|
|
|
|
|
[SerializeField] List<SpriteRenderer> lightningLefts = new List<SpriteRenderer>();
|
|
|
|
[SerializeField] List<SpriteRenderer> lightningRights = new List<SpriteRenderer>();
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
anim = GetComponent<Animator>();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
{
|
|
|
|
StopSounds();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void StopSounds()
|
|
|
|
{
|
|
|
|
foreach (var sound in stringSounds)
|
|
|
|
{
|
|
|
|
if (sound != null)
|
|
|
|
{
|
|
|
|
sound.KillLoop(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (chordSound != null)
|
|
|
|
{
|
|
|
|
chordSound.KillLoop(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void PrepareTogether(bool forceMute = false)
|
|
|
|
{
|
|
|
|
together = true;
|
2023-10-29 19:44:47 +00:00
|
|
|
if ((PlayerInput.GetIsAction(Rockers.InputAction_BasicPressing) && !JJ) || forceMute)
|
2023-05-29 20:09:34 +00:00
|
|
|
{
|
|
|
|
DoScaledAnimationAsync("ComeOnPrepare", 0.5f);
|
|
|
|
if (forceMute) Mute(true, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DoScaledAnimationAsync("ComeOnPrepareNoMute", 0.5f);
|
|
|
|
if (strumming) strumEffect.GetComponent<Animator>().Play("StrumRight", 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Miss()
|
|
|
|
{
|
|
|
|
if (strumming) return;
|
|
|
|
DoScaledAnimationAsync(together ? "Miss" : "MissComeOn", 0.5f);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ReturnBack()
|
|
|
|
{
|
|
|
|
together = false;
|
|
|
|
if (JJ)
|
|
|
|
{
|
|
|
|
muted = false;
|
|
|
|
DoScaledAnimationAsync("Return", 0.5f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (strumming) strumEffect.GetComponent<Animator>().Play("StrumIdle", 0, 0);
|
2023-10-29 19:44:47 +00:00
|
|
|
if (PlayerInput.GetIsAction(Rockers.InputAction_BasicPressing) || (GameManager.instance.autoplay && muted))
|
2023-05-29 20:09:34 +00:00
|
|
|
{
|
|
|
|
DoScaledAnimationAsync("Crouch", 0.5f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
muted = false;
|
|
|
|
DoScaledAnimationAsync("Return", 0.5f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-09 16:55:00 +00:00
|
|
|
private bool lastGleeClub = false;
|
|
|
|
private Rockers.PremadeSamples lastSample;
|
|
|
|
private int lastSampleTones;
|
|
|
|
|
|
|
|
public void StrumStringsLast(bool disableStrumEffect = false, bool jump = false, bool barely = false)
|
|
|
|
{
|
|
|
|
StrumStrings(lastGleeClub, lastPitches, lastSample, lastSampleTones, disableStrumEffect, jump, barely);
|
|
|
|
}
|
|
|
|
|
2023-05-29 20:09:34 +00:00
|
|
|
public void StrumStrings(bool gleeClub, int[] pitches, Rockers.PremadeSamples sample, int sampleTones, bool disableStrumEffect = false, bool jump = false, bool barely = false)
|
|
|
|
{
|
2023-06-03 14:51:30 +00:00
|
|
|
if (strumming) return;
|
2024-01-09 16:55:00 +00:00
|
|
|
lastGleeClub = gleeClub;
|
|
|
|
lastSample = sample;
|
|
|
|
lastSampleTones = sampleTones;
|
2023-05-29 20:09:34 +00:00
|
|
|
muted = false;
|
|
|
|
strumming = true;
|
|
|
|
StopSounds();
|
|
|
|
if (sample == Rockers.PremadeSamples.None)
|
|
|
|
{
|
|
|
|
lastPitches = pitches;
|
|
|
|
for (int i = 0; i < pitches.Length; i++)
|
|
|
|
{
|
|
|
|
if (pitches[i] == -1) continue;
|
2023-06-10 19:13:29 +00:00
|
|
|
float pitch = SoundByte.GetPitchFromSemiTones(pitches[i], true);
|
2023-05-29 20:09:34 +00:00
|
|
|
float volume = GetVolumeBasedOnAmountOfStrings(pitches.Length);
|
2024-02-11 05:24:52 +00:00
|
|
|
string soundName = "rockers/strings/" + (gleeClub ? "gleeClub/gleeClub" : "normal/normal" + (i + 1));
|
2024-01-15 02:04:10 +00:00
|
|
|
// Debug.Log("Pitch: " + pitch + " Volume: " + volume + " Name: " + soundName);
|
2023-06-10 19:13:29 +00:00
|
|
|
stringSounds[i] = SoundByte.PlayOneShotGame(soundName, -1, pitch, volume, true);
|
2023-05-29 20:09:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-10 19:13:29 +00:00
|
|
|
float pitch = SoundByte.GetPitchFromSemiTones(sampleTones, true);
|
2023-05-29 20:09:34 +00:00
|
|
|
string soundName = sample switch
|
|
|
|
{
|
|
|
|
Rockers.PremadeSamples.None => "",
|
|
|
|
Rockers.PremadeSamples.BendG5 => "rockers/BendG5",
|
|
|
|
Rockers.PremadeSamples.BendC6 => "rockers/BendC6",
|
2024-02-11 05:24:52 +00:00
|
|
|
Rockers.PremadeSamples.ChordA => "rockers/rocker/rockerChordA",
|
|
|
|
Rockers.PremadeSamples.ChordAsus4 => "rockers/rocker/rockerChordAsus4",
|
|
|
|
Rockers.PremadeSamples.ChordBm => "rockers/rocker/rockerChordBm",
|
|
|
|
Rockers.PremadeSamples.ChordCSharpm7 => "rockers/rocker/rockerChordC#m7",
|
|
|
|
Rockers.PremadeSamples.ChordDmaj7 => "rockers/rocker/rockerChordDmaj7",
|
|
|
|
Rockers.PremadeSamples.ChordDmaj9 => "rockers/rocker/rockerChordDmaj9",
|
|
|
|
Rockers.PremadeSamples.ChordFSharp5 => "rockers/rocker/rockerChordF#5",
|
|
|
|
Rockers.PremadeSamples.ChordG => "rockers/rocker/rockerChordG",
|
|
|
|
Rockers.PremadeSamples.ChordG5 => "rockers/rocker/rockerChordG5",
|
|
|
|
Rockers.PremadeSamples.ChordGdim7 => "rockers/rocker/rockerChordGdim7",
|
|
|
|
Rockers.PremadeSamples.ChordGm => "rockers/rocker/rockerChordGm",
|
|
|
|
Rockers.PremadeSamples.NoteASharp4 => "rockers/rocker/rockerNoteA#4",
|
|
|
|
Rockers.PremadeSamples.NoteA5 => "rockers/rocker/rockerNoteA5",
|
|
|
|
Rockers.PremadeSamples.PracticeChordD => "rockers/rocker/rockerPracticeChordD",
|
|
|
|
Rockers.PremadeSamples.Remix6ChordA => "rockers/rocker/rockerRemix6ChordA",
|
|
|
|
Rockers.PremadeSamples.Remix10ChordD => "rockers/rocker/rockerRemix10ChordD",
|
|
|
|
Rockers.PremadeSamples.Remix10ChordFSharpm => "rockers/rocker/rockerRemix10ChordF#m",
|
|
|
|
Rockers.PremadeSamples.DoremiChordA7 => "rockers/doremi/doremiChordA7",
|
|
|
|
Rockers.PremadeSamples.DoremiChordAm7 => "rockers/doremi/doremiChordAm7",
|
|
|
|
Rockers.PremadeSamples.DoremiChordC => "rockers/doremi/doremiChordC",
|
|
|
|
Rockers.PremadeSamples.DoremiChordC7 => "rockers/doremi/doremiChordC7",
|
|
|
|
Rockers.PremadeSamples.DoremiChordCadd9 => "rockers/doremi/doremiChordCadd9",
|
|
|
|
Rockers.PremadeSamples.DoremiChordDm => "rockers/doremi/doremiChordDm",
|
|
|
|
Rockers.PremadeSamples.DoremiChordDm7 => "rockers/doremi/doremiChordDm7",
|
|
|
|
Rockers.PremadeSamples.DoremiChordEm => "rockers/doremi/doremiChordEm",
|
|
|
|
Rockers.PremadeSamples.DoremiChordF => "rockers/doremi/doremiChordF",
|
|
|
|
Rockers.PremadeSamples.DoremiChordFadd9 => "rockers/doremi/doremiChordFadd9",
|
|
|
|
Rockers.PremadeSamples.DoremiChordFm => "rockers/doremi/doremiChordFm",
|
|
|
|
Rockers.PremadeSamples.DoremiChordG => "rockers/doremi/doremiChordG",
|
|
|
|
Rockers.PremadeSamples.DoremiChordG7 => "rockers/doremi/doremiChordG7",
|
|
|
|
Rockers.PremadeSamples.DoremiChordGm => "rockers/doremi/doremiChordGm",
|
|
|
|
Rockers.PremadeSamples.DoremiChordGsus4 => "rockers/doremi/doremiChordGsus4",
|
|
|
|
Rockers.PremadeSamples.DoremiNoteA2 => "rockers/doremi/doremiNoteA2",
|
|
|
|
Rockers.PremadeSamples.DoremiNoteE2 => "rockers/doremi/doremiNoteE2",
|
2023-05-29 20:09:34 +00:00
|
|
|
_ => throw new System.NotImplementedException(),
|
|
|
|
};
|
2023-06-10 19:13:29 +00:00
|
|
|
chordSound = SoundByte.PlayOneShotGame(soundName, -1, pitch, 1, true);
|
2023-05-29 20:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (together)
|
|
|
|
{
|
|
|
|
DoScaledAnimationAsync(jump ? "Jump" : "ComeOnStrum", 0.5f);
|
|
|
|
if (disableStrumEffect) return;
|
|
|
|
strumEffect.SetActive(true);
|
|
|
|
bool strumLeft = JJ && jump;
|
|
|
|
strumEffect.GetComponent<Animator>().Play(strumLeft ? "StrumStartLeft" : "StrumStartRIght", 0, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DoScaledAnimationAsync("Strum", 0.5f);
|
|
|
|
if (disableStrumEffect) return;
|
|
|
|
strumEffect.SetActive(true);
|
|
|
|
strumEffect.GetComponent<Animator>().Play("StrumStart", 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!JJ)
|
|
|
|
{
|
|
|
|
if (barely)
|
|
|
|
{
|
|
|
|
bool useYel = UnityEngine.Random.Range(1, 3) == 1;
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
if (lightningRights[i].gameObject.activeSelf) lightningRights[i].sprite = useYel ? yelSprites[i] : bluSprites[i];
|
|
|
|
if (lightningLefts[i].gameObject.activeSelf) lightningLefts[i].sprite = useYel ? yelSprites[i] : bluSprites[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
if (lightningRights[i].gameObject.activeSelf) lightningRights[i].sprite = normalSprites[i];
|
|
|
|
if (lightningLefts[i].gameObject.activeSelf) lightningLefts[i].sprite = normalSprites[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void BendUp(int pitch)
|
|
|
|
{
|
|
|
|
if (bending || !strumming) return;
|
|
|
|
bending = true;
|
|
|
|
lastBendPitch = pitch;
|
2024-03-14 01:18:13 +00:00
|
|
|
if (chordSound != null) {
|
|
|
|
chordSound.BendUp(0.05f, GetBentPitch(chordSound.pitch, pitch));
|
2023-05-29 20:09:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i = 0; i < stringSounds.Length; i++)
|
|
|
|
{
|
|
|
|
if (stringSounds[i] != null)
|
|
|
|
{
|
2024-03-14 01:18:13 +00:00
|
|
|
stringSounds[i].BendUp(0.05f, GetBentPitch(stringSounds[i].pitch, pitch));
|
2023-05-29 20:09:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShotGame("rockers/bendUp");
|
2023-05-29 20:09:34 +00:00
|
|
|
DoScaledAnimationAsync("Bend", 0.5f);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void BendDown()
|
|
|
|
{
|
|
|
|
if (!bending) return;
|
|
|
|
bending = false;
|
|
|
|
foreach (var sound in stringSounds)
|
|
|
|
{
|
|
|
|
if (sound != null)
|
|
|
|
{
|
|
|
|
sound.BendDown(0.05f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (chordSound != null)
|
|
|
|
{
|
|
|
|
chordSound.BendDown(0.05f);
|
|
|
|
}
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShotGame("rockers/bendDown");
|
2023-05-29 20:09:34 +00:00
|
|
|
DoScaledAnimationAsync("Unbend", 0.5f);
|
|
|
|
}
|
|
|
|
|
|
|
|
private float GetVolumeBasedOnAmountOfStrings(int stringAmount)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (stringAmount)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
case 3:
|
|
|
|
return 0.893f;
|
|
|
|
case 4:
|
|
|
|
return 0.75f;
|
|
|
|
case 5:
|
|
|
|
return 0.686f;
|
|
|
|
case 6:
|
|
|
|
return 0.62f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Mute(bool soundExists = true, bool noAnim = false)
|
|
|
|
{
|
|
|
|
strumming = false;
|
|
|
|
strumEffect.SetActive(false);
|
|
|
|
bending = false;
|
|
|
|
StopSounds();
|
2023-06-10 19:13:29 +00:00
|
|
|
if (soundExists) SoundByte.PlayOneShotGame("rockers/mute");
|
2023-05-29 20:09:34 +00:00
|
|
|
if (!noAnim) DoScaledAnimationAsync(together ? "ComeOnMute" : "Crouch", 0.5f);
|
|
|
|
muted = true;
|
|
|
|
}
|
|
|
|
|
2023-06-03 14:51:30 +00:00
|
|
|
public void UnHold(bool overrideMute = false)
|
2023-05-29 20:09:34 +00:00
|
|
|
{
|
2023-06-03 14:51:30 +00:00
|
|
|
if (!muted && !overrideMute) return;
|
2023-05-29 20:09:34 +00:00
|
|
|
muted = false;
|
|
|
|
if (!together) DoScaledAnimationAsync("UnCrouch", 0.5f);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void DoScaledAnimationAsync(string name, float time)
|
|
|
|
{
|
|
|
|
anim.DoScaledAnimationAsync((JJ ? "JJ" : "") + name, time);
|
|
|
|
}
|
2024-03-14 01:18:13 +00:00
|
|
|
|
|
|
|
private float GetBentPitch(float pitch, int bend)
|
|
|
|
{
|
|
|
|
float unscaledPitch = chordSound.pitch / Conductor.instance.musicSource.pitch;
|
|
|
|
float bendPitch = SoundByte.GetPitchFromSemiTones(bend, false);
|
|
|
|
|
|
|
|
return (unscaledPitch * bendPitch) * Conductor.instance.musicSource.pitch;
|
|
|
|
}
|
2023-05-29 20:09:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|