2021-12-24 00:58:48 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
using RhythmHeavenMania.Util;
|
|
|
|
|
|
|
|
namespace RhythmHeavenMania.Games.ClappyTrio
|
|
|
|
{
|
|
|
|
public class ClappyTrioPlayer : MonoBehaviour
|
|
|
|
{
|
|
|
|
public bool early;
|
|
|
|
public bool perfect;
|
|
|
|
public bool late;
|
|
|
|
|
|
|
|
private float lastClapBeat;
|
2021-12-25 02:37:03 +00:00
|
|
|
private float lastClapLength;
|
2021-12-24 08:35:54 +00:00
|
|
|
[SerializeField] private bool clapVacant;
|
2021-12-24 00:58:48 +00:00
|
|
|
|
|
|
|
private int lastIndex;
|
|
|
|
|
|
|
|
private bool hit;
|
|
|
|
|
2021-12-24 03:36:16 +00:00
|
|
|
public bool clapStarted = false;
|
|
|
|
public bool canHit;
|
|
|
|
|
|
|
|
private GameObject clapEffect;
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
clapEffect = transform.GetChild(4).GetChild(3).gameObject;
|
|
|
|
}
|
|
|
|
|
2021-12-24 00:58:48 +00:00
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
if (PlayerInput.Pressed())
|
|
|
|
{
|
|
|
|
Clap();
|
|
|
|
}
|
|
|
|
|
2021-12-25 02:37:03 +00:00
|
|
|
if (clapVacant == true)
|
2021-12-24 00:58:48 +00:00
|
|
|
{
|
2021-12-25 02:37:03 +00:00
|
|
|
float normalizedBeat = (Conductor.instance.GetLoopPositionFromBeat(lastClapBeat, lastClapLength));
|
2021-12-24 00:58:48 +00:00
|
|
|
|
2021-12-25 02:37:03 +00:00
|
|
|
if (normalizedBeat > Minigame.EarlyTime() && normalizedBeat < Minigame.PerfectTime() && lastIndex == 0)
|
2021-12-24 00:58:48 +00:00
|
|
|
{
|
|
|
|
SetEligibility(true, false, false);
|
|
|
|
lastIndex++;
|
|
|
|
}
|
2021-12-25 02:37:03 +00:00
|
|
|
else if (normalizedBeat > Minigame.PerfectTime() && normalizedBeat < Minigame.LateTime() && lastIndex == 1)
|
2021-12-24 00:58:48 +00:00
|
|
|
{
|
|
|
|
SetEligibility(false, true, false);
|
|
|
|
// Clap();
|
|
|
|
lastIndex++;
|
|
|
|
}
|
2021-12-25 02:37:03 +00:00
|
|
|
else if (normalizedBeat > Minigame.LateTime() && lastIndex == 2)
|
2021-12-24 00:58:48 +00:00
|
|
|
{
|
|
|
|
SetEligibility(false, false, true);
|
|
|
|
clapVacant = false;
|
|
|
|
lastIndex = 0;
|
2021-12-25 02:37:03 +00:00
|
|
|
lastClapLength = 0;
|
|
|
|
lastClapBeat = 0;
|
2021-12-24 00:58:48 +00:00
|
|
|
hit = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-26 05:11:54 +00:00
|
|
|
/*public void ClearLog()
|
2021-12-25 02:37:03 +00:00
|
|
|
{
|
|
|
|
var assembly = System.Reflection.Assembly.GetAssembly(typeof(UnityEditor.Editor));
|
|
|
|
var type = assembly.GetType("UnityEditor.LogEntries");
|
|
|
|
var method = type.GetMethod("Clear");
|
|
|
|
method.Invoke(new object(), null);
|
2021-12-26 05:11:54 +00:00
|
|
|
}*/
|
2021-12-25 02:37:03 +00:00
|
|
|
|
|
|
|
public void SetClapAvailability(float startBeat, float length)
|
2021-12-24 00:58:48 +00:00
|
|
|
{
|
|
|
|
lastClapBeat = startBeat;
|
|
|
|
clapVacant = true;
|
2021-12-25 02:37:03 +00:00
|
|
|
lastClapLength = length;
|
2021-12-24 00:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void SetEligibility(bool early, bool perfect, bool late)
|
|
|
|
{
|
|
|
|
this.early = false;
|
|
|
|
this.perfect = false;
|
|
|
|
this.late = false;
|
|
|
|
|
|
|
|
if (early)
|
|
|
|
this.early = true;
|
|
|
|
else if (perfect)
|
|
|
|
this.perfect = true;
|
|
|
|
else if (late)
|
|
|
|
this.late = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Clap()
|
|
|
|
{
|
|
|
|
bool canHit = early != true && late != true && perfect == true && hit == false;
|
|
|
|
|
|
|
|
if (canHit)
|
|
|
|
{
|
2021-12-24 03:36:16 +00:00
|
|
|
clapEffect.SetActive(true);
|
2021-12-24 00:58:48 +00:00
|
|
|
Jukebox.PlayOneShotGame("clappyTrio/rightClap");
|
2021-12-24 03:36:16 +00:00
|
|
|
|
|
|
|
if (this.canHit)
|
|
|
|
ClappyTrio.instance.playerHitLast = true;
|
2021-12-24 00:58:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-24 03:36:16 +00:00
|
|
|
clapEffect.SetActive(false);
|
2021-12-24 00:58:48 +00:00
|
|
|
Jukebox.PlayOneShot("miss");
|
|
|
|
ClappyTrio.instance.playerHitLast = false;
|
2021-12-24 03:36:16 +00:00
|
|
|
|
|
|
|
if (clapStarted)
|
|
|
|
this.canHit = false;
|
2021-12-24 00:58:48 +00:00
|
|
|
}
|
|
|
|
|
2021-12-24 08:35:54 +00:00
|
|
|
ClappyTrio.instance.SetFace(ClappyTrio.instance.Lion.Count - 1, 4);
|
2021-12-24 00:58:48 +00:00
|
|
|
this.GetComponent<Animator>().Play("Clap", 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|