2022-02-05 03:48:35 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
using DG.Tweening;
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
2022-02-05 03:48:35 +00:00
|
|
|
using Starpelly;
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games.Scripts_DJSchool
|
2022-02-05 03:48:35 +00:00
|
|
|
{
|
|
|
|
public class Student : PlayerActionObject
|
|
|
|
{
|
|
|
|
public Animator anim;
|
|
|
|
|
|
|
|
[Header("Properties")]
|
|
|
|
public float holdBeat;
|
|
|
|
public float swipeBeat;
|
|
|
|
public bool isHolding;
|
2022-02-20 17:28:56 +00:00
|
|
|
public bool shouldBeHolding;
|
|
|
|
public bool eligible;
|
|
|
|
public bool missed;
|
2022-02-05 03:48:35 +00:00
|
|
|
|
|
|
|
[Header("Components")]
|
|
|
|
[SerializeField] private SpriteRenderer flash;
|
|
|
|
[SerializeField] private GameObject flashFX;
|
|
|
|
[SerializeField] private GameObject flashFXInverse;
|
|
|
|
[SerializeField] private GameObject TurnTable;
|
|
|
|
[SerializeField] private GameObject slamFX;
|
|
|
|
|
2022-02-20 17:28:56 +00:00
|
|
|
private Animator tableAnim;
|
|
|
|
|
|
|
|
private DJSchool game;
|
|
|
|
|
2022-03-26 02:08:46 +00:00
|
|
|
public void Init()
|
2022-02-05 03:48:35 +00:00
|
|
|
{
|
2022-02-20 17:28:56 +00:00
|
|
|
game = DJSchool.instance;
|
2022-02-05 03:48:35 +00:00
|
|
|
anim = GetComponent<Animator>();
|
2022-02-20 17:28:56 +00:00
|
|
|
tableAnim = TurnTable.GetComponent<Animator>();
|
|
|
|
tableAnim.speed = 0;
|
2022-02-05 03:48:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
2022-02-20 17:28:56 +00:00
|
|
|
float beatToUse = shouldBeHolding ? swipeBeat : holdBeat;
|
|
|
|
float normalizedBeat = Conductor.instance.GetPositionFromMargin(beatToUse + 2, 1);
|
|
|
|
|
|
|
|
if (eligible)
|
2022-02-05 03:48:35 +00:00
|
|
|
{
|
2022-02-20 17:28:56 +00:00
|
|
|
StateCheck(normalizedBeat);
|
2022-02-05 03:48:35 +00:00
|
|
|
|
2022-02-20 17:28:56 +00:00
|
|
|
if (normalizedBeat > Minigame.LateTime())
|
|
|
|
{
|
|
|
|
eligible = false;
|
|
|
|
missed = true;
|
2022-02-05 03:48:35 +00:00
|
|
|
|
2022-02-20 17:28:56 +00:00
|
|
|
if (shouldBeHolding)
|
|
|
|
{
|
|
|
|
shouldBeHolding = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shouldBeHolding = true;
|
|
|
|
game.SetDJYellowHead(3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isHolding)
|
|
|
|
{
|
2022-02-05 03:48:35 +00:00
|
|
|
if (PlayerInput.Pressed())
|
|
|
|
{
|
2022-02-20 17:28:56 +00:00
|
|
|
if (!shouldBeHolding && state.perfect && eligible)
|
2022-02-05 03:48:35 +00:00
|
|
|
{
|
|
|
|
Hold(true);
|
2022-02-20 17:28:56 +00:00
|
|
|
eligible = false;
|
2022-02-05 03:48:35 +00:00
|
|
|
}
|
2022-02-05 20:28:04 +00:00
|
|
|
else
|
2022-02-05 03:48:35 +00:00
|
|
|
{
|
2022-02-20 17:28:56 +00:00
|
|
|
if (!shouldBeHolding)
|
|
|
|
eligible = false;
|
|
|
|
|
2022-02-05 03:48:35 +00:00
|
|
|
Hold(false);
|
2022-02-20 17:28:56 +00:00
|
|
|
|
|
|
|
missed = true;
|
|
|
|
game.SetDJYellowHead(3, true);
|
2022-02-05 03:48:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-20 17:28:56 +00:00
|
|
|
else
|
2022-02-05 03:48:35 +00:00
|
|
|
{
|
|
|
|
if (PlayerInput.PressedUp())
|
|
|
|
{
|
2022-02-20 17:28:56 +00:00
|
|
|
if (shouldBeHolding && state.perfect && eligible)
|
2022-02-05 03:48:35 +00:00
|
|
|
{
|
2022-02-20 17:28:56 +00:00
|
|
|
Swipe(true);
|
|
|
|
eligible = false;
|
2022-02-05 03:48:35 +00:00
|
|
|
}
|
2022-02-05 20:28:04 +00:00
|
|
|
else
|
2022-02-05 03:48:35 +00:00
|
|
|
{
|
2022-02-20 17:28:56 +00:00
|
|
|
if (shouldBeHolding)
|
|
|
|
{
|
|
|
|
Swipe(false);
|
|
|
|
eligible = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UnHold();
|
|
|
|
}
|
|
|
|
|
|
|
|
missed = true;
|
|
|
|
game.SetDJYellowHead(3);
|
2022-02-05 03:48:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Hold(bool ace)
|
|
|
|
{
|
|
|
|
isHolding = true;
|
2022-02-20 17:28:56 +00:00
|
|
|
|
|
|
|
if (ace)
|
|
|
|
{
|
|
|
|
missed = false;
|
|
|
|
shouldBeHolding = true;
|
|
|
|
game.SetDJYellowHead(1);
|
|
|
|
}
|
2022-02-05 03:48:35 +00:00
|
|
|
|
|
|
|
Jukebox.PlayOneShotGame("djSchool/recordStop");
|
|
|
|
anim.Play("Hold", 0, 0);
|
|
|
|
|
|
|
|
if (ace)
|
|
|
|
{
|
|
|
|
FlashFX(true);
|
|
|
|
}
|
2022-02-05 04:40:33 +00:00
|
|
|
|
|
|
|
// Settings.GetMusicMixer().audioMixer.FindSnapshot("DJSchool_Hold").TransitionTo(0.15f);
|
2022-02-05 03:48:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void UnHold()
|
|
|
|
{
|
2022-02-05 20:28:04 +00:00
|
|
|
isHolding = false;
|
|
|
|
|
2022-02-20 17:28:56 +00:00
|
|
|
anim.Play("Unhold", 0, 0);
|
2022-02-05 04:40:33 +00:00
|
|
|
|
|
|
|
// Settings.GetMusicMixer().audioMixer.FindSnapshot("Main").TransitionTo(0.15f);
|
2022-02-05 03:48:35 +00:00
|
|
|
}
|
|
|
|
|
2022-02-20 17:28:56 +00:00
|
|
|
public void Swipe(bool ace)
|
2022-02-05 03:48:35 +00:00
|
|
|
{
|
|
|
|
isHolding = false;
|
2022-02-20 17:28:56 +00:00
|
|
|
|
|
|
|
if (ace)
|
|
|
|
{
|
|
|
|
missed = false;
|
|
|
|
shouldBeHolding = false;
|
|
|
|
Jukebox.PlayOneShotGame("djSchool/recordSwipe");
|
|
|
|
FlashFX(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Missed record swipe sound should play here.
|
|
|
|
}
|
2022-02-05 03:48:35 +00:00
|
|
|
|
|
|
|
anim.Play("Swipe", 0, 0);
|
|
|
|
|
2022-02-20 17:28:56 +00:00
|
|
|
tableAnim.speed = 1;
|
|
|
|
tableAnim.Play("Student_Turntable_Swipe", 0, 0);
|
2022-02-05 03:48:35 +00:00
|
|
|
|
|
|
|
Instantiate(slamFX).SetActive(true);
|
2022-02-05 04:40:33 +00:00
|
|
|
|
|
|
|
// Settings.GetMusicMixer().audioMixer.FindSnapshot("Main").TransitionTo(0.15f);
|
2022-02-05 03:48:35 +00:00
|
|
|
}
|
|
|
|
|
2022-02-20 17:28:56 +00:00
|
|
|
public override void OnAce()
|
|
|
|
{
|
|
|
|
if (!shouldBeHolding)
|
|
|
|
{
|
|
|
|
Hold(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Swipe(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
eligible = false;
|
|
|
|
}
|
|
|
|
|
2022-02-05 03:48:35 +00:00
|
|
|
private void FlashFX(bool inverse)
|
|
|
|
{
|
|
|
|
GameObject prefab = flashFX;
|
|
|
|
|
|
|
|
if (inverse)
|
|
|
|
prefab = flashFXInverse;
|
|
|
|
|
|
|
|
GameObject flashFX_ = Instantiate(prefab, this.transform.parent);
|
|
|
|
flashFX_.SetActive(true);
|
|
|
|
Destroy(flashFX_, 0.5f);
|
|
|
|
|
|
|
|
flash.color = "D0FBFF".Hex2RGB();
|
|
|
|
flash.color = new Color(flash.color.r, flash.color.g, flash.color.b, 0.85f);
|
|
|
|
flash.DOColor(new Color(flash.color.r, flash.color.g, flash.color.b, 0), 0.15f);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void TransitionBackToIdle()
|
|
|
|
{
|
|
|
|
// for letting go of "hold"
|
|
|
|
if (anim.speed == 0)
|
|
|
|
{
|
|
|
|
anim.speed = 1;
|
|
|
|
anim.Play("Idle", 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|