説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

UGLExample.cs 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. namespace XUGL
  5. {
  6. [ExecuteInEditMode]
  7. public class UGLExample : MaskableGraphic
  8. {
  9. private float m_Width = 800;
  10. private float m_Height = 800;
  11. private Vector3 m_Center = Vector3.zero;
  12. private Vector3 m_LeftTopPos = Vector3.zero;
  13. private Color32 m_BackgroundColor = new Color32(224, 224, 224, 255);
  14. private Color32 m_DrawColor = new Color32(255, 132, 142, 255);
  15. private float[] m_BorderRadius = new float[] { 5, 5, 10, 10 };
  16. protected override void Awake()
  17. {
  18. base.Awake();
  19. var rectTransform = GetComponent<RectTransform>();
  20. rectTransform.sizeDelta = new Vector2(500, 500);
  21. rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
  22. rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
  23. rectTransform.pivot = new Vector2(0.5f, 0.5f);
  24. m_Center = Vector3.zero;
  25. m_LeftTopPos = new Vector3(-m_Width / 2, m_Height / 2);
  26. }
  27. protected override void OnPopulateMesh(VertexHelper vh)
  28. {
  29. Vector3 sp, cp, ep;
  30. vh.Clear();
  31. //背景边框
  32. UGL.DrawSquare(vh, m_Center, m_Width / 2, m_BackgroundColor);
  33. UGL.DrawBorder(vh, m_Center, m_Width, m_Height, 40, Color.green, Color.red, 0, m_BorderRadius, false, 1);
  34. //点
  35. UGL.DrawCricle(vh, m_LeftTopPos + new Vector3(20, -20), 10, m_DrawColor);
  36. //直线
  37. sp = new Vector3(m_LeftTopPos.x + 50, m_LeftTopPos.y - 20);
  38. ep = new Vector3(m_LeftTopPos.x + 250, m_LeftTopPos.y - 20);
  39. UGL.DrawLine(vh, sp, ep, 3, m_DrawColor);
  40. //3点确定的折线
  41. sp = new Vector3(m_LeftTopPos.x + 20, m_LeftTopPos.y - 100);
  42. cp = new Vector3(m_LeftTopPos.x + 200, m_LeftTopPos.y - 40);
  43. ep = new Vector3(m_LeftTopPos.x + 250, m_LeftTopPos.y - 80);
  44. UGL.DrawLine(vh, sp, cp, ep, 5, m_DrawColor);
  45. }
  46. }
  47. }