-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHeadingShow.cs
50 lines (46 loc) · 1.73 KB
/
HeadingShow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Windows;
public class HeadingShow : MonoBehaviour
{
public GameObject textParent;
public GameObject textPrefab;
public GameObject drone;
public Text hdgMainText;
public float spaceScale = 25f;
public int hdgMeterRange = 40;
// Update is called once per frame
void Update()
{
float hdg = drone.transform.rotation.eulerAngles.y;
hdgMainText.text = hdg.ToString("F0") + "\n\u25BD";
GenText(MyFuntions.GenMeter(hdg, hdgMeterRange, textParent.transform));
foreach (Transform tr in textParent.transform) //Òƶ¯¶ÔÏóµ½ÕýÈ·µÄλÖÃ
{
var number = int.Parse(tr.name[3..]);
float delta = (number - hdg) * spaceScale;
var mainTextPos = hdgMainText.transform.position;
tr.position = new Vector3(mainTextPos.x + delta, mainTextPos.y - 120, mainTextPos.z);
}
}
void GenText(List<int> list)
{
string str;
foreach (int i in list)
{
int showHdg = i;
if (i >= 360) showHdg -= 360;
if (i < 0) showHdg += 360;
if (showHdg % 5 == 0) str = "|\n" + showHdg.ToString() ; else str = "|";
if (showHdg == 90) str = "|\nE";
if (showHdg == 180) str = "|\nS";
if (showHdg == 270) str = "|\nW";
if (showHdg == 0) str = "|\nN";
var newText = Instantiate(textPrefab, new Vector3(0, 0, 0), Quaternion.identity, textParent.transform);
newText.GetComponent<Text>().text = str;
newText.name = "hdg" + i.ToString();
}
}
}