Ejemplo n.º 1
0
 void Start()
 {
     ExclamationMark.gameObject.SetActive(false);
     _audio             = GetComponent <AudioSource>();
     _state             = BarrierState.Up;
     _startPosition     = transform.position;
     _health            = GetComponent <Health>();
     _health.OnDamaged += OnDamaged;
     _health.OnDeath   += OnDeath;
 }
Ejemplo n.º 2
0
 private void Rebuild()
 {
     ExclamationMark.gameObject.SetActive(false);
     _state = BarrierState.GoingUpOrDown;
     _health.Reset();
     StartCoroutine(Move(false));
     if (RebuildEffectPrefab != null)
     {
         Instantiate(RebuildEffectPrefab, transform.position, transform.rotation);
     }
 }
Ejemplo n.º 3
0
 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);
     }
 }
Ejemplo n.º 4
0
        void DeactivateBarrier()
        {
            barrierState = BarrierState.DOWN;

            spawner.enabled = false;

            rb.isKinematic = false;

            innerRing.ExplodeAnimation();
            midRing.ExplodeAnimation();
            outerRing.ExplodeAnimation();
        }
Ejemplo n.º 5
0
        void ActivateBarrier()
        {
            barrierState = BarrierState.UP;

            spawner.enabled = true;

            rb.isKinematic = true;
            rise.StartAnimation();

            innerRing.InitializeAnimation();
            midRing.InitializeAnimation();
            outerRing.InitializeAnimation();
        }
Ejemplo n.º 6
0
 public IEnumerator StateCheck()
 {
     if (isBarrier)
     {
         barrierState = BarrierState.barrierOn;
         yield return(StartCoroutine(BarrierOn()));
     }
     else
     {
         barrierState = BarrierState.barrierOff;
         yield return(StartCoroutine(BarrierOff()));
     }
 }
Ejemplo n.º 7
0
    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;
    }
Ejemplo n.º 8
0
    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;
            }
        }
    }
Ejemplo n.º 9
0
    //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;
        }
    }
Ejemplo n.º 10
0
 public void CustomerPayment()
 {
     BarrierState.Pay();
 }
Ejemplo n.º 11
0
 public void CustomerEntrance()
 {
     BarrierState.Enter();
 }
Ejemplo n.º 12
0
 public void Update()
 {
     BarrierState.DoWork();
 }