2024-03-04 05:58:22 +00:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
using HeavenStudio.Util;
|
2024-03-15 19:18:21 +00:00
|
|
|
using HeavenStudio.InputSystem;
|
2024-03-04 05:58:22 +00:00
|
|
|
|
|
|
|
namespace HeavenStudio.Games.Scripts_NailCarpenter
|
|
|
|
{
|
|
|
|
public class LongNail : MonoBehaviour
|
|
|
|
{
|
|
|
|
public double targetBeat;
|
2024-03-15 19:18:21 +00:00
|
|
|
public float targetX;
|
|
|
|
public float metresPerSecond;
|
2024-03-04 05:58:22 +00:00
|
|
|
public Animator nailAnim;
|
|
|
|
|
|
|
|
private NailCarpenter game;
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
{
|
|
|
|
game = NailCarpenter.instance;
|
2024-03-15 19:18:21 +00:00
|
|
|
|
|
|
|
game.ScheduleInput(targetBeat, 0, NailCarpenter.InputAction_AltPress, HammmerJust, HammmerMiss, null);
|
2024-03-04 05:58:22 +00:00
|
|
|
// wrongInput
|
2024-03-15 19:18:21 +00:00
|
|
|
if (PlayerInput.CurrentControlStyle != InputController.ControlStyles.Touch)
|
|
|
|
{
|
|
|
|
game.ScheduleUserInput(targetBeat, 0, NailCarpenter.InputAction_RegPress, WeakHammmerJust, null, null);
|
|
|
|
}
|
2024-04-07 04:56:37 +00:00
|
|
|
targetBeat = Conductor.instance.GetUnSwungBeat(targetBeat);
|
2024-03-15 19:18:21 +00:00
|
|
|
Update();
|
2024-03-04 05:58:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void HammmerJust(PlayerActionEvent caller, float state)
|
|
|
|
{
|
2024-03-15 19:18:21 +00:00
|
|
|
game.Carpenter.DoScaledAnimationAsync("carpenterHit", 0.25f);
|
2024-03-04 05:58:22 +00:00
|
|
|
if (state >= 1f || state <= -1f)
|
|
|
|
{
|
|
|
|
nailAnim.DoScaledAnimationAsync(
|
2024-03-15 19:18:21 +00:00
|
|
|
(state >= 1f ? "longNailBendRight" : "longNailBendLeft"), 0.25f);
|
2024-03-04 05:58:22 +00:00
|
|
|
SoundByte.PlayOneShot("miss");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SoundByte.PlayOneShotGame("nailCarpenter/HammerStrong");
|
2024-03-15 19:18:21 +00:00
|
|
|
nailAnim.DoScaledAnimationAsync("longNailHammered", 0.25f);
|
|
|
|
game.Carpenter.DoScaledAnimationAsync("eyeSmile", 0.25f, animLayer: 1);
|
2024-03-04 05:58:22 +00:00
|
|
|
}
|
|
|
|
|
2024-03-15 19:18:21 +00:00
|
|
|
private void WeakHammmerJust(PlayerActionEvent caller, float state)
|
2024-03-04 05:58:22 +00:00
|
|
|
{
|
|
|
|
game.ScoreMiss();
|
2024-03-15 19:18:21 +00:00
|
|
|
game.Carpenter.DoScaledAnimationAsync("carpenterHit", 0.25f);
|
2024-03-04 05:58:22 +00:00
|
|
|
if (state >= 1f || state <= -1f)
|
|
|
|
{
|
|
|
|
nailAnim.DoScaledAnimationAsync(
|
2024-03-15 19:18:21 +00:00
|
|
|
(state >= 1f ? "longNailBendRight" : "longNailBendLeft"), 0.25f);
|
2024-03-04 05:58:22 +00:00
|
|
|
SoundByte.PlayOneShot("miss");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SoundByte.PlayOneShotGame("nailCarpenter/HammerWeak");
|
2024-03-15 19:18:21 +00:00
|
|
|
nailAnim.DoScaledAnimationAsync("longNailWeakHammered", 0.25f);
|
2024-03-04 05:58:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void HammmerMiss(PlayerActionEvent caller)
|
|
|
|
{
|
2024-03-15 19:18:21 +00:00
|
|
|
game.Carpenter.DoScaledAnimationAsync("eyeBlink", 0.25f, animLayer: 1);
|
|
|
|
nailAnim.DoScaledAnimationAsync("longNailMiss", 0.5f);
|
2024-03-04 05:58:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
var cond = Conductor.instance;
|
|
|
|
|
|
|
|
if (cond.isPlaying && !cond.isPaused)
|
|
|
|
{
|
2024-04-07 04:56:37 +00:00
|
|
|
double beat = cond.unswungSongPositionInBeatsAsDouble;
|
2024-03-15 19:18:21 +00:00
|
|
|
Vector3 pos = transform.position;
|
|
|
|
pos.x = targetX + (float)((beat - targetBeat) * metresPerSecond);
|
|
|
|
transform.position = pos;
|
|
|
|
if (targetBeat != double.MinValue)
|
2024-03-04 05:58:22 +00:00
|
|
|
{
|
|
|
|
if (beat >= targetBeat + 9) Destroy(gameObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|