2022-02-10 08:13:54 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
2023-05-29 20:09:34 +00:00
|
|
|
using UnityEngine.UIElements;
|
2022-02-11 02:14:09 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games.Scripts_RhythmTweezers
|
2022-02-10 08:13:54 +00:00
|
|
|
{
|
2023-05-07 20:33:15 +00:00
|
|
|
public class LongHair : MonoBehaviour
|
2022-02-10 08:13:54 +00:00
|
|
|
{
|
2023-06-10 19:13:29 +00:00
|
|
|
public double createBeat;
|
2022-02-11 02:14:09 +00:00
|
|
|
public GameObject hairSprite;
|
|
|
|
public GameObject stubbleSprite;
|
2022-02-10 08:13:54 +00:00
|
|
|
private RhythmTweezers game;
|
|
|
|
private Tweezers tweezers;
|
2022-02-11 07:21:43 +00:00
|
|
|
private Animator anim;
|
|
|
|
private int pluckState = 0;
|
2022-02-11 02:14:09 +00:00
|
|
|
|
|
|
|
public GameObject holder;
|
2022-02-11 07:21:43 +00:00
|
|
|
public GameObject loop;
|
|
|
|
|
2022-03-10 03:59:48 +00:00
|
|
|
private Sound pullSound;
|
2022-02-11 02:14:09 +00:00
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
private double inputBeat;
|
2023-05-29 20:09:34 +00:00
|
|
|
|
2023-01-16 03:05:25 +00:00
|
|
|
PlayerActionEvent endEvent;
|
|
|
|
|
2023-06-28 04:51:53 +00:00
|
|
|
public void StartInput(double beat, double length, Tweezers tweezer)
|
2022-02-10 08:13:54 +00:00
|
|
|
{
|
|
|
|
game = RhythmTweezers.instance;
|
2022-02-11 07:21:43 +00:00
|
|
|
anim = GetComponent<Animator>();
|
2023-06-28 04:51:53 +00:00
|
|
|
tweezers = tweezer;
|
2023-05-29 20:09:34 +00:00
|
|
|
inputBeat = beat + length;
|
2023-10-29 19:44:47 +00:00
|
|
|
game.ScheduleInput(beat, length, RhythmTweezers.InputAction_Press, StartJust, StartMiss, Out);
|
2023-01-16 03:05:25 +00:00
|
|
|
}
|
|
|
|
|
2022-02-10 08:13:54 +00:00
|
|
|
private void Update()
|
|
|
|
{
|
2022-02-11 07:21:43 +00:00
|
|
|
if (pluckState == 1)
|
2022-02-11 02:14:09 +00:00
|
|
|
{
|
2022-02-12 01:15:36 +00:00
|
|
|
Vector3 tst = tweezers.tweezerSpriteTrans.position;
|
|
|
|
var hairDirection = new Vector3(tst.x + 0.173f, tst.y) - holder.transform.position;
|
2022-02-11 07:21:43 +00:00
|
|
|
holder.transform.rotation = Quaternion.FromToRotation(Vector3.down, hairDirection);
|
2022-02-11 02:14:09 +00:00
|
|
|
|
2024-04-07 04:54:06 +00:00
|
|
|
float normalizedBeat = Conductor.instance.GetPositionFromBeat(inputBeat, 0.5f, ignoreSwing: false);
|
2022-02-11 07:21:43 +00:00
|
|
|
anim.Play("LoopPull", 0, normalizedBeat);
|
2022-02-11 02:14:09 +00:00
|
|
|
tweezers.anim.Play("Tweezers_LongPluck", 0, normalizedBeat);
|
2023-10-29 19:44:47 +00:00
|
|
|
if (!game.IsExpectingInputNow(RhythmTweezers.InputAction_Release) && PlayerInput.GetIsAction(RhythmTweezers.InputAction_Release) && normalizedBeat < 1f)
|
2023-05-29 20:09:34 +00:00
|
|
|
{
|
|
|
|
EndEarly();
|
|
|
|
endEvent.Disable();
|
|
|
|
}
|
2022-02-11 07:21:43 +00:00
|
|
|
// Auto-release if holding at release time.
|
2023-06-06 18:59:56 +00:00
|
|
|
if (normalizedBeat >= 1f)
|
|
|
|
endEvent.Hit(0, 1);
|
2022-02-11 02:14:09 +00:00
|
|
|
}
|
2022-02-11 07:21:43 +00:00
|
|
|
|
|
|
|
loop.transform.localScale = Vector2.one / holder.transform.localScale;
|
2022-02-11 02:14:09 +00:00
|
|
|
}
|
|
|
|
|
2023-01-16 03:05:25 +00:00
|
|
|
public void EndAce()
|
2022-02-10 08:13:54 +00:00
|
|
|
{
|
2023-05-29 20:09:34 +00:00
|
|
|
if (pluckState != 1) return;
|
2022-02-10 08:13:54 +00:00
|
|
|
tweezers.LongPluck(true, this);
|
|
|
|
tweezers.hitOnFrame++;
|
2022-02-11 07:21:43 +00:00
|
|
|
|
|
|
|
if (pullSound != null)
|
2024-04-08 02:18:51 +00:00
|
|
|
pullSound.KillLoop();
|
2022-02-11 07:21:43 +00:00
|
|
|
|
|
|
|
pluckState = -1;
|
|
|
|
}
|
|
|
|
|
2023-01-16 03:05:25 +00:00
|
|
|
public void EndEarly()
|
2022-02-11 07:21:43 +00:00
|
|
|
{
|
2024-04-07 04:54:06 +00:00
|
|
|
var normalized = Conductor.instance.GetPositionFromBeat(inputBeat, 0.5f, ignoreSwing: false);
|
2023-01-16 03:05:25 +00:00
|
|
|
anim.Play("LoopPullReverse", 0, normalized);
|
2023-05-29 20:09:34 +00:00
|
|
|
tweezers.anim.Play("Tweezers_Idle", 0, 0);
|
2023-01-16 03:05:25 +00:00
|
|
|
|
|
|
|
if (pullSound != null)
|
2024-04-08 02:18:51 +00:00
|
|
|
pullSound.KillLoop();
|
2023-01-16 03:05:25 +00:00
|
|
|
|
|
|
|
pluckState = -1;
|
2024-01-17 23:43:26 +00:00
|
|
|
game.ScoreMiss();
|
2023-01-16 03:05:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void StartJust(PlayerActionEvent caller, float state)
|
|
|
|
{
|
|
|
|
// don't count near misses
|
|
|
|
if (state >= 1f || state <= -1f) {
|
|
|
|
pluckState = -1;
|
|
|
|
return;
|
|
|
|
}
|
2023-06-10 19:13:29 +00:00
|
|
|
pullSound = SoundByte.PlayOneShotGame($"rhythmTweezers/longPull{UnityEngine.Random.Range(1, 5)}");
|
2023-01-16 03:05:25 +00:00
|
|
|
pluckState = 1;
|
2023-10-29 19:44:47 +00:00
|
|
|
endEvent = game.ScheduleInput(inputBeat, 0.5f, RhythmTweezers.InputAction_Release, EndJust, Out, Out);
|
2023-01-16 03:05:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void StartMiss(PlayerActionEvent caller)
|
|
|
|
{
|
|
|
|
// this is where perfect challenge breaks
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Out(PlayerActionEvent caller) {}
|
|
|
|
|
|
|
|
private void EndJust(PlayerActionEvent caller, float state)
|
|
|
|
{
|
|
|
|
if (state <= -1f) {
|
|
|
|
EndEarly();
|
|
|
|
return;
|
2022-02-11 07:21:43 +00:00
|
|
|
}
|
2023-01-16 03:05:25 +00:00
|
|
|
EndAce();
|
2022-02-10 08:13:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|