@@ -1,8 +1,5 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DG.Tweening;
|
||||
using Ichni;
|
||||
|
||||
using Ichni.RhythmGame;
|
||||
@@ -10,6 +7,7 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.UI.Extensions;
|
||||
|
||||
public partial class EventPoint : MonoBehaviour
|
||||
{
|
||||
@@ -24,7 +22,7 @@ public partial class EventPoint : MonoBehaviour
|
||||
public RectTransform LeftSide;
|
||||
public RectTransform RightSide;
|
||||
public Button selectButton;
|
||||
public RawImage CurveCanvas;
|
||||
public UILineRenderer Linerender;
|
||||
|
||||
public FlexibleFloatTab FatherTab;
|
||||
public TMP_Text ViewText;
|
||||
@@ -33,6 +31,20 @@ public partial class EventPoint : MonoBehaviour
|
||||
public int BeatDeviver => FatherTab.BeatDeviver;
|
||||
public void Initialize(AnimatedFloat animatedFloat)
|
||||
{
|
||||
// 初始化 UILineRenderer
|
||||
if (Linerender != null)
|
||||
{
|
||||
// 移除残留的旧 RawImage 组件(预制体迁移用)
|
||||
var oldRawImage = Linerender.GetComponent<RawImage>();
|
||||
if (oldRawImage != null)
|
||||
Destroy(oldRawImage);
|
||||
|
||||
Linerender.RelativeSize = true;
|
||||
Linerender.color = Color.green;
|
||||
Linerender.LineThickness = 2;
|
||||
Linerender.raycastTarget = false;
|
||||
}
|
||||
|
||||
this.animatedFloat = animatedFloat;
|
||||
transform.localPosition = new Vector3(
|
||||
animatedFloat.startTime / EditorManager.instance.timeline.timePerBeat * BeatDeviver, 0, 0
|
||||
@@ -44,9 +56,12 @@ public partial class EventPoint : MonoBehaviour
|
||||
EvDrawimage.transform.localPosition = new Vector3(EvDrawimage.rectTransform.sizeDelta.x / 2, 0, 0);
|
||||
OvDrawimage.transform.localPosition = RightSide.localPosition;
|
||||
|
||||
CurveCanvas.rectTransform.sizeDelta = new Vector2(EvDrawimage.rectTransform.sizeDelta.x, EvDrawimage.rectTransform.sizeDelta.y);
|
||||
|
||||
|
||||
// 锁定 UILineRenderer 位置以匹配 EvDrawimage
|
||||
Linerender.rectTransform.sizeDelta = new Vector2(EvDrawimage.rectTransform.sizeDelta.x, EvDrawimage.rectTransform.sizeDelta.y);
|
||||
Linerender.rectTransform.anchorMin = EvDrawimage.rectTransform.anchorMin;
|
||||
Linerender.rectTransform.anchorMax = EvDrawimage.rectTransform.anchorMax;
|
||||
Linerender.rectTransform.pivot = EvDrawimage.rectTransform.pivot;
|
||||
Linerender.rectTransform.anchoredPosition = EvDrawimage.rectTransform.anchoredPosition;
|
||||
|
||||
|
||||
|
||||
@@ -222,111 +237,26 @@ public partial class EventPoint : MonoBehaviour
|
||||
}
|
||||
public partial class EventPoint//显示?
|
||||
{
|
||||
public IEnumerator GenerateTextureCoroutine(int width, int height, float value)
|
||||
{
|
||||
Task<Color[]> task = Task.Run(() => GenerateTextureColors(width, height, value));
|
||||
while (!task.IsCompleted)
|
||||
{
|
||||
yield return null; // 等待下一帧
|
||||
}
|
||||
Color[] textureColors = task.Result;
|
||||
Texture2D Texture = new Texture2D(width, height);
|
||||
Texture.SetPixels(textureColors);
|
||||
Texture.Apply();
|
||||
CurveCanvas.texture = Texture;
|
||||
// CurveCanvas.color = new Color(1, 1, 1, 0);
|
||||
// CurveCanvas.DOColor(new Color(1, 1, 1, 1), 0.2f).SetEase(Ease.InOutSine);
|
||||
|
||||
}
|
||||
public Color[] GenerateTextureColors(int width, int height, float value)
|
||||
{
|
||||
Color[] pixels = new Color[width * height];
|
||||
|
||||
// 初始化所有像素为透明
|
||||
for (int i = 0; i < pixels.Length; i++)
|
||||
{
|
||||
pixels[i] = new Color(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
int LastEventPointY = 0;
|
||||
for (int i = 0; i < width; i++)
|
||||
{
|
||||
float t = (float)i / width;
|
||||
int f = (int)(
|
||||
(height / 2) + (animatedFloat.startValue * value + ((animatedFloat.endValue - animatedFloat.startValue)
|
||||
* AnimationCurveEvaluator.Evaluate(animatedFloat.animationCurveType, t) * value))
|
||||
);
|
||||
|
||||
// 绘制垂直线段 - 保留超出边界的红色标记
|
||||
if (LastEventPointY < f)
|
||||
{
|
||||
for (int j = LastEventPointY; j < f; j++)
|
||||
{
|
||||
// 检查是否超出边界
|
||||
bool isOutOfBounds = j < 0 || j >= height;
|
||||
|
||||
// 计算实际坐标(循环调整)
|
||||
int actualY = j;
|
||||
while (actualY < 0) actualY += height;
|
||||
while (actualY >= height) actualY -= height;
|
||||
|
||||
int index = actualY * width + i;
|
||||
if (index >= 0 && index < pixels.Length)
|
||||
{
|
||||
// 根据是否超出边界设置颜色
|
||||
pixels[index] = isOutOfBounds ? Color.red : Color.green;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int j = LastEventPointY; j > f; j--)
|
||||
{
|
||||
// 检查是否超出边界
|
||||
bool isOutOfBounds = j < 0 || j >= height;
|
||||
|
||||
// 计算实际坐标(循环调整)
|
||||
int actualY = j;
|
||||
while (actualY < 0) actualY += height;
|
||||
while (actualY >= height) actualY -= height;
|
||||
|
||||
int index = actualY * width + i;
|
||||
if (index >= 0 && index < pixels.Length)
|
||||
{
|
||||
// 根据是否超出边界设置颜色
|
||||
pixels[index] = isOutOfBounds ? Color.red : Color.green;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前点 - 保留超出边界的红色标记
|
||||
bool isFOutOfBounds = f < 0 || f >= height;
|
||||
int actualF = f;
|
||||
while (actualF < 0) actualF += height;
|
||||
while (actualF >= height) actualF -= height;
|
||||
|
||||
int currentIndex = actualF * width + i;
|
||||
if (currentIndex >= 0 && currentIndex < pixels.Length)
|
||||
{
|
||||
// 根据是否超出边界设置颜色
|
||||
pixels[currentIndex] = isFOutOfBounds ? Color.red : Color.green;
|
||||
}
|
||||
|
||||
LastEventPointY = f;
|
||||
}
|
||||
|
||||
return pixels;
|
||||
}
|
||||
|
||||
public void ReDraw(float value)
|
||||
{
|
||||
int width = (int)CurveCanvas.rectTransform.sizeDelta.x / 5;
|
||||
int height = (int)CurveCanvas.rectTransform.sizeDelta.y / 5;
|
||||
if (Linerender == null) return;
|
||||
|
||||
// 获取颜色数组(可在多线程环境中调用)
|
||||
int width = Mathf.Max(2, (int)Linerender.rectTransform.sizeDelta.x / 5);
|
||||
int height = Mathf.Max(1, (int)Linerender.rectTransform.sizeDelta.y / 5);
|
||||
|
||||
// 在主线程中创建和设置纹理(Unity对象操作必须在主线程)
|
||||
StartCoroutine(GenerateTextureCoroutine(width, height, value));
|
||||
// 使用 UILineRenderer 直接绘制曲线(替代原来的纹理生成)
|
||||
Linerender.RelativeSize = true;
|
||||
Linerender.color = Color.green;
|
||||
Vector2[] points = new Vector2[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);
|
||||
}
|
||||
Linerender.Points = points;
|
||||
|
||||
// 其余的非纹理相关代码保持不变
|
||||
if (NextEventPoint != null)
|
||||
|
||||
Reference in New Issue
Block a user