2022-02-08 14:26:55 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
2022-02-09 10:29:09 +00:00
|
|
|
using System;
|
|
|
|
using Starpelly;
|
|
|
|
using DG.Tweening;
|
2022-02-08 14:26:55 +00:00
|
|
|
|
|
|
|
using RhythmHeavenMania.Util;
|
|
|
|
|
|
|
|
namespace RhythmHeavenMania.Games.RhythmTweezers
|
|
|
|
{
|
2022-02-09 03:58:25 +00:00
|
|
|
// use PlayerActionObject for the actual tweezers but this isn't playable rn so IDC
|
2022-02-08 14:26:55 +00:00
|
|
|
public class RhythmTweezers : Minigame
|
|
|
|
{
|
2022-02-09 10:29:09 +00:00
|
|
|
public Transform VegetableHolder;
|
2022-02-09 03:58:25 +00:00
|
|
|
public GameObject Vegetable;
|
2022-02-09 06:52:50 +00:00
|
|
|
public Animator VegetableAnimator;
|
|
|
|
public Tweezers Tweezers;
|
2022-02-09 10:29:09 +00:00
|
|
|
public GameObject hairBase;
|
2022-02-09 03:58:25 +00:00
|
|
|
|
|
|
|
[SerializeField] private GameObject HairsHolder;
|
2022-02-09 10:29:09 +00:00
|
|
|
[NonSerialized] public int hairsLeft = 0;
|
2022-02-09 03:58:25 +00:00
|
|
|
|
2022-02-09 10:29:09 +00:00
|
|
|
public float beatInterval = 4f;
|
|
|
|
float intervalStartBeat;
|
|
|
|
bool intervalStarted;
|
|
|
|
public float tweezerBeatOffset = 0f;
|
|
|
|
|
|
|
|
Tween transitionTween;
|
|
|
|
bool transitioning = false;
|
2022-02-09 03:58:25 +00:00
|
|
|
|
|
|
|
public static RhythmTweezers instance { get; set; }
|
|
|
|
|
|
|
|
private void Awake()
|
2022-02-08 14:26:55 +00:00
|
|
|
{
|
2022-02-09 03:58:25 +00:00
|
|
|
instance = this;
|
|
|
|
}
|
2022-02-08 14:26:55 +00:00
|
|
|
|
2022-02-09 10:29:09 +00:00
|
|
|
public void SpawnHair(float beat)
|
2022-02-09 03:58:25 +00:00
|
|
|
{
|
2022-02-09 10:29:09 +00:00
|
|
|
// End transition early if the next hair is a lil early.
|
|
|
|
StopTransitionIfActive();
|
|
|
|
|
|
|
|
// If interval hasn't started, assume this is the first hair of the interval.
|
|
|
|
if (!intervalStarted)
|
2022-02-09 03:58:25 +00:00
|
|
|
{
|
2022-02-09 10:29:09 +00:00
|
|
|
SetIntervalStart(beat, beatInterval);
|
|
|
|
}
|
|
|
|
|
|
|
|
Jukebox.PlayOneShotGame("rhythmTweezers/shortAppear", beat);
|
|
|
|
Hair hair = Instantiate(hairBase, HairsHolder.transform).GetComponent<Hair>();
|
|
|
|
hair.gameObject.SetActive(true);
|
|
|
|
|
|
|
|
float rot = -58f + 116 * Mathp.Normalize(beat, intervalStartBeat, intervalStartBeat + beatInterval - 1f);
|
|
|
|
hair.transform.eulerAngles = new Vector3(0, 0, rot);
|
|
|
|
hair.createBeat = beat;
|
|
|
|
hairsLeft++;
|
2022-02-08 14:26:55 +00:00
|
|
|
}
|
|
|
|
|
2022-02-09 10:29:09 +00:00
|
|
|
public void SetIntervalStart(float beat, float interval = 4f)
|
2022-02-08 14:26:55 +00:00
|
|
|
{
|
2022-02-09 10:29:09 +00:00
|
|
|
// End transition early if the interval starts a lil early.
|
|
|
|
StopTransitionIfActive();
|
|
|
|
|
|
|
|
intervalStartBeat = beat;
|
|
|
|
beatInterval = interval;
|
|
|
|
intervalStarted = true;
|
|
|
|
hairsLeft = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const float vegDupeOffset = 16.7f;
|
|
|
|
public void NextVegetable(float beat)
|
|
|
|
{
|
|
|
|
transitioning = true;
|
2022-02-09 03:58:25 +00:00
|
|
|
|
2022-02-09 10:29:09 +00:00
|
|
|
Jukebox.PlayOneShotGame("rhythmTweezers/register", beat);
|
2022-02-08 14:26:55 +00:00
|
|
|
|
2022-02-09 10:29:09 +00:00
|
|
|
// Move both vegetables to the left by vegDupeOffset, then reset their positions.
|
|
|
|
// On position reset, reset state of core vegetable.
|
|
|
|
transitionTween = VegetableHolder.DOLocalMoveX(-vegDupeOffset, Conductor.instance.secPerBeat * 0.5f)
|
|
|
|
.OnComplete(() => {
|
|
|
|
|
|
|
|
var holderPos = VegetableHolder.localPosition;
|
|
|
|
VegetableHolder.localPosition = new Vector3(0f, holderPos.y, holderPos.z);
|
|
|
|
|
|
|
|
ResetVegetable();
|
|
|
|
transitioning = false;
|
|
|
|
intervalStarted = false;
|
|
|
|
|
|
|
|
}).SetEase(Ease.InOutSine);
|
2022-02-09 03:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
2022-02-09 10:29:09 +00:00
|
|
|
if (!Conductor.instance.isPlaying && !Conductor.instance.isPaused && intervalStarted)
|
|
|
|
{
|
|
|
|
StopTransitionIfActive();
|
|
|
|
ResetVegetable();
|
|
|
|
intervalStarted = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void LateUpdate()
|
|
|
|
{
|
|
|
|
// Set tweezer angle.
|
|
|
|
var tweezerAngle = -180f;
|
|
|
|
|
|
|
|
if (intervalStarted)
|
|
|
|
{
|
|
|
|
var tweezerTime = Conductor.instance.songPositionInBeats - beatInterval - tweezerBeatOffset;
|
|
|
|
var unclampedAngle = -58f + 116 * Mathp.Normalize(tweezerTime, intervalStartBeat, intervalStartBeat + beatInterval - 1f);
|
|
|
|
tweezerAngle = Mathf.Clamp(unclampedAngle, -180f, 180f);
|
|
|
|
}
|
|
|
|
|
|
|
|
Tweezers.transform.eulerAngles = new Vector3(0, 0, tweezerAngle);
|
|
|
|
|
|
|
|
// Set tweezer to follow vegetable.
|
|
|
|
var currentTweezerPos = Tweezers.transform.localPosition;
|
|
|
|
Tweezers.transform.localPosition = new Vector3(currentTweezerPos.x, Vegetable.transform.localPosition.y + 1f, currentTweezerPos.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ResetVegetable()
|
|
|
|
{
|
|
|
|
foreach (Transform t in HairsHolder.transform)
|
|
|
|
{
|
|
|
|
var go = t.gameObject;
|
|
|
|
if (go != hairBase)
|
|
|
|
GameObject.Destroy(go);
|
|
|
|
}
|
|
|
|
|
|
|
|
VegetableAnimator.Play("Idle", 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void StopTransitionIfActive()
|
|
|
|
{
|
|
|
|
if (transitioning)
|
|
|
|
{
|
|
|
|
if (transitionTween != null)
|
|
|
|
transitionTween.Kill(true);
|
|
|
|
}
|
2022-02-08 14:26:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|