HeavenStudio/Assets/Scripts/Games/Chameleon/Fly.cs
fu-majime 89c03e045c wip
2024-04-10 12:51:20 +09:00

171 lines
4.9 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HeavenStudio.Util;
namespace HeavenStudio.Games.Scripts_Chameleon
{
public enum FlyType
{
Far,
Close,
}
public class Fly : MonoBehaviour
{
public double startBeat;
public FlyType flyType;
[SerializeField] private Animator flyAnim;
private Sound loopSound;
bool isPresent, isAction;
private Chameleon game;
public void Init()
{
game = Chameleon.instance;
string typePrefix = flyType switch
{
FlyType.Far => "Far",
FlyType.Close => "Close",
_ => throw new System.NotImplementedException()
};
loopSound = SoundByte.PlayOneShotGame("chameleon/", -1, 1, 1, true);
MultiSound.Play(
new MultiSound.Sound[] {
new MultiSound.Sound("chameleon/", startBeat + 4),
new MultiSound.Sound("chameleon/", startBeat + 5),
new MultiSound.Sound("chameleon/", startBeat + 6),
}
);
BeatAction.New(this, new List<BeatAction.Action>()
{
new BeatAction.Action(startBeat, delegate {
flyAnim.DoScaledAnimationAsync("" + typePrefix, 0.5f);
loopSoundRelease();
}),
new BeatAction.Action(startBeat + 4, delegate {
flyAnim.DoScaledAnimationAsync("" + typePrefix, 0.5f);
loopSoundRelease();
}),
});
var InputAction = flyType switch
{
FlyType.Far => Chameleon.InputAction_Alt,
FlyType.Close => Chameleon.InputAction_BasicPress,
_ => throw new System.NotImplementedException()
};
game.ScheduleInput(startBeat + 4, 4, InputAction, JustCatch, MissCatch, Empty, CanCatch);
}
private void Update()
{
var cond = Conductor.instance;
if (cond.isPlaying && !cond.isPaused)
{
if (PlayerInput.GetIsAction(Chameleon.InputAction_BasicPress) && !game.IsExpectingInputNow(Chameleon.InputAction_BasicPress))
{
if (!isAction && isPresent && flyType is FlyType.Close)
{
isPresent = false;
string typePrefix = flyType switch
{
FlyType.Far => "Far",
FlyType.Close => "Close",
_ => throw new System.NotImplementedException()
};
SoundByte.PlayOneShotGame("chameleon/" + typePrefix);
flyAnim.DoScaledAnimationAsync("" + typePrefix, 0.5f);
}
}
if (PlayerInput.GetIsAction(Chameleon.InputAction_Alt) && !game.IsExpectingInputNow(Chameleon.InputAction_Alt))
{
if (!isAction && isPresent)
{
isPresent = false;
string typePrefix = flyType switch
{
FlyType.Far => "Far",
FlyType.Close => "Close",
_ => throw new System.NotImplementedException()
};
SoundByte.PlayOneShotGame("chameleon/" + typePrefix);
flyAnim.DoScaledAnimationAsync("" + typePrefix, 0.5f);
}
}
}
}
void JustCatch(PlayerActionEvent caller, float state)
{
isAction = true;
string typePrefix = flyType switch
{
FlyType.Far => "Far",
FlyType.Close => "Close",
_ => throw new System.NotImplementedException()
};
game.chameleonAnim.DoScaledAnimationAsync("" + typePrefix, 0.5f);
if (state <= -1f || state >= 1f)
{
return;
}
}
void MissCatch(PlayerActionEvent caller)
{
isAction = true;
string typePrefix = flyType switch
{
FlyType.Far => "Far",
FlyType.Close => "Close",
_ => throw new System.NotImplementedException()
};
game.chameleonAnim.DoScaledAnimationAsync("" + typePrefix, 0.5f);
}
bool CanCatch() { return isPresent;}
void Empty(PlayerActionEvent caller) { }
private void loopSoundRelease()
{
if (loopSound != null)
{
loopSound.KillLoop(0);
loopSound = null;
}
}
}
}