129 lines
4.1 KiB
C#
129 lines
4.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
using HeavenStudio.Util;
|
|
|
|
namespace HeavenStudio.Games.Scripts_Chameleon
|
|
{
|
|
public enum FlyType
|
|
{
|
|
Close,
|
|
Far,
|
|
}
|
|
|
|
public class Fly : MonoBehaviour
|
|
{
|
|
public double startBeat;
|
|
public FlyType flyType;
|
|
[SerializeField] private Animator flyAnim;
|
|
|
|
private Sound loopSound;
|
|
|
|
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/fly" + typePrefix + "Loop", -1, 1, 1, true);
|
|
MultiSound.Play(
|
|
new MultiSound.Sound[] {
|
|
new MultiSound.Sound("chameleon/fly" + typePrefix + "1", startBeat + 4),
|
|
new MultiSound.Sound("chameleon/fly" + typePrefix + "2", startBeat + 5),
|
|
new MultiSound.Sound("chameleon/fly" + typePrefix + "3", startBeat + 6),
|
|
}
|
|
);
|
|
|
|
BeatAction.New(game, new List<BeatAction.Action>()
|
|
{
|
|
new BeatAction.Action(startBeat, delegate {
|
|
var currentBeat = Conductor.instance.songPositionInBeatsAsDouble;
|
|
flyAnim.DoScaledAnimationAsync("move" + typePrefix, 0.5f, (float)((currentBeat - startBeat)/8));
|
|
}),
|
|
new BeatAction.Action(startBeat + 4, delegate {
|
|
// flyAnim.DoScaledAnimationAsync("" + typePrefix, 0.5f);
|
|
loopSoundRelease();
|
|
}),
|
|
});
|
|
|
|
var InputAction = flyType switch
|
|
{
|
|
FlyType.Far => Chameleon.InputAction_Far,
|
|
FlyType.Close => Chameleon.InputAction_Close,
|
|
_ => throw new System.NotImplementedException()
|
|
};
|
|
game.ScheduleInput(startBeat + 4, 3, InputAction, JustCatch, MissCatch, Empty);
|
|
|
|
BeatAction.New(this, new List<BeatAction.Action>()
|
|
{
|
|
new BeatAction.Action(startBeat + 8, delegate {
|
|
Destroy();
|
|
}),
|
|
});
|
|
}
|
|
|
|
void JustCatch(PlayerActionEvent caller, float state)
|
|
{
|
|
string typePrefix = flyType switch
|
|
{
|
|
FlyType.Far => "Far",
|
|
FlyType.Close => "Close",
|
|
_ => throw new System.NotImplementedException()
|
|
};
|
|
game.chameleonAnim.DoScaledAnimationAsync("tongue" + typePrefix, 0.5f);
|
|
if (state <= -1f || state >= 1f)
|
|
{
|
|
flyAnim.DoScaledAnimationAsync("fall" + typePrefix, 0.5f);
|
|
return;
|
|
}
|
|
game.currentFly = null;
|
|
SoundByte.PlayOneShotGame("chameleon/eatCatch");
|
|
SoundByte.PlayOneShotGame("chameleon/eatGulp", startBeat + 7.25);
|
|
flyAnim.Play("idle", 1, 0);
|
|
flyAnim.DoScaledAnimationAsync("catch" + typePrefix, 0.5f);
|
|
BeatAction.New(game, new List<BeatAction.Action>()
|
|
{
|
|
new BeatAction.Action(startBeat + 7.25, delegate {
|
|
game.chameleonAnim.DoScaledAnimationAsync("gurp", 0.5f);
|
|
}),
|
|
});
|
|
}
|
|
|
|
void MissCatch(PlayerActionEvent caller)
|
|
{
|
|
string typePrefix = flyType switch
|
|
{
|
|
FlyType.Far => "Far",
|
|
FlyType.Close => "Close",
|
|
_ => throw new System.NotImplementedException()
|
|
};
|
|
flyAnim.DoScaledAnimationAsync("gone" + typePrefix, 0.5f);
|
|
}
|
|
|
|
void Empty(PlayerActionEvent caller) { }
|
|
|
|
private void loopSoundRelease()
|
|
{
|
|
if (loopSound != null)
|
|
{
|
|
loopSound.KillLoop(0);
|
|
loopSound = null;
|
|
}
|
|
}
|
|
|
|
private void Destroy()
|
|
{
|
|
game.currentFly = null;
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
} |