AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
AC_Airplane_Tachometer.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using Commons;
5 using System.ComponentModel;
6 
7 namespace AirControl
8 {
12  public class AC_Airplane_Tachometer : MonoBehaviour, IAirplaneUI
13  {
14  #region Variables
15  [Header("Tachometer Properties")]
16  [Tooltip("Drag and drop Engine Here")]
17  [SerializeField]
18  private AC_Airplane_Engine engine;
19  [Tooltip("Drag and drop pointer Here")]
20  public RectTransform pointer;
21  public float maxRPMIntachometer = 3500f;
22 
23  private float smoothrotation;
24  #endregion
25 
26  #region Builtin methods
27  void Start(){
28  engine = GameObject.Find(CommonFunctions.ActiveAirplane).GetComponent<AC_Airplane_Engine>();
29  }
30  #endregion
31 
32  #region Interface Methods
33  public void HandleAirplaneUI()
37  {
38  if(engine && pointer)
39  {
40  float normalizedRPM = Mathf.InverseLerp(0f, (float)CommonFunctions.airplanePreset[CommonFunctions.activeAirplane+"/maxRPM"] , engine.CurrentRPM);
41  float radialspeed = 360f * normalizedRPM;
42  //smoothly move tachmeter
43  smoothrotation = Mathf.Lerp(smoothrotation, radialspeed, Time.deltaTime*0.1f);
44  pointer.rotation = Quaternion.Euler(0f,0f,-smoothrotation);
45  }
46 
47 
48  }
49  #endregion
50  }
51 
52 }
AirControl.IAirplaneUI
Definition: IAirplaneUI.cs:8
AirControl.AC_Airplane_Engine
Engine controls
Definition: AC_Airplane_Engine.cs:22
AirControl
Definition: AirplaneSelector.cs:8
AirControl.AC_Airplane_Tachometer
Monitor and updates the tachometer to UI
Definition: AC_Airplane_Tachometer.cs:12
AirControl.AC_Airplane_Tachometer.HandleAirplaneUI
void HandleAirplaneUI()
Updates to UI
Definition: AC_Airplane_Tachometer.cs:36
Commons
Definition: AirplaneProperties.cs:14