暂时存档

Timeline
WindowAnim不止window能用
This commit is contained in:
2025-02-21 15:30:14 +08:00
parent cd9ef00d13
commit 6781de4d53
14 changed files with 642 additions and 85 deletions

View File

@@ -12,15 +12,15 @@ namespace Ichni.Editor
{
private Timeline timeline => EditorManager.instance.uiManager.timeline;
private SongInformation songInformation => EditorManager.instance.songInformation;
public GameObject timePointerPrefab;
public List<TimePointer> timePointerList;
public RectTransform timePointerArea;
public RectTransform visibleTimePointerArea;
public RectTransform mainTimePointer;
public float intervalUnit;
public float timePointerInterval;
public float sizeNegative, sizePositive;
@@ -29,7 +29,7 @@ namespace Ichni.Editor
/// delay时间区间中(-delay, 0)的距离偏移量
/// </summary>
public float delayDistanceOffset;
public float leftSideSongTime, rightSideSongTime, songTimeDistance;
private void Start()
@@ -62,20 +62,20 @@ namespace Ichni.Editor
/// <param name="delay"></param>
/// <param name="bpm"></param>
public void Initialize(float delay, float bpm)
{
{
timePointerInterval = 30;
ClearPointers();
int beatDivider = 1;
intervalUnit = (60f / bpm) / beatDivider * 1000;
sizeNegative = delay * beatDivider / timeline.timePerBeat;
sizePositive = songInformation.song.length * beatDivider / timeline.timePerBeat;
negativePointerAmount = Mathf.CeilToInt(sizeNegative);
positivePointerAmount = Mathf.CeilToInt(sizePositive);
totalPointerAmount = negativePointerAmount + positivePointerAmount;
timePointerArea.sizeDelta = new Vector2(timePointerInterval * (sizeNegative + sizePositive), 60f);
@@ -90,12 +90,12 @@ namespace Ichni.Editor
{
CreatePointer(beatDivider, i);
}
//ChangeSongTimeDistance(0);
SetRange(timeline.beatmapStartTime);
}
}
public partial class TimePointerModule
{
/// <summary>
@@ -115,7 +115,7 @@ namespace Ichni.Editor
leftSideSongTime = startTime - songTimeDistance * proportion;
rightSideSongTime = startTime + songTimeDistance * (1 - proportion);
}
/// <summary>
/// 生成指示线
/// </summary>
@@ -132,13 +132,16 @@ namespace Ichni.Editor
pointer.time = index * intervalUnit / 1000f;
pointer.intervalUnitText.text = Mathf.RoundToInt(index * intervalUnit).ToString();
if (beatDivider > 1)
{
}
}
/// <summary>
/// 更新指示线位置
/// </summary>
private void UpdatePointers()
public void UpdatePointers()
{
delayDistanceOffset = timePointerInterval * (negativePointerAmount - sizeNegative);
timePointerArea.sizeDelta = new Vector2(timePointerInterval * totalPointerAmount, 55f);
@@ -149,7 +152,7 @@ namespace Ichni.Editor
new Vector2((pointer.index + negativePointerAmount) * timePointerInterval + 15f - delayDistanceOffset, 0);
}
}
/// <summary>
/// 清楚所有指示线
/// </summary>
@@ -161,7 +164,7 @@ namespace Ichni.Editor
}
timePointerList.Clear();
}
/// <summary>
/// 缩放时间线的展示时间宽度
/// </summary>

View File

@@ -1,18 +1,119 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Ichni.RhythmGame;
using Sirenix.Utilities;
using TMPro;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
namespace Ichni.Editor
{
public class Timeline : MonoBehaviour
public partial class Timeline : MonoBehaviour
{
public float songTime => EditorManager.instance.songInformation.songTime;
public float songBeat => EditorManager.instance.songInformation.songBeat;
public float beatmapStartTime => -EditorManager.instance.songInformation.delay;
public float timePerBeat => 60f / EditorManager.instance.songInformation.bpm;
public GameObject timelineTabRect;
public TimePointerModule timePointerModule;
public MusicPlayer musicPlayer;
public TMP_InputField TimeField;
public TMP_InputField BeatField;
public RectTransform GetinputArea;
public void Update()
{
if (musicPlayer.isPlaying) UpdateTime();
if (RectTransformUtility.RectangleContainsScreenPoint(GetinputArea, Mouse.current.position.ReadValue()))
{
DetectSetRange();
}
}
private void DetectSetRange()
{
if (Mouse.current.scroll.ReadValue().y != 0)
{
if (Keyboard.current.leftCtrlKey.isPressed || Keyboard.current.rightCtrlKey.isPressed)
{
float scrollValue = Mouse.current.scroll.ReadValue().y / 12;
if (timePointerModule.timePointerInterval + scrollValue >= 30)
{
timePointerModule.timePointerInterval += scrollValue;
timePointerModule.UpdatePointers();
timePointerModule.SetRange(songTime);
}
}
else
{
if (Mouse.current.scroll.ReadValue().y >= 0)
{
SetTime((EditorManager.instance.songInformation.songTime + timePerBeat).ToString());
}
else
{
if (EditorManager.instance.songInformation.songTime - timePerBeat >= 0)
SetTime((EditorManager.instance.songInformation.songTime - timePerBeat).ToString());
else
SetTime("0");
}
UpdateTime();
}
}
}
private void UpdateTime()
{
TimeField.text = songTime.ToString("F2");
BeatField.text = songBeat.ToString("F2");
}
public void SetTime(string time)
{
musicPlayer.PauseMusic();
musicPlayer.audioSource.time = float.Parse(time);
EditorManager.instance.songInformation.songTime = float.Parse(time);
timePointerModule.UpdatePointers();
timePointerModule.SetRange(songTime);
}
public void SetBeat(string beat)
{
musicPlayer.PauseMusic();
musicPlayer.audioSource.time = float.Parse(beat) * timePerBeat;
EditorManager.instance.songInformation.songTime = float.Parse(beat) * timePerBeat;
timePointerModule.UpdatePointers();
timePointerModule.SetRange(songTime);
}
}
public partial class Timeline
{
public TimelineTab timelineTabPrefab;
public Dictionary<Type, TimelineTab> timelineTabList = new Dictionary<Type, TimelineTab>();
public void SetTimeLine(GameElement element)
{
//在做了
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Ichni.RhythmGame;
using TMPro;
using UnityEngine;
public class TimelineTab : MonoBehaviour
{
public TMP_Text Title;
public GameElement connectedGameElement;
public List<GameElement> GelementPointer;
public void SetTab(GameElement element, Type DisplayType)
{
connectedGameElement = element;
Title.text = DisplayType.ToString();
foreach (var i in element.childElementList) if (i.GetType() == DisplayType) GelementPointer.Add(i);
}
public void AddElement(GameElement gameElement)
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2508d5efc83bb294aa25a45eb1d2f59d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: