Archived
* 将组件加入到菜单中。
* 添加一个任意形状编辑器
This commit is contained in:
@@ -4,7 +4,7 @@ using UnityEngine;
|
||||
using UnityEngine.Pool;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XericLibrary
|
||||
namespace XericLibrary.Runtime.Renderer
|
||||
{
|
||||
/// <summary>
|
||||
/// 自定义渲染组件
|
||||
@@ -20,13 +20,13 @@ namespace XericLibrary
|
||||
private readonly List<UIVertex> _vertexList = new List<UIVertex>();
|
||||
private readonly List<int> _indexList = new List<int>();
|
||||
// 阵列原点
|
||||
private readonly List<Vector4> _arrayTransformList = new List<Vector4>();
|
||||
private List<Vector4> _arrayTransformList = new List<Vector4>();
|
||||
// 中间数据
|
||||
private List<UIVertex> _temp_vertexList = new List<UIVertex>();
|
||||
private List<int> _temp_indexList = new List<int>();
|
||||
|
||||
private bool _dirty;
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#if UNITY_EDITOR
|
||||
@@ -54,6 +54,8 @@ namespace XericLibrary
|
||||
/// <param name="vh"></param>
|
||||
protected override void OnPopulateMesh(VertexHelper vh)
|
||||
{
|
||||
if (vh == null) return;
|
||||
vh.Clear();
|
||||
ClearCache();
|
||||
// 填充图元
|
||||
OnPopulatePrefabricateVertex(_vertexList, _indexList);
|
||||
@@ -80,7 +82,6 @@ namespace XericLibrary
|
||||
{
|
||||
_vertexList.Clear();
|
||||
_indexList.Clear();
|
||||
_arrayTransformList.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -88,9 +89,30 @@ namespace XericLibrary
|
||||
/// </summary>
|
||||
/// <param name="offset">偏移</param>
|
||||
/// <param name="angle">角度</param>
|
||||
protected void AddArrayModifier(Vector3 offset, float angle)
|
||||
public int AddArrayModifier(Vector3 offset, float angle)
|
||||
{
|
||||
var index = _arrayTransformList.Count;
|
||||
_arrayTransformList.Add(new Vector4(offset.x, offset.y, offset.z, angle));
|
||||
Refresh();
|
||||
return index;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空阵列节点
|
||||
/// </summary>
|
||||
public void ClearArrayModifier()
|
||||
{
|
||||
_arrayTransformList.Clear();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public bool ModifyArrayModifier(int index, Vector3 offset, float angle)
|
||||
{
|
||||
if (index < 0 || index >= _arrayTransformList.Count)
|
||||
return false;
|
||||
_arrayTransformList[index] = new Vector4(offset.x, offset.y, offset.z, angle);
|
||||
Refresh();
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -104,27 +126,31 @@ namespace XericLibrary
|
||||
/// <param name="trans"></param>
|
||||
protected void ArrayVertexList(List<Vector4> trans)
|
||||
{
|
||||
_temp_vertexList.Clear();
|
||||
_temp_indexList.Clear();
|
||||
|
||||
if (trans == null || trans.Count == 0)
|
||||
{
|
||||
Copy();
|
||||
return;
|
||||
}
|
||||
foreach (var t in trans)
|
||||
Copy2(t);
|
||||
|
||||
for (int i = 0; i < trans.Count; i++)
|
||||
Copy2(i, trans[i]);
|
||||
|
||||
void Copy()
|
||||
{
|
||||
_temp_vertexList = _vertexList.GetRange(0, _vertexList.Count);
|
||||
_temp_indexList = _indexList.GetRange(0, _indexList.Count);
|
||||
_temp_vertexList.AddRange(_vertexList.GetRange(0, _vertexList.Count));
|
||||
_temp_indexList.AddRange(_indexList.GetRange(0, _indexList.Count));
|
||||
}
|
||||
void Copy2(Vector4 transform)
|
||||
void Copy2(int index, Vector4 transform)
|
||||
{
|
||||
_temp_vertexList = _vertexList.Select(a =>
|
||||
_temp_vertexList.AddRange(_vertexList.Select(a =>
|
||||
{
|
||||
var newPos = new Vector3(a.position.x, a.position.y, a.position.z);
|
||||
if (a.position.z != 0)
|
||||
var newPos = a.position;
|
||||
if (transform.w != 0)
|
||||
{
|
||||
var rot = Quaternion.Euler(0, 0, a.position.z);
|
||||
var rot = Quaternion.Euler(0, 0, transform.w);
|
||||
newPos = rot * newPos;
|
||||
}
|
||||
newPos += (Vector3)transform;
|
||||
@@ -139,8 +165,8 @@ namespace XericLibrary
|
||||
uv2 = a.uv2,
|
||||
uv3 = a.uv3,
|
||||
};
|
||||
}).ToList();
|
||||
_temp_indexList = _indexList.GetRange(0, _indexList.Count);
|
||||
}));
|
||||
_temp_indexList.AddRange(_indexList.Select(a => index * _vertexList.Count + a));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user