|
@@ -4,7 +4,7 @@ using UnityEngine.UI;
|
|
|
|
|
|
|
|
namespace LineUI
|
|
namespace LineUI
|
|
|
{
|
|
{
|
|
|
- // 定义 ArrowInfo 类
|
|
|
|
|
|
|
+ // 瀹氫箟 ArrowInfo 绫�
|
|
|
public class ArrowInfo
|
|
public class ArrowInfo
|
|
|
{
|
|
{
|
|
|
public Vector2 Position { get; set; }
|
|
public Vector2 Position { get; set; }
|
|
@@ -21,34 +21,34 @@ namespace LineUI
|
|
|
[RequireComponent(typeof(RectTransform))]
|
|
[RequireComponent(typeof(RectTransform))]
|
|
|
public class Line : Graphic
|
|
public class Line : Graphic
|
|
|
{
|
|
{
|
|
|
- [Header("绘制线段")]
|
|
|
|
|
|
|
+ [Header("缁樺埗绾挎�")]
|
|
|
[SerializeField] private bool loop = false;
|
|
[SerializeField] private bool loop = false;
|
|
|
[SerializeField] private float thickness = 1f;
|
|
[SerializeField] private float thickness = 1f;
|
|
|
[SerializeField] private int roundCount = 0;
|
|
[SerializeField] private int roundCount = 0;
|
|
|
[SerializeField] private List<Vector2> screenPositions = new List<Vector2>();
|
|
[SerializeField] private List<Vector2> screenPositions = new List<Vector2>();
|
|
|
- //获取当前的points
|
|
|
|
|
|
|
+ //鑾峰彇褰撳墠鐨刾oints
|
|
|
[HideInInspector]
|
|
[HideInInspector]
|
|
|
public List<Vector2> ScreenPositions => screenPositions;
|
|
public List<Vector2> ScreenPositions => screenPositions;
|
|
|
|
|
|
|
|
- [Header("绘制内四边形")]
|
|
|
|
|
- //是否绘制内四边形
|
|
|
|
|
|
|
+ [Header("缁樺埗鍐呭洓杈瑰舰")]
|
|
|
|
|
+ //鏄�惁缁樺埗鍐呭洓杈瑰舰
|
|
|
[SerializeField] bool bDrawQuad = true;
|
|
[SerializeField] bool bDrawQuad = true;
|
|
|
[SerializeField] private Vector2 quadrilateralSize = new Vector2(100, 100);
|
|
[SerializeField] private Vector2 quadrilateralSize = new Vector2(100, 100);
|
|
|
[SerializeField] private Color quadColor = Color.red;
|
|
[SerializeField] private Color quadColor = Color.red;
|
|
|
|
|
|
|
|
- [Header("绘制外围蒙板")]
|
|
|
|
|
- //是否绘制外围蒙板
|
|
|
|
|
|
|
+ [Header("缁樺埗澶栧洿钂欐澘")]
|
|
|
|
|
+ //鏄�惁缁樺埗澶栧洿钂欐澘
|
|
|
[SerializeField] bool bDrawMask = false;
|
|
[SerializeField] bool bDrawMask = false;
|
|
|
[SerializeField] private Color maskColor = Color.red;
|
|
[SerializeField] private Color maskColor = Color.red;
|
|
|
- //控制扇形角绘制
|
|
|
|
|
- [Header("扇形角绘制")]
|
|
|
|
|
|
|
+ //鎺у埗鎵囧舰瑙掔粯鍒�
|
|
|
|
|
+ [Header("鎵囧舰瑙掔粯鍒�")]
|
|
|
[SerializeField] private bool bDrawFan = false;
|
|
[SerializeField] private bool bDrawFan = false;
|
|
|
[SerializeField] private Color fanColor = Color.white;
|
|
[SerializeField] private Color fanColor = Color.white;
|
|
|
- [SerializeField] private int fanSegments = 20; // 扇形的平滑度
|
|
|
|
|
- [SerializeField] private float fanOuterRadius = 150f; // 扇形的半径
|
|
|
|
|
|
|
+ [SerializeField] private int fanSegments = 20; // 鎵囧舰鐨勫钩婊戝害
|
|
|
|
|
+ [SerializeField] private float fanOuterRadius = 150f; // 鎵囧舰鐨勫崐寰�
|
|
|
private float fanInnerRadius = 0f;
|
|
private float fanInnerRadius = 0f;
|
|
|
|
|
|
|
|
- [Tooltip("扇形指向箭头")]
|
|
|
|
|
|
|
+ [Tooltip("鎵囧舰鎸囧悜绠�ご")]
|
|
|
[SerializeField] private bool bDrawArrow = false;
|
|
[SerializeField] private bool bDrawArrow = false;
|
|
|
[SerializeField] private Color arrowColor = Color.white;
|
|
[SerializeField] private Color arrowColor = Color.white;
|
|
|
[SerializeField] float arrowLength = 50f;
|
|
[SerializeField] float arrowLength = 50f;
|
|
@@ -57,7 +57,7 @@ namespace LineUI
|
|
|
[SerializeField] float arrowDis = 100f;
|
|
[SerializeField] float arrowDis = 100f;
|
|
|
|
|
|
|
|
private List<ArrowInfo> arrowInfos = new List<ArrowInfo>();
|
|
private List<ArrowInfo> arrowInfos = new List<ArrowInfo>();
|
|
|
- //获取当前的points
|
|
|
|
|
|
|
+ //鑾峰彇褰撳墠鐨刾oints
|
|
|
[HideInInspector]
|
|
[HideInInspector]
|
|
|
public List<ArrowInfo> ArrowInfos => arrowInfos;
|
|
public List<ArrowInfo> ArrowInfos => arrowInfos;
|
|
|
|
|
|
|
@@ -69,6 +69,9 @@ namespace LineUI
|
|
|
//private List<GameObject> quadObjects = new List<GameObject>();
|
|
//private List<GameObject> quadObjects = new List<GameObject>();
|
|
|
//private Stack<GameObject> objectPool = new Stack<GameObject>();
|
|
//private Stack<GameObject> objectPool = new Stack<GameObject>();
|
|
|
|
|
|
|
|
|
|
+ [Tooltip("鎶楅敮榻垮�鐞嗛儴鍒�")]
|
|
|
|
|
+ [SerializeField, Range(0f, 5f)]
|
|
|
|
|
+ private float antiAliasValue = 2f; // 鎶楅敮榻跨窘鍖栧�搴�
|
|
|
|
|
|
|
|
private const int ObjectPoolLimit = 4;
|
|
private const int ObjectPoolLimit = 4;
|
|
|
|
|
|
|
@@ -135,9 +138,9 @@ namespace LineUI
|
|
|
|
|
|
|
|
if(bDrawQuad) SetQuadrilateralVertices(vh);
|
|
if(bDrawQuad) SetQuadrilateralVertices(vh);
|
|
|
|
|
|
|
|
- if(bDrawMask) DrawMask(vh); // 绘制蒙版
|
|
|
|
|
|
|
+ if(bDrawMask) DrawMask(vh); // 缁樺埗钂欑増
|
|
|
|
|
|
|
|
- if (bDrawFan) DrawFansAtCorners(vh); // 在转折角绘制扇形
|
|
|
|
|
|
|
+ if (bDrawFan) DrawFansAtCorners(vh); // 鍦ㄨ浆鎶樿�缁樺埗鎵囧舰
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void SetLineVertices(VertexHelper vh)
|
|
private void SetLineVertices(VertexHelper vh)
|
|
@@ -188,6 +191,13 @@ namespace LineUI
|
|
|
|
|
|
|
|
vert.position = currentPos + offset;
|
|
vert.position = currentPos + offset;
|
|
|
vh.AddVert(vert);
|
|
vh.AddVert(vert);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 馃敼 鍦ㄦ瘡娈电嚎鏉′袱渚у�鍔犳姉閿�娇缇藉寲
|
|
|
|
|
+ if (antiAliasValue > 0.01f)
|
|
|
|
|
+ {
|
|
|
|
|
+ AddAntiAliasForLine(vh, previousPos, currentPos, offset, antiAliasValue);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -267,41 +277,41 @@ namespace LineUI
|
|
|
UIVertex vert = UIVertex.simpleVert;
|
|
UIVertex vert = UIVertex.simpleVert;
|
|
|
vert.color = maskColor;
|
|
vert.color = maskColor;
|
|
|
|
|
|
|
|
- //// 屏幕四个角的坐标
|
|
|
|
|
|
|
+ //// 灞忓箷鍥涗釜瑙掔殑鍧愭爣
|
|
|
//Vector2[] screenCorners = new Vector2[]
|
|
//Vector2[] screenCorners = new Vector2[]
|
|
|
//{
|
|
//{
|
|
|
- // new Vector2(-Screen.width / 2, -Screen.height / 2), // 左下角
|
|
|
|
|
- // new Vector2(Screen.width / 2, -Screen.height / 2), // 右下角
|
|
|
|
|
- // new Vector2(Screen.width / 2, Screen.height / 2), // 右上角
|
|
|
|
|
- // new Vector2(-Screen.width / 2, Screen.height / 2), // 左上角
|
|
|
|
|
|
|
+ // new Vector2(-Screen.width / 2, -Screen.height / 2), // 宸︿笅瑙�
|
|
|
|
|
+ // new Vector2(Screen.width / 2, -Screen.height / 2), // 鍙充笅瑙�
|
|
|
|
|
+ // new Vector2(Screen.width / 2, Screen.height / 2), // 鍙充笂瑙�
|
|
|
|
|
+ // new Vector2(-Screen.width / 2, Screen.height / 2), // 宸︿笂瑙�
|
|
|
//};
|
|
//};
|
|
|
|
|
|
|
|
- // 获取 RectTransform 的实际四个角坐标
|
|
|
|
|
|
|
+ // 鑾峰彇 RectTransform 鐨勫疄闄呭洓涓��鍧愭爣
|
|
|
Rect rect = rectTransform.rect;
|
|
Rect rect = rectTransform.rect;
|
|
|
|
|
|
|
|
Vector2[] screenCorners = new Vector2[]
|
|
Vector2[] screenCorners = new Vector2[]
|
|
|
{
|
|
{
|
|
|
- new Vector2(rect.xMin, rect.yMin), // 左下角
|
|
|
|
|
- new Vector2(rect.xMax, rect.yMin), // 右下角
|
|
|
|
|
- new Vector2(rect.xMax, rect.yMax), // 右上角
|
|
|
|
|
- new Vector2(rect.xMin, rect.yMax), // 左上角
|
|
|
|
|
|
|
+ new Vector2(rect.xMin, rect.yMin), // 宸︿笅瑙�
|
|
|
|
|
+ new Vector2(rect.xMax, rect.yMin), // 鍙充笅瑙�
|
|
|
|
|
+ new Vector2(rect.xMax, rect.yMax), // 鍙充笂瑙�
|
|
|
|
|
+ new Vector2(rect.xMin, rect.yMax), // 宸︿笂瑙�
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- // 添加四个点作为内框(中间区域的四个顶点)
|
|
|
|
|
|
|
+ // 娣诲姞鍥涗釜鐐逛綔涓哄唴妗嗭紙涓�棿鍖哄煙鐨勫洓涓�《鐐癸級
|
|
|
Vector2[] innerCorners = screenPositions.ToArray();
|
|
Vector2[] innerCorners = screenPositions.ToArray();
|
|
|
|
|
|
|
|
- // 分别绘制四个蒙版区域
|
|
|
|
|
|
|
+ // 鍒嗗埆缁樺埗鍥涗釜钂欑増鍖哄煙
|
|
|
|
|
|
|
|
- // 1. 左上区域:围绕左上角和内框左上、右上
|
|
|
|
|
|
|
+ // 1. 宸︿笂鍖哄煙锛氬洿缁曞乏涓婅�鍜屽唴妗嗗乏涓娿€佸彸涓�
|
|
|
AddQuad(vh, screenCorners[3], innerCorners[3], innerCorners[2], screenCorners[2]);
|
|
AddQuad(vh, screenCorners[3], innerCorners[3], innerCorners[2], screenCorners[2]);
|
|
|
|
|
|
|
|
- // 2. 右上区域:围绕右上角和内框右上、右下
|
|
|
|
|
|
|
+ // 2. 鍙充笂鍖哄煙锛氬洿缁曞彸涓婅�鍜屽唴妗嗗彸涓娿€佸彸涓�
|
|
|
AddQuad(vh, innerCorners[2], screenCorners[2], screenCorners[1], innerCorners[1]);
|
|
AddQuad(vh, innerCorners[2], screenCorners[2], screenCorners[1], innerCorners[1]);
|
|
|
|
|
|
|
|
- // 3. 右下区域:围绕右下角和内框右下、左下
|
|
|
|
|
|
|
+ // 3. 鍙充笅鍖哄煙锛氬洿缁曞彸涓嬭�鍜屽唴妗嗗彸涓嬨€佸乏涓�
|
|
|
AddQuad(vh, innerCorners[0], innerCorners[1], screenCorners[1], screenCorners[0]);
|
|
AddQuad(vh, innerCorners[0], innerCorners[1], screenCorners[1], screenCorners[0]);
|
|
|
|
|
|
|
|
- // 4. 左下区域:围绕左下角和内框左下、左上
|
|
|
|
|
|
|
+ // 4. 宸︿笅鍖哄煙锛氬洿缁曞乏涓嬭�鍜屽唴妗嗗乏涓嬨€佸乏涓�
|
|
|
AddQuad(vh, screenCorners[3], screenCorners[0], innerCorners[0], innerCorners[3]);
|
|
AddQuad(vh, screenCorners[3], screenCorners[0], innerCorners[0], innerCorners[3]);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -326,10 +336,10 @@ namespace LineUI
|
|
|
vh.AddTriangle(startIndex + 2, startIndex + 3, startIndex);
|
|
vh.AddTriangle(startIndex + 2, startIndex + 3, startIndex);
|
|
|
}
|
|
}
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
- /// 1. 计算角度方向:
|
|
|
|
|
- /// 使用 Vector2.Angle 可以得到两个向量之间的夹角大小,但它不能确定角度的方向。为此,我们需要使用 Mathf.Atan2 来计算相对坐标的角度。Atan2 可以返回一个在 -π 到 π 之间的角度值,并且考虑了顺时针和逆时针的方向。
|
|
|
|
|
- /// 2. 从 X 轴正方向为 0 计算角度:
|
|
|
|
|
- /// 将角度计算为相对于 x 轴正方向的角度,并根据 Atan2 结果进行调整。
|
|
|
|
|
|
|
+ /// 1. 璁$畻瑙掑害鏂瑰悜锛�
|
|
|
|
|
+ /// 浣跨敤 Vector2.Angle 鍙�互寰楀埌涓や釜鍚戦噺涔嬮棿鐨勫す瑙掑ぇ灏忥紝浣嗗畠涓嶈兘纭�畾瑙掑害鐨勬柟鍚戙€備负姝わ紝鎴戜滑闇€瑕佷娇鐢� Mathf.Atan2 鏉ヨ�绠楃浉瀵瑰潗鏍囩殑瑙掑害銆侫tan2 鍙�互杩斿洖涓€涓�湪 -蟺 鍒� 蟺 涔嬮棿鐨勮�搴﹀€硷紝骞朵笖鑰冭檻浜嗛『鏃堕拡鍜岄€嗘椂閽堢殑鏂瑰悜銆�
|
|
|
|
|
+ /// 2. 浠� X 杞存�鏂瑰悜涓� 0 璁$畻瑙掑害锛�
|
|
|
|
|
+ /// 灏嗚�搴﹁�绠椾负鐩稿�浜� x 杞存�鏂瑰悜鐨勮�搴︼紝骞舵牴鎹� Atan2 缁撴灉杩涜�璋冩暣銆�
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
/// <param name="vh"></param>
|
|
/// <param name="vh"></param>
|
|
|
private void DrawFansAtCorners(VertexHelper vh)
|
|
private void DrawFansAtCorners(VertexHelper vh)
|
|
@@ -340,66 +350,66 @@ namespace LineUI
|
|
|
_screenPositions.Add(screenPositions[0]);
|
|
_screenPositions.Add(screenPositions[0]);
|
|
|
_screenPositions.Add(screenPositions[1]);
|
|
_screenPositions.Add(screenPositions[1]);
|
|
|
}
|
|
}
|
|
|
- //比如现在是6个点,实际从第二个点开始绘制
|
|
|
|
|
|
|
+ //姣斿�鐜板湪鏄�6涓�偣锛屽疄闄呬粠绗�簩涓�偣寮€濮嬬粯鍒�
|
|
|
for (int i = 1; i < _screenPositions.Count - 1; i++)
|
|
for (int i = 1; i < _screenPositions.Count - 1; i++)
|
|
|
{
|
|
{
|
|
|
Vector2 previousPos = _screenPositions[i - 1];
|
|
Vector2 previousPos = _screenPositions[i - 1];
|
|
|
Vector2 currentPos = _screenPositions[i];
|
|
Vector2 currentPos = _screenPositions[i];
|
|
|
Vector2 nextPos = _screenPositions[i + 1];
|
|
Vector2 nextPos = _screenPositions[i + 1];
|
|
|
|
|
|
|
|
- // 计算当前点到前一点的方向
|
|
|
|
|
|
|
+ // 璁$畻褰撳墠鐐瑰埌鍓嶄竴鐐圭殑鏂瑰悜
|
|
|
Vector2 prevDir = (currentPos - previousPos).normalized;
|
|
Vector2 prevDir = (currentPos - previousPos).normalized;
|
|
|
- // 计算当前点到下一点的方向
|
|
|
|
|
|
|
+ // 璁$畻褰撳墠鐐瑰埌涓嬩竴鐐圭殑鏂瑰悜
|
|
|
Vector2 currentDir = (nextPos - currentPos).normalized;
|
|
Vector2 currentDir = (nextPos - currentPos).normalized;
|
|
|
|
|
|
|
|
- // 使用 Atan2 计算方向相对于 x 轴的角度
|
|
|
|
|
- float prevAngle = Mathf.Atan2(prevDir.y, prevDir.x) * Mathf.Rad2Deg; // 前一个方向相对于 x 轴的角度
|
|
|
|
|
- float currentAngle = Mathf.Atan2(currentDir.y, currentDir.x) * Mathf.Rad2Deg; // 当前方向相对于 x 轴的角度
|
|
|
|
|
|
|
+ // 浣跨敤 Atan2 璁$畻鏂瑰悜鐩稿�浜� x 杞寸殑瑙掑害
|
|
|
|
|
+ float prevAngle = Mathf.Atan2(prevDir.y, prevDir.x) * Mathf.Rad2Deg; // 鍓嶄竴涓�柟鍚戠浉瀵逛簬 x 杞寸殑瑙掑害
|
|
|
|
|
+ float currentAngle = Mathf.Atan2(currentDir.y, currentDir.x) * Mathf.Rad2Deg; // 褰撳墠鏂瑰悜鐩稿�浜� x 杞寸殑瑙掑害
|
|
|
|
|
|
|
|
- // 计算两个方向之间的角度差
|
|
|
|
|
|
|
+ // 璁$畻涓や釜鏂瑰悜涔嬮棿鐨勮�搴﹀樊
|
|
|
float angleBetween = Vector2.Angle(prevDir, currentDir);
|
|
float angleBetween = Vector2.Angle(prevDir, currentDir);
|
|
|
|
|
|
|
|
- // 判断旋转方向
|
|
|
|
|
|
|
+ // 鍒ゆ柇鏃嬭浆鏂瑰悜
|
|
|
float cross = prevDir.x * currentDir.y - prevDir.y * currentDir.x;
|
|
float cross = prevDir.x * currentDir.y - prevDir.y * currentDir.x;
|
|
|
if (cross < 0)
|
|
if (cross < 0)
|
|
|
{
|
|
{
|
|
|
- // 逆时针旋转
|
|
|
|
|
|
|
+ // 閫嗘椂閽堟棆杞�
|
|
|
angleBetween = 360f - angleBetween;
|
|
angleBetween = 360f - angleBetween;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 内角的计算(补充180度)
|
|
|
|
|
|
|
+ // 鍐呰�鐨勮�绠楋紙琛ュ厖180搴︼級
|
|
|
float innerAngle = 180f - angleBetween;
|
|
float innerAngle = 180f - angleBetween;
|
|
|
|
|
|
|
|
- // 计算开始角度,这里用的是 x 轴为起始点来计算
|
|
|
|
|
|
|
+ // 璁$畻寮€濮嬭�搴︼紝杩欓噷鐢ㄧ殑鏄� x 杞翠负璧峰�鐐规潵璁$畻
|
|
|
float startAngle = currentAngle;
|
|
float startAngle = currentAngle;
|
|
|
|
|
|
|
|
//Debug.Log($"Index {i}: startAngle = {startAngle}, innerAngle = {innerAngle}");
|
|
//Debug.Log($"Index {i}: startAngle = {startAngle}, innerAngle = {innerAngle}");
|
|
|
|
|
|
|
|
- // 根据当前角的位置调整内角和起始角
|
|
|
|
|
|
|
+ // 鏍规嵁褰撳墠瑙掔殑浣嶇疆璋冩暣鍐呰�鍜岃捣濮嬭�
|
|
|
DrawFanAtCorner(vh, currentPos, startAngle, innerAngle, fanInnerRadius, fanOuterRadius, fanSegments, fanColor);
|
|
DrawFanAtCorner(vh, currentPos, startAngle, innerAngle, fanInnerRadius, fanOuterRadius, fanSegments, fanColor);
|
|
|
|
|
|
|
|
|
|
|
|
|
- // 计算箭头的中心角度,确保角度在 0-360° 范围内
|
|
|
|
|
|
|
+ // 璁$畻绠�ご鐨勪腑蹇冭�搴︼紝纭�繚瑙掑害鍦� 0-360掳 鑼冨洿鍐�
|
|
|
float centerAngle = (startAngle + innerAngle / 2) % 360f;
|
|
float centerAngle = (startAngle + innerAngle / 2) % 360f;
|
|
|
float radians = Mathf.Deg2Rad * centerAngle;
|
|
float radians = Mathf.Deg2Rad * centerAngle;
|
|
|
|
|
|
|
|
- // 计算箭头位置:在扇形外半径的基础上延长一定距离(箭头偏移量)
|
|
|
|
|
|
|
+ // 璁$畻绠�ご浣嶇疆锛氬湪鎵囧舰澶栧崐寰勭殑鍩虹�涓婂欢闀夸竴瀹氳窛绂伙紙绠�ご鍋忕Щ閲忥級
|
|
|
float arrowOffset = fanOuterRadius + arrowDis;
|
|
float arrowOffset = fanOuterRadius + arrowDis;
|
|
|
Vector2 arrowPosition = currentPos + new Vector2(Mathf.Cos(radians), Mathf.Sin(radians)) * arrowOffset;
|
|
Vector2 arrowPosition = currentPos + new Vector2(Mathf.Cos(radians), Mathf.Sin(radians)) * arrowOffset;
|
|
|
|
|
|
|
|
- // 箭头方向
|
|
|
|
|
|
|
+ // 绠�ご鏂瑰悜
|
|
|
Vector2 arrowDirection = new Vector2(Mathf.Cos(radians), Mathf.Sin(radians)).normalized;
|
|
Vector2 arrowDirection = new Vector2(Mathf.Cos(radians), Mathf.Sin(radians)).normalized;
|
|
|
|
|
|
|
|
- // 将箭头信息保存到列表中
|
|
|
|
|
|
|
+ // 灏嗙�澶翠俊鎭�繚瀛樺埌鍒楄〃涓�
|
|
|
arrowInfos.Add(new ArrowInfo(arrowPosition, arrowDirection));
|
|
arrowInfos.Add(new ArrowInfo(arrowPosition, arrowDirection));
|
|
|
|
|
|
|
|
- // 在所有扇形处绘制箭头
|
|
|
|
|
- // 在扇形中心绘制箭头
|
|
|
|
|
|
|
+ // 鍦ㄦ墍鏈夋墖褰㈠�缁樺埗绠�ご
|
|
|
|
|
+ // 鍦ㄦ墖褰�腑蹇冪粯鍒剁�澶�
|
|
|
if (bDrawArrow)
|
|
if (bDrawArrow)
|
|
|
{
|
|
{
|
|
|
- // 调试信息
|
|
|
|
|
|
|
+ // 璋冭瘯淇℃伅
|
|
|
//Debug.Log($"Index {i}: arrowPosition = {arrowPosition}, startAngle = {startAngle}, centerAngle = {centerAngle}, direction = {arrowDirection}");
|
|
//Debug.Log($"Index {i}: arrowPosition = {arrowPosition}, startAngle = {startAngle}, centerAngle = {centerAngle}, direction = {arrowDirection}");
|
|
|
- // 绘制箭头
|
|
|
|
|
|
|
+ // 缁樺埗绠�ご
|
|
|
DrawArrow(vh, arrowPosition, arrowDirection, arrowLength, arrowWidth, arrowHeadHeight);
|
|
DrawArrow(vh, arrowPosition, arrowDirection, arrowLength, arrowWidth, arrowHeadHeight);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -411,63 +421,63 @@ namespace LineUI
|
|
|
UIVertex vert = UIVertex.simpleVert;
|
|
UIVertex vert = UIVertex.simpleVert;
|
|
|
vert.color = color;
|
|
vert.color = color;
|
|
|
|
|
|
|
|
- float angleRad = Mathf.Deg2Rad * angleDegree; // 将绘制角度转换为弧度
|
|
|
|
|
- float startAngleRad = Mathf.Deg2Rad * startAngle; // 将起始角度转换为弧度
|
|
|
|
|
- float angleStep = angleRad / segments; // 每个扇形段的角度步长
|
|
|
|
|
|
|
+ float angleRad = Mathf.Deg2Rad * angleDegree; // 灏嗙粯鍒惰�搴﹁浆鎹�负寮у害
|
|
|
|
|
+ float startAngleRad = Mathf.Deg2Rad * startAngle; // 灏嗚捣濮嬭�搴﹁浆鎹�负寮у害
|
|
|
|
|
+ float angleStep = angleRad / segments; // 姣忎釜鎵囧舰娈电殑瑙掑害姝ラ暱
|
|
|
|
|
|
|
|
- int initialVertCount = vh.currentVertCount; // 记录当前顶点数量
|
|
|
|
|
|
|
+ int initialVertCount = vh.currentVertCount; // 璁板綍褰撳墠椤剁偣鏁伴噺
|
|
|
|
|
|
|
|
- // 添加中心点顶点
|
|
|
|
|
|
|
+ // 娣诲姞涓�績鐐归《鐐�
|
|
|
vert.position = center;
|
|
vert.position = center;
|
|
|
- vert.uv0 = new Vector2(0.5f, 0.5f); // 中心UV值
|
|
|
|
|
|
|
+ vert.uv0 = new Vector2(0.5f, 0.5f); // 涓�績UV鍊�
|
|
|
vh.AddVert(vert);
|
|
vh.AddVert(vert);
|
|
|
|
|
|
|
|
- // 绘制外圈和内圈的顶点
|
|
|
|
|
|
|
+ // 缁樺埗澶栧湀鍜屽唴鍦堢殑椤剁偣
|
|
|
for (int i = 0; i <= segments; i++)
|
|
for (int i = 0; i <= segments; i++)
|
|
|
{
|
|
{
|
|
|
float currentAngle = startAngleRad + i * angleStep;
|
|
float currentAngle = startAngleRad + i * angleStep;
|
|
|
float cosA = Mathf.Cos(currentAngle);
|
|
float cosA = Mathf.Cos(currentAngle);
|
|
|
float sinA = Mathf.Sin(currentAngle);
|
|
float sinA = Mathf.Sin(currentAngle);
|
|
|
|
|
|
|
|
- // 外圈顶点
|
|
|
|
|
|
|
+ // 澶栧湀椤剁偣
|
|
|
vert.position = center + new Vector2(cosA * outerRadius, sinA * outerRadius);
|
|
vert.position = center + new Vector2(cosA * outerRadius, sinA * outerRadius);
|
|
|
vert.uv0 = new Vector2(0.5f + cosA * 0.5f, 0.5f + sinA * 0.5f);
|
|
vert.uv0 = new Vector2(0.5f + cosA * 0.5f, 0.5f + sinA * 0.5f);
|
|
|
vh.AddVert(vert);
|
|
vh.AddVert(vert);
|
|
|
|
|
|
|
|
- // 内圈顶点
|
|
|
|
|
|
|
+ // 鍐呭湀椤剁偣
|
|
|
vert.position = center + new Vector2(cosA * innerRadius, sinA * innerRadius);
|
|
vert.position = center + new Vector2(cosA * innerRadius, sinA * innerRadius);
|
|
|
vert.uv0 = new Vector2(0.5f + cosA * innerRadius / outerRadius * 0.5f, 0.5f + sinA * innerRadius / outerRadius * 0.5f);
|
|
vert.uv0 = new Vector2(0.5f + cosA * innerRadius / outerRadius * 0.5f, 0.5f + sinA * innerRadius / outerRadius * 0.5f);
|
|
|
vh.AddVert(vert);
|
|
vh.AddVert(vert);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 创建三角形索引来绘制扇形
|
|
|
|
|
|
|
+ // 鍒涘缓涓夎�褰㈢储寮曟潵缁樺埗鎵囧舰
|
|
|
for (int i = 1; i <= segments; i++)
|
|
for (int i = 1; i <= segments; i++)
|
|
|
{
|
|
{
|
|
|
int baseIndex = initialVertCount + (i - 1) * 2;
|
|
int baseIndex = initialVertCount + (i - 1) * 2;
|
|
|
- vh.AddTriangle(initialVertCount, baseIndex + 1, baseIndex + 3); // 中心点连接外圈
|
|
|
|
|
- vh.AddTriangle(baseIndex + 1, baseIndex + 2, baseIndex + 3); // 内圈连接外圈
|
|
|
|
|
|
|
+ vh.AddTriangle(initialVertCount, baseIndex + 1, baseIndex + 3); // 涓�績鐐硅繛鎺ュ�鍦�
|
|
|
|
|
+ vh.AddTriangle(baseIndex + 1, baseIndex + 2, baseIndex + 3); // 鍐呭湀杩炴帴澶栧湀
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 新增箭头绘制方法
|
|
|
|
|
|
|
+ // 鏂板�绠�ご缁樺埗鏂规硶
|
|
|
private void DrawArrow(VertexHelper vh, Vector2 position, Vector2 direction, float arrowLength, float arrowWidth, float arrowHeadHeight)
|
|
private void DrawArrow(VertexHelper vh, Vector2 position, Vector2 direction, float arrowLength, float arrowWidth, float arrowHeadHeight)
|
|
|
{
|
|
{
|
|
|
- // 标准化方向向量
|
|
|
|
|
|
|
+ // 鏍囧噯鍖栨柟鍚戝悜閲�
|
|
|
direction.Normalize();
|
|
direction.Normalize();
|
|
|
|
|
|
|
|
- // 反向箭头的方向(箭头指向扇形方向)
|
|
|
|
|
|
|
+ // 鍙嶅悜绠�ご鐨勬柟鍚戯紙绠�ご鎸囧悜鎵囧舰鏂瑰悜锛�
|
|
|
Vector2 reversedDirection = -direction;
|
|
Vector2 reversedDirection = -direction;
|
|
|
|
|
|
|
|
- // 箭头尾部位置
|
|
|
|
|
|
|
+ // 绠�ご灏鹃儴浣嶇疆
|
|
|
Vector2 basePosition = position - reversedDirection * arrowLength;
|
|
Vector2 basePosition = position - reversedDirection * arrowLength;
|
|
|
|
|
|
|
|
- // 计算垂直向量用于箭头宽度
|
|
|
|
|
|
|
+ // 璁$畻鍨傜洿鍚戦噺鐢ㄤ簬绠�ご瀹藉害
|
|
|
Vector2 perpendicular = new Vector2(-reversedDirection.y, reversedDirection.x);
|
|
Vector2 perpendicular = new Vector2(-reversedDirection.y, reversedDirection.x);
|
|
|
|
|
|
|
|
- // 让箭头矩形部分的宽度比三角形的底边窄
|
|
|
|
|
- float adjustedArrowWidth = arrowWidth * 0.6f; // 调整宽度,使矩形比三角形窄
|
|
|
|
|
|
|
+ // 璁╃�澶寸煩褰㈤儴鍒嗙殑瀹藉害姣斾笁瑙掑舰鐨勫簳杈圭獎
|
|
|
|
|
+ float adjustedArrowWidth = arrowWidth * 0.6f; // 璋冩暣瀹藉害锛屼娇鐭╁舰姣斾笁瑙掑舰绐�
|
|
|
|
|
|
|
|
- // 箭头矩形部分的四个顶点
|
|
|
|
|
|
|
+ // 绠�ご鐭╁舰閮ㄥ垎鐨勫洓涓�《鐐�
|
|
|
Vector2 baseLeft = basePosition + perpendicular * (adjustedArrowWidth / 2);
|
|
Vector2 baseLeft = basePosition + perpendicular * (adjustedArrowWidth / 2);
|
|
|
Vector2 baseRight = basePosition - perpendicular * (adjustedArrowWidth / 2);
|
|
Vector2 baseRight = basePosition - perpendicular * (adjustedArrowWidth / 2);
|
|
|
Vector2 headLeft = position + perpendicular * (adjustedArrowWidth / 2);
|
|
Vector2 headLeft = position + perpendicular * (adjustedArrowWidth / 2);
|
|
@@ -476,11 +486,11 @@ namespace LineUI
|
|
|
Vector2 triangleHeadLeft = position + perpendicular * (arrowHeadHeight / 2);
|
|
Vector2 triangleHeadLeft = position + perpendicular * (arrowHeadHeight / 2);
|
|
|
Vector2 triangleHeadRight = position - perpendicular * (arrowHeadHeight / 2);
|
|
Vector2 triangleHeadRight = position - perpendicular * (arrowHeadHeight / 2);
|
|
|
|
|
|
|
|
- // 顶点颜色
|
|
|
|
|
|
|
+ // 椤剁偣棰滆壊
|
|
|
UIVertex vert = UIVertex.simpleVert;
|
|
UIVertex vert = UIVertex.simpleVert;
|
|
|
vert.color = arrowColor;
|
|
vert.color = arrowColor;
|
|
|
|
|
|
|
|
- // 先添加矩形部分的顶点
|
|
|
|
|
|
|
+ // 鍏堟坊鍔犵煩褰㈤儴鍒嗙殑椤剁偣
|
|
|
int rectStartIndex = vh.currentVertCount;
|
|
int rectStartIndex = vh.currentVertCount;
|
|
|
vert.position = baseLeft;
|
|
vert.position = baseLeft;
|
|
|
vh.AddVert(vert);
|
|
vh.AddVert(vert);
|
|
@@ -491,11 +501,11 @@ namespace LineUI
|
|
|
vert.position = headRight;
|
|
vert.position = headRight;
|
|
|
vh.AddVert(vert);
|
|
vh.AddVert(vert);
|
|
|
|
|
|
|
|
- // 添加矩形部分的两条三角形索引
|
|
|
|
|
|
|
+ // 娣诲姞鐭╁舰閮ㄥ垎鐨勪袱鏉′笁瑙掑舰绱㈠紩
|
|
|
vh.AddTriangle(rectStartIndex, rectStartIndex + 1, rectStartIndex + 2);
|
|
vh.AddTriangle(rectStartIndex, rectStartIndex + 1, rectStartIndex + 2);
|
|
|
vh.AddTriangle(rectStartIndex + 1, rectStartIndex + 3, rectStartIndex + 2);
|
|
vh.AddTriangle(rectStartIndex + 1, rectStartIndex + 3, rectStartIndex + 2);
|
|
|
|
|
|
|
|
- // 然后添加三角形头部的顶点
|
|
|
|
|
|
|
+ // 鐒跺悗娣诲姞涓夎�褰㈠ご閮ㄧ殑椤剁偣
|
|
|
Vector2 headPosition = position + reversedDirection * arrowHeadHeight;
|
|
Vector2 headPosition = position + reversedDirection * arrowHeadHeight;
|
|
|
int headStartIndex = vh.currentVertCount;
|
|
int headStartIndex = vh.currentVertCount;
|
|
|
|
|
|
|
@@ -503,15 +513,58 @@ namespace LineUI
|
|
|
vh.AddVert(vert);
|
|
vh.AddVert(vert);
|
|
|
vert.position = triangleHeadRight;
|
|
vert.position = triangleHeadRight;
|
|
|
vh.AddVert(vert);
|
|
vh.AddVert(vert);
|
|
|
- vert.position = headPosition; // 添加箭头尖端
|
|
|
|
|
|
|
+ vert.position = headPosition; // 娣诲姞绠�ご灏栫�
|
|
|
vh.AddVert(vert);
|
|
vh.AddVert(vert);
|
|
|
|
|
|
|
|
- // 添加三角形的索引
|
|
|
|
|
- int triangleStartIndex = vh.currentVertCount - 3; // 三角形部分的开始索引
|
|
|
|
|
- vh.AddTriangle(triangleStartIndex, triangleStartIndex + 1, triangleStartIndex + 2); // 三角形索引
|
|
|
|
|
|
|
+ // 娣诲姞涓夎�褰㈢殑绱㈠紩
|
|
|
|
|
+ int triangleStartIndex = vh.currentVertCount - 3; // 涓夎�褰㈤儴鍒嗙殑寮€濮嬬储寮�
|
|
|
|
|
+ vh.AddTriangle(triangleStartIndex, triangleStartIndex + 1, triangleStartIndex + 2); // 涓夎�褰㈢储寮�
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 鎶楅敮榻跨窘鍖栬竟缂�
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private void AddAntiAliasForLine(VertexHelper vh, Vector2 start, Vector2 end, Vector2 offset, float feather)
|
|
|
|
|
+ {
|
|
|
|
|
+ UIVertex vert = UIVertex.simpleVert;
|
|
|
|
|
+
|
|
|
|
|
+ Color featherColor = color;
|
|
|
|
|
+ featherColor.a = 0; // 閫忔槑鏀跺熬
|
|
|
|
|
+
|
|
|
|
|
+ // 涓婅竟缂�
|
|
|
|
|
+ vert.color = color;
|
|
|
|
|
+ vert.position = start + offset;
|
|
|
|
|
+ vh.AddVert(vert);
|
|
|
|
|
+ vert.position = end + offset;
|
|
|
|
|
+ vh.AddVert(vert);
|
|
|
|
|
|
|
|
|
|
+ vert.color = featherColor;
|
|
|
|
|
+ vert.position = start + offset + (offset.normalized * feather);
|
|
|
|
|
+ vh.AddVert(vert);
|
|
|
|
|
+ vert.position = end + offset + (offset.normalized * feather);
|
|
|
|
|
+ vh.AddVert(vert);
|
|
|
|
|
+
|
|
|
|
|
+ int idx = vh.currentVertCount - 4;
|
|
|
|
|
+ vh.AddTriangle(idx, idx + 1, idx + 2);
|
|
|
|
|
+ vh.AddTriangle(idx + 1, idx + 3, idx + 2);
|
|
|
|
|
+
|
|
|
|
|
+ // 涓嬭竟缂�
|
|
|
|
|
+ vert.color = color;
|
|
|
|
|
+ vert.position = start - offset;
|
|
|
|
|
+ vh.AddVert(vert);
|
|
|
|
|
+ vert.position = end - offset;
|
|
|
|
|
+ vh.AddVert(vert);
|
|
|
|
|
+
|
|
|
|
|
+ vert.color = featherColor;
|
|
|
|
|
+ vert.position = start - offset - (offset.normalized * feather);
|
|
|
|
|
+ vh.AddVert(vert);
|
|
|
|
|
+ vert.position = end - offset - (offset.normalized * feather);
|
|
|
|
|
+ vh.AddVert(vert);
|
|
|
|
|
+
|
|
|
|
|
+ idx = vh.currentVertCount - 4;
|
|
|
|
|
+ vh.AddTriangle(idx, idx + 1, idx + 2);
|
|
|
|
|
+ vh.AddTriangle(idx + 1, idx + 3, idx + 2);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|