AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
AC_Airplane_Attitude.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using Communicator;
5 using Commons;
6 
7 namespace AirControl
8 {
12  public class AC_Airplane_Attitude : MonoBehaviour, IAirplaneUI
13  {
14  #region Variables
15  [Header("Attitude Indicator Properties")]
16  [SerializeField]
17  private AC_Airplane_Controller airplane;
18  public RectTransform bgRect;
19  public RectTransform arrowRect;
20  protected float bankAngle;
21  protected float pitchAngle;
22  protected float bankAngleRad;
23  protected float pitchAngleRad;
24  #endregion
25 
26  #region Properties
27  public float BankAngle{
28  get{return bankAngle;}
29  }
30  public float PitchAngle{
31  get{return pitchAngle;}
32  }
33  #endregion
34 
35  #region Builtin methods
36  void Start(){
37  airplane = GameObject.Find(CommonFunctions.ActiveAirplane).GetComponent<AC_Airplane_Controller>();
38  }
39  #endregion
40 
41 
42  #region Interface Methods
43  public void HandleAirplaneUI()
47  {
48  if(airplane)
49  {
50  //Create Angles
51  bankAngleRad = Vector3.Dot(airplane.transform.right, Vector3.up); // value from -1 to 1
52  bankAngle = bankAngleRad * Mathf.Rad2Deg;
53  pitchAngleRad = Vector3.Dot(airplane.transform.forward, Vector3.up); // value from -1 to 1
54  pitchAngle = pitchAngleRad * Mathf.Rad2Deg;
55 
56  //Handle UI Elements
57  if(bgRect)
58  {
59  Quaternion bankRotation = Quaternion.Euler(0f, 0f, bankAngle);
60  bgRect.transform.rotation = bankRotation;
61 
62  Vector3 wantedPosition = new Vector3(0f, -pitchAngle, 0f);
63  bgRect.anchoredPosition = wantedPosition;
64 
65  if(arrowRect)
66  {
67  arrowRect.transform.rotation = bankRotation;
68  }
69  }
70  #region DBArea
71  StaticOutputSchema.BankAngle = bankAngleRad;
72  StaticOutputSchema.PitchAngle = pitchAngleRad;
73  #endregion
74 
75  }
76  }
77  #endregion
78  }
79 }
AirControl.IAirplaneUI
Definition: IAirplaneUI.cs:8
AirControl.AC_Airplane_Attitude.HandleAirplaneUI
void HandleAirplaneUI()
Updates to UI
Definition: AC_Airplane_Attitude.cs:46
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
Communicator
Definition: InputHandle.cs:10
AirControl.AC_Airplane_Attitude
Monitor and updates the Attitude to UI
Definition: AC_Airplane_Attitude.cs:12
Commons
Definition: AirplaneProperties.cs:14