2024-03-04 05:58:22 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
using HeavenStudio.Util;
|
|
|
|
|
|
|
|
namespace HeavenStudio.Games.Scripts_NailCarpenter
|
|
|
|
{
|
|
|
|
public class Sweet : 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 sweetsType sweetType;
|
|
|
|
public Animator sweetAnim;
|
2024-03-15 19:18:21 +00:00
|
|
|
|
|
|
|
bool broken = false;
|
|
|
|
|
2024-03-04 05:58:22 +00:00
|
|
|
public enum sweetsType
|
|
|
|
{
|
2024-03-15 19:18:21 +00:00
|
|
|
None = -1,
|
|
|
|
Pudding = 0,
|
|
|
|
CherryPudding = 1,
|
|
|
|
ShortCake = 2,
|
|
|
|
Cherry = 3,
|
|
|
|
LayerCake = 4,
|
2024-03-04 05:58:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private NailCarpenter game;
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
{
|
|
|
|
game = NailCarpenter.instance;
|
2024-03-15 19:18:21 +00:00
|
|
|
broken = false;
|
2024-03-04 05:58:22 +00:00
|
|
|
|
|
|
|
AwakeAnim();
|
2024-03-15 19:18:21 +00:00
|
|
|
game.ScheduleUserInput(targetBeat, 0, NailCarpenter.InputAction_SweetsHit, HammmerJust, null, null);
|
|
|
|
Update();
|
|
|
|
|
|
|
|
if (sweetType == sweetsType.Pudding)
|
|
|
|
{
|
|
|
|
BeatAction.New(this, new List<BeatAction.Action>()
|
|
|
|
{
|
|
|
|
new BeatAction.Action(targetBeat, delegate
|
|
|
|
{
|
|
|
|
if (!broken)
|
|
|
|
{
|
|
|
|
sweetAnim.Play("puddingBeat", -1, 0);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
2024-03-04 05:58:22 +00:00
|
|
|
}
|
2024-03-15 19:18:21 +00:00
|
|
|
|
2024-03-04 05:58:22 +00:00
|
|
|
private void AwakeAnim()
|
|
|
|
{
|
2024-03-15 19:18:21 +00:00
|
|
|
switch (sweetType)
|
2024-03-04 05:58:22 +00:00
|
|
|
{
|
|
|
|
case sweetsType.Pudding:
|
|
|
|
sweetAnim.Play("puddingIdle", -1, 0);
|
|
|
|
break;
|
|
|
|
case sweetsType.CherryPudding:
|
|
|
|
sweetAnim.Play("cherryPuddingIdle", -1, 0);
|
|
|
|
break;
|
|
|
|
case sweetsType.ShortCake:
|
|
|
|
sweetAnim.Play("shortCakeIdle", -1, 0);
|
|
|
|
break;
|
|
|
|
case sweetsType.Cherry:
|
|
|
|
sweetAnim.Play("cherryIdle", -1, 0);
|
|
|
|
break;
|
|
|
|
case sweetsType.LayerCake:
|
|
|
|
sweetAnim.Play("layerCakeIdle", -1, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-03-15 19:18:21 +00:00
|
|
|
|
2024-03-04 05:58:22 +00:00
|
|
|
private void BreakAnim()
|
|
|
|
{
|
2024-03-15 19:18:21 +00:00
|
|
|
broken = true;
|
|
|
|
switch (sweetType)
|
2024-03-04 05:58:22 +00:00
|
|
|
{
|
|
|
|
case sweetsType.Pudding:
|
2024-03-15 19:18:21 +00:00
|
|
|
sweetAnim.DoScaledAnimationAsync("puddingBreak", 0.25f);
|
2024-03-04 05:58:22 +00:00
|
|
|
break;
|
|
|
|
case sweetsType.CherryPudding:
|
2024-03-15 19:18:21 +00:00
|
|
|
sweetAnim.DoScaledAnimationAsync("cherryPuddingBreak", 0.25f);
|
2024-03-04 05:58:22 +00:00
|
|
|
break;
|
|
|
|
case sweetsType.ShortCake:
|
2024-03-15 19:18:21 +00:00
|
|
|
sweetAnim.DoScaledAnimationAsync("shortCakeBreak", 0.25f);
|
2024-03-04 05:58:22 +00:00
|
|
|
break;
|
|
|
|
case sweetsType.Cherry:
|
2024-03-15 19:18:21 +00:00
|
|
|
sweetAnim.DoScaledAnimationAsync("cherryBreak", 0.25f);
|
2024-03-04 05:58:22 +00:00
|
|
|
break;
|
|
|
|
case sweetsType.LayerCake:
|
2024-03-15 19:18:21 +00:00
|
|
|
sweetAnim.DoScaledAnimationAsync("layerCakeBreak", 0.25f);
|
2024-03-04 05:58:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void HammmerJust(PlayerActionEvent caller, float state)
|
|
|
|
{
|
|
|
|
game.ScoreMiss();
|
|
|
|
BreakAnim();
|
2024-03-15 19:18:21 +00:00
|
|
|
game.Carpenter.DoScaledAnimationAsync("eyeBlink", 0.25f, animLayer: 1);
|
2024-03-04 05:58:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
var cond = Conductor.instance;
|
|
|
|
|
|
|
|
if (cond.isPlaying && !cond.isPaused)
|
|
|
|
{
|
|
|
|
double beat = cond.songPositionInBeats;
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|