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

Commit 37ae7ff

Browse files
committed
修复精灵重复渲染的bug
1 parent 24a6df9 commit 37ae7ff

File tree

2 files changed

+32
-44
lines changed

2 files changed

+32
-44
lines changed

Assets/TextInlineSprite/Scripts/InlineManager.cs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,7 @@ public class InlineManager : MonoBehaviour {
2020
private readonly Dictionary<int, SpriteGraphicInfo> _indexSpriteGraphic = new Dictionary<int, SpriteGraphicInfo>();
2121
//绘制的模型数据索引
2222
private Dictionary<int, Dictionary<InlineText, MeshInfo>> _textMeshInfo = new Dictionary<int, Dictionary<InlineText, MeshInfo>>();
23-
//静态表情
24-
[SerializeField]
25-
private bool _isStatic = true;
26-
//动画速度
27-
[SerializeField]
28-
[Range(1, 10)]
29-
private float _animationSpeed = 5.0f;
30-
//动画时间
31-
float _animationTime = 0.0f;
32-
//动画索引
33-
int _animationIndex = 0;
34-
23+
3524
//图集
3625
[SerializeField]
3726
private List<SpriteGraphic02> _spriteGraphics = new List<SpriteGraphic02>();
@@ -118,7 +107,7 @@ private void Update()
118107
}
119108
}
120109

121-
public void UpdateTextInfo(InlineText key, int id, SpriteTagInfo value)
110+
public void UpdateTextInfo(InlineText key, int id, List<SpriteTagInfo> value)
122111
{
123112
Dictionary<InlineText, MeshInfo> textMeshInfo;
124113
if (value == null)
@@ -143,12 +132,12 @@ public void UpdateTextInfo(InlineText key, int id, SpriteTagInfo value)
143132
meshInfo = Pool<MeshInfo>.Get();
144133
textMeshInfo.Add(key, meshInfo);
145134
}
146-
//else
147-
// meshInfo.Clear();
148-
149-
meshInfo.Vertices.AddRange(value.Pos);
150-
meshInfo.UVs.AddRange(value.UVs);
151-
135+
meshInfo.Clear();
136+
for (int i = 0; i < value.Count; i++)
137+
{
138+
meshInfo.Vertices.AddRange(value[i].Pos);
139+
meshInfo.UVs.AddRange(value[i].UVs);
140+
}
152141
}
153142

154143
//添加到渲染列表里面 -- 等待下一帧渲染

Assets/TextInlineSprite/Scripts/InlineText.cs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@ public class InlineText : Text, IPointerClickHandler
1616
private static readonly Regex _inputTagRegex = new Regex(@"\[(\-{0,1}\d{0,})#(.+?)\]", RegexOptions.Singleline);
1717
//文本表情管理器
1818
private InlineManager _inlineManager;
19-
//更新后的文本
20-
private string _outputText = "";
19+
2120
//表情位置索引信息
2221
private List<SpriteTagInfo> _spriteInfo = new List<SpriteTagInfo>();
23-
//保留之前的图集ID,相关信息
24-
private Dictionary<int, List<SpriteTagInfo>> _oldDrawSpriteInfo = new Dictionary<int, List<SpriteTagInfo>>();
2522
//计算定点信息的缓存数组
2623
private readonly UIVertex[] m_TempVerts = new UIVertex[4];
2724

@@ -137,29 +134,29 @@ protected override void OnPopulateMesh(VertexHelper toFill)
137134
}
138135

139136
#region 文本所占的长宽
140-
public override float preferredWidth
141-
{
142-
get
143-
{
144-
var settings = GetGenerationSettings(Vector2.zero);
145-
return cachedTextGeneratorForLayout.GetPreferredWidth(_outputText, settings) / pixelsPerUnit;
146-
}
147-
}
148-
public override float preferredHeight
149-
{
150-
get
151-
{
152-
var settings = GetGenerationSettings(new Vector2(rectTransform.rect.size.x, 0.0f));
153-
return cachedTextGeneratorForLayout.GetPreferredHeight(_outputText, settings) / pixelsPerUnit;
154-
}
155-
}
156-
#endregion
137+
//public override float preferredWidth
138+
//{
139+
// get
140+
// {
141+
// var settings = GetGenerationSettings(Vector2.zero);
142+
// return cachedTextGeneratorForLayout.GetPreferredWidth(_outputText, settings) / pixelsPerUnit;
143+
// }
144+
//}
145+
//public override float preferredHeight
146+
//{
147+
// get
148+
// {
149+
// var settings = GetGenerationSettings(new Vector2(rectTransform.rect.size.x, 0.0f));
150+
// return cachedTextGeneratorForLayout.GetPreferredHeight(_outputText, settings) / pixelsPerUnit;
151+
// }
152+
//}
153+
#endregion
157154

158-
#region 绘制表情
155+
#region 绘制表情
159156
void UpdateDrawnSprite()
160157
{
161158
//记录之前的信息
162-
if (_spriteInfo == null || _spriteInfo.Count == 0&& _lastRenderIndexs.Count>0)
159+
if ((_spriteInfo == null || _spriteInfo.Count == 0)&& _lastRenderIndexs.Count>0)
163160
{
164161
for (int i = 0; i < _lastRenderIndexs.Count; i++)
165162
{
@@ -172,10 +169,12 @@ void UpdateDrawnSprite()
172169
_lastRenderIndexs.Clear();
173170
for (int i = 0; i < _spriteInfo.Count; i++)
174171
{
175-
_inlineManager.UpdateTextInfo(this, _spriteInfo[i].Id, _spriteInfo[i]);
176172
//添加渲染id索引
177-
if(_lastRenderIndexs.Contains(_spriteInfo[i].Id))
173+
if (!_lastRenderIndexs.Contains(_spriteInfo[i].Id))
174+
{
175+
_inlineManager.UpdateTextInfo(this, _spriteInfo[i].Id,_spriteInfo.FindAll(x=>x.Id== _spriteInfo[i].Id));
178176
_lastRenderIndexs.Add(_spriteInfo[i].Id);
177+
}
179178
}
180179
}
181180
}

0 commit comments

Comments
 (0)