AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
AC_Airplane_Altimeter.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using Commons;
5 
6 namespace AirControl
7 {
11  public class AC_Airplane_Altimeter : MonoBehaviour, IAirplaneUI
12  {
13  #region Variables
14  [Header("Altimeter Properties")]
15  [Tooltip("Drag and drop Airplane Here")]
16  [SerializeField]
17  private AC_Airplane_Controller airplane;
18  [Tooltip("Drag and drop Hundreds pointer Here")]
19  [SerializeField]
20  private RectTransform hundredspointer;
21  [Tooltip("Drag and drop Thousands Pointer Here")]
22  [SerializeField]
23  private RectTransform thousandsPointer;
24  #endregion
25 
26  #region Builtin methods
27  void Start(){
28  airplane = GameObject.Find(CommonFunctions.ActiveAirplane).GetComponent<AC_Airplane_Controller>();
29  }
30  #endregion
31 
32  #region Interface Methods
33  public void HandleAirplaneUI()
37  {
38  if(airplane)
39  {
40  float currentAltitude = airplane.CurrentMSL;
41  float currentThousands = currentAltitude/1000f;
42  currentThousands = Mathf.Clamp(currentThousands,0,10);
43 
44  float currentHundreds = currentAltitude - (Mathf.Floor(currentThousands)*1000f);
45  currentHundreds = Mathf.Clamp(currentHundreds, 0f,1000f);
46 
47  if(thousandsPointer)
48  {
49  // Calcualting degrees from the current height
50  float radialThousands = Mathf.InverseLerp(0,10,currentThousands);
51  radialThousands = 360f * radialThousands;
52  thousandsPointer.rotation = Quaternion.Euler(0f,0f,-radialThousands);
53  }
54  if(hundredspointer)
55  {
56  // Calcualting degrees from the current height
57  float radialHundreds = Mathf.InverseLerp(0f,1000f,currentHundreds);
58  radialHundreds = 360f * radialHundreds;
59  hundredspointer.rotation = Quaternion.Euler(0f,0f,-radialHundreds);
60  }
61  }
62  }
63  #endregion
64  }
65 
66 }
AirControl.IAirplaneUI
Definition: IAirplaneUI.cs:8
AirControl.AC_Airplane_Altimeter.HandleAirplaneUI
void HandleAirplaneUI()
Updates to UI
Definition: AC_Airplane_Altimeter.cs:36
AirControl.AC_Airplane_Controller
Master Controller, controls the entire Airplane it implements function to Handle Engines,...
Definition: AC_Airplane_Controller.cs:22
AirControl
Definition: AirplaneSelector.cs:8
AirControl.AC_Airplane_Altimeter
Monitor and updates the Altimeter to UI
Definition: AC_Airplane_Altimeter.cs:11
Commons
Definition: AirplaneProperties.cs:14