HeavenStudioPlus/Assets/Scripts/Games/KarateMan/Pot.cs

138 lines
5 KiB
C#
Raw Normal View History

2021-12-29 06:52:48 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace RhythmHeavenMania.Games.KarateMan
{
public class Pot : PlayerActionObject
{
public float startBeat;
2021-12-30 08:26:18 +00:00
public float createBeat;
[HideInInspector] public Animator anim;
2021-12-29 06:52:48 +00:00
2021-12-30 08:26:18 +00:00
public GameObject Holder;
private GameObject newHolder;
public GameObject Sprite;
[SerializeField] private GameObject Shadow;
public bool isThrown;
public bool isHit = false;
public float hitBeat;
private Vector3 lastPos;
private float lastShadowX;
public AnimationCurve hitCurve;
public AnimationCurve hitCurveX;
2022-01-01 18:54:17 +00:00
public AnimationCurve missCurve;
2021-12-30 08:26:18 +00:00
public int type;
public string hitSnd;
private float hitLength;
2021-12-29 06:52:48 +00:00
2022-01-01 18:54:17 +00:00
private float lastRot;
public bool kick;
2021-12-29 06:52:48 +00:00
private void Start()
{
PlayerActionInit(this.gameObject);
anim = GetComponent<Animator>();
Sprite.transform.eulerAngles = new Vector3(0, 0, Random.Range(0, 360));
2021-12-30 08:26:18 +00:00
isEligible = true;
if (type == 2)
hitLength = 23.45f;
else
hitLength = 16f;
2021-12-29 06:52:48 +00:00
}
private void Update()
{
2021-12-30 08:26:18 +00:00
float time2Destroy = Conductor.instance.GetLoopPositionFromBeat(createBeat, 4);
if (time2Destroy >= 1)
Destroy(this.gameObject);
if (isThrown)
{
float normalizedBeatAnim = Conductor.instance.GetLoopPositionFromBeat(startBeat, 2.15f);
anim.Play("PotThrow", 0, normalizedBeatAnim);
anim.speed = 0;
float normalizedBeat = Conductor.instance.GetLoopPositionFromBeat(startBeat, 1);
StateCheck(normalizedBeat, KarateMan.instance.EligibleHits);
lastPos = Holder.transform.localPosition;
lastShadowX = Shadow.transform.localPosition.x;
2022-01-01 18:54:17 +00:00
lastRot = Holder.transform.GetChild(0).eulerAngles.z;
2021-12-30 08:26:18 +00:00
}
2022-01-01 18:54:17 +00:00
if (!isHit && !isThrown)
2021-12-30 08:26:18 +00:00
{
2022-01-01 18:54:17 +00:00
float normalizedBeatAnim = Conductor.instance.GetLoopPositionFromBeat(hitBeat, 1.5f);
2021-12-30 08:26:18 +00:00
newHolder.transform.localPosition = new Vector3(transform.localPosition.x, Mathf.Lerp(0, 0.55f, Conductor.instance.GetLoopPositionFromBeat(hitBeat, 0.45f)));
2022-01-01 18:54:17 +00:00
Holder.transform.localPosition = new Vector3(Mathf.Lerp(lastPos.x, 0.9f, normalizedBeatAnim), Mathf.Lerp(lastPos.y, -3.43f, missCurve.Evaluate(normalizedBeatAnim)));
Holder.transform.GetChild(0).transform.eulerAngles = new Vector3(0, 0, Mathf.Lerp(lastRot, lastRot - 523.203f, normalizedBeatAnim));
Shadow.transform.localPosition = new Vector3(Mathf.Lerp(lastShadowX, 0.9f, normalizedBeatAnim), Shadow.transform.localPosition.y);
}
if (kick == false)
{
if (isHit)
{
float normalizedBeatAnim = Conductor.instance.GetLoopPositionFromBeat(hitBeat, 1.15f);
var y = Mathf.Lerp(lastPos.y, -3.27f, hitCurve.Evaluate(normalizedBeatAnim));
var x = Mathf.Lerp(lastPos.x, hitLength, hitCurveX.Evaluate(normalizedBeatAnim));
newHolder.transform.localPosition = new Vector3(transform.localPosition.x, Mathf.Lerp(0, 0.55f, Conductor.instance.GetLoopPositionFromBeat(hitBeat, 0.45f)));
Holder.transform.localPosition = new Vector3(x, y);
Shadow.transform.localPosition = new Vector3(Mathf.Lerp(lastShadowX, hitLength, hitCurveX.Evaluate(normalizedBeatAnim)), Shadow.transform.localPosition.y);
// anim.Play("PotHit", 0, normalizedBeatAnim);
// anim.speed = 0;
}
2021-12-30 08:26:18 +00:00
}
}
public void Hit()
2022-01-01 18:54:17 +00:00
{
if (!kick)
{
newHolder = new GameObject();
newHolder.transform.parent = this.gameObject.transform;
Holder.transform.parent = newHolder.transform;
Holder.transform.GetChild(0).gameObject.AddComponent<Rotate>().rotateSpeed = -7 * Conductor.instance.songBpm;
hitBeat = Conductor.instance.songPositionInBeats;
anim.enabled = false;
isThrown = false;
isHit = true;
Sprite.GetComponent<SpriteRenderer>().sortingOrder = 49;
}
else if (kick)
{
Instantiate(KarateMan.instance.Bomb, this.transform.parent).SetActive(true);
Destroy(this.gameObject);
}
}
public void Miss()
2021-12-30 08:26:18 +00:00
{
newHolder = new GameObject();
newHolder.transform.parent = this.gameObject.transform;
Holder.transform.parent = newHolder.transform;
hitBeat = Conductor.instance.songPositionInBeats;
2022-01-01 18:54:17 +00:00
isHit = false;
2021-12-30 08:26:18 +00:00
isThrown = false;
2022-01-01 18:54:17 +00:00
anim.enabled = false;
2021-12-30 08:26:18 +00:00
Sprite.GetComponent<SpriteRenderer>().sortingOrder = 49;
2021-12-29 06:52:48 +00:00
}
}
}