推进度!
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using SLSFramework.General;
|
||||
using UI_Spline_Renderer;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Splines;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.UI.Extensions;
|
||||
|
||||
|
||||
namespace Continentis.MainGame.UI
|
||||
{
|
||||
@@ -11,17 +15,18 @@ namespace Continentis.MainGame.UI
|
||||
public RectTransform startPoint;
|
||||
|
||||
[Tooltip("箭头线条")]
|
||||
public UILineRenderer arrowBody;
|
||||
|
||||
[Tooltip("箭头头部的RectTransform")]
|
||||
public Image endPoint;
|
||||
public SplineContainer splineContainer;
|
||||
public UISplineRenderer arrowBody;
|
||||
|
||||
[Tooltip("箭头头部的图片")]
|
||||
public Image endImage;
|
||||
|
||||
[Header("曲线设置")]
|
||||
[Tooltip("曲线的弯曲程度,数值越大越弯曲")]
|
||||
public float curveOffset = 150f;
|
||||
|
||||
[Tooltip("曲线的平滑度,点越多越平滑,性能开销也越大")]
|
||||
[Range(20, 100)]
|
||||
[Range(1, 100)]
|
||||
public int lineSegments = 50;
|
||||
|
||||
public void SetArrow(Vector3 start, Vector3 end)
|
||||
@@ -42,31 +47,26 @@ namespace Continentis.MainGame.UI
|
||||
Vector2 direction = (uiEnd - uiStart).normalized;
|
||||
Vector2 perpendicular = new Vector2(-direction.y, direction.x); // 计算垂直向量
|
||||
Vector2 controlPoint = midPoint + perpendicular * (isEndOnLeftSide ? -curveOffset : curveOffset);
|
||||
|
||||
splineContainer.Spline.Clear();
|
||||
|
||||
// 2. 计算贝塞尔曲线上所有的点
|
||||
Vector2[] points = new Vector2[lineSegments];
|
||||
List<BezierKnot> knots = new List<BezierKnot>();
|
||||
for (int i = 0; i < lineSegments; i++)
|
||||
{
|
||||
float t = (float)i / (lineSegments - 1);
|
||||
// 二次贝塞尔曲线公式: B(t) = (1-t)² * P₀ + 2(1-t)t * P₁ + t² * P₂
|
||||
points[i] = Mathf.Pow(1 - t, 2) * uiStart +
|
||||
2 * (1 - t) * t * controlPoint +
|
||||
Mathf.Pow(t, 2) * uiEnd;
|
||||
float3 point = math.pow(1 - t, 2) * new float3(uiStart.x, uiStart.y, 0) +
|
||||
2 * (1 - t) * t * new float3(controlPoint.x, controlPoint.y, 0) +
|
||||
math.pow(t, 2) * new float3(uiEnd.x, uiEnd.y, 0);
|
||||
knots.Add(new BezierKnot(point));
|
||||
}
|
||||
|
||||
arrowBody.Points = points;
|
||||
splineContainer.Spline.Knots = knots;
|
||||
arrowBody.SetAllDirty(); // 通知UI系统重绘
|
||||
|
||||
|
||||
endPoint.rectTransform.localPosition = uiEnd;
|
||||
Vector2 headDirection = (uiEnd - points[lineSegments - 2]).normalized;
|
||||
float angle = Vector2.SignedAngle(Vector2.up, headDirection);
|
||||
endPoint.rectTransform.localRotation = Quaternion.Euler(0, 0, angle);
|
||||
}
|
||||
|
||||
public void SetColor(Color color)
|
||||
{
|
||||
endPoint.color = color;
|
||||
endImage.color = color;
|
||||
arrowBody.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using Continentis.MainGame.Card;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
@@ -8,12 +9,13 @@ namespace Continentis.MainGame.UI
|
||||
public class PileBase : UIElementBase
|
||||
{
|
||||
public List<CardViewBase> cardViews;
|
||||
public TMP_Text cardCountText;
|
||||
|
||||
public virtual void AddCard(CardViewBase cardObject)
|
||||
{
|
||||
cardViews.Add(cardObject);
|
||||
cardObject.transform.SetParent(rectTransform);
|
||||
|
||||
UpdateCountText();
|
||||
}
|
||||
|
||||
public virtual void InsertCard(CardViewBase cardObject, int index)
|
||||
@@ -21,12 +23,22 @@ namespace Continentis.MainGame.UI
|
||||
cardViews.Insert(index, cardObject);
|
||||
cardObject.transform.SetParent(rectTransform);
|
||||
cardObject.transform.SetSiblingIndex(index);
|
||||
UpdateCountText();
|
||||
}
|
||||
|
||||
public virtual void RemoveCard(CardViewBase cardObject)
|
||||
{
|
||||
cardViews.Remove(cardObject);
|
||||
UpdateCountText();
|
||||
//Debug.Log($"Removed {cardObject.cardInstance.cardLogic.contentSubmodule.cardName} from {this.name}" );
|
||||
}
|
||||
|
||||
private void UpdateCountText()
|
||||
{
|
||||
if (cardCountText != null)
|
||||
{
|
||||
cardCountText.text = cardViews.Count.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user