Esempio n. 1
0
        /// <summary>
        /// Connect wagon to train
        /// </summary>
        /// <param name="carCoupler">Current wagon coupler (front or back)</param>
        /// <param name="otherCarCoupler">Other wagon coupler</param>
        public void Connect(TrainCarCoupler carCoupler, TrainCarCoupler otherCarCoupler, bool playSFX)
        {
            if (coupling == WagonCoupling.Enabled)
            {
                if (otherCarCoupler.IsLocomotive)
                {
                    _locomotive          = otherCarCoupler.Locomotive;
                    _reverseAcceleration = (carCoupler.IsBackJoint == otherCarCoupler.IsBackJoint);
                }
                else if (otherCarCoupler.IsWagon)
                {
                    if (!otherCarCoupler.Wagon.IsConected)
                    {
                        return;
                    }

                    _locomotive          = otherCarCoupler.Wagon.Locomotive;
                    _reverseAcceleration = (carCoupler.IsBackJoint != otherCarCoupler.IsBackJoint) ? otherCarCoupler.Wagon.ReverseAcceleration : !otherCarCoupler.Wagon.ReverseAcceleration;
                }

                TrainPhysics.ConnectTrainCar(_carJoint, otherCarCoupler.GetComponent <Rigidbody>());
                _locomotive.wagons.Add(this);
                _locomotive.UpdateDoorController();

                if (playSFX && _sfx.wagonConnectionSFX != null)
                {
                    _sfx.wagonConnectionSFX.Play();
                }
            }
        }
Esempio n. 2
0
        private void OnTriggerEnter(Collider other)
        {
            TrainController_v3 train = other.GetComponent <TrainController_v3>();

            if (train != null)
            {
                switch (reverseDirectionMode)
                {
                case ReverseDirectionMode.Always:
                    train.acceleration *= -1;
                    break;

                case ReverseDirectionMode.OnlyIfMovingForward:
                    if (train.acceleration > 0f)
                    {
                        train.acceleration *= -1;
                    }
                    break;

                case ReverseDirectionMode.OnlyIfMovingBackwards:
                    if (train.acceleration < 0f)
                    {
                        train.acceleration *= -1;
                    }
                    break;
                }
            }
        }
Esempio n. 3
0
        private void OnEnable()
        {
            // Parent must be always wagon or locomotive
            _locomotive = this.transform.parent.GetComponent <TrainController_v3>();
            _wagon      = this.transform.parent.GetComponent <Wagon_v3>();

            _isLocomotive = (_locomotive != null);
            _isWagon      = (_wagon != null);
        }
Esempio n. 4
0
        private void OnTriggerEnter(Collider other)
        {
            TrainController_v3 train = other.GetComponent <TrainController_v3>();

            if (train != null)
            {
                train.maxSpeedKph = targetSpeedKph;
            }
        }
Esempio n. 5
0
        private void OnTriggerEnter(Collider other)
        {
            TrainController_v3 train = other.GetComponent <TrainController_v3>();

            if (train != null)
            {
                train.Honk();
            }
        }
Esempio n. 6
0
        private void OnTriggerEnter(Collider other)
        {
            TrainController_v3 train = other.GetComponent <TrainController_v3>();

            if (train != null)
            {
                if ((triggerType == ZoneTriggerType.Activate && !train.BellOn) || (triggerType == ZoneTriggerType.Deactivate && train.BellOn))
                {
                    train.ToogleBell();
                }
            }
        }
Esempio n. 7
0
        private void OnTriggerEnter(Collider other)
        {
            TrainController_v3 train = other.GetComponent <TrainController_v3>();

            if (train != null)
            {
                if (customEvents != null)
                {
                    customEvents.Invoke();
                }
            }
        }
        private void OnTriggerEnter(Collider other)
        {
            TrainController_v3 train = other.GetComponent <TrainController_v3>();

            if (train != null)
            {
                if (railroadSwitches == null || railroadSwitches.Count == 0)
                {
                    Debug.LogWarning("Railroad Switch not set on Switch Trigger");
                    return;
                }

                switch (switchMode)
                {
                case SwitchMode.Always:
                    SwitchRails();
                    break;

                case SwitchMode.Once:
                    if (!_alreadySwitched)
                    {
                        SwitchRails();
                        _alreadySwitched = true;
                    }
                    break;

                case SwitchMode.Random:
                    if (Probability.RandomEvent(randomSwitchProbability))
                    {
                        SwitchRails();
                    }
                    break;

                case SwitchMode.IfActivated:
                    SwitchActivatedRails();
                    break;

                case SwitchMode.IfDeactivated:
                    SwitchDeactivatedRails();
                    break;
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Disconnect wagon from train
        /// </summary>
        public void Disconnect(bool disconnectJoint)
        {
            if (disconnectJoint)
            {
                _carJoint.connectedBody = jointAnchor;
            }
            _locomotive = null;

            if (_sfx.wagonConnectionSFX != null)
            {
                _sfx.wagonConnectionSFX.Play();
            }

            coupling = WagonCoupling.Disabled;

            if (decouplingSettings == WagonDecouplingSettings.AllowRecoupling)
            {
                Invoke("ReenabledCoupling", Mathf.Abs(recouplingTimeout));
            }
        }
Esempio n. 10
0
 // Use this for initialization
 void Start()
 {
     _locomotive     = GetComponent <TrainController_v3>();
     _doorController = GetComponent <TrainDoorsController>();
 }
 // Use this for initialization
 void Start()
 {
     _trainController = GetComponent<TrainController_v3>();
     UpdateWagonsPassengerTags();
 }
 private void Start()
 {
     _trainController = GetComponent <TrainController_v3>();
     UpdateWagonsDoorsControllers();
 }
Esempio n. 13
0
 // Use this for initialization
 void Start()
 {
     _trainController = GetComponent <TrainController_v3>();
 }