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:17:06 +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:17:06 +00:00
|
|
|
private double inputBeat;
|
2023-05-29 20:09:34 +00:00
|
|
|
|
2023-01-16 03:05:25 +00:00
|
|
|
PlayerActionEvent endEvent;
|
|
|
|
|
2022-02-10 08:13:54 +00:00
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
game = RhythmTweezers.instance;
|
2022-02-11 07:21:43 +00:00
|
|
|
anim = GetComponent<Animator>();
|
2022-02-10 08:13:54 +00:00
|
|
|
tweezers = game.Tweezers;
|
|
|
|
}
|
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
public void StartInput(double beat, double length)
|
2023-05-29 20:09:34 +00:00
|
|
|
{
|
|
|
|
inputBeat = beat + length;
|
|
|
|
game.ScheduleInput(beat, length, InputType.STANDARD_DOWN | InputType.DIRECTION_DOWN, 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
|
|
|
|
2023-05-29 20:09:34 +00:00
|
|
|
float normalizedBeat = Conductor.instance.GetPositionFromBeat(inputBeat, 0.5f);
|
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-05-29 20:09:34 +00:00
|
|
|
if (!game.IsExpectingInputNow(InputType.STANDARD_UP | InputType.DIRECTION_DOWN_UP) && PlayerInput.PressedUp(true) && normalizedBeat < 1f)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
pullSound.Stop();
|
|
|
|
|
|
|
|
pluckState = -1;
|
|
|
|
}
|
|
|
|
|
2023-01-16 03:05:25 +00:00
|
|
|
public void EndEarly()
|
2022-02-11 07:21:43 +00:00
|
|
|
{
|
2023-05-29 20:09:34 +00:00
|
|
|
var normalized = Conductor.instance.GetPositionFromBeat(inputBeat, 0.5f);
|
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)
|
|
|
|
pullSound.Stop();
|
|
|
|
|
|
|
|
pluckState = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void StartJust(PlayerActionEvent caller, float state)
|
|
|
|
{
|
|
|
|
// don't count near misses
|
|
|
|
if (state >= 1f || state <= -1f) {
|
|
|
|
pluckState = -1;
|
|
|
|
return;
|
|
|
|
}
|
2023-06-10 19:17:06 +00:00
|
|
|
pullSound = SoundByte.PlayOneShotGame($"rhythmTweezers/longPull{UnityEngine.Random.Range(1, 5)}");
|
2023-01-16 03:05:25 +00:00
|
|
|
pluckState = 1;
|
2023-05-29 20:09:34 +00:00
|
|
|
endEvent = game.ScheduleInput(inputBeat, 0.5f, InputType.STANDARD_UP | InputType.DIRECTION_DOWN_UP, 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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|