2f6aff7691
- SongController: loads MP3 + Beat Saber JSON map, runs countdown (3→2→1→GO), spawns cubes via VR_BeatManager.Spawn() synced to audioSource.time - NoteData → SpawnEventInfo mapping: position/lineLayer → x/y, colorType → ColorSide, cutDirection → Direction enum - travelTimeOverride on SpawnEventInfo: each cube's travel time is back-calculated from remaining time at spawn moment, so simultaneous notes arrive at hit zone together regardless of frame-level spawn delay - AudioManager: add PlayClip(AudioClip) and CurrentTime property - VR_BeatManager: respect travelTimeOverride when non-zero - Settings.asset: targetTravelTime 0.5 → 1.8 for natural Beat Saber approach feel - SceneBuilder ④: auto-builds Game.unity from SaberStyle, wires SongController refs, registers in Build Settings - LiberationSans SDF fallback updated with NanumGothic for Korean text support - Remove unused SampleScene Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
142 lines
4.6 KiB
C#
142 lines
4.6 KiB
C#
using UnityEngine;
|
|
using Platinio;
|
|
using UnityEngine.Playables;
|
|
using VRBeats.ScriptableEvents;
|
|
using VRSDK;
|
|
|
|
namespace VRBeats
|
|
{
|
|
public class VR_BeatManager : Singleton<VR_BeatManager>
|
|
{
|
|
[SerializeField] private BoxCollider playZone = null;
|
|
[SerializeField] private Transform player = null;
|
|
[SerializeField] private VR_BeatSettings settings = null;
|
|
[SerializeField] private GameEvent onGameOver = null;
|
|
|
|
private AudioManager audioManager = null;
|
|
private EnviromentController enviromentController = null;
|
|
private PlayableDirector playableDirector = null;
|
|
private bool isGameRunning = true;
|
|
|
|
public Color RightColor { get { return settings.RightColor * settings.GlowIntensity; } }
|
|
public Color LeftColor { get { return settings.LeftColor * settings.GlowIntensity; } }
|
|
public VR_BeatSettings GameSettings { get { return settings; } }
|
|
|
|
public Transform Player { get { return player; } }
|
|
|
|
private int playerConsecutiveMiss = 0;
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
audioManager = FindObjectOfType<AudioManager>();
|
|
enviromentController = FindObjectOfType<EnviromentController>();
|
|
playableDirector = FindObjectOfType<PlayableDirector>();
|
|
}
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
playerConsecutiveMiss = 0;
|
|
}
|
|
|
|
|
|
public Color GetColorFromColorSide(ColorSide side)
|
|
{
|
|
return side == ColorSide.Right ? RightColor : LeftColor;
|
|
}
|
|
|
|
public Color GetColorFromControllerType(VR_ControllerType controller)
|
|
{
|
|
return controller == VR_ControllerType.Right ? RightColor : LeftColor;
|
|
}
|
|
|
|
private int frame = 0;
|
|
private void Update()
|
|
{
|
|
frame++;
|
|
}
|
|
|
|
public void Spawn(Spawneable spawneable , SpawnEventInfo info)
|
|
{
|
|
if (!isGameRunning)
|
|
return;
|
|
|
|
Vector3 finalPosition = CalculateSpawnPosition( info.position);
|
|
Vector3 travelOffset = Vector3.forward * -settings.TargetTravelDistance;
|
|
Vector3 spawnPosition = finalPosition - travelOffset;
|
|
|
|
Spawneable clone = Instantiate( spawneable , spawnPosition , Quaternion.Euler( info.rotation ) );
|
|
SetSpeedRelativeToPlayZone(info);
|
|
clone.Construct(info);
|
|
|
|
Vector3 finalScale = clone.transform.localScale;
|
|
clone.transform.localScale = Vector3.zero;
|
|
|
|
float travelTime = info.travelTimeOverride > 0f ? info.travelTimeOverride : settings.TargetTravelTime;
|
|
|
|
clone.transform.Move(finalPosition, travelTime).SetEase(settings.TargetTravelEase).SetOnComplete(delegate
|
|
{
|
|
clone.OnSpawn();
|
|
}).SetUpdateMode(Platinio.TweenEngine.UpdateMode.Update);
|
|
|
|
|
|
clone.transform.ScaleTween(finalScale, travelTime).SetEase(settings.TargetTravelEase);
|
|
|
|
}
|
|
|
|
private void SetSpeedRelativeToPlayZone(SpawnEventInfo info)
|
|
{
|
|
info.speedMultiplier = (int) Mathf.Sign(playZone.transform.forward.z * -1.0f);
|
|
}
|
|
|
|
private Vector3 CalculateSpawnPosition(Vector3 relativePosition)
|
|
{
|
|
Vector3 pos = CalculatePlayZoneCenter();
|
|
|
|
pos += Vector3.right * relativePosition.x * playZone.size.x;
|
|
pos += Vector3.up * relativePosition.y * playZone.size.y;
|
|
pos += Vector3.forward * relativePosition.z * playZone.size.z;
|
|
|
|
return pos;
|
|
}
|
|
|
|
private Vector3 CalculatePlayZoneCenter()
|
|
{
|
|
return playZone.transform.position + playZone.center;
|
|
}
|
|
|
|
public void GameOver()
|
|
{
|
|
//the game is already stopped
|
|
if (!isGameRunning)
|
|
{
|
|
return;
|
|
}
|
|
|
|
isGameRunning = false;
|
|
//slowdown the music to 0 and stop the playabledirector
|
|
audioManager.BlendAudioMixerPitch(1.0f , 0.0f).SetOnComplete( delegate {
|
|
if (playableDirector != null)
|
|
playableDirector.Stop();
|
|
}
|
|
).SetOwner(gameObject);
|
|
enviromentController.TurnLightsOff();
|
|
|
|
}
|
|
|
|
public void RestartLevel()
|
|
{
|
|
gameObject.CancelAllTweens();
|
|
|
|
isGameRunning = true;
|
|
audioManager.SetAudioMixerPitch(1.0f);
|
|
enviromentController.TurnLightsOn();
|
|
playableDirector.time = 0.0f;
|
|
playableDirector.Play();
|
|
}
|
|
|
|
}
|
|
|
|
}
|