コード例 #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();
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Connect wagons hinges
        /// </summary>
        private void ConnectWagons()
        {
            for (int i = 0; i < wagons.Count; i++)
            {
                if (i == 0) // Connect wagon to locomotive
                {
                    TrainPhysics.ConnectTrainCar(wagons[i].GetComponent <HingeJoint>(), backJoint);
                }
                else // Connect wagon to wagon
                {
                    TrainPhysics.ConnectTrainCar(wagons[i].GetComponent <HingeJoint>(), wagons[i - 1].backJoint);
                }

                wagons[i].Locomotive = this;
            }
        }