AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
UGLExample.cs
1 /******************************************/
2 /* */
3 /* Copyright (c) 2020 monitor1394 */
4 /* https://github.com/monitor1394 */
5 /* */
6 /******************************************/
7 
8 using System.Collections.Generic;
9 using UnityEngine;
10 using UnityEngine.UI;
11 
12 namespace XUGL
13 {
14  [ExecuteInEditMode]
15  public class UGLExample : MaskableGraphic
16  {
17  private float m_Width = 800;
18  private float m_Height = 800;
19  private Vector3 m_Center = Vector3.zero;
20  private Vector3 m_LeftTopPos = Vector3.zero;
21  private Color32 m_BackgroundColor = new Color32(224, 224, 224, 255);
22  private Color32 m_DrawColor = new Color32(255, 132, 142, 255);
23  private float[] m_BorderRadius = new float[] { 5, 5, 10, 10 };
24 
25  protected override void Awake()
26  {
27  base.Awake();
28  var rectTransform = GetComponent<RectTransform>();
29  rectTransform.sizeDelta = new Vector2(500, 500);
30  rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
31  rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
32  rectTransform.pivot = new Vector2(0.5f, 0.5f);
33  m_Center = Vector3.zero;
34  m_LeftTopPos = new Vector3(-m_Width / 2, m_Height / 2);
35  }
36 
37  protected override void OnPopulateMesh(VertexHelper vh)
38  {
39  Vector3 sp, cp, ep;
40  vh.Clear();
41 
42  //背景边框
43  UGL.DrawSquare(vh, m_Center, m_Width / 2, m_BackgroundColor);
44  UGL.DrawBorder(vh, m_Center, m_Width, m_Height, 40, Color.green, Color.red, 0, m_BorderRadius,false,1);
45 
46  //点
47  UGL.DrawCricle(vh, m_LeftTopPos + new Vector3(20, -20), 10, m_DrawColor);
48 
49  //直线
50  sp = new Vector3(m_LeftTopPos.x + 50, m_LeftTopPos.y - 20);
51  ep = new Vector3(m_LeftTopPos.x + 250, m_LeftTopPos.y - 20);
52  UGL.DrawLine(vh, sp, ep, 3, m_DrawColor);
53 
54  //3点确定的折线
55  sp = new Vector3(m_LeftTopPos.x + 20, m_LeftTopPos.y - 100);
56  cp = new Vector3(m_LeftTopPos.x + 200, m_LeftTopPos.y - 40);
57  ep = new Vector3(m_LeftTopPos.x + 250, m_LeftTopPos.y - 80);
58  UGL.DrawLine(vh, sp, cp, ep, 5, m_DrawColor);
59 
60  }
61  }
62 }
XUGL
Definition: UGL.cs:12
XUGL.UGLExample
Definition: UGLExample.cs:15