void Start() { ExclamationMark.gameObject.SetActive(false); _audio = GetComponent <AudioSource>(); _state = BarrierState.Up; _startPosition = transform.position; _health = GetComponent <Health>(); _health.OnDamaged += OnDamaged; _health.OnDeath += OnDeath; }
private void Rebuild() { ExclamationMark.gameObject.SetActive(false); _state = BarrierState.GoingUpOrDown; _health.Reset(); StartCoroutine(Move(false)); if (RebuildEffectPrefab != null) { Instantiate(RebuildEffectPrefab, transform.position, transform.rotation); } }
private void TearDown() { _audio.PlayOneShot(TearDownClip); ExclamationMark.gameObject.SetActive(true); _state = BarrierState.GoingUpOrDown; StartCoroutine(Move(true)); if (TeardownEffectPrefab != null) { Instantiate(TeardownEffectPrefab, transform.position, transform.rotation); } }
void DeactivateBarrier() { barrierState = BarrierState.DOWN; spawner.enabled = false; rb.isKinematic = false; innerRing.ExplodeAnimation(); midRing.ExplodeAnimation(); outerRing.ExplodeAnimation(); }
void ActivateBarrier() { barrierState = BarrierState.UP; spawner.enabled = true; rb.isKinematic = true; rise.StartAnimation(); innerRing.InitializeAnimation(); midRing.InitializeAnimation(); outerRing.InitializeAnimation(); }
public IEnumerator StateCheck() { if (isBarrier) { barrierState = BarrierState.barrierOn; yield return(StartCoroutine(BarrierOn())); } else { barrierState = BarrierState.barrierOff; yield return(StartCoroutine(BarrierOff())); } }
private IEnumerator Move(bool down) { _currentTeardown = 0f; var currentPosition = transform.position; var targetPosition = down ? _startPosition + (Vector3.down * TeardownDistance) : _startPosition; while (_currentTeardown <= TearDownDuration) { _currentTeardown += Time.deltaTime; var progress = _currentTeardown / TearDownDuration; transform.position = Vector3.Lerp(currentPosition, targetPosition, progress); yield return(new WaitForEndOfFrame()); } transform.position = targetPosition; _state = down ? BarrierState.Down : BarrierState.Up; }
private void SetBarrierState(LaneTypes lanetype, int groupID, int componentID, BarrierState newState) { //Finds all barriers with id List <Barrier> barrierList = barriers.FindAll(b => b.laneType == lanetype && b.GroupId == groupID && b.ComponentID == componentID); //No barrier found if (barrierList == null) { Debug.LogError($"ERROR: Barrier with groupID: {groupID} and componentID: {componentID} not found"); return; } foreach (var barrier in barrierList) { if (newState != barrier.state) { barrier.state = newState; } } }
//Handles MQTT messages when they are received public void HandleMessage(string topic, string message) { //Parse and store topic information TopicInformation info = ParseTopic(topic); switch (info.componentType) { case ComponentTypes.traffic_light: //Handle traffic lights //Try setting new traffic light state try { TrafficLightState newState = (TrafficLightState)System.Enum.Parse(typeof(TrafficLightState), message); SetTrafficLightState(info.laneType, info.groupID, info.componentID, newState); } catch { Debug.LogError($"ERROR: Tried setting invalid traffic light state: '{message}' for traffic light with GroupID: {info.groupID} and ComponentID: {info.componentID}"); } break; case ComponentTypes.warning_light: //Handle warning lights //Try setting new warning light state try { WarningLightState newState = (WarningLightState)System.Enum.Parse(typeof(WarningLightState), message); SetWarningLightState(info.laneType, info.groupID, info.componentID, newState); } catch { Debug.LogError($"ERROR: Tried setting invalid warning light state: '{message}' for warning light with GroupID: {info.groupID} and ComponentID: {info.componentID}"); } break; case ComponentTypes.boat_light: //Handle boat lights //Try setting new boat light state try { BoatAndTrainLightState newState = (BoatAndTrainLightState)System.Enum.Parse(typeof(BoatAndTrainLightState), message); SetBoatLightState(info.laneType, info.groupID, info.componentID, newState); } catch { Debug.LogError($"ERROR: Tried setting invalid boat light state: '{message}' for boat light with GroupID: {info.groupID} and ComponentID: {info.componentID}"); } break; case ComponentTypes.sensor: //Don't have to handle sensor data break; case ComponentTypes.barrier: //Handle barriers //Try setting new barrier state try { BarrierState newState = (BarrierState)System.Enum.Parse(typeof(BarrierState), message); SetBarrierState(info.laneType, info.groupID, info.componentID, newState); } catch { Debug.LogError($"ERROR: Tried setting invalid barrier state: '{message}' for barrier with GroupID: {info.groupID} and ComponentID: {info.componentID}"); } break; case ComponentTypes.deck: //Handle deck(bridge) //Try setting new deck(bridge) state try { DeckState newState = (DeckState)System.Enum.Parse(typeof(DeckState), message); SetDeckState(info.laneType, info.groupID, info.componentID, newState); } catch { Debug.LogError($"ERROR: Tried setting invalid deck(bridge) state: '{message}' for deck with GroupID: {info.groupID} and ComponentID: {info.componentID}"); } break; case ComponentTypes.train_light: //Handle train_light //Try setting new train_light state try { BoatAndTrainLightState newState = (BoatAndTrainLightState)System.Enum.Parse(typeof(BoatAndTrainLightState), message); SetTrainLightState(info.laneType, info.groupID, info.componentID, newState); } catch { Debug.LogError($"ERROR: Tried setting invalid train_light state: '{message}' for train_light with GroupID: {info.groupID} and ComponentID: {info.componentID}"); } break; } }
public void CustomerPayment() { BarrierState.Pay(); }
public void CustomerEntrance() { BarrierState.Enter(); }
public void Update() { BarrierState.DoWork(); }