mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 12:27:36 +02:00
Playback visualization + started on timeline in editor
This commit is contained in:
56
Assets/Scripts/LevelEditor/BeatGrid.cs
Normal file
56
Assets/Scripts/LevelEditor/BeatGrid.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
using TMPro;
|
||||
|
||||
namespace RhythmHeavenMania.Editor
|
||||
{
|
||||
public class BeatGrid : MonoBehaviour
|
||||
{
|
||||
private RectTransform rectTransform;
|
||||
|
||||
public float snap;
|
||||
public float count;
|
||||
|
||||
private float lastPosX;
|
||||
|
||||
private List<GameObject> Lines = new List<GameObject>();
|
||||
|
||||
private void Start()
|
||||
{
|
||||
rectTransform = GetComponent<RectTransform>();
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
GameObject line = Instantiate(transform.GetChild(0).gameObject, transform);
|
||||
line.transform.localPosition = new Vector3(i, line.transform.localPosition.y);
|
||||
line.SetActive(true);
|
||||
|
||||
Lines.Add(line);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
var pos = new Vector2(Mathf.RoundToInt(Mathf.Abs(transform.parent.localPosition.x) / 100) - 1, transform.localPosition.y);
|
||||
transform.localPosition = pos;
|
||||
|
||||
if (pos.x != lastPosX)
|
||||
UpdateGridNum();
|
||||
|
||||
lastPosX = transform.localPosition.x;
|
||||
}
|
||||
|
||||
private void UpdateGridNum()
|
||||
{
|
||||
for (int i = 0; i < Lines.Count; i++)
|
||||
{
|
||||
var line = Lines[i];
|
||||
float newNum = transform.localPosition.x + i;
|
||||
line.transform.GetChild(0).GetComponent<TMP_Text>().text = newNum.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user