mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-11-26 03:25:22 +00:00
50a1b7bcdb
* add Jukebox library todo: - saving / loading of new format - inferrence of unknown data like past versions - move the temporary float casts to proper use of double - make sound related functions take double for timing - inform people that the Jukebox sound player was renamed to SoundByte lol * make sound, input scheduling, and super curve use double precision * successfully load charts * editor works again v1 riqs can be saved and loaded * first tempo and volume markers are unmovable fix loading of charts' easing values * use gsync / freesync * update Jukebox refs to SoundByte * game events use double part 1 Air Rally - Glee Club converted * don't load song if chart load fails * finish conversion of all minigames * remove editor waveform toggle * timeline now respects added song offset length clear cache files on app close prepped notes for dsp sync * update timeline length when offset changed * update to latest Jukebox * make error panel object in global game manager * improve conductor music scheduling * added error message box fix first game events sometimes not playing
114 lines
No EOL
3.5 KiB
C#
114 lines
No EOL
3.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using Starpelly;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace HeavenStudio.Editor.Track
|
|
{
|
|
public class BeatGrid : MonoBehaviour
|
|
{
|
|
#region Public
|
|
|
|
public float snap;
|
|
public float count;
|
|
|
|
#endregion
|
|
|
|
#region Private
|
|
|
|
private RectTransform rectTransform;
|
|
|
|
private float lastPosX;
|
|
private float lastContentScale;
|
|
private float lastTimelineSize;
|
|
|
|
private float contentPosX => Mathf.Abs(scrollRect.content.localPosition.x / scrollRect.content.localScale.x);
|
|
|
|
private List<GameObject> Lines = new List<GameObject>();
|
|
|
|
|
|
#endregion
|
|
|
|
#region Exposed
|
|
|
|
[Header("Components")]
|
|
[SerializeField] private ScrollRect scrollRect;
|
|
|
|
#endregion
|
|
|
|
#region MonoBehaviour
|
|
|
|
private void Start()
|
|
{
|
|
rectTransform = GetComponent<RectTransform>();
|
|
UpdateCount();
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (Editor.instance.fullscreen) return;
|
|
|
|
var x = Mathf.FloorToInt(contentPosX);
|
|
var pos = new Vector3(x, transform.localPosition.y, transform.localPosition.z);
|
|
transform.localPosition = pos;
|
|
GetComponent<RectTransform>().anchoredPosition = new Vector3(rectTransform.anchoredPosition.x, rectTransform.anchoredPosition.y, 0);
|
|
|
|
UpdateCount();
|
|
}
|
|
|
|
#endregion
|
|
|
|
private void UpdateCount()
|
|
{
|
|
var changeScale = (scrollRect.viewport.rect.size.x != lastTimelineSize || scrollRect.content.localScale.x != lastContentScale);
|
|
if (changeScale)
|
|
{
|
|
var rightSide = (scrollRect.viewport.GetComponent<RectTransform>().rect.width / scrollRect.content.localScale.x) + contentPosX;
|
|
|
|
for (int i = 0; i < Lines.Count; i++)
|
|
Destroy(Lines[i].gameObject);
|
|
Lines.Clear();
|
|
|
|
count = Mathf.RoundToInt(rightSide - contentPosX) + 2;
|
|
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
var line = Instantiate(transform.GetChild(0).gameObject, transform);
|
|
line.transform.localPosition = new Vector3(i, line.transform.localPosition.y, line.transform.localPosition.z);
|
|
|
|
var halfBeatRect = line.transform.GetChild(2).GetComponent<RectTransform>();
|
|
halfBeatRect.anchoredPosition = new Vector3(scrollRect.content.localScale.x * 0.5f, halfBeatRect.anchoredPosition.y);
|
|
|
|
line.SetActive(true);
|
|
|
|
Lines.Add(line);
|
|
}
|
|
UpdateGridNum();
|
|
|
|
if (count > 0) transform.GetChild(0).gameObject.SetActive(false);
|
|
}
|
|
if (rectTransform.anchoredPosition.x != lastPosX)
|
|
{
|
|
UpdateGridNum();
|
|
}
|
|
|
|
lastContentScale = scrollRect.content.localScale.x;
|
|
lastTimelineSize = scrollRect.viewport.rect.size.x;
|
|
lastPosX = rectTransform.anchoredPosition.x;
|
|
}
|
|
|
|
private void UpdateGridNum()
|
|
{
|
|
for (int i = 0; i < Lines.Count; i++)
|
|
{
|
|
var line = Lines[i];
|
|
if (line.transform.childCount == 0) continue;
|
|
|
|
var newNum = Mathf.RoundToInt(rectTransform.anchoredPosition.x + ((i) / snap));
|
|
line.transform.GetChild(0).GetComponent<TMP_Text>().text = newNum.ToString(CultureInfo.CurrentCulture);
|
|
}
|
|
}
|
|
}
|
|
} |