mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 11:47:38 +02:00
Editor: Song offset!
This commit is contained in:
@ -14,6 +14,7 @@ namespace RhythmHeavenMania
|
||||
public float bpm;
|
||||
public List<Entity> entities = new List<Entity>();
|
||||
public List<TempoChange> tempoChanges = new List<TempoChange>();
|
||||
public float firstBeatOffset;
|
||||
|
||||
[Serializable]
|
||||
public class Entity : ICloneable
|
||||
|
@ -79,16 +79,17 @@ namespace RhythmHeavenMania
|
||||
|
||||
public void Play(float beat)
|
||||
{
|
||||
this.time = GetSongPosFromBeat(beat);
|
||||
songPosBeat = GetSongPosFromBeat(beat) / secPerBeat;
|
||||
var startPos = GetSongPosFromBeat(beat);
|
||||
this.time = startPos - firstBeatOffset;
|
||||
songPosBeat = time / secPerBeat;
|
||||
|
||||
isPlaying = true;
|
||||
isPaused = false;
|
||||
|
||||
if (SongPosLessThanClipLength(time))
|
||||
if (SongPosLessThanClipLength(startPos))
|
||||
{
|
||||
musicSource.time = time;
|
||||
musicSource.PlayScheduled(Time.time);
|
||||
musicSource.time = startPos;
|
||||
musicSource.PlayScheduled(AudioSettings.dspTime);
|
||||
}
|
||||
|
||||
// GameManager.instance.SetCurrentEventToClosest(songPositionInBeats);
|
||||
@ -122,12 +123,14 @@ namespace RhythmHeavenMania
|
||||
|
||||
if (isPlaying)
|
||||
{
|
||||
time += Time.unscaledDeltaTime * musicSource.pitch;
|
||||
var dt = Time.unscaledDeltaTime * musicSource.pitch;
|
||||
|
||||
time += dt;
|
||||
|
||||
songPos = time;
|
||||
songPosition = songPos;
|
||||
|
||||
songPosBeat += ((Time.unscaledDeltaTime * musicSource.pitch) / secPerBeat);
|
||||
songPosBeat += (dt / secPerBeat);
|
||||
songPositionInBeats = songPosBeat;
|
||||
// songPositionInBeats = Time.deltaTime / secPerBeat;
|
||||
|
||||
|
@ -75,6 +75,7 @@ namespace RhythmHeavenMania
|
||||
{
|
||||
Beatmap = new Beatmap();
|
||||
Beatmap.bpm = 120f;
|
||||
Beatmap.firstBeatOffset = 0f;
|
||||
}
|
||||
|
||||
SortEventsList();
|
||||
@ -85,6 +86,7 @@ namespace RhythmHeavenMania
|
||||
eventCaller.GamesHolder = GamesHolder.transform;
|
||||
eventCaller.Init();
|
||||
Conductor.instance.SetBpm(Beatmap.bpm);
|
||||
Conductor.instance.firstBeatOffset = Beatmap.firstBeatOffset;
|
||||
|
||||
if (playOnStart)
|
||||
{
|
||||
@ -110,6 +112,7 @@ namespace RhythmHeavenMania
|
||||
|
||||
Beatmap = JsonConvert.DeserializeObject<Beatmap>(json);
|
||||
Conductor.instance.SetBpm(Beatmap.bpm);
|
||||
Conductor.instance.firstBeatOffset = Beatmap.firstBeatOffset;
|
||||
Stop(0);
|
||||
SetCurrentEventToClosest(0);
|
||||
|
||||
@ -193,6 +196,7 @@ namespace RhythmHeavenMania
|
||||
bool paused = Conductor.instance.isPaused;
|
||||
|
||||
Conductor.instance.SetBpm(Beatmap.bpm);
|
||||
Conductor.instance.firstBeatOffset = Beatmap.firstBeatOffset;
|
||||
|
||||
Conductor.instance.Play(beat);
|
||||
if (!paused)
|
||||
|
@ -160,7 +160,7 @@ namespace RhythmHeavenMania.Games.RhythmTweezers
|
||||
|
||||
// Move both vegetables to the left by vegDupeOffset, then reset their positions.
|
||||
// On position reset, reset state of core vegetable.
|
||||
transitionTween = VegetableHolder.DOLocalMoveX(-vegDupeOffset, Conductor.instance.secPerBeat * 0.5f)
|
||||
transitionTween = VegetableHolder.DOLocalMoveX(-vegDupeOffset, Conductor.instance.secPerBeat * 0.5f / Conductor.instance.musicSource.pitch)
|
||||
.OnComplete(() => {
|
||||
|
||||
var holderPos = VegetableHolder.localPosition;
|
||||
|
@ -351,6 +351,7 @@ namespace RhythmHeavenMania.Editor
|
||||
GameManager.instance.LoadRemix(json);
|
||||
Timeline.instance.LoadRemix();
|
||||
Timeline.instance.TempoInfo.UpdateStartingBPMText();
|
||||
Timeline.instance.TempoInfo.UpdateOffsetText();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ namespace RhythmHeavenMania.Editor.Track
|
||||
[SerializeField] private RectTransform RefTempoChange;
|
||||
public TMP_InputField StartingBPM;
|
||||
private RectTransform StartingBPMRect;
|
||||
public TMP_InputField FirstBeatOffset;
|
||||
|
||||
public List<TempoTimelineObj> tempoTimelineObjs = new List<TempoTimelineObj>();
|
||||
|
||||
@ -38,6 +39,7 @@ namespace RhythmHeavenMania.Editor.Track
|
||||
if (!firstUpdate)
|
||||
{
|
||||
UpdateStartingBPMText();
|
||||
UpdateOffsetText();
|
||||
firstUpdate = true;
|
||||
}
|
||||
|
||||
@ -79,6 +81,11 @@ namespace RhythmHeavenMania.Editor.Track
|
||||
StartingBPM.text = GameManager.instance.Beatmap.bpm.ToString("G");
|
||||
}
|
||||
|
||||
public void UpdateOffsetText()
|
||||
{
|
||||
FirstBeatOffset.text = (GameManager.instance.Beatmap.firstBeatOffset * 1000f).ToString("G");
|
||||
}
|
||||
|
||||
public void UpdateStartingBPMFromText()
|
||||
{
|
||||
// Failsafe against empty string.
|
||||
@ -103,6 +110,23 @@ namespace RhythmHeavenMania.Editor.Track
|
||||
UpdateStartingBPMText();
|
||||
}
|
||||
|
||||
public void UpdateOffsetFromText()
|
||||
{
|
||||
// Failsafe against empty string.
|
||||
if (String.IsNullOrEmpty(FirstBeatOffset.text))
|
||||
FirstBeatOffset.text = "0";
|
||||
|
||||
// Convert ms to s.
|
||||
var newOffset = Convert.ToSingle(FirstBeatOffset.text) / 1000f;
|
||||
|
||||
// Limit decimal places to 4.
|
||||
newOffset = (float)System.Math.Round(newOffset, 4);
|
||||
|
||||
GameManager.instance.Beatmap.firstBeatOffset = newOffset;
|
||||
|
||||
UpdateOffsetText();
|
||||
}
|
||||
|
||||
private void AddTempoChange(bool create, Beatmap.TempoChange tempoChange_ = null)
|
||||
{
|
||||
GameObject tempoChange = Instantiate(RefTempoChange.gameObject, this.transform);
|
||||
|
Reference in New Issue
Block a user