Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit 4a53e0d

Browse files
committed
流程跑通
1 parent 1f1530d commit 4a53e0d

File tree

4 files changed

+101
-77
lines changed

4 files changed

+101
-77
lines changed

Assets/Hidden/SpriteGraphic02.cs

Lines changed: 90 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,57 @@ public class SpriteGraphic02 : MaskableGraphic
1919
[SerializeField]
2020
private float _speed;
2121

22-
private MeshInfo _meshInfo;
22+
private MeshInfo _meshInfo=new MeshInfo();
2323
public MeshInfo MeshInfo
2424
{
2525
get { return _meshInfo; }
2626
set
2727
{
28+
//if (_meshInfo == null)
29+
//{
30+
// _meshInfo = new MeshInfo();
31+
//}
32+
2833
//if (_spriteTagInfo.Equals(value))
2934
// return;
3035

31-
workerMesh.Clear();
36+
// workerMesh.Clear();
3237

3338
_meshInfo = value;
3439

35-
int length = _meshInfo.Vertices.Count;
40+
// int length = _meshInfo.Vertices.Count;
3641

37-
workerMesh.vertices = new Vector3[length];
38-
workerMesh.colors = new Color[length];
39-
workerMesh.uv = new Vector2[length];
40-
workerMesh.triangles = new int[length/2*3];
42+
// workerMesh.vertices = new Vector3[length];
43+
// workerMesh.colors = new Color[length];
44+
// workerMesh.uv = new Vector2[length];
45+
// workerMesh.triangles = new int[length/2*3];
4146

42-
for (int i = 0; i < length; i++)
43-
{
44-
_meshInfo.Colors.Add(color);
45-
46-
if (i % 6 == 0)
47-
{
48-
int num = i / 6;
49-
_meshInfo.Triangles.Add(0 + 4 * num);
50-
_meshInfo.Triangles.Add(1 + 4 * num);
51-
_meshInfo.Triangles.Add(2 + 4 * num);
52-
53-
_meshInfo.Triangles.Add(2 + 4 * num);
54-
_meshInfo.Triangles.Add(3 + 4 * num);
55-
_meshInfo.Triangles.Add(0 + 4 * num);
56-
}
57-
}
47+
// for (int i = 0; i < length; i++)
48+
// {
49+
// _meshInfo.Colors.Add(color);
50+
51+
// if (i % 6 == 0)
52+
// {
53+
// int num = i / 6;
54+
// _meshInfo.Triangles.Add(0 + 4 * num);
55+
// _meshInfo.Triangles.Add(1 + 4 * num);
56+
// _meshInfo.Triangles.Add(2 + 4 * num);
5857

59-
workerMesh.SetVertices(_meshInfo.Vertices);
60-
workerMesh.SetUVs(0,_meshInfo.UVs);
61-
workerMesh.SetColors(_meshInfo.Colors);
62-
workerMesh.triangles = _meshInfo.Triangles.ToArray();
58+
// _meshInfo.Triangles.Add(2 + 4 * num);
59+
// _meshInfo.Triangles.Add(3 + 4 * num);
60+
// _meshInfo.Triangles.Add(0 + 4 * num);
61+
// }
62+
// }
6363

64-
canvasRenderer.SetMesh(workerMesh);
64+
// workerMesh.SetVertices(_meshInfo.Vertices);
65+
// workerMesh.SetUVs(0,_meshInfo.UVs);
66+
// workerMesh.SetColors(_meshInfo.Colors);
67+
// workerMesh.triangles = _meshInfo.Triangles.ToArray();
6568

66-
// SetMaterialDirty();
67-
SetAllDirty();
69+
// canvasRenderer.SetMesh(workerMesh);
70+
71+
//// SetMaterialDirty();
72+
SetAllDirty();
6873
// UpdateMaterial();
6974
}
7075
}
@@ -92,8 +97,9 @@ public override Material material
9297
_defaultMater = new Material(Shader.Find(_defaultShader));
9398
_defaultMater.SetFloat("_CellAmount", _cellAmount);
9499
_defaultMater.SetFloat("_Speed", _speed);
95-
_defaultMater.SetTexture("_MainTex", mainTexture);
96-
// _defaultMater.EnableKeyword("EMOJI_ANIMATION");
100+
//_defaultMater.SetTexture("_MainTex", mainTexture);
101+
// _defaultMater.EnableKeyword("EMOJI_ANIMATION");
102+
_defaultMater.DisableKeyword("EMOJI_ANIMATION");
97103
}
98104
return _defaultMater;
99105
}
@@ -110,43 +116,58 @@ protected override void OnEnable()
110116

111117
protected override void OnPopulateMesh(VertexHelper vh)
112118
{
113-
// base.OnPopulateMesh(vh);
114-
115-
//if (_inlineManager == null|| m_spriteAsset==null|| !_inlineManager.GetMeshInfo.ContainsKey(m_spriteAsset.Id))
116-
// return;
117-
118-
//SpriteTagInfo meshInfo = _inlineManager.GetMeshInfo[m_spriteAsset.Id];
119-
//if (meshInfo == null || meshInfo.Pos == null || meshInfo.Pos.Length == 0)
120-
//{
121-
// vh.Clear();
122-
// //base.OnPopulateMesh(vh);
123-
//}
124-
//else
125-
//{
126-
// vh.Clear();
127-
// for (int i = 0; i < meshInfo.Pos.Length; i++)
128-
// {
129-
// int tempVertsIndex = i & 3;
130-
// _tempVerts[tempVertsIndex].position = meshInfo.Pos[i];
131-
// _tempVerts[tempVertsIndex].uv0 = meshInfo.Uv[i];
132-
// _tempVerts[tempVertsIndex].color = color;
133-
// if (tempVertsIndex == 3)
134-
// vh.AddUIVertexQuad(_tempVerts);
135-
136-
// // //--------------------------------------------------------------------------------------
137-
// // //看到unity 的mesh支持多层uv 还在想shader渲染动图有思路了呢
138-
// // //结果调试shader的时候发现uv1-uv3的值跟uv0一样
139-
// // //意思就是 unity canvasrender 目前的设计,为了优化性能,不支持uv1-3,并不是bug,所以没法存多套uv。。。
140-
// // //https://issuetracker.unity3d.com/issues/canvasrenderer-dot-setmesh-does-not-seem-to-support-more-than-one-uv-set
141-
// // //不知道后面会不会更新 ------ 于是现在还是用老办法吧, 规则图集 --> uv移动
142-
// // //--------------------------------------------------------------------------------------
143-
144-
// // //h.uv2 = spriteInfors[1].Uv;
145-
// // //h.uv3 = spriteInfors[2].Uv;
146-
// // //h.uv4 = spriteInfors[3].Uv;
147-
// }
148-
//}
149-
}
119+
if (_meshInfo != null)
120+
{
121+
vh.Clear();
122+
for (int i = 0; i < _meshInfo.Vertices.Count; i++)
123+
{
124+
int tempVertsIndex = i & 3;
125+
_tempVerts[tempVertsIndex].position = _meshInfo.Vertices[i];
126+
_tempVerts[tempVertsIndex].uv0 = _meshInfo.UVs[i];
127+
_tempVerts[tempVertsIndex].color = color;
128+
if (tempVertsIndex == 3)
129+
vh.AddUIVertexQuad(_tempVerts);
130+
}
131+
}
132+
133+
134+
// base.OnPopulateMesh(vh);
135+
136+
//if (_inlineManager == null|| m_spriteAsset==null|| !_inlineManager.GetMeshInfo.ContainsKey(m_spriteAsset.Id))
137+
// return;
138+
139+
//SpriteTagInfo meshInfo = _inlineManager.GetMeshInfo[m_spriteAsset.Id];
140+
//if (meshInfo == null || meshInfo.Pos == null || meshInfo.Pos.Length == 0)
141+
//{
142+
// vh.Clear();
143+
// //base.OnPopulateMesh(vh);
144+
//}
145+
//else
146+
//{
147+
// vh.Clear();
148+
// for (int i = 0; i < meshInfo.Pos.Length; i++)
149+
// {
150+
// int tempVertsIndex = i & 3;
151+
// _tempVerts[tempVertsIndex].position = meshInfo.Pos[i];
152+
// _tempVerts[tempVertsIndex].uv0 = meshInfo.Uv[i];
153+
// _tempVerts[tempVertsIndex].color = color;
154+
// if (tempVertsIndex == 3)
155+
// vh.AddUIVertexQuad(_tempVerts);
156+
157+
// // //--------------------------------------------------------------------------------------
158+
// // //看到unity 的mesh支持多层uv 还在想shader渲染动图有思路了呢
159+
// // //结果调试shader的时候发现uv1-uv3的值跟uv0一样
160+
// // //意思就是 unity canvasrender 目前的设计,为了优化性能,不支持uv1-3,并不是bug,所以没法存多套uv。。。
161+
// // //https://issuetracker.unity3d.com/issues/canvasrenderer-dot-setmesh-does-not-seem-to-support-more-than-one-uv-set
162+
// // //不知道后面会不会更新 ------ 于是现在还是用老办法吧, 规则图集 --> uv移动
163+
// // //--------------------------------------------------------------------------------------
164+
165+
// // //h.uv2 = spriteInfors[1].Uv;
166+
// // //h.uv3 = spriteInfors[2].Uv;
167+
// // //h.uv4 = spriteInfors[3].Uv;
168+
// }
169+
//}
170+
}
150171

151172

152173
}

Assets/TextInlineSprite/Examples/Scene/Text 1.unity

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,13 +636,13 @@ MonoBehaviour:
636636
m_HorizontalOverflow: 0
637637
m_VerticalOverflow: 0
638638
m_LineSpacing: 1
639-
m_Text: 00000[#emoji_0]0000
639+
m_Text: 00000[#emoji_0]000
640640
OnHrefClick:
641641
m_PersistentCalls:
642642
m_Calls: []
643643
m_TypeName: InlineText+HrefClickEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
644644
PublicKeyToken=null
645-
_text: 00000[#emoji_0]0000
645+
_text: 00000[#emoji_0]000
646646
--- !u!222 &1707421984
647647
CanvasRenderer:
648648
m_ObjectHideFlags: 0

Assets/TextInlineSprite/Scripts/InlineManager.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ private void Update()
8888
if (spriteGraphic02 != null)
8989
{
9090
spriteGraphic02.MeshInfo = _graphicMeshInfo[id];
91-
//清理掉渲染的数据
92-
_graphicMeshInfo[id].Clear();
9391
}
9492
}
9593
//清掉渲染索引
@@ -106,12 +104,16 @@ public void UpdateTextInfo(int id,InlineText key, SpriteTagInfo value)
106104
_graphicMeshInfo[id] = meshInfo;
107105
}
108106

109-
meshInfo.Vertices.AddRange(value.Pos);
110-
meshInfo.UVs.AddRange(value.UVs);
111-
112107
//添加到渲染列表里面 -- 等待下一帧渲染
113108
if (!_renderIndexs.Contains(id))
109+
{
114110
_renderIndexs.Add(id);
111+
meshInfo.Clear();
112+
}
113+
114+
meshInfo.Vertices.AddRange(value.Pos);
115+
meshInfo.UVs.AddRange(value.UVs);
116+
115117
}
116118

117119

@@ -133,7 +135,7 @@ public class MeshInfo
133135
public List<Vector2> UVs = ListPool<Vector2>.Get();
134136
public List<Color> Colors = ListPool<Color>.Get();
135137
public List<int> Triangles = ListPool<int>.Get();
136-
138+
137139
public void Clear()
138140
{
139141
Vertices.Clear();

Assets/TextInlineSprite/Scripts/InlineText.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using UnityEngine.Events;
99
using System;
1010

11+
[ExecuteInEditMode]
1112
public class InlineText : Text, IPointerClickHandler
1213
{
1314
#region 属性

0 commit comments

Comments
 (0)