AR + GPS Location  3.0.0
All Classes Namespaces Functions Variables Properties Events Pages
LoadingBar.cs
1 using UnityEngine;
2 using UnityEngine.Serialization;
3 using UnityEngine.UI;
4 
5 namespace ARLocation.UI
6 {
7  public class LoadingBar : MonoBehaviour
8  {
9 
10  [FormerlySerializedAs("fillPercentage")] [Range(0, 1)]
11  public float FillPercentage = 0.4f;
12 
13  [FormerlySerializedAs("startColor")] public Color StartColor = Color.green;
14  [FormerlySerializedAs("middleColor")] public Color MiddleColor = Color.yellow;
15  [FormerlySerializedAs("endColor")] public Color EndColor = Color.red;
16  [FormerlySerializedAs("textColor")] public Color TextColor = Color.blue;
17  [FormerlySerializedAs("usePercentageText")] public bool UsePercentageText;
18  [FormerlySerializedAs("text")] public string Text = "100";
19 
20  private GameObject fillBar;
21  private Text barText;
22  private RectTransform rectTransform;
23  private RectTransform fillBarRect;
24  private Image fillBarImage;
25 
26  // Use this for initialization
27  void Start()
28  {
29  fillBar = transform.Find("Bar").gameObject;
30  barText = transform.Find("Text").gameObject.GetComponent<Text>();
31  barText.color = TextColor;
32  barText.fontStyle = FontStyle.Bold;
33  rectTransform = GetComponent<RectTransform>();
34  fillBarRect = fillBar.GetComponent<RectTransform>();
35  fillBarImage = fillBar.GetComponent<Image>();
36  }
37 
38  // Update is called once per frame
39  void Update()
40  {
41  var w = rectTransform.rect.width;
42 
43  fillBarRect.offsetMin = new Vector2(0, 0);
44  fillBarRect.offsetMax = new Vector2((FillPercentage - 1) * w, 0);
45 
46  if (FillPercentage < 0.5)
47  {
48  fillBarImage.color = Color.Lerp(StartColor, MiddleColor, FillPercentage * 2);
49  }
50  else
51  {
52  fillBarImage.color = Color.Lerp(MiddleColor, EndColor, (FillPercentage - 0.5f) * 2);
53  }
54 
55  if (UsePercentageText)
56  {
57  barText.text = ((int)(FillPercentage * 100.0f)) + "%";
58  }
59  else
60  {
61  barText.text = Text;
62  }
63  }
64  }
65 }
ARLocation.UI.LoadingBar
Definition: LoadingBar.cs:8
ARLocation.UI
Definition: ARTrackingInfo.cs:5