This commit is contained in:
2025-05-13 03:19:28 +03:00
parent e2847b060d
commit 762dcf4524
784 changed files with 542617 additions and 2 deletions
+46
View File
@@ -0,0 +1,46 @@
using UnityEngine;
using System.Collections;
public enum PowerBusType{
Acc = 0,
On = 1
}
public class CarElectricSystem : MonoBehaviour {
public IElecticEnergySource energySource;
public IgnitionSystem ignition;
private PowerBus[] _powerBus;
// Use this for initialization
void Start () {
//create electric power buses
_powerBus = new PowerBus[]{new PowerBus(), new PowerBus()};
foreach (var bus in _powerBus) {
bus.ElectricSystem = this;
}
//attach to ignition system
if (ignition != null) {
ignition.PowerBus = _powerBus [(int)PowerBusType.On];
ignition.StateChanged += HandleIgnitionStateChanged;
} else {
Debug.LogWarning("Electric system: no ignition system attached");
}
}
void HandleIgnitionStateChanged (IgnitionSystem caller, IgnitionState oldState, IgnitionState newState){
_powerBus [(int)PowerBusType.Acc].Enabled = newState != IgnitionState.Lock;
_powerBus [(int)PowerBusType.On].Enabled = (newState != IgnitionState.Lock) && (newState != IgnitionState.Acc);
}
public PowerBus GetPowerBus(PowerBusType busType){
return _powerBus[(int)busType];
}
// Update is called once per frame
void Update () {
}
}