2024-03-08 05:11:52 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
2024-03-11 12:22:30 +00:00
|
|
|
using UnityEngine.Rendering;
|
2024-03-08 05:11:52 +00:00
|
|
|
|
|
|
|
using HeavenStudio.Util;
|
|
|
|
|
|
|
|
namespace HeavenStudio.Games.Scripts_PowerCalligraphy
|
|
|
|
{
|
|
|
|
public class Writing : MonoBehaviour
|
|
|
|
{
|
2024-03-11 12:22:30 +00:00
|
|
|
[Serializable]
|
|
|
|
public struct PatternItem
|
2024-03-08 05:11:52 +00:00
|
|
|
{
|
2024-03-11 12:22:30 +00:00
|
|
|
public double beat;
|
|
|
|
public SoundType soundType;
|
|
|
|
public float soundVolume;
|
|
|
|
public StrokeType stroke;
|
|
|
|
public FudeType fudeAnim;
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum SoundType {
|
|
|
|
None = 0,
|
|
|
|
brushTap,
|
|
|
|
brush1,
|
|
|
|
brush2,
|
|
|
|
brush3,
|
|
|
|
reShout,
|
|
|
|
comma1,
|
|
|
|
comma2,
|
|
|
|
comma3,
|
2024-03-08 05:11:52 +00:00
|
|
|
}
|
|
|
|
|
2024-03-11 12:22:30 +00:00
|
|
|
public enum StrokeType {
|
|
|
|
None = 0,
|
|
|
|
TOME = 1,
|
|
|
|
HANE,
|
|
|
|
HARAI,
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum FudeType {
|
|
|
|
None = 0,
|
|
|
|
Release,
|
|
|
|
Tap,
|
|
|
|
Prepare,
|
|
|
|
}
|
|
|
|
|
|
|
|
public double startBeat;
|
2024-03-18 02:40:24 +00:00
|
|
|
public double ongoingBeat = Double.MinValue;
|
2024-03-11 12:22:30 +00:00
|
|
|
public double nextBeat;
|
|
|
|
[SerializeField] PatternItem[] AnimPattern;
|
|
|
|
|
|
|
|
private Animator paperAnim;
|
|
|
|
private SortingGroup paperSort;
|
2024-03-08 05:11:52 +00:00
|
|
|
|
|
|
|
public Vector3 scrollSpeed;
|
|
|
|
Vector3 scrollRate => scrollSpeed / (Conductor.instance.pitchedSecPerBeat * 2f);
|
|
|
|
|
|
|
|
public bool onGoing = false;
|
|
|
|
bool isFinish = false;
|
2024-03-11 12:22:30 +00:00
|
|
|
int process_num;
|
2024-03-08 05:11:52 +00:00
|
|
|
StrokeType stroke;
|
|
|
|
public int Stroke { get { return (int)stroke; }}
|
|
|
|
|
|
|
|
private PowerCalligraphy game;
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
{
|
|
|
|
game = PowerCalligraphy.instance;
|
2024-03-11 12:22:30 +00:00
|
|
|
paperAnim = GetComponent<Animator>();
|
|
|
|
paperSort = GetComponent<SortingGroup>();
|
|
|
|
nextBeat = AnimPattern[^1].beat;
|
2024-03-08 05:11:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Play()
|
|
|
|
{
|
2024-03-11 12:22:30 +00:00
|
|
|
paperSort.sortingOrder++;
|
|
|
|
var sounds = new List<MultiSound.Sound>();
|
|
|
|
var actions = new List<BeatAction.Action>();
|
|
|
|
|
|
|
|
int anim_num = 0;
|
|
|
|
foreach (var item in AnimPattern)
|
2024-03-08 05:11:52 +00:00
|
|
|
{
|
2024-03-11 12:22:30 +00:00
|
|
|
double itemBeat = startBeat + item.beat;
|
|
|
|
string sound = item.soundType switch {
|
|
|
|
SoundType.brushTap => "powerCalligraphy/brushTap",
|
|
|
|
SoundType.brush1 => "powerCalligraphy/brush1",
|
|
|
|
SoundType.brush2 => "powerCalligraphy/brush2",
|
|
|
|
SoundType.brush3 => "powerCalligraphy/brush3",
|
|
|
|
SoundType.reShout => "powerCalligraphy/reShout",
|
|
|
|
SoundType.comma1 => "powerCalligraphy/comma1",
|
|
|
|
SoundType.comma2 => "powerCalligraphy/comma2",
|
|
|
|
SoundType.comma3 => "powerCalligraphy/comma3",
|
|
|
|
_ => ""
|
|
|
|
};
|
|
|
|
if (!string.IsNullOrEmpty(sound)) sounds.Add(new MultiSound.Sound(sound, itemBeat, volume:item.soundVolume));
|
2024-03-08 05:11:52 +00:00
|
|
|
|
2024-03-11 12:22:30 +00:00
|
|
|
int current_anim_num;
|
|
|
|
switch (item.fudeAnim)
|
|
|
|
{
|
|
|
|
case FudeType.Release:
|
|
|
|
anim_num++;
|
|
|
|
current_anim_num = anim_num;
|
|
|
|
actions.Add(new BeatAction.Action(itemBeat, delegate { Anim(current_anim_num); game.fudeAnim.DoScaledAnimationAsync("fude-none", 0.5f);}));
|
|
|
|
break;
|
|
|
|
case FudeType.Tap:
|
|
|
|
anim_num++;
|
|
|
|
current_anim_num = anim_num;
|
|
|
|
actions.Add(new BeatAction.Action(itemBeat, delegate { Anim(current_anim_num); game.fudeAnim.DoScaledAnimationAsync("fude-tap", 0.5f);}));
|
|
|
|
break;
|
|
|
|
case FudeType.Prepare:
|
|
|
|
actions.Add(new BeatAction.Action(itemBeat, delegate { game.fudeAnim.DoScaledAnimationAsync("fude-prepare", 0.5f);}));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2024-03-08 05:11:52 +00:00
|
|
|
|
2024-03-11 12:22:30 +00:00
|
|
|
int current_anim_num_1;
|
|
|
|
switch(item.stroke)
|
|
|
|
{
|
|
|
|
case StrokeType.TOME:
|
|
|
|
anim_num++;
|
|
|
|
current_anim_num_1 = anim_num;
|
|
|
|
actions.Add(new BeatAction.Action(itemBeat, delegate {
|
|
|
|
Halt(); stroke = StrokeType.TOME; process_num = current_anim_num_1;}));
|
2024-03-18 02:40:24 +00:00
|
|
|
actions.Add(new BeatAction.Action(itemBeat, delegate { onGoing = true; ongoingBeat = itemBeat;}));
|
2024-03-11 12:22:30 +00:00
|
|
|
game.ScheduleInput(itemBeat, 1f, PowerCalligraphy.InputAction_BasicPress, writeSuccess, writeMiss, Empty, CanSuccess);
|
|
|
|
break;
|
|
|
|
case StrokeType.HANE:
|
|
|
|
anim_num++;
|
|
|
|
current_anim_num_1 = anim_num;
|
|
|
|
actions.Add(new BeatAction.Action(itemBeat, delegate {
|
|
|
|
Sweep(); stroke = StrokeType.HANE; process_num = current_anim_num_1;}));
|
2024-03-18 02:40:24 +00:00
|
|
|
actions.Add(new BeatAction.Action(itemBeat+1, delegate { onGoing = true; ongoingBeat = itemBeat + 1;}));
|
2024-03-11 12:22:30 +00:00
|
|
|
game.ScheduleInput(itemBeat, 2f, PowerCalligraphy.InputAction_FlickPress, writeSuccess, writeMiss, Empty, CanSuccess);
|
|
|
|
break;
|
|
|
|
case StrokeType.HARAI:
|
|
|
|
anim_num++;
|
|
|
|
current_anim_num_1 = anim_num;
|
|
|
|
actions.Add(new BeatAction.Action(itemBeat, delegate {
|
|
|
|
Sweep(); stroke = StrokeType.HARAI; process_num = current_anim_num_1;}));
|
2024-03-18 02:40:24 +00:00
|
|
|
actions.Add(new BeatAction.Action(itemBeat+1, delegate { onGoing = true; ongoingBeat = itemBeat + 1;}));
|
2024-03-11 12:22:30 +00:00
|
|
|
game.ScheduleInput(itemBeat, 2f, PowerCalligraphy.InputAction_FlickPress, writeSuccess, writeMiss, Empty, CanSuccess);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2024-03-08 05:11:52 +00:00
|
|
|
}
|
2024-03-11 12:22:30 +00:00
|
|
|
actions.Add(new BeatAction.Action(startBeat + nextBeat, delegate { Finish();}));
|
|
|
|
|
|
|
|
if (sounds.Count > 0) MultiSound.Play(sounds.ToArray());
|
|
|
|
if (actions.Count > 0) BeatAction.New(game, actions);
|
2024-03-08 05:11:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TOME
|
|
|
|
private void Halt()
|
|
|
|
{
|
2024-03-11 12:22:30 +00:00
|
|
|
game.fudeAnim.Play("fude-halt");
|
|
|
|
SoundByte.PlayOneShotGame("powerCalligraphy/releaseB1");
|
2024-03-08 05:11:52 +00:00
|
|
|
}
|
|
|
|
// HANE HARAI
|
|
|
|
private void Sweep()
|
|
|
|
{
|
2024-03-11 12:22:30 +00:00
|
|
|
game.fudeAnim.Play("fude-sweep");
|
|
|
|
SoundByte.PlayOneShotGame("powerCalligraphy/releaseA1", forcePlay: true);
|
2024-03-08 05:11:52 +00:00
|
|
|
}
|
|
|
|
private void Finish()
|
|
|
|
{
|
|
|
|
isFinish = true;
|
2024-03-18 02:40:24 +00:00
|
|
|
paperSort.sortingOrder++;
|
|
|
|
transform.SetParent(game.paperHolder.transform, true);
|
2024-03-11 12:22:30 +00:00
|
|
|
game.fudeAnim.Play("fude-none");
|
2024-03-08 05:11:52 +00:00
|
|
|
paperAnim.enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void writeSuccess(PlayerActionEvent caller, float state)
|
|
|
|
{
|
2024-03-18 02:40:24 +00:00
|
|
|
if (state >= 1f) {
|
2024-03-08 05:11:52 +00:00
|
|
|
ProcessInput("late");
|
2024-03-18 02:40:24 +00:00
|
|
|
game.ChouninMiss();
|
|
|
|
} else if (state <= -1f) {
|
2024-03-08 05:11:52 +00:00
|
|
|
ProcessInput("fast");
|
2024-03-18 02:40:24 +00:00
|
|
|
game.ChouninMiss();
|
|
|
|
} else {
|
2024-03-08 05:11:52 +00:00
|
|
|
ProcessInput("just");
|
2024-03-18 02:40:24 +00:00
|
|
|
}
|
|
|
|
|
2024-03-08 05:11:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void writeMiss(PlayerActionEvent caller)
|
|
|
|
{
|
2024-03-18 02:40:24 +00:00
|
|
|
if (onGoing) Miss();
|
2024-03-08 05:11:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Empty(PlayerActionEvent caller) { }
|
|
|
|
|
|
|
|
bool CanSuccess()
|
|
|
|
{
|
|
|
|
return onGoing;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ProcessInput(string input)
|
|
|
|
{
|
|
|
|
onGoing = false;
|
2024-03-11 12:22:30 +00:00
|
|
|
Anim(process_num, input);
|
2024-03-08 05:11:52 +00:00
|
|
|
|
|
|
|
switch (input)
|
|
|
|
{
|
|
|
|
case "just":
|
|
|
|
switch (stroke) {
|
|
|
|
case StrokeType.TOME:
|
2024-03-11 12:22:30 +00:00
|
|
|
game.fudeAnim.DoScaledAnimationAsync("fude-tap", 0.5f);
|
2024-03-08 05:11:52 +00:00
|
|
|
SoundByte.PlayOneShotGame("powerCalligraphy/releaseB2");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case StrokeType.HANE:
|
|
|
|
case StrokeType.HARAI:
|
2024-03-11 12:22:30 +00:00
|
|
|
game.fudeAnim.DoScaledAnimationAsync("fude-none", 0.5f);
|
2024-03-08 05:11:52 +00:00
|
|
|
SoundByte.PlayOneShotGame("powerCalligraphy/releaseA2");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "late":
|
|
|
|
case "fast":
|
2024-03-18 02:40:24 +00:00
|
|
|
game.fudeAnim.DoScaledAnimationAsync("fude-none", 0.5f);
|
2024-03-08 05:11:52 +00:00
|
|
|
switch (stroke) { // WIP
|
|
|
|
case StrokeType.TOME:
|
|
|
|
SoundByte.PlayOneShotGame("powerCalligraphy/8");
|
|
|
|
break;
|
|
|
|
case StrokeType.HANE:
|
|
|
|
SoundByte.PlayOneShotGame("powerCalligraphy/6");
|
|
|
|
break;
|
|
|
|
case StrokeType.HARAI:
|
|
|
|
SoundByte.PlayOneShotGame("powerCalligraphy/9");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Miss()
|
|
|
|
{
|
|
|
|
onGoing = false;
|
|
|
|
SoundByte.PlayOneShotGame("powerCalligraphy/7"); // WIP
|
2024-03-11 12:22:30 +00:00
|
|
|
Anim(process_num, "miss");
|
2024-03-08 05:11:52 +00:00
|
|
|
|
2024-03-11 12:22:30 +00:00
|
|
|
switch (stroke) {
|
|
|
|
case StrokeType.TOME:
|
|
|
|
game.fudeAnim.DoScaledAnimationAsync("fude-none", 0.5f);
|
2024-03-08 05:11:52 +00:00
|
|
|
break;
|
2024-03-11 12:22:30 +00:00
|
|
|
|
|
|
|
case StrokeType.HANE:
|
|
|
|
case StrokeType.HARAI:
|
|
|
|
game.fudeAnim.DoScaledAnimationAsync("fude-sweep-end", 0.5f);
|
2024-03-08 05:11:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Anim(int num, string str = "")
|
|
|
|
{
|
2024-03-11 12:22:30 +00:00
|
|
|
string pattern = num.ToString() + str;
|
2024-03-08 05:11:52 +00:00
|
|
|
|
2024-03-11 12:22:30 +00:00
|
|
|
game.fudePosAnim.DoScaledAnimationAsync(pattern, 0.5f);
|
2024-03-18 02:40:24 +00:00
|
|
|
game.shiftAnim.DoScaledAnimationAsync(pattern, 0.5f);
|
2024-03-11 12:22:30 +00:00
|
|
|
paperAnim.DoScaledAnimationAsync(pattern, 0.5f);
|
2024-03-08 05:11:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
var cond = Conductor.instance;
|
|
|
|
|
|
|
|
if (cond.isPlaying && !cond.isPaused)
|
|
|
|
{
|
2024-03-18 02:40:24 +00:00
|
|
|
if (ongoingBeat > 0)
|
|
|
|
{
|
|
|
|
float normalizedBeat = cond.GetPositionFromBeat(ongoingBeat, 1);
|
|
|
|
float redRate = (normalizedBeat <= 0.5f) ? normalizedBeat/0.5f : (1.5f-normalizedBeat);
|
|
|
|
if (game is not null) game.playerFude.redRate = redRate;
|
|
|
|
}
|
2024-03-08 05:11:52 +00:00
|
|
|
if (isFinish)
|
|
|
|
{
|
|
|
|
double beat = cond.songPositionInBeats;
|
|
|
|
// Paper scroll.
|
|
|
|
var paperPos = transform.localPosition;
|
|
|
|
transform.localPosition = paperPos + (scrollRate * Time.deltaTime);
|
2024-03-11 12:22:30 +00:00
|
|
|
if (beat >= startBeat + 24) Destroy(gameObject);
|
2024-03-08 05:11:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|