mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-11-24 02:25:18 +00:00
56 lines
No EOL
1.5 KiB
C#
56 lines
No EOL
1.5 KiB
C#
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();
|
|
}
|
|
}
|
|
}
|
|
} |