Line.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. namespace LineUI
  5. {
  6. // 定义 ArrowInfo 类
  7. public class ArrowInfo
  8. {
  9. public Vector2 Position { get; set; }
  10. public Vector2 Direction { get; set; }
  11. public ArrowInfo(Vector2 position, Vector2 direction)
  12. {
  13. Position = position;
  14. Direction = direction;
  15. }
  16. }
  17. [RequireComponent(typeof(CanvasRenderer))]
  18. [RequireComponent(typeof(RectTransform))]
  19. public class Line : Graphic
  20. {
  21. [Header("绘制线段")]
  22. [SerializeField] private bool loop = false;
  23. [SerializeField] private float thickness = 1f;
  24. [SerializeField] private int roundCount = 0;
  25. [SerializeField] private List<Vector2> screenPositions = new List<Vector2>();
  26. //获取当前的points
  27. [HideInInspector]
  28. public List<Vector2> ScreenPositions => screenPositions;
  29. [Header("绘制内四边形")]
  30. //是否绘制内四边形
  31. [SerializeField] bool bDrawQuad = true;
  32. [SerializeField] private Vector2 quadrilateralSize = new Vector2(100, 100);
  33. [SerializeField] private Color quadColor = Color.red;
  34. [Header("绘制外围蒙板")]
  35. //是否绘制外围蒙板
  36. [SerializeField] bool bDrawMask = false;
  37. [SerializeField] private Color maskColor = Color.red;
  38. //控制扇形角绘制
  39. [Header("扇形角绘制")]
  40. [SerializeField] private bool bDrawFan = false;
  41. [SerializeField] private Color fanColor = Color.white;
  42. [SerializeField] private int fanSegments = 20; // 扇形的平滑度
  43. [SerializeField] private float fanOuterRadius = 150f; // 扇形的半径
  44. private float fanInnerRadius = 0f;
  45. [Tooltip("扇形指向箭头")]
  46. [SerializeField] private bool bDrawArrow = false;
  47. [SerializeField] private Color arrowColor = Color.white;
  48. [SerializeField] float arrowLength = 50f;
  49. [SerializeField] float arrowWidth = 50f;
  50. [SerializeField] float arrowHeadHeight = 30f;
  51. [SerializeField] float arrowDis = 100f;
  52. private List<ArrowInfo> arrowInfos = new List<ArrowInfo>();
  53. //获取当前的points
  54. [HideInInspector]
  55. public List<ArrowInfo> ArrowInfos => arrowInfos;
  56. //[SerializeField] private Color quadTextColor = Color.black;
  57. //[SerializeField] private int quadFontSize = 14;
  58. //private List<Vector2> quadsToDraw = new List<Vector2>();
  59. //private List<string> quadTextToDraw = new List<string>();
  60. //private List<GameObject> quadObjects = new List<GameObject>();
  61. //private Stack<GameObject> objectPool = new Stack<GameObject>();
  62. [Tooltip("抗锯齿处理部分")]
  63. [SerializeField, Range(0f, 5f)]
  64. private float antiAliasValue = 2f; // 抗锯齿羽化宽度
  65. private const int ObjectPoolLimit = 4;
  66. public RectTransform RectTr => rectTransform;
  67. public float MyThickness
  68. {
  69. get => thickness;
  70. set
  71. {
  72. if (value >= 1)
  73. {
  74. thickness = value;
  75. }
  76. }
  77. }
  78. public float MyFanWidth
  79. {
  80. get => fanOuterRadius;
  81. set
  82. {
  83. if (value >= 1)
  84. {
  85. fanOuterRadius = value;
  86. }
  87. }
  88. }
  89. public void SetLine(List<Vector2> screenPositions)
  90. {
  91. this.screenPositions = screenPositions;
  92. SetVerticesDirty();
  93. }
  94. public void SetDrawQuad(bool value) {
  95. bDrawQuad = value;
  96. SetVerticesDirty();
  97. }
  98. public void SetDrawMask(bool value)
  99. {
  100. bDrawMask = value;
  101. SetVerticesDirty();
  102. }
  103. public void SetDrawFan(bool value)
  104. {
  105. bDrawFan = value;
  106. SetVerticesDirty();
  107. }
  108. protected override void OnPopulateMesh(VertexHelper vh)
  109. {
  110. vh.Clear();
  111. arrowInfos.Clear();
  112. //quadsToDraw.Clear();
  113. //quadTextToDraw.Clear();
  114. if (screenPositions.Count < 2)
  115. return;
  116. SetLineVertices(vh);
  117. SetLineTriangles(vh);
  118. if(bDrawQuad) SetQuadrilateralVertices(vh);
  119. if(bDrawMask) DrawMask(vh); // 绘制蒙版
  120. if (bDrawFan) DrawFansAtCorners(vh); // 在转折角绘制扇形
  121. }
  122. private void SetLineVertices(VertexHelper vh)
  123. {
  124. UIVertex vert = UIVertex.simpleVert;
  125. vert.color = color;
  126. List<Vector2> _screenPositions = new List<Vector2>(screenPositions);
  127. if (loop)
  128. {
  129. _screenPositions.Add(screenPositions[0]);
  130. _screenPositions.Add(screenPositions[1]);
  131. }
  132. float lastAngle = 0;
  133. for (int i = 1; i < _screenPositions.Count; i++)
  134. {
  135. Vector2 previousPos = _screenPositions[i - 1];
  136. Vector2 currentPos = _screenPositions[i];
  137. Vector2 dif = currentPos - previousPos;
  138. float angle = Vector2.SignedAngle(Vector2.right, dif);
  139. Vector2 offset = Quaternion.Euler(0, 0, angle) * Vector3.up * thickness;
  140. if (i > 1)
  141. {
  142. float anglePerRound = (angle - lastAngle) / roundCount;
  143. for (int j = 0; j <= roundCount; j++)
  144. {
  145. float ang = lastAngle + anglePerRound * j;
  146. Vector2 roundOffset = Quaternion.Euler(0, 0, ang) * Vector2.up * thickness;
  147. vert.position = previousPos - roundOffset;
  148. vh.AddVert(vert);
  149. vert.position = previousPos + roundOffset;
  150. vh.AddVert(vert);
  151. }
  152. }
  153. lastAngle = angle;
  154. vert.position = previousPos - offset;
  155. vh.AddVert(vert);
  156. vert.position = previousPos + offset;
  157. vh.AddVert(vert);
  158. vert.position = currentPos - offset;
  159. vh.AddVert(vert);
  160. vert.position = currentPos + offset;
  161. vh.AddVert(vert);
  162. // 🔹 在每段线条两侧增加抗锯齿羽化
  163. if (antiAliasValue > 0.01f)
  164. {
  165. AddAntiAliasForLine(vh, previousPos, currentPos, offset, antiAliasValue);
  166. }
  167. }
  168. }
  169. private void SetQuadrilateralVertices(VertexHelper vh)
  170. {
  171. UIVertex vert = UIVertex.simpleVert;
  172. vert.color = quadColor;
  173. List<Vector2> _screenPositions = new List<Vector2>(screenPositions);
  174. if (loop)
  175. {
  176. _screenPositions.Add(screenPositions[0]);
  177. _screenPositions.Add(screenPositions[1]);
  178. }
  179. for (int i = 1; i < _screenPositions.Count; i++)
  180. {
  181. Vector2 previousPos = _screenPositions[i - 1];
  182. Vector2 currentPos = _screenPositions[i];
  183. if (i > 1)
  184. {
  185. Vector2 prevDir = (_screenPositions[i - 1] - _screenPositions[i - 2]).normalized;
  186. Vector2 currentDir = (currentPos - previousPos).normalized;
  187. int index = i == 4 ? 4 : i % 4;
  188. if (index == 4 || index == 2)
  189. {
  190. DrawSquareAtCorner(vh, previousPos, prevDir, currentDir, quadrilateralSize.x, quadrilateralSize.y, index);
  191. }
  192. else {
  193. DrawSquareAtCorner(vh, previousPos, prevDir, currentDir, quadrilateralSize.y, quadrilateralSize.x, index);
  194. }
  195. }
  196. }
  197. }
  198. private void DrawSquareAtCorner(VertexHelper vh, Vector2 corner, Vector2 prevDir, Vector2 currentDir, float width, float height, int index)
  199. {
  200. UIVertex vert = UIVertex.simpleVert;
  201. vert.color = quadColor;
  202. Vector2[] corners = new Vector2[4];
  203. corners[0] = corner;
  204. corners[1] = corner + prevDir * -width;
  205. corners[2] = corner + prevDir * -width + currentDir * height;
  206. corners[3] = corner + currentDir * height;
  207. foreach (Vector2 pos in corners)
  208. {
  209. vert.position = pos;
  210. vh.AddVert(vert);
  211. }
  212. int startIndex = vh.currentVertCount - 4;
  213. vh.AddTriangle(startIndex, startIndex + 1, startIndex + 2);
  214. vh.AddTriangle(startIndex + 2, startIndex + 3, startIndex);
  215. // Store the quad's center position and text for later use
  216. //Vector2 quadCenter = corner + (prevDir * -width + currentDir * height) / 2;
  217. //quadsToDraw.Add(quadCenter);
  218. //quadTextToDraw.Add(index.ToString());
  219. }
  220. private void SetLineTriangles(VertexHelper vh)
  221. {
  222. for (int i = 0; i < vh.currentVertCount - 2; i += 2)
  223. {
  224. int index = i;
  225. vh.AddTriangle(index, index + 1, index + 3);
  226. vh.AddTriangle(index + 3, index + 2, index);
  227. }
  228. }
  229. private void DrawMask(VertexHelper vh)
  230. {
  231. UIVertex vert = UIVertex.simpleVert;
  232. vert.color = maskColor;
  233. //// 屏幕四个角的坐标
  234. //Vector2[] screenCorners = new Vector2[]
  235. //{
  236. // new Vector2(-Screen.width / 2, -Screen.height / 2), // 左下角
  237. // new Vector2(Screen.width / 2, -Screen.height / 2), // 右下角
  238. // new Vector2(Screen.width / 2, Screen.height / 2), // 右上角
  239. // new Vector2(-Screen.width / 2, Screen.height / 2), // 左上角
  240. //};
  241. // 获取 RectTransform 的实际四个角坐标
  242. Rect rect = rectTransform.rect;
  243. Vector2[] screenCorners = new Vector2[]
  244. {
  245. new Vector2(rect.xMin, rect.yMin), // 左下角
  246. new Vector2(rect.xMax, rect.yMin), // 右下角
  247. new Vector2(rect.xMax, rect.yMax), // 右上角
  248. new Vector2(rect.xMin, rect.yMax), // 左上角
  249. };
  250. // 添加四个点作为内框(中间区域的四个顶点)
  251. Vector2[] innerCorners = screenPositions.ToArray();
  252. // 分别绘制四个蒙版区域
  253. // 1. 左上区域:围绕左上角和内框左上、右上
  254. AddQuad(vh, screenCorners[3], innerCorners[3], innerCorners[2], screenCorners[2]);
  255. // 2. 右上区域:围绕右上角和内框右上、右下
  256. AddQuad(vh, innerCorners[2], screenCorners[2], screenCorners[1], innerCorners[1]);
  257. // 3. 右下区域:围绕右下角和内框右下、左下
  258. AddQuad(vh, innerCorners[0], innerCorners[1], screenCorners[1], screenCorners[0]);
  259. // 4. 左下区域:围绕左下角和内框左下、左上
  260. AddQuad(vh, screenCorners[3], screenCorners[0], innerCorners[0], innerCorners[3]);
  261. }
  262. private void AddQuad(VertexHelper vh, Vector2 corner1, Vector2 corner2, Vector2 corner3, Vector2 corner4)
  263. {
  264. UIVertex vert = UIVertex.simpleVert;
  265. vert.color = maskColor;
  266. vert.position = corner1;
  267. vh.AddVert(vert);
  268. vert.position = corner2;
  269. vh.AddVert(vert);
  270. vert.position = corner3;
  271. vh.AddVert(vert);
  272. vert.position = corner4;
  273. vh.AddVert(vert);
  274. //Debug.Log("vh.currentVertCount:"+ vh.currentVertCount);
  275. int startIndex = vh.currentVertCount - 4;
  276. vh.AddTriangle(startIndex, startIndex + 1, startIndex + 2);
  277. vh.AddTriangle(startIndex + 2, startIndex + 3, startIndex);
  278. }
  279. /// <summary>
  280. /// 1. 计算角度方向:
  281. /// 使用 Vector2.Angle 可以得到两个向量之间的夹角大小,但它不能确定角度的方向。为此,我们需要使用 Mathf.Atan2 来计算相对坐标的角度。Atan2 可以返回一个在 -π 到 π 之间的角度值,并且考虑了顺时针和逆时针的方向。
  282. /// 2. 从 X 轴正方向为 0 计算角度:
  283. /// 将角度计算为相对于 x 轴正方向的角度,并根据 Atan2 结果进行调整。
  284. /// </summary>
  285. /// <param name="vh"></param>
  286. private void DrawFansAtCorners(VertexHelper vh)
  287. {
  288. List<Vector2> _screenPositions = new List<Vector2>(screenPositions);
  289. if (loop)
  290. {
  291. _screenPositions.Add(screenPositions[0]);
  292. _screenPositions.Add(screenPositions[1]);
  293. }
  294. //比如现在是6个点,实际从第二个点开始绘制
  295. for (int i = 1; i < _screenPositions.Count - 1; i++)
  296. {
  297. Vector2 previousPos = _screenPositions[i - 1];
  298. Vector2 currentPos = _screenPositions[i];
  299. Vector2 nextPos = _screenPositions[i + 1];
  300. // 计算当前点到前一点的方向
  301. Vector2 prevDir = (currentPos - previousPos).normalized;
  302. // 计算当前点到下一点的方向
  303. Vector2 currentDir = (nextPos - currentPos).normalized;
  304. // 使用 Atan2 计算方向相对于 x 轴的角度
  305. float prevAngle = Mathf.Atan2(prevDir.y, prevDir.x) * Mathf.Rad2Deg; // 前一个方向相对于 x 轴的角度
  306. float currentAngle = Mathf.Atan2(currentDir.y, currentDir.x) * Mathf.Rad2Deg; // 当前方向相对于 x 轴的角度
  307. // 计算两个方向之间的角度差
  308. float angleBetween = Vector2.Angle(prevDir, currentDir);
  309. // 判断旋转方向
  310. float cross = prevDir.x * currentDir.y - prevDir.y * currentDir.x;
  311. if (cross < 0)
  312. {
  313. // 逆时针旋转
  314. angleBetween = 360f - angleBetween;
  315. }
  316. // 内角的计算(补充180度)
  317. float innerAngle = 180f - angleBetween;
  318. // 计算开始角度,这里用的是 x 轴为起始点来计算
  319. float startAngle = currentAngle;
  320. //Debug.Log($"Index {i}: startAngle = {startAngle}, innerAngle = {innerAngle}");
  321. // 根据当前角的位置调整内角和起始角
  322. DrawFanAtCorner(vh, currentPos, startAngle, innerAngle, fanInnerRadius, fanOuterRadius, fanSegments, fanColor);
  323. // 计算箭头的中心角度,确保角度在 0-360° 范围内
  324. float centerAngle = (startAngle + innerAngle / 2) % 360f;
  325. float radians = Mathf.Deg2Rad * centerAngle;
  326. // 计算箭头位置:在扇形外半径的基础上延长一定距离(箭头偏移量)
  327. float arrowOffset = fanOuterRadius + arrowDis;
  328. Vector2 arrowPosition = currentPos + new Vector2(Mathf.Cos(radians), Mathf.Sin(radians)) * arrowOffset;
  329. // 箭头方向
  330. Vector2 arrowDirection = new Vector2(Mathf.Cos(radians), Mathf.Sin(radians)).normalized;
  331. // 将箭头信息保存到列表中
  332. arrowInfos.Add(new ArrowInfo(arrowPosition, arrowDirection));
  333. // 在所有扇形处绘制箭头
  334. // 在扇形中心绘制箭头
  335. if (bDrawArrow)
  336. {
  337. // 调试信息
  338. //Debug.Log($"Index {i}: arrowPosition = {arrowPosition}, startAngle = {startAngle}, centerAngle = {centerAngle}, direction = {arrowDirection}");
  339. // 绘制箭头
  340. DrawArrow(vh, arrowPosition, arrowDirection, arrowLength, arrowWidth, arrowHeadHeight);
  341. }
  342. }
  343. }
  344. private void DrawFanAtCorner(VertexHelper vh, Vector2 center, float startAngle, float angleDegree, float innerRadius, float outerRadius, int segments ,Color color)
  345. {
  346. UIVertex vert = UIVertex.simpleVert;
  347. vert.color = color;
  348. float angleRad = Mathf.Deg2Rad * angleDegree; // 将绘制角度转换为弧度
  349. float startAngleRad = Mathf.Deg2Rad * startAngle; // 将起始角度转换为弧度
  350. float angleStep = angleRad / segments; // 每个扇形段的角度步长
  351. int initialVertCount = vh.currentVertCount; // 记录当前顶点数量
  352. // 添加中心点顶点
  353. vert.position = center;
  354. vert.uv0 = new Vector2(0.5f, 0.5f); // 中心UV值
  355. vh.AddVert(vert);
  356. // 绘制外圈和内圈的顶点
  357. for (int i = 0; i <= segments; i++)
  358. {
  359. float currentAngle = startAngleRad + i * angleStep;
  360. float cosA = Mathf.Cos(currentAngle);
  361. float sinA = Mathf.Sin(currentAngle);
  362. // 外圈顶点
  363. vert.position = center + new Vector2(cosA * outerRadius, sinA * outerRadius);
  364. vert.uv0 = new Vector2(0.5f + cosA * 0.5f, 0.5f + sinA * 0.5f);
  365. vh.AddVert(vert);
  366. // 内圈顶点
  367. vert.position = center + new Vector2(cosA * innerRadius, sinA * innerRadius);
  368. vert.uv0 = new Vector2(0.5f + cosA * innerRadius / outerRadius * 0.5f, 0.5f + sinA * innerRadius / outerRadius * 0.5f);
  369. vh.AddVert(vert);
  370. }
  371. // 创建三角形索引来绘制扇形
  372. for (int i = 1; i <= segments; i++)
  373. {
  374. int baseIndex = initialVertCount + (i - 1) * 2;
  375. vh.AddTriangle(initialVertCount, baseIndex + 1, baseIndex + 3); // 中心点连接外圈
  376. vh.AddTriangle(baseIndex + 1, baseIndex + 2, baseIndex + 3); // 内圈连接外圈
  377. }
  378. }
  379. // 新增箭头绘制方法
  380. private void DrawArrow(VertexHelper vh, Vector2 position, Vector2 direction, float arrowLength, float arrowWidth, float arrowHeadHeight)
  381. {
  382. // 标准化方向向量
  383. direction.Normalize();
  384. // 反向箭头的方向(箭头指向扇形方向)
  385. Vector2 reversedDirection = -direction;
  386. // 箭头尾部位置
  387. Vector2 basePosition = position - reversedDirection * arrowLength;
  388. // 计算垂直向量用于箭头宽度
  389. Vector2 perpendicular = new Vector2(-reversedDirection.y, reversedDirection.x);
  390. // 让箭头矩形部分的宽度比三角形的底边窄
  391. float adjustedArrowWidth = arrowWidth * 0.6f; // 调整宽度,使矩形比三角形窄
  392. // 箭头矩形部分的四个顶点
  393. Vector2 baseLeft = basePosition + perpendicular * (adjustedArrowWidth / 2);
  394. Vector2 baseRight = basePosition - perpendicular * (adjustedArrowWidth / 2);
  395. Vector2 headLeft = position + perpendicular * (adjustedArrowWidth / 2);
  396. Vector2 headRight = position - perpendicular * (adjustedArrowWidth / 2);
  397. Vector2 triangleHeadLeft = position + perpendicular * (arrowHeadHeight / 2);
  398. Vector2 triangleHeadRight = position - perpendicular * (arrowHeadHeight / 2);
  399. // 顶点颜色
  400. UIVertex vert = UIVertex.simpleVert;
  401. vert.color = arrowColor;
  402. // 先添加矩形部分的顶点
  403. int rectStartIndex = vh.currentVertCount;
  404. vert.position = baseLeft;
  405. vh.AddVert(vert);
  406. vert.position = baseRight;
  407. vh.AddVert(vert);
  408. vert.position = headLeft;
  409. vh.AddVert(vert);
  410. vert.position = headRight;
  411. vh.AddVert(vert);
  412. // 添加矩形部分的两条三角形索引
  413. vh.AddTriangle(rectStartIndex, rectStartIndex + 1, rectStartIndex + 2);
  414. vh.AddTriangle(rectStartIndex + 1, rectStartIndex + 3, rectStartIndex + 2);
  415. // 然后添加三角形头部的顶点
  416. Vector2 headPosition = position + reversedDirection * arrowHeadHeight;
  417. int headStartIndex = vh.currentVertCount;
  418. vert.position = triangleHeadLeft;
  419. vh.AddVert(vert);
  420. vert.position = triangleHeadRight;
  421. vh.AddVert(vert);
  422. vert.position = headPosition; // 添加箭头尖端
  423. vh.AddVert(vert);
  424. // 添加三角形的索引
  425. int triangleStartIndex = vh.currentVertCount - 3; // 三角形部分的开始索引
  426. vh.AddTriangle(triangleStartIndex, triangleStartIndex + 1, triangleStartIndex + 2); // 三角形索引
  427. }
  428. /// <summary>
  429. /// 抗锯齿羽化边缘
  430. /// </summary>
  431. private void AddAntiAliasForLine(VertexHelper vh, Vector2 start, Vector2 end, Vector2 offset, float feather)
  432. {
  433. UIVertex vert = UIVertex.simpleVert;
  434. Color featherColor = color;
  435. featherColor.a = 0; // 透明收尾
  436. // 上边缘
  437. vert.color = color;
  438. vert.position = start + offset;
  439. vh.AddVert(vert);
  440. vert.position = end + offset;
  441. vh.AddVert(vert);
  442. vert.color = featherColor;
  443. vert.position = start + offset + (offset.normalized * feather);
  444. vh.AddVert(vert);
  445. vert.position = end + offset + (offset.normalized * feather);
  446. vh.AddVert(vert);
  447. int idx = vh.currentVertCount - 4;
  448. vh.AddTriangle(idx, idx + 1, idx + 2);
  449. vh.AddTriangle(idx + 1, idx + 3, idx + 2);
  450. // 下边缘
  451. vert.color = color;
  452. vert.position = start - offset;
  453. vh.AddVert(vert);
  454. vert.position = end - offset;
  455. vh.AddVert(vert);
  456. vert.color = featherColor;
  457. vert.position = start - offset - (offset.normalized * feather);
  458. vh.AddVert(vert);
  459. vert.position = end - offset - (offset.normalized * feather);
  460. vh.AddVert(vert);
  461. idx = vh.currentVertCount - 4;
  462. vh.AddTriangle(idx, idx + 1, idx + 2);
  463. vh.AddTriangle(idx + 1, idx + 3, idx + 2);
  464. }
  465. //private void LateUpdate()
  466. //{
  467. // foreach (var quadObj in quadObjects)
  468. // {
  469. // if (quadObj != null)
  470. // {
  471. // objectPool.Push(quadObj);
  472. // }
  473. // }
  474. // quadObjects.Clear();
  475. // for (int i = 0; i < quadsToDraw.Count; i++)
  476. // {
  477. // GameObject quadGO = GetQuadObject();
  478. // if (quadGO != null)
  479. // {
  480. // quadGO.SetActive(true);
  481. // quadGO.GetComponent<RectTransform>().anchoredPosition = quadsToDraw[i];
  482. // Text quadTextComponent = quadGO.GetComponent<Text>();
  483. // quadTextComponent.text = quadTextToDraw[i];
  484. // quadTextComponent.fontSize = quadFontSize;
  485. // quadTextComponent.color = quadTextColor;
  486. // quadTextComponent.alignment = TextAnchor.MiddleCenter;
  487. // }
  488. // }
  489. // quadsToDraw.Clear();
  490. // quadTextToDraw.Clear();
  491. //}
  492. //private GameObject GetQuadObject()
  493. //{
  494. // if (objectPool.Count > 0)
  495. // {
  496. // GameObject quadGO = objectPool.Pop();
  497. // if (quadGO != null)
  498. // {
  499. // quadObjects.Add(quadGO);
  500. // return quadGO;
  501. // }
  502. // }
  503. // if (quadObjects.Count < ObjectPoolLimit)
  504. // {
  505. // GameObject newQuadGO = new GameObject("QuadText", typeof(RectTransform), typeof(Text));
  506. // newQuadGO.transform.SetParent(this.transform);
  507. // Text quadTextComponent = newQuadGO.GetComponent<Text>();
  508. // quadTextComponent.alignment = TextAnchor.MiddleCenter;
  509. // quadTextComponent.rectTransform.sizeDelta = new Vector2(quadrilateralSize.x, quadrilateralSize.y);
  510. // quadObjects.Add(newQuadGO);
  511. // return newQuadGO;
  512. // }
  513. // return null;
  514. //}
  515. }
  516. }