47 lines
1.2 KiB
C#
47 lines
1.2 KiB
C#
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 () {
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|