2022-08-13 01:06:41 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
using HeavenStudio.Util;
|
|
|
|
|
|
|
|
namespace HeavenStudio.Games.Scripts_KarateMan
|
|
|
|
{
|
|
|
|
public class KarateManNoriController : MonoBehaviour
|
|
|
|
{
|
|
|
|
public GameObject NoriController;
|
|
|
|
public GameObject NoriHeart;
|
2022-08-13 22:38:22 +00:00
|
|
|
public Transform NoriHolderTengoku;
|
|
|
|
public Transform NoriHolderMania00;
|
|
|
|
public Transform NoriHolderMania01;
|
|
|
|
|
|
|
|
public GameObject NoriManiaInk00;
|
|
|
|
public GameObject NoriManiaInk01;
|
2022-08-13 01:06:41 +00:00
|
|
|
public Material NoriMaterial;
|
|
|
|
|
2022-08-13 02:06:43 +00:00
|
|
|
public Color[] NoriColorsTengoku;
|
|
|
|
public Color[] NoriColorsMania;
|
|
|
|
|
2022-08-13 01:06:41 +00:00
|
|
|
public float Nori;
|
|
|
|
public int MaxNori;
|
|
|
|
Animator[] NoriHeartAnimators;
|
|
|
|
Material[] NoriHeartMaterials;
|
2022-08-13 22:38:22 +00:00
|
|
|
Transform NoriHolder;
|
2022-08-13 01:06:41 +00:00
|
|
|
|
|
|
|
static Vector2 HeartScale = new Vector2(60, 52);
|
2022-08-13 22:38:22 +00:00
|
|
|
static float ScaleFactorTengoku = 1 / 46f;
|
|
|
|
static float ScaleFactorMania = 1 / 72f;
|
2022-08-13 01:06:41 +00:00
|
|
|
|
|
|
|
static float CameraOffset = 10;
|
2022-08-13 22:38:22 +00:00
|
|
|
static float PeriodLow = 24 / 60f;
|
|
|
|
static float PeriodHigh = 15 / 60f;
|
|
|
|
|
|
|
|
int noriMode = (int)KarateMan.NoriMode.None;
|
2022-08-13 01:06:41 +00:00
|
|
|
|
2022-08-13 22:38:22 +00:00
|
|
|
int inputsToSwitch = 0;
|
|
|
|
//takes 10% of inputs to fill the nori bar
|
|
|
|
float hitNoriAdd { get { return MaxNori / (inputsToSwitch * 0.15f); } }
|
2022-08-13 01:06:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-08-13 22:38:22 +00:00
|
|
|
public void SetNoriMode(float fromBeat, int mode, int startingNori = 0)
|
2022-08-13 01:06:41 +00:00
|
|
|
{
|
|
|
|
float scaleFactor = 0f;
|
|
|
|
//clear all children of the holder
|
2022-08-13 22:38:22 +00:00
|
|
|
if (NoriHolder != null)
|
2022-08-13 01:06:41 +00:00
|
|
|
{
|
2022-08-13 22:38:22 +00:00
|
|
|
foreach (Transform child in NoriHolder)
|
|
|
|
{
|
|
|
|
Destroy(child.gameObject);
|
|
|
|
}
|
2022-08-13 01:06:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case (int) KarateMan.NoriMode.Tengoku:
|
|
|
|
MaxNori = 5;
|
|
|
|
Nori = Mathf.Clamp(startingNori, 0, MaxNori);
|
|
|
|
scaleFactor = ScaleFactorTengoku;
|
2022-08-13 22:38:22 +00:00
|
|
|
NoriHolder = NoriHolderTengoku;
|
|
|
|
NoriManiaInk00.SetActive(false);
|
|
|
|
NoriManiaInk01.SetActive(false);
|
2022-08-13 01:06:41 +00:00
|
|
|
break;
|
|
|
|
case (int) KarateMan.NoriMode.Mania:
|
|
|
|
MaxNori = 10;
|
|
|
|
Nori = Mathf.Clamp(startingNori, 0, MaxNori);
|
|
|
|
scaleFactor = ScaleFactorMania;
|
2022-08-13 22:38:22 +00:00
|
|
|
NoriHolder = NoriHolderMania00;
|
|
|
|
NoriManiaInk00.SetActive(true);
|
|
|
|
NoriManiaInk01.SetActive(false);
|
|
|
|
|
|
|
|
inputsToSwitch = KarateMan.CountHitsToEnd(fromBeat);
|
|
|
|
Debug.Log($"inputs to segment end: {inputsToSwitch}");
|
2022-08-13 01:06:41 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MaxNori = 0;
|
|
|
|
Nori = 0;
|
2022-08-13 22:38:22 +00:00
|
|
|
NoriManiaInk00.SetActive(false);
|
|
|
|
NoriManiaInk01.SetActive(false);
|
2022-08-13 01:06:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NoriHeartAnimators = new Animator[MaxNori];
|
|
|
|
NoriHeartMaterials = new Material[MaxNori];
|
|
|
|
noriMode = mode;
|
|
|
|
|
|
|
|
if (mode == (int) KarateMan.NoriMode.None) return;
|
|
|
|
|
|
|
|
//add the label?
|
|
|
|
|
|
|
|
for (int i = 0; i < MaxNori; i++)
|
|
|
|
{
|
|
|
|
GameObject h = GameObject.Instantiate(NoriHeart, NoriHolder);
|
|
|
|
h.SetActive(true);
|
|
|
|
|
|
|
|
Material m_Material = Instantiate(NoriMaterial);
|
|
|
|
NoriHeartMaterials[i] = m_Material;
|
|
|
|
h.GetComponent<Image>().material = m_Material;
|
|
|
|
|
|
|
|
RectTransform hrect = h.GetComponent<RectTransform>();
|
|
|
|
hrect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, HeartScale.x * scaleFactor);
|
|
|
|
hrect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, HeartScale.y * scaleFactor);
|
|
|
|
|
|
|
|
NoriHeartAnimators[i] = h.GetComponent<Animator>();
|
|
|
|
NoriHeartAnimators[i].Play(i <= (int) (startingNori - 1) ? "NoriFull" : "NoriNone", -1, (Time.time * PeriodLow) % 1f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DoHit()
|
|
|
|
{
|
|
|
|
if (noriMode == (int) KarateMan.NoriMode.None) return;
|
|
|
|
if (noriMode == (int) KarateMan.NoriMode.Tengoku)
|
|
|
|
{
|
|
|
|
Nori += 1;
|
2022-08-13 22:38:22 +00:00
|
|
|
if (Nori > MaxNori) Nori = MaxNori;
|
|
|
|
if (Nori - 1 >= 0)
|
|
|
|
NoriHeartAnimators[(int) Nori - 1].Play("NoriFull", -1, (Time.time * PeriodHigh) % 1f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float oldNori = Nori;
|
|
|
|
Nori += hitNoriAdd;
|
|
|
|
if (Nori > MaxNori) Nori = MaxNori;
|
|
|
|
Debug.Log($"Nori: {Nori}, added {hitNoriAdd}, old nori: {oldNori}");
|
|
|
|
for (int i = 0; i < MaxNori; i++)
|
|
|
|
{
|
|
|
|
if (i <= (int) Nori && i >= (int) oldNori)
|
|
|
|
NoriHeartAnimators[i].Play("NoriFull", -1, (Time.time * PeriodHigh) % 1f);
|
|
|
|
}
|
2022-08-13 01:06:41 +00:00
|
|
|
}
|
2022-08-13 22:38:22 +00:00
|
|
|
UpdateHeartColours();
|
2022-08-13 01:06:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void DoNG()
|
|
|
|
{
|
|
|
|
if (noriMode == (int) KarateMan.NoriMode.None) return;
|
|
|
|
if (noriMode == (int) KarateMan.NoriMode.Tengoku)
|
|
|
|
{
|
|
|
|
Nori -= 1;
|
2022-08-13 22:38:22 +00:00
|
|
|
if (Nori < 0) Nori = 0;
|
2022-08-13 01:06:41 +00:00
|
|
|
NoriHeartAnimators[(int) Nori].Play("NoriNone", -1, (Time.time * PeriodLow) % 1f);
|
|
|
|
}
|
2022-08-13 22:38:22 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Nori -= hitNoriAdd;
|
|
|
|
if (Nori < 0) Nori = 0;
|
|
|
|
Debug.Log($"Nori: {Nori}, removed {hitNoriAdd}");
|
|
|
|
if (Nori == 0)
|
|
|
|
{
|
|
|
|
foreach (Animator anim in NoriHeartAnimators)
|
|
|
|
{
|
|
|
|
anim.Play("NoriNone", -1, (Time.time * PeriodLow) % 1f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i = 0; i < MaxNori; i++)
|
|
|
|
{
|
|
|
|
if (i > (int) Nori)
|
|
|
|
NoriHeartAnimators[i].Play("NoriNone", -1, (Time.time * PeriodLow) % 1f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UpdateHeartColours();
|
2022-08-13 01:06:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void DoThrough()
|
|
|
|
{
|
|
|
|
if (noriMode == (int) KarateMan.NoriMode.None) return;
|
|
|
|
if (noriMode == (int) KarateMan.NoriMode.Tengoku)
|
|
|
|
{
|
|
|
|
Nori = 0;
|
|
|
|
foreach (Animator anim in NoriHeartAnimators)
|
|
|
|
{
|
|
|
|
anim.Play("NoriNone", -1, (Time.time * PeriodLow) % 1f);
|
|
|
|
}
|
|
|
|
}
|
2022-08-13 22:38:22 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Nori -= hitNoriAdd * 2;
|
|
|
|
if (Nori < 0) Nori = 0;
|
|
|
|
Debug.Log($"Nori: {Nori}, removed {hitNoriAdd * 4}");
|
|
|
|
if (Nori == 0)
|
|
|
|
{
|
|
|
|
foreach (Animator anim in NoriHeartAnimators)
|
|
|
|
{
|
|
|
|
anim.Play("NoriNone", -1, (Time.time * PeriodLow) % 1f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i = 0; i < MaxNori; i++)
|
|
|
|
{
|
|
|
|
if (i > (int) Nori)
|
|
|
|
NoriHeartAnimators[i].Play("NoriNone", -1, (Time.time * PeriodLow) % 1f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UpdateHeartColours();
|
2022-08-13 01:06:41 +00:00
|
|
|
}
|
|
|
|
|
2022-08-13 02:06:43 +00:00
|
|
|
void UpdateHeartColours()
|
|
|
|
{
|
2022-08-13 22:38:22 +00:00
|
|
|
var cond = Conductor.instance;
|
2022-08-13 02:06:43 +00:00
|
|
|
if (noriMode == (int) KarateMan.NoriMode.None) return;
|
2022-08-13 22:38:22 +00:00
|
|
|
float flashPeriod;
|
|
|
|
for (int i = 0; i < NoriHeartMaterials.Length; i++)
|
2022-08-13 02:06:43 +00:00
|
|
|
{
|
2022-08-13 22:38:22 +00:00
|
|
|
Material mat = NoriHeartMaterials[i];
|
|
|
|
if (noriMode == (int) KarateMan.NoriMode.Tengoku)
|
2022-08-13 02:06:43 +00:00
|
|
|
{
|
|
|
|
if (Nori == MaxNori)
|
|
|
|
{
|
|
|
|
mat.SetColor("_ColorAlpha", NoriColorsTengoku[3]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (KarateMan.instance.NoriPerformance < 0.6)
|
|
|
|
mat.SetColor("_ColorAlpha", NoriColorsTengoku[0]);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (i < 2)
|
|
|
|
mat.SetColor("_ColorAlpha", NoriColorsTengoku[1]);
|
|
|
|
else
|
|
|
|
mat.SetColor("_ColorAlpha", NoriColorsTengoku[2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-13 22:38:22 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Color c = NoriColorsMania[0];
|
|
|
|
Color s = Color.black;
|
|
|
|
if (Nori == MaxNori)
|
|
|
|
{
|
|
|
|
flashPeriod = Mathf.Sin((cond.songPositionInBeats - i / (float) MaxNori) * Mathf.PI);
|
|
|
|
c = NoriColorsMania[2] + (NoriColorsMania[3] * ((1 - flashPeriod * 0.5f) + 0.5f));
|
|
|
|
s = Color.HSVToRGB(((cond.songPositionInBeats + 0.5f) * 4) % 1, 1, flashPeriod * 0.75f + 0.25f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flashPeriod = Mathf.Sin(cond.songPositionInBeats * Mathf.PI);
|
|
|
|
if (KarateMan.instance.NoriPerformance < 0.6)
|
|
|
|
c = NoriColorsMania[0];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (i < MaxNori - 2)
|
|
|
|
c = NoriColorsMania[1];
|
|
|
|
else
|
|
|
|
c = NoriColorsMania[2];
|
|
|
|
}
|
|
|
|
c *= (flashPeriod * 0.5f) + 1f;
|
|
|
|
}
|
|
|
|
mat.SetColor("_ColorAlpha", c);
|
|
|
|
mat.SetColor("_AddColor", s);
|
|
|
|
}
|
2022-08-13 02:06:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-13 01:06:41 +00:00
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
Transform target = GameCamera.instance.transform;
|
|
|
|
|
|
|
|
Vector3 displacement = target.forward * CameraOffset;
|
|
|
|
transform.position = target.position + displacement;
|
|
|
|
transform.rotation = target.rotation;
|
2022-08-13 02:06:43 +00:00
|
|
|
|
|
|
|
UpdateHeartColours();
|
2022-08-13 22:38:22 +00:00
|
|
|
|
|
|
|
float inkRot = (Conductor.instance.songPositionInBeats/ 8f) % 1f;
|
|
|
|
NoriManiaInk00.transform.localRotation = Quaternion.Euler(0, 0, inkRot * 360);
|
|
|
|
NoriManiaInk01.transform.localRotation = Quaternion.Euler(0, 0, inkRot * 360);
|
2022-08-13 01:06:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|