AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
AC_Airplane_Fuel.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEngine.Events;
5 
6 
7 namespace AirControl
8 {
12  public class AC_Airplane_Fuel : MonoBehaviour
13  {
14  #region Variables
15  [Header("Fuel Properties")]
16  [Tooltip("The total number of gallons in the fuel tank.")]
17  public float fuelCapacity = 26f;
18  [Tooltip("The average fuel burn per hour")]
19  public float fuelBurnRate = 6.1f;
20 
21  [Header("Events")]
22  public UnityEvent onFuelFull = new UnityEvent();
23  #endregion
24 
25 
26  #region Properties
27  private float currentFuel;
28  public float CurrentFuel
29  {
30  get{return currentFuel;}
31  }
32 
33  private float normalizeFuel;
34  public float NormalizedFuel
35  {
36  get{return normalizeFuel;}
37  }
38  #endregion
39 
40 
41  #region Custom Methods
42  public void InitFuel()
46  {
47  currentFuel = fuelCapacity;
48  }
53  public void AddFuel(float aFuelAmount)
54  {
55  currentFuel += aFuelAmount;
56  currentFuel = Mathf.Clamp(currentFuel, 0f, fuelCapacity);
57 
58  if(currentFuel >= fuelCapacity)
59  {
60  if(onFuelFull != null)
61  {
62  onFuelFull.Invoke();
63  }
64  }
65  }
69  public void ResetFuel()
70  {
71  currentFuel = fuelCapacity;
72  }
77  public void UpdateFuel(float aPrecentage)
78  {
79  float currentBurn = ((fuelBurnRate * aPrecentage) / 3600f) * Time.deltaTime;
80  currentFuel -= currentBurn;
81  currentFuel = Mathf.Clamp(currentFuel, 0f, fuelCapacity);
82  // Debug.Log("currentFuel -- "+currentFuel);
83 
84  normalizeFuel = currentFuel / fuelCapacity;
85  }
86  #endregion
87  }
88 }
AirControl.AC_Airplane_Fuel.UpdateFuel
void UpdateFuel(float aPrecentage)
Fuel burnout calculations
Definition: AC_Airplane_Fuel.cs:77
AirControl.AC_Airplane_Fuel.AddFuel
void AddFuel(float aFuelAmount)
Add fuel in case of mid airfueling facility
Definition: AC_Airplane_Fuel.cs:53
AirControl.AC_Airplane_Fuel.ResetFuel
void ResetFuel()
Reset fuel in case of mid airfueling facility
Definition: AC_Airplane_Fuel.cs:69
AirControl.AC_Airplane_Fuel.InitFuel
void InitFuel()
Initialize full to full capacity
Definition: AC_Airplane_Fuel.cs:45
AirControl
Definition: AirplaneSelector.cs:8
AirControl.AC_Airplane_Fuel
Control fuel consumption
Definition: AC_Airplane_Fuel.cs:12