HeavenStudio/Assets/Scripts/Games/FanClub/NtrIdolAmie.cs
ev 9b16a8d5a9
Fan Club Retouch (#416)
* new sprites not done

* more sprites more anim chanegs

* almost done

* INSANE

* sheet done

* its done

* re-implement improved squat sprite

* remove many unused assets

allow games to be hidden in the editor

* start animations of backup dancers

* finish backup dancer animations

* add effects to backup dancers' tree

* add dancers to the prefab

* import new sprites

* backup dancers fully functional

* game camera now updates in LateUpdate()

* touched some anims

* oops

* oops 2

* add audience applause

fix the mapped cellanim shaders

---------

Co-authored-by: minenice55 <star.elementa@gmail.com>
2023-05-21 17:35:00 +00:00

231 lines
8.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HeavenStudio.Util;
using static HeavenStudio.Games.FanClub;
namespace HeavenStudio.Games.Scripts_FanClub
{
public class NtrIdolAmie : MonoBehaviour
{
[Header("Params")]
[SerializeField] float stepDistance = 1f;
[SerializeField] float startPostion = 0f;
[SerializeField] float rootYPos = 0f;
[Header("Objects")]
[SerializeField] ParticleSystem clapEffect;
[SerializeField] ParticleSystem winkEffect;
[SerializeField] GameObject rootTransform;
[SerializeField] GameObject shadow;
[Header("References")]
public Material coreMat;
Animator anim;
float startStepBeat = float.MaxValue;
float stepLength = 16f;
bool exiting = false;
int currentAnim = 0;
float startJumpTime = float.MinValue;
bool hasJumped = false;
const int StepCount = 8;
const int AnimCount = StepCount * 2;
Conductor cond;
private void Update() {
if (cond.songPositionInBeatsAsDouble >= startStepBeat + stepLength)
{
FinishEntrance(exiting);
startStepBeat = float.MaxValue;
currentAnim = 0;
}
else if (cond.songPositionInBeatsAsDouble >= startStepBeat)
{
currentAnim = (int)((cond.songPositionInBeatsAsDouble - startStepBeat) / (stepLength / AnimCount));
float startAnimBeat = startStepBeat + (stepLength / AnimCount) * currentAnim;
float endAnimBeat = startAnimBeat + (stepLength / AnimCount);
float prog = (float)((cond.songPositionInBeatsAsDouble - startAnimBeat - 0.75) / (endAnimBeat - startAnimBeat));
prog = Mathf.Clamp01(prog * 4);
if (exiting)
{
currentAnim = AnimCount - currentAnim;
prog = (float)((cond.songPositionInBeatsAsDouble - startAnimBeat) / (endAnimBeat - startAnimBeat));
prog = Mathf.Clamp01(prog * 4);
}
anim.DoScaledAnimation(currentAnim % 2 == 0 ? "WalkB" : "WalkA", startAnimBeat - (exiting ? 0.75f : 0), stepLength / AnimCount);
if (exiting)
rootTransform.transform.localPosition = new Vector3(startPostion + stepDistance * currentAnim - stepDistance * prog, rootYPos);
else
rootTransform.transform.localPosition = new Vector3(startPostion + stepDistance * currentAnim + stepDistance * prog, rootYPos);
}
if (startStepBeat == float.MaxValue)
{
//idol jumping physics
float jumpPos = cond.GetPositionFromBeat(startJumpTime, 1f);
float IDOL_SHADOW_SCALE = 1.18f;
if (cond.songPositionInBeats >= startJumpTime && cond.songPositionInBeats < startJumpTime + 1f)
{
hasJumped = true;
float yMul = jumpPos * 2f - 1f;
float yWeight = -(yMul*yMul) + 1f;
rootTransform.transform.localPosition = new Vector3(startPostion + stepDistance * AnimCount, rootYPos + (2f * yWeight + 0.25f));
shadow.transform.localScale = new Vector3((1f-yWeight*0.8f) * IDOL_SHADOW_SCALE, (1f-yWeight*0.8f) * IDOL_SHADOW_SCALE, 1f);
anim.DoScaledAnimation("Jump", startJumpTime, 1f);
}
else
{
startJumpTime = float.MinValue;
rootTransform.transform.localPosition = new Vector3(startPostion + stepDistance * AnimCount, rootYPos);
shadow.transform.localScale = new Vector3(IDOL_SHADOW_SCALE, IDOL_SHADOW_SCALE, 1f);
}
}
shadow.transform.localPosition = new Vector3(rootTransform.transform.localPosition.x, shadow.transform.localPosition.y);
}
public void ClapParticle()
{
if (clapEffect == null) return;
clapEffect.Play();
}
public void WinkParticle()
{
if (winkEffect == null) return;
winkEffect.Play();
}
public void Init()
{
gameObject.SetActive(false);
rootTransform.SetActive(false);
shadow.SetActive(false);
cond = Conductor.instance;
anim = GetComponent<Animator>();
}
public void StartEntrance(float beat, float length, bool exit) {
gameObject.SetActive(true);
rootTransform.SetActive(true);
shadow.SetActive(true);
startStepBeat = beat;
stepLength = length;
exiting = exit;
if (exiting)
{
rootTransform.transform.localPosition = new Vector3(startPostion + stepDistance * AnimCount, rootYPos);
}
else
{
rootTransform.transform.localPosition = new Vector3(startPostion, rootYPos);
}
}
public void FinishEntrance(bool exit) {
exiting = exit;
if (exiting)
{
rootTransform.transform.localPosition = new Vector3(startPostion, rootYPos);
gameObject.SetActive(false);
rootTransform.SetActive(false);
shadow.SetActive(false);
}
else
{
rootTransform.transform.localPosition = new Vector3(startPostion + stepDistance * AnimCount, rootYPos);
gameObject.SetActive(true);
rootTransform.SetActive(true);
shadow.SetActive(true);
}
}
public void ToSpot(bool unspot = true)
{
if (unspot)
coreMat.SetColor("_Color", new Color(1, 1, 1, 1));
else
coreMat.SetColor("_Color", new Color(117/255f, 177/255f, 209/255f, 1));
}
public void DoIdolJump(float beat)
{
if (startStepBeat != float.MaxValue) return;
if (!gameObject.activeInHierarchy) return;
startJumpTime = beat;
//play anim
BeatAction.New(gameObject, new List<BeatAction.Action>()
{
// new BeatAction.Action(beat, delegate { anim.Play("Jump", -1, 0); }),
new BeatAction.Action(beat + 1f, delegate { anim.Play("Land", -1, 0); }),
});
}
public void PlayAnim(float beat, float length, int type)
{
if (startStepBeat != float.MaxValue) return;
if (!gameObject.activeInHierarchy) return;
startJumpTime = float.MinValue;
// DisableResponse(beat, length + 0.5f);
// DisableBop(beat, length + 0.5f);
// DisableCall(beat, length + 0.5f);
switch (type)
{
case (int) IdolAnimations.Bop:
anim.Play("Beat", -1, 0);
break;
case (int) IdolAnimations.PeaceVocal:
anim.Play("Peace", -1, 0);
break;
case (int) IdolAnimations.Peace:
anim.Play("Peace", -1, 0);
break;
case (int) IdolAnimations.Clap:
anim.Play("Crap", -1, 0);
break;
case (int) IdolAnimations.Jump:
DoIdolJump(beat);
break;
case (int) IdolAnimations.Squat:
BeatAction.New(gameObject, new List<BeatAction.Action>()
{
new BeatAction.Action(beat, delegate { anim.Play("Squat0", -1, 0); }),
new BeatAction.Action(beat + length, delegate { anim.Play("Squat1", -1, 0); }),
});
break;
case (int) IdolAnimations.Wink:
BeatAction.New(gameObject, new List<BeatAction.Action>()
{
new BeatAction.Action(beat, delegate { anim.Play("Wink0", -1, 0); }),
new BeatAction.Action(beat + length, delegate { anim.Play("Wink1", -1, 0); }),
});
break;
case (int) IdolAnimations.Dab:
anim.Play("Dab", -1, 0);
break;
case (int) IdolAnimations.Call:
case (int) IdolAnimations.Response:
case (int) IdolAnimations.BigCall:
default:
break;
}
}
public void PlayAnimState(string state)
{
if (startStepBeat != float.MaxValue) return;
if (!gameObject.activeInHierarchy) return;
anim.Play(state, -1, 0);
}
}
}