Пример #1
0
 public void Initialize(VehicleController vc)
 {
     this.vc = vc;
     ReconstructGearList();
     initialShiftDuration = shiftDuration;
     UpdateRandomShiftDuration();
     UpdateRandomShiftPointAddition();
 }
Пример #2
0
 public void Initialize(VehicleController vc)
 {
     this.vc = vc;
     if (steeringWheel != null)
     {
         initialSteeringWheelRotation = steeringWheel.transform.localRotation.eulerAngles;
     }
 }
Пример #3
0
        public void Initialize(VehicleController vc)
        {
            this.vc = vc;

            audioMixer             = Resources.Load("VehicleAudioMixer") as AudioMixer;
            masterGroup            = audioMixer.FindMatchingGroups("Master")[0];
            engineMixerGroup       = audioMixer.FindMatchingGroups("Engine")[0];
            transmissionMixerGroup = audioMixer.FindMatchingGroups("Transmission")[0];
            surfaceNoiseMixerGroup = audioMixer.FindMatchingGroups("SurfaceNoise")[0];
            turboMixerGroup        = audioMixer.FindMatchingGroups("Turbo")[0];
            suspensionMixerGroup   = audioMixer.FindMatchingGroups("Suspension")[0];
            crashMixerGroup        = audioMixer.FindMatchingGroups("Crash")[0];
            otherMixerGroup        = audioMixer.FindMatchingGroups("Other")[0];

            // Remember initial states
            audioMixer.GetFloat("attenuation", out originalAttenuation);

            /*
             * IMPORTANT
             * When adding a new sound component also add it to the list below so it can be enabled / disabled when vehicle is activated or suspended.
             */
            components = new List <SoundComponent>
            {
                engineIdleComponent,
                engineStartStopComponent,
                skidComponent,
                surfaceComponent,
                turboFlutterComponent,
                turboWhistleComponent,
                transmissionWhineComponent,
                gearChangeComponent,
                airBrakeComponent,
                blinkerComponent,
                hornComponent,
                exhaustPopComponent
            };

            // Do not use following components if vehicle is trailer.
            if (!vc.trailer.isTrailer)
            {
                engineStartStopComponent.Initialize(vc, engineMixerGroup);
                engineIdleComponent.Initialize(vc, engineMixerGroup);
                exhaustPopComponent.Initialize(vc, engineMixerGroup);
                turboWhistleComponent.Initialize(vc, turboMixerGroup);
                turboFlutterComponent.Initialize(vc, turboMixerGroup);
                transmissionWhineComponent.Initialize(vc, transmissionMixerGroup);
                gearChangeComponent.Initialize(vc, transmissionMixerGroup);
                airBrakeComponent.Initialize(vc, otherMixerGroup);
                blinkerComponent.Initialize(vc, otherMixerGroup);
                hornComponent.Initialize(vc, otherMixerGroup);
            }

            skidComponent.Initialize(vc, surfaceNoiseMixerGroup);
            surfaceComponent.Initialize(vc, surfaceNoiseMixerGroup);
            crashComponent.Initialize(vc, crashMixerGroup);
            suspensionComponent.Initialize(vc, suspensionMixerGroup);
        }
Пример #4
0
        public void Initialize(VehicleController vc)
        {
            this.vc = vc;
            leftWheel.Initialize(vc);
            rightWheel.Initialize(vc);

            leftWheel.brakeCoefficient  = brakeCoefficient;
            rightWheel.brakeCoefficient = brakeCoefficient;
        }
Пример #5
0
        void SetCameras(VehicleController vc, bool state)
        {
            var cameras = vc.gameObject.GetComponentsInChildren <Camera>(true);

            foreach (Camera camera in cameras)
            {
                camera.gameObject.SetActive(state);
            }
        }
Пример #6
0
 /// <summary>
 /// Changes vehicle to a vehicle with the requested name if there is such a vehicle.
 /// </summary>
 public void ChangeVehicle(VehicleController vc)
 {
     for (int i = 0; i < vehicles.Count; i++)
     {
         if (vehicles[i] == vc)
         {
             ChangeVehicle(i);
             return;
         }
     }
 }
Пример #7
0
        public override void Initialize(VehicleController vc, AudioMixerGroup amg)
        {
            this.vc = vc;
            this.audioMixerGroup = amg;

            if (Clip != null)
            {
                Source = vc.gameObject.AddComponent <AudioSource>();
                vc.sound.SetAudioSourceDefaults(Source, false, false, volume, Clip);
                RegisterSources();
            }
        }
Пример #8
0
        public void Initialize(VehicleController vc)
        {
            this.vc = vc;

            try
            {
                trailerGOs = GameObject.FindGameObjectsWithTag(trailersTag);
            }
            catch
            {
                Debug.LogWarning("'" + trailersTag + "' tag does not exist.");
            }
        }
Пример #9
0
        public override void Initialize(VehicleController vc, AudioMixerGroup amg)
        {
            this.vc = vc;
            this.audioMixerGroup = amg;

            if (Clips.Count != 0)
            {
                // Initialize gear shift sound
                Source = vc.gameObject.AddComponent <AudioSource>();
                vc.sound.SetAudioSourceDefaults(Source, false, false, volume, RandomClip);
                RegisterSources();
            }
        }
Пример #10
0
        public void Initialize(VehicleController vc)
        {
            this.vc = vc;

            float radiusSum = 0;

            foreach (Wheel wheel in vc.Wheels)
            {
                wheel.WheelController.trackedVehicle = true;
                radiusSum += wheel.Radius;
            }
            averageRadius = radiusSum / vc.Wheels.Count;
        }
Пример #11
0
        public override void Initialize(VehicleController vc, AudioMixerGroup amg)
        {
            this.vc = vc;
            this.audioMixerGroup = amg;

            if (Clip != null)
            {
                Source = vc.gameObject.AddComponent <AudioSource>();
                vc.sound.SetAudioSourceDefaults(Source, false, false);
                RegisterSources();
            }

            vc.damage.OnCollision.AddListener(Play);
        }
Пример #12
0
        public override void Initialize(VehicleController vc, AudioMixerGroup amg)
        {
            this.vc = vc;
            this.audioMixerGroup = amg;

            // Initilize start/stop source
            if (Clips.Count > 1)
            {
                Source = vc.gameObject.AddComponent <AudioSource>();
                vc.sound.SetAudioSourceDefaults(Source, false, false);
                RegisterSources();
                Source.enabled = false;
            }
        }
Пример #13
0
        public void Initialize(VehicleController vc, Wheel wheel)
        {
            maxTris = maxMarks * 6;

            this.vc    = vc;
            this.wheel = wheel;

            // Calculate common variables
            markWidth         = wheel.Width;
            minSqrDistance    = vc.effects.skidmarks.minDistance * vc.effects.skidmarks.minDistance;
            groundEntityCount = vc.groundDetection.groundEntities.Count;

            CreateNewSnapshot();
        }
Пример #14
0
        public void Initialize(VehicleController vc)
        {
            this.vc = vc;

            // Find all mesh filters of the vehicle
            MeshFilter[] mfs = vc.transform.GetComponentsInChildren <MeshFilter>();
            foreach (MeshFilter mf in mfs)
            {
                if (!deformableMeshFilters.Contains(mf))
                {
                    deformableMeshFilters.Add(mf);
                    originalMeshes.Add(mf.sharedMesh);
                }
            }
        }
Пример #15
0
        public override void Initialize(VehicleController vc, AudioMixerGroup amg)
        {
            this.vc = vc;
            this.audioMixerGroup = amg;

            // Initialize engine sound
            if (Clip != null)
            {
                Source = vc.gameObject.AddComponent <AudioSource>();
                vc.sound.SetAudioSourceDefaults(Source, true, true, 0f, Clip);
                RegisterSources();
                Source.Stop();
                SetVolume(0);
            }
        }
Пример #16
0
 public void Update(VehicleController vc)
 {
     foreach (Axle axle in vc.axles)
     {
         foreach (Wheel wheel in vc.Wheels)
         {
             if (wheel.WheelController.isGrounded)
             {
                 float   forceMag = wheel.WheelController.sideFriction.force * Mathf.Clamp01(Mathf.Abs(wheel.WheelController.sideFriction.slip)) * intensity * (vc.Speed / 6f);
                 Vector3 force    = wheel.WheelController.wheelHit.sidewaysDir * -forceMag;
                 vc.vehicleRigidbody.AddForceAtPosition(force, wheel.WheelController.wheelHit.groundPoint);
             }
         }
     }
 }
Пример #17
0
        public void Update(VehicleController vc)
        {
            if (!enabled)
            {
                return;
            }

            if (solidAxle)
            {
                if (axleBones.Count == vc.axles.Count && axleBones != null)
                {
                    for (int i = 0; i < axleBones.Count; i++)
                    {
                        // Adjust axle position
                        Axle axle = vc.axles[i];

                        Vector3 position = (axle.leftWheel.WheelController.springTravelPoint + axle.rightWheel.WheelController.springTravelPoint) / 2f;
                        axleBones[i].position = position;
                        axleBones[i].LookAt(axle.leftWheel.WheelController.springTravelPoint, vc.transform.up);
                        axleBones[i].Rotate(0, 90, 0);

                        // Adjust camber
                        float camberAngle = VehicleController.AngleSigned(vc.transform.right, axleBones[i].right, vc.transform.forward);
                        axle.leftWheel.WheelController.SetCamber(camberAngle);
                        axle.rightWheel.WheelController.SetCamber(-camberAngle);
                    }
                }
                else
                {
                    Debug.LogError("Number of axle bones must be the same as the number of axles.");
                }
            }
            else
            {
                if (wheelBones.Count == vc.Wheels.Count && wheelBones != null)
                {
                    for (int i = 0; i < wheelBones.Count; i++)
                    {
                        wheelBones[i].position = vc.Wheels[i].WheelController.springTravelPoint;
                    }
                }
                else
                {
                    Debug.LogError("Number of wheel bones must be the same as the number of wheels.");
                }
            }
        }
Пример #18
0
        public override void Initialize(VehicleController vc, AudioMixerGroup amg)
        {
            this.vc = vc;
            this.audioMixerGroup = amg;

            smoothedVolume = new HysteresisSmoothedValue(0, 0.25f, 0.5f);
            smoothedPitch  = new HysteresisSmoothedValue(0, 0.25f, 0.5f);

            foreach (Wheel wheel in vc.Wheels)
            {
                AudioSource a = wheel.ControllerGO.AddComponent <AudioSource>();
                vc.sound.SetAudioSourceDefaults(a, true, true);
                Sources.Add(a);
            }

            RegisterSources();
        }
Пример #19
0
        public void Update()
        {
            if (Input.GetButtonDown("RepairVehicle"))
            {
                if (IsInGarage)
                {
                    vehicle = GameObject.FindWithTag("Vehicle");

                    VehicleController otherScript = vehicle.GetComponent <VehicleController>();
                    otherScript.damage.Repair();
                }
                else
                {
                    Debug.Log("vous devez entrer dans un garage");
                }
            }
        }
Пример #20
0
        public void Update(VehicleController vc)
        {
            if (deactivateOnVerticalInput && (vc.input.Vertical < 0.1f || vc.input.Vertical > 0.1f))
            {
                enabled = false;
            }

            speedDiff  = vc.ForwardVelocity - targetSpeed;
            correction = -Mathf.Sign(speedDiff) * Mathf.Pow(speedDiff, 2f) * 0.5f;
            vertical   = useBrakesOnOverspeed ?
                         Mathf.Clamp(correction, -1f, 0f) * overspeedBrakeIntensity + Mathf.Clamp(correction, 0f, 1f)
                : Mathf.Clamp(correction, 0f, 1f);

            vc.input.Vertical = Mathf.Lerp(prevVerticalInput, vertical, Time.fixedDeltaTime * 10f);

            prevVerticalInput = vc.input.Vertical;
        }
Пример #21
0
        private void DetachTrailer()
        {
            if (trailerVC.trailer.trailerStand != null)
            {
                trailerVC.trailer.trailerStand.SetActive(true);
            }
            trailerVC.trailer.attached = false;
            //trailerVC.input = null;
            trailerVC.effects.lights.enabled = false;
            vc.trailer.attached = false;

            GameObject.Destroy(cj);
            cj = null;
            trailerVC.Active = false;
            trailerVC        = null;

            vc.input.trailerAttachDetach = false;
        }
Пример #22
0
        public override void Initialize(VehicleController vc, AudioMixerGroup amg)
        {
            this.vc = vc;
            this.audioMixerGroup = amg;

            foreach (Wheel wheel in vc.Wheels)
            {
                // Initialize surface audio source
                AudioSource a = wheel.ControllerGO.AddComponent <AudioSource>();
                vc.sound.SetAudioSourceDefaults(a, false, false, volume);
                Sources.Add(a);

                bool hasHit = true;
                prevHasHits.Add(hasHit);
            }

            RegisterSources();
        }
Пример #23
0
        public void Initialize(VehicleController vc)
        {
            this.vc = vc;

            float radiusSum = 0;

            foreach (Wheel wheel in vc.Wheels)
            {
                wheel.WheelController.trackedVehicle = true;
                radiusSum += wheel.Radius;
            }
            averageRadius = radiusSum / vc.Wheels.Count;

            if (trackedVehicle)
            {
                vc.vehicleRigidbody.maxAngularVelocity = turnSpeedLimit;
            }
        }
Пример #24
0
        public void Update()
        {
            if (Input.GetButtonDown("RefuelVehicle"))
            {
                if (IsInStation)
                {
                    vehicle = GameObject.FindWithTag("Vehicle");

                    VehicleController otherScript = vehicle.GetComponent <VehicleController>();
                    otherScript.fuel.amount = otherScript.fuel.capacity;
                    label.text = "Le plein est fait. Merci de votre visite.";
                }
                else
                {
                    Debug.Log("vous devez entrer dans une station pour faire le plein");
                }
            }
        }
Пример #25
0
        public void Initialize(VehicleController vc)
        {
            this.vc = vc;

            if (vc.groundDetection != null)
            {
                foreach (Wheel wheel in vc.Wheels)
                {
                    SurfaceParticles particle = new SurfaceParticles();
                    particle.Initialize(vc, wheel);
                    particleList.Add(particle);
                }
            }

            skidmarks.Initialize(vc);
            exhausts.Initialize(vc);
            exhaustFlash.Initialize(vc);
            lights.Initialize(vc);
        }
Пример #26
0
        public void Update()
        {
            // Set camber only if it has not already been set by the WC3D's inspector and if axle is not solid (in which case camber is set automatically).
            if (!(geometry.isSolid || (geometry.camberAtBottom == 0 && geometry.camberAtTop == 0)))
            {
                leftWheel.WheelController.SetCamber(geometry.camberAtTop, geometry.camberAtBottom);
                rightWheel.WheelController.SetCamber(geometry.camberAtTop, geometry.camberAtBottom);
            }

            // Apply anti roll bar
            if (geometry.antiRollBarForce != 0)
            {
                float leftTravel  = leftWheel.SpringTravel;
                float rightTravel = rightWheel.SpringTravel;

                // Anti-roll bar is linear to prevent possible jitter at lower update rates.
                float arf = (leftTravel - rightTravel) * geometry.antiRollBarForce;

                if (leftWheel.IsGrounded && rightWheel.IsGrounded)
                {
                    vc.vehicleRigidbody.AddForceAtPosition(leftWheel.ControllerTransform.up * -arf, leftWheel.ControllerTransform.position);
                    vc.vehicleRigidbody.AddForceAtPosition(rightWheel.ControllerTransform.up * arf, rightWheel.ControllerTransform.position);
                }
            }

            // Calculate camber for solid axle
            if (geometry.isSolid)
            {
                // Center point of imaginary axle
                Vector3 position  = (leftWheel.WheelController.springTravelPoint + rightWheel.WheelController.springTravelPoint) / 2f;
                Vector3 direction = position - leftWheel.WheelController.springTravelPoint;

                // Calculate camber from the mid point
                float camberAngle = VehicleController.AngleSigned(vc.transform.right, direction, vc.transform.forward);
                camberAngle = Mathf.Clamp(camberAngle, -25f, 25f);

                // Set camber
                leftWheel.WheelController.SetCamber(camberAngle);
                rightWheel.WheelController.SetCamber(-camberAngle);
                geometry.camberAtBottom = geometry.camberAtTop = camberAngle;
            }
        }
        public override void OnInspectorGUI()
        {
            VehicleController vehicleController = (VehicleController)target;

            GUILayout.Space(40);
            lastRect = GUILayoutUtility.GetLastRect();

            DrawDefaultInspector();
            TrailerSettings();
            GeneralSettings();

            if (!vehicleController.GetComponent <DesktopInputManager>() &&
                !vehicleController.GetComponent <MobileInputManager>())
            {
                EditorGUILayout.HelpBox(
                    "Using input from vehicle manager or other external source. Check 'Input' section inside manual for other options.",
                    MessageType.Info, true);
            }

            if (Time.fixedDeltaTime > 0.017f)
            {
                EditorGUILayout.HelpBox(
                    "Fixed Delta Time is " + Time.fixedDeltaTime + ". It is recommended to use 0.017 or lower.",
                    MessageType.Warning, true);
            }

            if (logo != null)
            {
                float width      = Screen.width;
                float height     = 53f;
                float logoHeight = height * 0.7f;
                float logoWidth  = logoHeight * 8.34f;

                GUIDrawRect(new Rect(0, lastRect.y + 3, width, height), new Color(0.89f, 0.89f, 0.89f));
                GUI.DrawTexture(
                    new Rect(lastRect.x + width * 0.5f - logoWidth * 0.55f,
                             lastRect.y + height * 0.5f - logoHeight * 0.4f, logoWidth, logoHeight), logo);
            }

            serializedObject.ApplyModifiedProperties();
            EditorUtility.SetDirty(vehicleController);
        }
Пример #28
0
        public void Update(VehicleController vc)
        {
            // Drift assist
            if (intensity > 0)
            {
                Vector3 normVel    = vc.vehicleRigidbody.velocity.normalized;
                Vector3 vehicleDir = vc.transform.forward;
                float   driftAngle = VehicleController.AngleSigned(normVel, vehicleDir, vc.transform.up);
                driftAngle = Mathf.Sign(driftAngle) * Mathf.Clamp(Mathf.Abs(Mathf.Clamp(driftAngle, -90f, 90f)), 0f, Mathf.Infinity);

                if (vc.axles.Count > 0)
                {
                    Axle    a        = vc.axles[vc.axles.Count - 1];
                    Vector3 center   = (a.leftWheel.ControllerTransform.position + a.rightWheel.ControllerTransform.position) / 2f;
                    float   forceMag = driftAngle * Mathf.Lerp(0f, vc.vehicleRigidbody.mass, vc.Speed / 15f) * intensity;
                    Vector3 force    = vc.transform.right * forceMag;
                    vc.vehicleRigidbody.AddForceAtPosition(force, center);
                }
            }
        }
Пример #29
0
        public void Initialize(VehicleController vc)
        {
            this.vc = vc;
            forcedInduction.Initialize(vc);

            starting   = false;
            stopping   = false;
            wasRunning = false;
            isRunning  = false;

            if (vc.sound.engineStartStopComponent.Clips.Count > 0)
            {
                startDuration = vc.sound.engineStartStopComponent.Clips[0].length * 0.9f;
            }

            if (!isRunning && runOnStartup)
            {
                Start();
            }
        }
Пример #30
0
        void Update()
        {
            if (vehicleChanger != null)
            {
                vehicleController = vehicleChanger.ActiveVehicleController;
            }

#if PHOTON_MULTIPLAYER
            // Check if selected vehicle has photon view and if it does, if it is mine.
            PhotonView photonView = vehicleController?.GetComponent <PhotonView>();
            if (photonView)
            {
                if (!photonView.isMine)
                {
                    return;
                }
            }
#endif

            UpdateSteering();
        }