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

Commit 3cf2f2b

Browse files
committed
重新进行了坐标系的转换
1 parent 4a53e0d commit 3cf2f2b

File tree

5 files changed

+67
-74
lines changed

5 files changed

+67
-74
lines changed

Assets/Hidden/SpriteGraphic02.cs

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,52 +25,9 @@ public MeshInfo MeshInfo
2525
get { return _meshInfo; }
2626
set
2727
{
28-
//if (_meshInfo == null)
29-
//{
30-
// _meshInfo = new MeshInfo();
31-
//}
32-
33-
//if (_spriteTagInfo.Equals(value))
34-
// return;
35-
36-
// workerMesh.Clear();
37-
3828
_meshInfo = value;
3929

40-
// int length = _meshInfo.Vertices.Count;
41-
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];
46-
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);
57-
58-
// _meshInfo.Triangles.Add(2 + 4 * num);
59-
// _meshInfo.Triangles.Add(3 + 4 * num);
60-
// _meshInfo.Triangles.Add(0 + 4 * num);
61-
// }
62-
// }
63-
64-
// workerMesh.SetVertices(_meshInfo.Vertices);
65-
// workerMesh.SetUVs(0,_meshInfo.UVs);
66-
// workerMesh.SetColors(_meshInfo.Colors);
67-
// workerMesh.triangles = _meshInfo.Triangles.ToArray();
68-
69-
// canvasRenderer.SetMesh(workerMesh);
70-
71-
//// SetMaterialDirty();
7230
SetAllDirty();
73-
// UpdateMaterial();
7431
}
7532
}
7633

@@ -122,7 +79,7 @@ protected override void OnPopulateMesh(VertexHelper vh)
12279
for (int i = 0; i < _meshInfo.Vertices.Count; i++)
12380
{
12481
int tempVertsIndex = i & 3;
125-
_tempVerts[tempVertsIndex].position = _meshInfo.Vertices[i];
82+
_tempVerts[tempVertsIndex].position = Utility.Transform2World2Point(transform,_meshInfo.Vertices[i]);
12683
_tempVerts[tempVertsIndex].uv0 = _meshInfo.UVs[i];
12784
_tempVerts[tempVertsIndex].color = color;
12885
if (tempVertsIndex == 3)

Assets/Hidden/Utility.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
public class Utility {
6+
7+
/// <summary>
8+
/// 获取Transform的世界坐标
9+
/// </summary>
10+
/// <param name="rectTransform"></param>
11+
/// <param name="canvas"></param>
12+
/// <returns></returns>
13+
public static Vector3 TransformPoint2World(Transform transform, Vector3 point)
14+
{
15+
return transform.localToWorldMatrix.MultiplyPoint(point);
16+
}
17+
18+
/// <summary>
19+
/// 获取Transform的本地坐标
20+
/// </summary>
21+
/// <param name="transform"></param>
22+
/// <param name="point"></param>
23+
/// <returns></returns>
24+
public static Vector3 Transform2World2Point(Transform transform, Vector3 point)
25+
{
26+
return transform.worldToLocalMatrix.MultiplyPoint(point);
27+
}
28+
29+
30+
}

Assets/Hidden/Utility.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ Canvas:
192192
m_Enabled: 1
193193
serializedVersion: 3
194194
m_RenderMode: 0
195-
m_Camera: {fileID: 0}
195+
m_Camera: {fileID: 1807511896}
196196
m_PlaneDistance: 100
197197
m_PixelPerfect: 0
198198
m_ReceivesEvents: 1
@@ -498,9 +498,9 @@ RectTransform:
498498
m_Father: {fileID: 1742962090}
499499
m_RootOrder: 0
500500
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
501-
m_AnchorMin: {x: 0.5, y: 0.5}
502-
m_AnchorMax: {x: 0.5, y: 0.5}
503-
m_AnchoredPosition: {x: 0, y: 0}
501+
m_AnchorMin: {x: 0, y: 1}
502+
m_AnchorMax: {x: 0, y: 1}
503+
m_AnchoredPosition: {x: 574, y: -251}
504504
m_SizeDelta: {x: 334.35, y: 207.6}
505505
m_Pivot: {x: 0.5, y: 0.5}
506506
--- !u!114 &1546337849
@@ -716,8 +716,8 @@ Camera:
716716
m_GameObject: {fileID: 1807511892}
717717
m_Enabled: 1
718718
serializedVersion: 2
719-
m_ClearFlags: 1
720-
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
719+
m_ClearFlags: 2
720+
m_BackGroundColor: {r: 0.09839966, g: 0.16021481, b: 0.25735295, a: 0}
721721
m_NormalizedViewPortRect:
722722
serializedVersion: 2
723723
x: 0

Assets/TextInlineSprite/Scripts/InlineText.cs

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class InlineText : Text, IPointerClickHandler
2727

2828
private StringBuilder _textBuilder = new StringBuilder();
2929

30-
30+
UIVertex _tempVertex = UIVertex.simpleVert;
3131
#region 超链接
3232
[System.Serializable]
3333
public class HrefClickEvent : UnityEvent<string,int> { }
@@ -84,7 +84,7 @@ protected override void OnEnable()
8484
supportRichText = true;
8585
alignByGeometry = true;
8686
_inlineManager = GetComponentInParent<InlineManager>();
87-
}
87+
}
8888

8989

9090
//protected override void Start()
@@ -95,7 +95,7 @@ protected override void OnEnable()
9595
#if UNITY_EDITOR
9696
protected override void OnValidate()
9797
{
98-
// ActiveText();
98+
// ActiveText();
9999
}
100100
#endif
101101

@@ -124,13 +124,12 @@ protected override void OnPopulateMesh(VertexHelper toFill)
124124
{
125125
for (int j = index; j < index + 4; j++)
126126
{
127-
UIVertex vertex = UIVertex.simpleVert;
128-
toFill.PopulateUIVertex(ref vertex, j);
127+
toFill.PopulateUIVertex(ref _tempVertex, j);
129128
//清理多余的乱码uv
130-
vertex.uv0 = Vector2.zero;
131-
//获取quad的位置
132-
_spriteInfo[i].Pos[j - index] = vertex.position;
133-
toFill.SetUIVertex(vertex, j);
129+
_tempVertex.uv0 = Vector2.zero;
130+
//获取quad的位置 --> 转为世界坐标
131+
_spriteInfo[i].Pos[j - index] =Utility.TransformPoint2World(transform,_tempVertex.position);
132+
toFill.SetUIVertex(_tempVertex, j);
134133
}
135134

136135
}
@@ -361,21 +360,17 @@ private void ReleaseSpriteTageInfo()
361360

362361
private void OnDrawGizmos()
363362
{
364-
Gizmos.color = Color.yellow;
365-
366-
//for (int i = 0; i < _spriteInfo.Count; i++)
367-
//{
368-
// Vector2 point00= RectTransformUtility.PixelAdjustPoint(_spriteInfo[i].Pos[0], transform, canvas);
369-
// Vector2 point01 = RectTransformUtility.PixelAdjustPoint(_spriteInfo[i].Pos[1], transform, canvas);
370-
// Vector2 point02 = RectTransformUtility.PixelAdjustPoint(_spriteInfo[i].Pos[2], transform, canvas);
371-
// Vector2 point03 = RectTransformUtility.PixelAdjustPoint(_spriteInfo[i].Pos[3], transform, canvas);
372-
373-
// Gizmos.DrawLine(point00, point01);
374-
// Gizmos.DrawLine(point01, point02);
375-
// Gizmos.DrawLine(point02, point03);
376-
// Gizmos.DrawLine(point00, point03);
377-
378-
//}
363+
Gizmos.color = Color.red;
364+
365+
Vector3 vec= transform.localToWorldMatrix.MultiplyPoint(Vector3.zero);
366+
Gizmos.DrawCube(vec, Vector3.one);
367+
for (int i = 0; i < _spriteInfo.Count; i++)
368+
{
369+
Gizmos.DrawLine(_spriteInfo[i].Pos[0], _spriteInfo[i].Pos[1]);
370+
Gizmos.DrawLine(_spriteInfo[i].Pos[1], _spriteInfo[i].Pos[2]);
371+
Gizmos.DrawLine(_spriteInfo[i].Pos[3], _spriteInfo[i].Pos[2]);
372+
Gizmos.DrawLine(_spriteInfo[i].Pos[0], _spriteInfo[i].Pos[3]);
373+
}
379374
}
380375
}
381376

0 commit comments

Comments
 (0)