using System; using System.Collections; using System.Collections.Generic; using System.Reflection; using Ichni.RhythmGame; using UniRx; using UnityEngine; using UnityEngine.Serialization; namespace Ichni.Editor { public partial class TimePointerModule : MonoBehaviour { private Timeline timeline => EditorManager.instance.uiManager.timeline; private SongInformation songInformation => EditorManager.instance.songInformation; public GameObject timePointerPrefab; public List timePointerList; public List ActivePointer => timePointerList.FindAll(pointer => pointer.isInScreen); private TimePointer NowPointer; public RectTransform moveTabPoint; public RectTransform timePointerContainer; public RectTransform rightSide; public float timePointerInterval = 100f; public void Start() { timePointerInterval = 100f; EditorManager.instance.uiManager.timeline.timePointerModule = this; OnceSpawn(); } public void OnceSpawn() { for (int i = timePointerList.Count - 1; i >= 0; i--) { Destroy(timePointerList[i].gameObject); } timePointerList.Clear(); for (int i = 0; i < songInformation.songLength / timeline.timePerBeat; i++) { TimePointer timePointer = Instantiate(timePointerPrefab, timePointerContainer).GetComponent(); timePointerList.Add(timePointer); timePointer.time = i * timeline.timePerBeat; timePointer.intervalUnitText.text = (i * timeline.timePerBeat).ToString("F3"); timePointer.GetComponent().localPosition = new Vector3(i * timePointerInterval, 0f, 0f); timePointer.index = i; } // for (int i = -1; i > -songInformation.delay / timeline.timePerBeat; i--) // { // TimePointer timePointer = Instantiate(timePointerPrefab, timePointerContainer).GetComponent(); // timePointerList.Insert(0, timePointer); // timePointer.intervalUnitText.text = (i * timeline.timePerBeat).ToString("F3"); // timePointer.GetComponent().localPosition = new Vector3(i * timePointerInterval, 0f, 0f); // timePointer.index = i; // timePointer.gameObject.SetActive(false); // } } public void SortPos() { foreach (var i in timePointerList) { i.GetComponent().localPosition = new Vector3(i.index * timePointerInterval, 0f, 0f); } } public void Update() { timePointerContainer.localPosition = new Vector3(-EditorManager.instance.songInformation.songTime / timeline.timePerBeat * timePointerInterval, timePointerContainer.localPosition.y, 0f); if (NowPointer == null) { NowPointer = timePointerList[0]; } else { while (NowPointer.index < timePointerList.Count - 1 && NowPointer.index * timeline.timePerBeat < EditorManager.instance.songInformation.songTime) { NowPointer.isInScreen = false; NowPointer = timePointerList[NowPointer.index + 1]; } while (NowPointer.index > 0 && NowPointer.index * timeline.timePerBeat >= EditorManager.instance.songInformation.songTime) { NowPointer.isInScreen = true; NowPointer = timePointerList[NowPointer.index - 1 >= 0 ? NowPointer.index - 1 : 0]; } } for (int i = NowPointer.index + 1; i < timePointerList.Count; i++) { timePointerList[i].isInScreen = true; if (timePointerList[i].GetComponent().position.x > rightSide.position.x) { timePointerList[i].isInScreen = false; break; } } } } }