113 lines
3.9 KiB
C#
113 lines
3.9 KiB
C#
using HeavenStudio.Util;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace HeavenStudio.Games.Scripts_AgbNightWalk
|
|
{
|
|
public class AgbPlatformHandler : MonoBehaviour
|
|
{
|
|
private AgbNightWalk game;
|
|
[Header("Properties")]
|
|
[SerializeField] private AgbPlatform platformRef;
|
|
public float defaultYPos = -11.76f;
|
|
public float heightAmount = 2;
|
|
public float platformDistance = 3.80f;
|
|
public float playerXPos = -6.78f;
|
|
[Range(1, 100)]
|
|
public int platformCount = 20;
|
|
private float lastHeight = 0;
|
|
private float heightToRaiseTo = 0;
|
|
private double raiseBeat = -1;
|
|
[NonSerialized] public List<AgbPlatform> allPlatforms = new();
|
|
|
|
private void Awake()
|
|
{
|
|
game = AgbNightWalk.instance;
|
|
}
|
|
|
|
public void SpawnPlatforms(double beat)
|
|
{
|
|
if (game.countInBeat != -1)
|
|
{
|
|
for (int i = 0; i < platformCount; i++)
|
|
{
|
|
AgbPlatform platform = Instantiate(platformRef, transform);
|
|
allPlatforms.Add(platform);
|
|
platform.handler = this;
|
|
platform.StartInput(game.countInBeat + i + game.countInLength - (platformCount * 0.5), game.countInBeat + i + game.countInLength);
|
|
platform.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < platformCount; i++)
|
|
{
|
|
AgbPlatform platform = Instantiate(platformRef, transform);
|
|
allPlatforms.Add(platform);
|
|
platform.handler = this;
|
|
platform.StartInput(beat, Math.Ceiling(beat) + i - platformCount);
|
|
platform.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
var cond = Conductor.instance;
|
|
if (cond.isPlaying && !cond.isPaused)
|
|
{
|
|
if (raiseBeat != -1)
|
|
{
|
|
float normalizedBeat = Mathf.Clamp(cond.GetPositionFromBeat(raiseBeat, 1), 0, 1);
|
|
EasingFunction.Function func = EasingFunction.GetEasingFunction(EasingFunction.Ease.EaseOutQuint);
|
|
|
|
float newPosY = func(lastHeight, heightToRaiseTo, normalizedBeat);
|
|
|
|
transform.localPosition = new Vector3(0, -newPosY, 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void StopAll()
|
|
{
|
|
foreach (var platform in allPlatforms)
|
|
{
|
|
platform.Stop();
|
|
}
|
|
}
|
|
|
|
public bool PlatformsStopped()
|
|
{
|
|
return allPlatforms[0].stopped;
|
|
}
|
|
|
|
public void DestroyPlatforms(double startBeat, double firstBeat, double lastBeat)
|
|
{
|
|
List<AgbPlatform> platformsToDestroy = allPlatforms.FindAll(x => x.endBeat >= firstBeat && x.endBeat <= lastBeat);
|
|
platformsToDestroy.Sort((x, y) => x.endBeat.CompareTo(y.endBeat));
|
|
List<BeatAction.Action> actions = new();
|
|
for (int i = 0; i < platformsToDestroy.Count; i++)
|
|
{
|
|
AgbPlatform currentPlatformToDdestroy = platformsToDestroy[i];
|
|
double fallBeat = startBeat + i;
|
|
actions.Add(new BeatAction.Action(fallBeat, delegate
|
|
{
|
|
currentPlatformToDdestroy.Disappear(fallBeat);
|
|
}));
|
|
}
|
|
BeatAction.New(gameObject, actions);
|
|
}
|
|
|
|
public void RaiseHeight(double beat, int lastUnits, int currentUnits)
|
|
{
|
|
raiseBeat = beat;
|
|
lastHeight = lastUnits * heightAmount * transform.localScale.y;
|
|
heightToRaiseTo = currentUnits * heightAmount * transform.localScale.y;
|
|
Update();
|
|
}
|
|
}
|
|
}
|
|
|