*
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System;
|
||||
|
||||
public class IgnitionButtonController : IIgnitionStateController{
|
||||
private bool _pressed;
|
||||
private float _starterTime = 7.0f;
|
||||
private float _startBeginTime;
|
||||
|
||||
public virtual void SetButtonState(IgnitionSystem sys, int button, bool press){
|
||||
_pressed = press;
|
||||
|
||||
bool brakePressed = sys.Car.GetPedalState (CarPedal.Brake) > 0.5f;
|
||||
|
||||
if (press) {
|
||||
switch(sys.State){
|
||||
case IgnitionState.Start:
|
||||
sys.State = IgnitionState.Lock;
|
||||
break;
|
||||
case IgnitionState.Lock:
|
||||
if(brakePressed){
|
||||
SetStartState(sys);
|
||||
}else{
|
||||
sys.State = IgnitionState.Acc;
|
||||
}
|
||||
break;
|
||||
case IgnitionState.Acc:
|
||||
if(brakePressed){
|
||||
SetStartState(sys);
|
||||
}else{
|
||||
sys.State = IgnitionState.On;
|
||||
}
|
||||
break;
|
||||
case IgnitionState.On:
|
||||
if(brakePressed){
|
||||
SetStartState(sys);
|
||||
}else{
|
||||
sys.State = IgnitionState.Lock;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetStartState(IgnitionSystem sys){
|
||||
_startBeginTime = Time.time;
|
||||
sys.State = IgnitionState.Start;
|
||||
}
|
||||
|
||||
public void Update(IgnitionSystem sys){
|
||||
if (sys.State == IgnitionState.Start) {
|
||||
if(sys.Car.engine.Started){
|
||||
sys.State = IgnitionState.On;
|
||||
}else{
|
||||
if((Time.time - _startBeginTime) >= _starterTime){
|
||||
sys.State = IgnitionState.On;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user