各种优化,movable采音器完善

This commit is contained in:
2025-05-11 00:20:27 +08:00
parent 440ffc183e
commit c5e8908b47
42 changed files with 275829 additions and 7312 deletions

View File

@@ -8,6 +8,7 @@ using Ichni.RhythmGame;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class FlexibleFloatTab : MonoBehaviour
{
@@ -18,8 +19,8 @@ public class FlexibleFloatTab : MonoBehaviour
public RectTransform XBeatArea;
public EventPoint eventPoint;
public GameObject BeatLine;
public Button TabButton;
public string Title;
public GameObject FirstBeatLine;
public FlexibleFloat connectFloat;
public int BeatDeviver => FatherWindow.BeatDeviver;
public int BeatNextDeviver => FatherWindow.BeatNextDeviver;
@@ -34,8 +35,8 @@ public class FlexibleFloatTab : MonoBehaviour
connectFloat = flexibleFloat;
CreateBeatLines();
CreateEventPoints();
RedrawEventPoints();
Area.localPosition = new Vector3(FatherWindow.songBeat * BeatDeviver, 0, 0);
TabButton.onClick.AddListener(AddEvent);
}
// 清除子节点
@@ -54,7 +55,6 @@ public class FlexibleFloatTab : MonoBehaviour
{
GameObject u = Instantiate(BeatLine, BeatArea);
u.transform.localPosition = new Vector3(BeatDeviver * i, 0, 0);
if (i == 1) FirstBeatLine = u;
}
}
@@ -70,29 +70,6 @@ public class FlexibleFloatTab : MonoBehaviour
eventPoints.Add(eventPoint);
LinkEventPoints(i, eventPoint);
}
}
// 连接事件点
private void LinkEventPoints(int index, EventPoint eventPoint)
{
if (index - 1 >= 0)
{
eventPoint.LastEventPoint = eventPoints[index - 1];
eventPoint.LastEventPoint.NextEventPoint = eventPoint;
}
else
{
eventPoint.LastEventPoint = null;
}
if (index == connectFloat.animations.Count - 1)
{
eventPoint.NextEventPoint = null;
}
}
// 重绘事件点
private void RedrawEventPoints()
{
foreach (var i in eventPoints)
{
i.ReDraw(scalevalue);
@@ -141,57 +118,40 @@ public class FlexibleFloatTab : MonoBehaviour
connectFloat.Add(eventPoint.animatedFloat);
connectFloat.Sort();
}
// 连接新事件点
private void LinkNewEventPoint(EventPoint eventPoint, bool link = false)
// 添加调用 EventPoint 类的接口
public void LinkEventPoints(int index, EventPoint eventPoint)
{
int index = eventPoints.IndexOf(eventPoint);
if (index - 1 >= 0)
{
eventPoint.LastEventPoint = eventPoints[index - 1];
eventPoint.LastEventPoint.NextEventPoint = eventPoint;
eventPoint.LastEventPoint.ReDraw(scalevalue);
}
if (index + 1 < eventPoints.Count)
{
eventPoint.NextEventPoint = eventPoints[index + 1];
if (link) eventPoint.animatedFloat.endTime = eventPoint.NextEventPoint.animatedFloat.startTime;
eventPoint.Initialize(eventPoint.animatedFloat);
eventPoint.NextEventPoint.LastEventPoint = eventPoint;
}
eventPoint.LinkEventPoints(eventPoints, index);
}
public void LinkNewEventPoint(EventPoint eventPoint, bool link = false)
{
eventPoint.LinkNewEventPoint(eventPoints, link, scalevalue);
}
// 查找插入索引
public int FindInsertIndex(float startTime)
{
int low = 0;
int high = eventPoints.Count - 1;
while (low <= high)
{
int mid = (low + high) / 2;
if (eventPoints[mid].animatedFloat.startTime < startTime)
{
low = mid + 1;
}
else
{
high = mid - 1;
}
}
return low;
return EventPoint.FindInsertIndex(eventPoints, startTime);
}
// 获取节拍
public float GetBeat()
{
float mouseInputX = Mouse.current.position.ReadValue().x;
float far = BeatArea.transform.position.x;
float Beat = 0;
while (far < mouseInputX)
// 获取鼠标在 BeatArea 中的相对位置
Vector2 localMousePosition = BeatArea.InverseTransformPoint(Mouse.current.position.ReadValue());
//Debug.Log(localMousePosition);
float mouseBeat = localMousePosition.x / BeatDeviver;
float far = 0f;
while (far < mouseBeat)
{
far += (FirstBeatLine.transform.position.x - BeatArea.transform.position.x) / BeatNextDeviver;
Beat += 1f / BeatNextDeviver;
far += 1f / BeatNextDeviver;
}
return FatherWindow.timePerBeat * (Beat - (1f / BeatNextDeviver));
far -= 1f / BeatNextDeviver;
return far * FatherWindow.timePerBeat;
}
public float scalevalue => FatherWindow.scalevalue;
@@ -233,4 +193,35 @@ public class FlexibleFloatTab : MonoBehaviour
connectFloat.animations.Remove(a);
}
}
/// <summary>
/// 从事件点列表中移除指定的事件点,并更新其前后连接关系。
/// </summary>
/// <param name="eventPoint">要移除的事件点。</param>
public void RemoveEventPoint(EventPoint eventPoint)
{
if (eventPoints.Contains(eventPoint))
{
// 更新前后事件点的连接关系
if (eventPoint.LastEventPoint != null)
{
eventPoint.LastEventPoint.NextEventPoint = eventPoint.NextEventPoint;
eventPoint.LastEventPoint.ReDraw(scalevalue);
}
if (eventPoint.NextEventPoint != null)
{
eventPoint.NextEventPoint.LastEventPoint = eventPoint.LastEventPoint;
eventPoint.NextEventPoint.ReDraw(scalevalue);
}
// 从列表中移除事件点
eventPoints.Remove(eventPoint);
// 从连接的动画中移除
connectFloat.animations.Remove(eventPoint.animatedFloat);
// 销毁事件点对象
Destroy(eventPoint.gameObject);
}
}
}