@@ -28,6 +28,7 @@ public partial class EventPoint : MonoBehaviour
|
||||
public TMP_Text ViewText;
|
||||
|
||||
public static bool Locked = false;
|
||||
private UILineRenderer _overflowLine;
|
||||
public int BeatDeviver => FatherTab.BeatDeviver;
|
||||
public void Initialize(AnimatedFloat animatedFloat)
|
||||
{
|
||||
@@ -63,10 +64,8 @@ public partial class EventPoint : MonoBehaviour
|
||||
Linerender.rectTransform.pivot = EvDrawimage.rectTransform.pivot;
|
||||
Linerender.rectTransform.anchoredPosition = EvDrawimage.rectTransform.anchoredPosition;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 创建/同步溢出红色线条
|
||||
SyncOverflowLine();
|
||||
}
|
||||
|
||||
public float value => FatherTab.scalevalue;
|
||||
@@ -234,6 +233,30 @@ public partial class EventPoint : MonoBehaviour
|
||||
animatedFloat.animationCurveType
|
||||
);
|
||||
}
|
||||
|
||||
private void SyncOverflowLine()
|
||||
{
|
||||
if (Linerender == null) return;
|
||||
|
||||
if (_overflowLine == null)
|
||||
{
|
||||
GameObject go = new GameObject("OverflowLine", typeof(RectTransform));
|
||||
go.transform.SetParent(Linerender.transform.parent, false);
|
||||
|
||||
_overflowLine = go.AddComponent<UILineRenderer>();
|
||||
_overflowLine.color = Color.red;
|
||||
_overflowLine.RelativeSize = true;
|
||||
_overflowLine.LineThickness = Linerender.LineThickness;
|
||||
_overflowLine.raycastTarget = false;
|
||||
}
|
||||
|
||||
// 每次同步位置/大小,确保跟随 EventPoint 变化
|
||||
_overflowLine.rectTransform.anchorMin = Linerender.rectTransform.anchorMin;
|
||||
_overflowLine.rectTransform.anchorMax = Linerender.rectTransform.anchorMax;
|
||||
_overflowLine.rectTransform.pivot = Linerender.rectTransform.pivot;
|
||||
_overflowLine.rectTransform.sizeDelta = Linerender.rectTransform.sizeDelta;
|
||||
_overflowLine.rectTransform.anchoredPosition = Linerender.rectTransform.anchoredPosition;
|
||||
}
|
||||
}
|
||||
public partial class EventPoint//显示?
|
||||
{
|
||||
@@ -244,19 +267,66 @@ public partial class EventPoint//显示?
|
||||
int width = Mathf.Max(2, (int)Linerender.rectTransform.sizeDelta.x / 5);
|
||||
int height = Mathf.Max(1, (int)Linerender.rectTransform.sizeDelta.y / 5);
|
||||
|
||||
// 使用 UILineRenderer 直接绘制曲线(替代原来的纹理生成)
|
||||
Linerender.RelativeSize = true;
|
||||
Linerender.color = Color.green;
|
||||
Vector2[] points = new Vector2[width];
|
||||
// 计算原始 y 值(未裁剪)
|
||||
float[] rawY = new float[width];
|
||||
for (int i = 0; i < width; i++)
|
||||
{
|
||||
float t = (float)i / (width - 1);
|
||||
float curveVal = animatedFloat.startValue * value + ((animatedFloat.endValue - animatedFloat.startValue)
|
||||
* AnimationCurveEvaluator.Evaluate(animatedFloat.animationCurveType, t) * value);
|
||||
float yNorm = 0.5f + curveVal / height;
|
||||
points[i] = new Vector2(t, yNorm);
|
||||
rawY[i] = 0.5f + curveVal / height;
|
||||
}
|
||||
|
||||
// 分割为绿色连续段(框内)和红色连续段(框外Y循环)
|
||||
var greenSegs = new List<Vector2[]>();
|
||||
var redSegs = new List<Vector2[]>();
|
||||
var curGreen = new List<Vector2>();
|
||||
var curRed = new List<Vector2>();
|
||||
|
||||
for (int i = 0; i < width; i++)
|
||||
{
|
||||
float t = (float)i / (width - 1);
|
||||
float y = rawY[i];
|
||||
bool inBounds = y >= 0f && y <= 1f;
|
||||
|
||||
if (inBounds)
|
||||
{
|
||||
if (curRed.Count > 0)
|
||||
{
|
||||
if (curRed.Count >= 2) redSegs.Add(curRed.ToArray());
|
||||
curRed.Clear();
|
||||
}
|
||||
curGreen.Add(new Vector2(t, y));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (curGreen.Count > 0)
|
||||
{
|
||||
if (curGreen.Count >= 2) greenSegs.Add(curGreen.ToArray());
|
||||
curGreen.Clear();
|
||||
}
|
||||
// Y 循环回框内
|
||||
float wrappedY = y;
|
||||
while (wrappedY < 0f) wrappedY += 1f;
|
||||
while (wrappedY > 1f) wrappedY -= 1f;
|
||||
curRed.Add(new Vector2(t, wrappedY));
|
||||
}
|
||||
}
|
||||
|
||||
if (curGreen.Count >= 2) greenSegs.Add(curGreen.ToArray());
|
||||
if (curRed.Count >= 2) redSegs.Add(curRed.ToArray());
|
||||
|
||||
// 设置绿色主线和红色溢出线
|
||||
Linerender.RelativeSize = true;
|
||||
Linerender.color = Color.green;
|
||||
Linerender.Segments = greenSegs.Count > 0 ? greenSegs : null;
|
||||
|
||||
if (_overflowLine != null)
|
||||
{
|
||||
_overflowLine.RelativeSize = true;
|
||||
_overflowLine.color = Color.red;
|
||||
_overflowLine.Segments = redSegs.Count > 0 ? redSegs : null;
|
||||
}
|
||||
Linerender.Points = points;
|
||||
|
||||
// 其余的非纹理相关代码保持不变
|
||||
if (NextEventPoint != null)
|
||||
|
||||
Reference in New Issue
Block a user