161 lines
3.7 KiB
C#
161 lines
3.7 KiB
C#
|
using System;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace Thousandto.Launcher.ExternalLibs
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 运行时子节点的MeshInfo
|
|||
|
/// </summary>
|
|||
|
[Serializable]
|
|||
|
public class RuntimeChildMesh
|
|||
|
{
|
|||
|
[SerializeField]
|
|||
|
private Color[] _colors;
|
|||
|
[SerializeField]
|
|||
|
private int _lightmapIndex;
|
|||
|
[SerializeField]
|
|||
|
private Vector4 _lightmapScaleOffset;
|
|||
|
[SerializeField]
|
|||
|
private int _startIndex;
|
|||
|
[SerializeField]
|
|||
|
private Vector3[] _newVertices = null;
|
|||
|
[SerializeField]
|
|||
|
private bool _isDirty = false;
|
|||
|
public Vector3[] OldVertices { get; private set; }
|
|||
|
public bool IsDirty
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return _isDirty;
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
_isDirty = value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public int StartIndex
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return _startIndex;
|
|||
|
}
|
|||
|
|
|||
|
set
|
|||
|
{
|
|||
|
_startIndex = value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public int LightmapIndex
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return _lightmapIndex;
|
|||
|
}
|
|||
|
|
|||
|
set
|
|||
|
{
|
|||
|
_lightmapIndex = value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public Vector4 LightmapScaleOffset
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return _lightmapScaleOffset;
|
|||
|
}
|
|||
|
|
|||
|
set
|
|||
|
{
|
|||
|
_lightmapScaleOffset = value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public Color[] Colors
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return _colors;
|
|||
|
}
|
|||
|
|
|||
|
set
|
|||
|
{
|
|||
|
_colors = value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public Vector3[] NewVertices
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return _newVertices;
|
|||
|
}
|
|||
|
|
|||
|
set
|
|||
|
{
|
|||
|
_newVertices = value;
|
|||
|
}
|
|||
|
}
|
|||
|
#region//编辑器编辑的时候调用
|
|||
|
#if UNITY_EDITOR && !FUNCELL_LAUNCHER
|
|||
|
//构造函数
|
|||
|
public RuntimeChildMesh(Transform tran,int lightmapIndex, Vector4 offset, Color[] color)
|
|||
|
{
|
|||
|
LightmapIndex = lightmapIndex;
|
|||
|
LightmapScaleOffset = offset;
|
|||
|
MeshFilter mf = tran.GetComponent<MeshFilter>();
|
|||
|
if (mf)
|
|||
|
{
|
|||
|
Colors = mf.sharedMesh.colors;
|
|||
|
}
|
|||
|
Colors = color;
|
|||
|
}
|
|||
|
#endif
|
|||
|
#endregion
|
|||
|
|
|||
|
#region//运行时调用
|
|||
|
|
|||
|
//重新刷新顶点
|
|||
|
public void RefreshVertex(SetNewVertexDelegate func)
|
|||
|
{
|
|||
|
//如果当前没有顶点时就返回
|
|||
|
if (func == null || NewVertices == null || NewVertices.Length == 0 || Colors == null) return;
|
|||
|
|
|||
|
_isDirty = true;
|
|||
|
|
|||
|
//第一次刷新顶点时,要把顶点给保存起来
|
|||
|
if (OldVertices == null)
|
|||
|
{
|
|||
|
OldVertices = new Vector3[NewVertices.Length];
|
|||
|
for (int i = 0; i < NewVertices.Length; i++)
|
|||
|
{
|
|||
|
OldVertices[i] = NewVertices[i];
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//刷新顶点操作
|
|||
|
for(int i = 0;i < OldVertices.Length;i++)
|
|||
|
{
|
|||
|
if (i < NewVertices.Length && i< Colors.Length )
|
|||
|
{
|
|||
|
func(ref NewVertices[i], ref OldVertices[i], ref Colors[i]);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//重置
|
|||
|
public void Reset()
|
|||
|
{
|
|||
|
_isDirty = false;
|
|||
|
_startIndex = -1;
|
|||
|
NewVertices = null;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
//设置新顶点的委托
|
|||
|
public delegate void SetNewVertexDelegate(ref Vector3 newV, ref Vector3 oldV, ref Color vcolor);
|
|||
|
}
|