This commit is contained in:
2026-06-29 14:36:02 +08:00
parent d938aa9929
commit 6af5616e50
5 changed files with 406 additions and 134 deletions
+17
View File
@@ -3,6 +3,10 @@ using System.Linq;
using UnityEngine;
using UnityEngine.UI;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace XericLibrary.Runtime.UIGraph
{
/// <summary>
@@ -794,6 +798,19 @@ namespace XericLibrary.Runtime.UIGraph
base.OnValidate();
isDirty = true;
}
[MenuItem("GameObject/Xeric Library/UI/UIAnyPatternRenderer", false, 10)]
private static void CreateGameObject()
{
GameObject newObject = new GameObject(nameof(UIAnyPatternRenderer), typeof(UIAnyPatternRenderer));
if (Selection.activeGameObject != null)
newObject.transform.SetParent(Selection.activeGameObject.transform);
Undo.RegisterCreatedObjectUndo(newObject, $"Create {nameof(UIAnyPatternRenderer)}");
Selection.activeObject = newObject;
}
#endif
}
+50 -6
View File
@@ -3,6 +3,10 @@ using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace XericLibrary.Runtime.UIGraph
{
/// <summary>
@@ -23,12 +27,34 @@ namespace XericLibrary.Runtime.UIGraph
public List<Vector2> points = new List<Vector2>();
private Vector2[] _points;
/// <summary>
/// 线路宽度
/// </summary>
public float thickness = 10f;
/// <summary>
/// 居中对齐
/// </summary>
public bool center = true;
/// <summary>
/// 循环线路
/// </summary>
public bool cycleLoop = false;
/// <summary>
/// 启用额外绘制的矢量箭头
/// </summary>
public bool enableVectorArrow = false;
/// <summary>
/// 矢量箭头尺寸(宽长)
/// </summary>
public Vector2 vectorArrowSize = Vector2.one;
public bool absVectorProgress = true;
public float vectorProgress = 15f;
public float vectorArrowProgress = 0.5f;
public bool reverseVector = false;
/// <summary>
/// 是否启用倒角功能
/// 是/否启用倒角功能
/// </summary>
public bool useChamfer = false;
@@ -76,7 +102,7 @@ namespace XericLibrary.Runtime.UIGraph
points.Clear();
Refresh();
}
/// <summary>
/// 生成线条网格
/// </summary>
@@ -89,15 +115,18 @@ namespace XericLibrary.Runtime.UIGraph
var offset = XericRendererUtils.SwitchCenterOffset(center, rectTransform.sizeDelta);
_points = points.ToArray();
// 切换线路绘制模式
if (useChamfer)
{
vh.PopulateLineByPointsArray_CFAL(_points, thickness, cycleLoop, color, offset, chamferSegments, innerRadius);
}
else
{
vh.PopulateLineByPointsArray_DSL5(_points, thickness, cycleLoop, color, offset);
}
{
vh.PopulateLineByPointsArray_DSL5(_points, thickness, cycleLoop, color, offset,
enableVectorArrow,
color, vectorArrowSize, vectorProgress, vectorArrowProgress, absVectorProgress, reverseVector);
}
return;
@@ -138,5 +167,20 @@ namespace XericLibrary.Runtime.UIGraph
}
}
}
#if UNITY_EDITOR
[MenuItem("GameObject/Xeric Library/UI/UILineRenderer", false, 10)]
private static void CreateGameObject()
{
GameObject newObject = new GameObject(nameof(UILineRenderer), typeof(UILineRenderer));
if (Selection.activeGameObject != null)
newObject.transform.SetParent(Selection.activeGameObject.transform);
Undo.RegisterCreatedObjectUndo(newObject, $"Create {nameof(UILineRenderer)}");
Selection.activeObject = newObject;
}
#endif
}
}
}
+17
View File
@@ -7,6 +7,10 @@ using UnityEngine.Serialization;
using UnityEngine.UI;
using XericLibrary.Runtime.Debuger;
using XericLibrary.Runtime.MacroLibrary;
#if UNITY_EDITOR
using UnityEditor;
#endif
#if ODIN_INSPECTOR
using Sirenix.OdinInspector;
#endif
@@ -315,6 +319,19 @@ namespace XericLibrary.Runtime.UIGraph
BorderColorLinear = borderColor2;
FillColor = fillColor;
}
[MenuItem("GameObject/Xeric Library/UI/UIPatternRenderer", false, 10)]
private static void CreateGameObject()
{
GameObject newObject = new GameObject(nameof(UIPatternRenderer), typeof(UIPatternRenderer));
if (Selection.activeGameObject != null)
newObject.transform.SetParent(Selection.activeGameObject.transform);
Undo.RegisterCreatedObjectUndo(newObject, $"Create {nameof(UIPatternRenderer)}");
Selection.activeObject = newObject;
}
#endif
}
}
+79 -10
View File
@@ -3,6 +3,7 @@ using System.Linq;
using UnityEngine;
using UnityEngine.Pool;
using UnityEngine.UI;
using XericLibrary.Runtime.MacroLibrary;
namespace XericLibrary.Runtime.UIGraph
{
@@ -21,6 +22,7 @@ namespace XericLibrary.Runtime.UIGraph
private readonly List<int> _indexList = new List<int>();
// 阵列原点
private List<Vector4> _arrayTransformList = new List<Vector4>();
private List<Color32> _arrayColorList = new List<Color32>();
// 中间数据
private List<UIVertex> _temp_vertexList = new List<UIVertex>();
private List<int> _temp_indexList = new List<int>();
@@ -89,14 +91,26 @@ namespace XericLibrary.Runtime.UIGraph
/// </summary>
/// <param name="offset">偏移</param>
/// <param name="angle">角度</param>
public int AddArrayModifier(Vector3 offset, float angle)
public int AddArrayModifier(Vector2 offset, float angle, float size)
{
var index = _arrayTransformList.Count;
_arrayTransformList.Add(new Vector4(offset.x, offset.y, offset.z, angle));
_arrayTransformList.Add(new Vector4(offset.x, offset.y, angle, size));
Refresh();
return index;
}
/// <summary>
/// 设置阵列节点
/// </summary>
/// <param name="trans"></param>
public void SetArrayModifier(IList<Vector4> trans)
{
if (trans == null)
return;
_arrayTransformList.Clear();
_arrayTransformList.AddRange(trans);
}
/// <summary>
/// 清空阵列节点
/// </summary>
@@ -105,15 +119,62 @@ namespace XericLibrary.Runtime.UIGraph
_arrayTransformList.Clear();
Refresh();
}
public bool ModifyArrayModifier(int index, Vector3 offset, float angle)
/// <summary>
/// 修改阵列节点
/// </summary>
/// <param name="index"></param>
/// <param name="offset"></param>
/// <param name="angle"></param>
/// <param name="size"></param>
/// <returns></returns>
public bool ModifyArrayModifier(int index, Vector2 offset, float angle, float size)
{
if (index < 0 || index >= _arrayTransformList.Count)
return false;
_arrayTransformList[index] = new Vector4(offset.x, offset.y, offset.z, angle);
_arrayTransformList[index] = new Vector4(offset.x, offset.y, angle, size);
Refresh();
return true;
}
public IList<Vector4> GetArrayModifier() => _arrayTransformList;
/// <summary>
/// 添加颜色
/// </summary>
/// <param name="color"></param>
public void AddColor(Color color) => _arrayColorList.Add(color);
/// <summary>
/// 添加颜色
/// </summary>
/// <param name="color"></param>
public void AddColor(Color32 color) => _arrayColorList.Add(color);
/// <summary>
/// 设置颜色节点
/// </summary>
/// <param name="index"></param>
/// <param name="color"></param>
public void SetColor(int index, Color color) => _arrayColorList.SetAtIndex<Color32>(color, index);
/// <summary>
/// 设置颜色节点
/// </summary>
/// <param name="index"></param>
/// <param name="color"></param>
public void SetColor(int index, Color32 color) => _arrayColorList.SetAtIndex<Color32>(color, index);
/// <summary>
/// 清空颜色
/// </summary>
public void ClearArrayColor() => _arrayColorList.Clear();
/// <summary>
/// 获取颜色列表
/// </summary>
/// <returns></returns>
public IList<Color32> GetArrayColor() => _arrayColorList;
#endregion
@@ -147,19 +208,27 @@ namespace XericLibrary.Runtime.UIGraph
{
_temp_vertexList.AddRange(_vertexList.Select(a =>
{
var newPos = a.position;
if (transform.w != 0)
Vector2 newPos = a.position;
if (transform.z != 0)
{
var rot = Quaternion.Euler(0, 0, transform.w);
var rot = Quaternion.Euler(0, 0, transform.z);
newPos = rot * newPos;
}
newPos += (Vector3)transform;
if (transform.z > 0)
newPos *= transform.w;
newPos += (Vector2)transform;
var newColor = a.color;
if (index < _arrayColorList.Count && !default(Color32).Equals(_arrayColorList[index]))
{
newColor = _arrayColorList[index];
}
return new UIVertex()
{
position = newPos,
normal = a.normal,
tangent = a.tangent,
color = a.color,
color = newColor,
uv0 = a.uv0,
uv1 = a.uv1,
uv2 = a.uv2,