Esempio n. 1
0
    /// <summary>
    /// Enable / Disable Exhaust Flame Particles.
    /// </summary>
    public static void SetExhaustFlame(RCC_CarControllerV3 car, bool state)
    {
        RCC_Exhaust[] exhausts = car.GetComponentsInChildren <RCC_Exhaust> ();

        foreach (RCC_Exhaust exhaust in exhausts)
        {
            exhaust.previewFlames = state;
        }
    }
Esempio n. 2
0
    void SetLayerMask()
    {
        Transform[] allTransforms = carScript.GetComponentsInChildren <Transform>();

        foreach (Transform t in allTransforms)
        {
            t.gameObject.layer = (int)Mathf.Log(RCC_Settings.Instance.vehicleLayer.value, 2);
        }
    }
    /// <summary>
    /// Save all stats with PlayerPrefs.
    /// </summary>
    public static void SaveStats(RCC_CarControllerV3 vehicle)
    {
        if (!CheckVehicle(vehicle))
        {
            return;
        }

        PlayerPrefs.SetFloat(vehicle.transform.name + "_FrontCamber", vehicle.FrontLeftWheelCollider.camber);
        PlayerPrefs.SetFloat(vehicle.transform.name + "_RearCamber", vehicle.RearLeftWheelCollider.camber);

        PlayerPrefs.SetFloat(vehicle.transform.name + "_FrontSuspensionsDistance", vehicle.FrontLeftWheelCollider.wheelCollider.suspensionDistance);
        PlayerPrefs.SetFloat(vehicle.transform.name + "_RearSuspensionsDistance", vehicle.RearLeftWheelCollider.wheelCollider.suspensionDistance);

        PlayerPrefs.SetFloat(vehicle.transform.name + "_FrontSuspensionsSpring", vehicle.FrontLeftWheelCollider.wheelCollider.suspensionSpring.spring);
        PlayerPrefs.SetFloat(vehicle.transform.name + "_RearSuspensionsSpring", vehicle.RearLeftWheelCollider.wheelCollider.suspensionSpring.spring);

        PlayerPrefs.SetFloat(vehicle.transform.name + "_FrontSuspensionsDamper", vehicle.FrontLeftWheelCollider.wheelCollider.suspensionSpring.damper);
        PlayerPrefs.SetFloat(vehicle.transform.name + "_RearSuspensionsDamper", vehicle.RearLeftWheelCollider.wheelCollider.suspensionSpring.damper);

        PlayerPrefs.SetFloat(vehicle.transform.name + "_MaximumSpeed", vehicle.maxspeed);
        PlayerPrefs.SetFloat(vehicle.transform.name + "_MaximumBrake", vehicle.brakeTorque);
        PlayerPrefs.SetFloat(vehicle.transform.name + "_MaximumTorque", vehicle.engineTorque);

        PlayerPrefs.SetString(vehicle.transform.name + "_DrivetrainMode", vehicle._wheelTypeChoise.ToString());

        PlayerPrefs.SetFloat(vehicle.transform.name + "_GearShiftingThreshold", vehicle.gearShiftingThreshold);
        PlayerPrefs.SetFloat(vehicle.transform.name + "_ClutchingThreshold", vehicle.clutchInertia);

        RCC_PlayerPrefsX.SetBool(vehicle.transform.name + "_CounterSteering", vehicle.applyCounterSteering);

        foreach (RCC_Light _light in vehicle.GetComponentsInChildren <RCC_Light>())
        {
            if (_light.lightType == RCC_Light.LightType.HeadLight)
            {
                RCC_PlayerPrefsX.SetColor(vehicle.transform.name + "_HeadlightsColor", _light.GetComponentInChildren <Light>().color);
                break;
            }
        }

        ParticleSystem ps = vehicle.RearLeftWheelCollider.allWheelParticles[0];

        ParticleSystem.MainModule psmain = ps.main;

        RCC_PlayerPrefsX.SetColor(vehicle.transform.name + "_WheelsSmokeColor", psmain.startColor.color);

        RCC_PlayerPrefsX.SetBool(vehicle.transform.name + "_ABS", vehicle.ABS);
        RCC_PlayerPrefsX.SetBool(vehicle.transform.name + "_ESP", vehicle.ESP);
        RCC_PlayerPrefsX.SetBool(vehicle.transform.name + "_TCS", vehicle.TCS);
        RCC_PlayerPrefsX.SetBool(vehicle.transform.name + "_SH", vehicle.steeringHelper);

        RCC_PlayerPrefsX.SetBool(vehicle.transform.name + "NOS", vehicle.useNOS);
        RCC_PlayerPrefsX.SetBool(vehicle.transform.name + "Turbo", vehicle.useTurbo);
        RCC_PlayerPrefsX.SetBool(vehicle.transform.name + "ExhaustFlame", vehicle.useExhaustFlame);
        RCC_PlayerPrefsX.SetBool(vehicle.transform.name + "SteeringSensitivity", vehicle.steerAngleSensitivityAdjuster);
        RCC_PlayerPrefsX.SetBool(vehicle.transform.name + "RevLimiter", vehicle.useRevLimiter);
        RCC_PlayerPrefsX.SetBool(vehicle.transform.name + "ClutchMargin", vehicle.useClutchMarginAtFirstGear);
    }
Esempio n. 4
0
    /// <summary>
    /// Set Smoke Color.
    /// </summary>
    public static void SetSmokeColor(RCC_CarControllerV3 car, int indexOfGroundMaterial, Color color)
    {
        RCC_WheelCollider[] wheels = car.GetComponentsInChildren <RCC_WheelCollider> ();

        foreach (RCC_WheelCollider wheel in wheels)
        {
            for (int i = 0; i < wheel.allWheelParticles.Count; i++)
            {
                wheel.allWheelParticles [i].startColor = color;
            }
        }
    }
Esempio n. 5
0
    void SetLayerMask()
    {
        if (string.IsNullOrEmpty(RCC_Settings.Instance.RCCLayer))
        {
            Debug.LogError("RCC Layer is missing in RCC Settings. Go to Tools --> BoneCracker Games --> RCC --> Edit Settings, and set the layer of RCC.");
            return;
        }

        if (string.IsNullOrEmpty(RCC_Settings.Instance.RCCTag))
        {
            Debug.LogError("RCC Tag is missing in RCC Settings. Go to Tools --> BoneCracker Games --> RCC --> Edit Settings, and set the tag of RCC.");
            return;
        }

        Transform[] allTransforms = carScript.GetComponentsInChildren <Transform>();

        foreach (Transform t in allTransforms)
        {
            int layerInt = LayerMask.NameToLayer(RCC_Settings.Instance.RCCLayer);

            if (layerInt >= 0 && layerInt <= 31)
            {
                t.gameObject.layer = LayerMask.NameToLayer(RCC_Settings.Instance.RCCLayer);

                if (!carScript.AIController)
                {
                    if (RCC_Settings.Instance.tagAllChildrenGameobjects)
                    {
                        t.gameObject.transform.tag = RCC_Settings.Instance.RCCTag;
                    }
                    else
                    {
                        carScript.transform.gameObject.tag = RCC_Settings.Instance.RCCTag;
                    }
                }
                else
                {
                    t.gameObject.transform.tag = "Untagged";
                }
            }
            else
            {
                Debug.LogError("RCC Layer selected in RCC Settings doesn't exist on your Tags & Layers. Go to Edit --> Project Settings --> Tags & Layers, and create a new layer named ''" + RCC_Settings.Instance.RCCLayer + "''.");
                Debug.LogError("From now on, ''Setting Tags and Layers'' disabled in RCCSettings! You can enable this when you created this layer.");
                foreach (Transform tr in allTransforms)
                {
                    tr.gameObject.layer = LayerMask.NameToLayer("Default");
                }
                RCC_Settings.Instance.setTagsAndLayers = false;
                return;
            }
        }
    }
Esempio n. 6
0
    /// <summary>
    /// Set Headlights Color.
    /// </summary>
    public static void SetHeadlightsColor(RCC_CarControllerV3 car, Color color)
    {
        RCC_Light[] lights = car.GetComponentsInChildren <RCC_Light> ();
        car.lowBeamHeadLightsOn = true;

        foreach (RCC_Light l in lights)
        {
            if (l.lightType == RCC_Light.LightType.HeadLight)
            {
                l.GetComponent <Light>().color = color;
            }
        }
    }
Esempio n. 7
0
    /// <summary>
    /// Enable / Disable Exhaust Flame Particles.
    /// </summary>
    public static void SetExhaustFlame(RCC_CarControllerV3 vehicle, bool state)
    {
        if (!CheckVehicle(vehicle))
        {
            return;
        }

        RCC_Exhaust[] exhausts = vehicle.GetComponentsInChildren <RCC_Exhaust> ();

        foreach (RCC_Exhaust exhaust in exhausts)
        {
            exhaust.previewFlames = state;
        }
    }
Esempio n. 8
0
    /// <summary>
    /// Set Rear Wheel Cambers.
    /// </summary>
    public static void SetRearCambers(RCC_CarControllerV3 car, float camberAngle)
    {
        RCC_WheelCollider[] wc = car.GetComponentsInChildren <RCC_WheelCollider> ();

        foreach (RCC_WheelCollider w in wc)
        {
            if (w != car.FrontLeftWheelCollider && w != car.FrontRightWheelCollider)
            {
                w.camber = camberAngle;
            }
        }

        UpdateRCC(car);
    }
Esempio n. 9
0
    /// <summary>
    /// Set Headlights Color.
    /// </summary>
    public static void SetHeadlightsColor(RCC_CarControllerV3 vehicle, Color color)
    {
        if (!CheckVehicle(vehicle))
        {
            return;
        }

        vehicle.lowBeamHeadLightsOn = true;
        RCC_Light[] lights = vehicle.GetComponentsInChildren <RCC_Light> ();

        foreach (RCC_Light l in lights)
        {
            if (l.lightType == RCC_Light.LightType.HeadLight || l.lightType == RCC_Light.LightType.HighBeamHeadLight || l.lightType == RCC_Light.LightType.ParkLight)
            {
                l.GetComponent <Light>().color = color;
            }
        }
    }
Esempio n. 10
0
    /// <summary>
    /// Set Rear Wheel Cambers.
    /// </summary>
    public static void SetRearCambers(RCC_CarControllerV3 vehicle, float camberAngle)
    {
        if (!CheckVehicle(vehicle))
        {
            return;
        }

        RCC_WheelCollider[] wc = vehicle.GetComponentsInChildren <RCC_WheelCollider> ();

        foreach (RCC_WheelCollider w in wc)
        {
            if (w != vehicle.FrontLeftWheelCollider && w != vehicle.FrontRightWheelCollider)
            {
                w.camber = camberAngle;
            }
        }

        OverrideRCC(vehicle);
    }
Esempio n. 11
0
    /// <summary>
    /// Set Smoke Color.
    /// </summary>
    public static void SetSmokeColor(RCC_CarControllerV3 vehicle, int indexOfGroundMaterial, Color color)
    {
        if (!CheckVehicle(vehicle))
        {
            return;
        }

        RCC_WheelCollider[] wheels = vehicle.GetComponentsInChildren <RCC_WheelCollider> ();

        foreach (RCC_WheelCollider wheel in wheels)
        {
            for (int i = 0; i < wheel.allWheelParticles.Count; i++)
            {
                ParticleSystem            ps     = wheel.allWheelParticles[i];
                ParticleSystem.MainModule psmain = ps.main;
                color.a           = psmain.startColor.color.a;
                psmain.startColor = color;
            }
        }
    }
Esempio n. 12
0
    void SetLayerMask()
    {
        if (string.IsNullOrEmpty(RCC_Settings.Instance.RCCLayer))
        {
            Debug.LogError("RCC Layer is missing in RCC Settings. Go to Tools --> BoneCracker Games --> RCC --> Edit Settings, and set the layer of RCC.");
            return;
        }

        if (string.IsNullOrEmpty(RCC_Settings.Instance.RCCTag))
        {
            Debug.LogError("RCC Tag is missing in RCC Settings. Go to Tools --> BoneCracker Games --> RCC --> Edit Settings, and set the tag of RCC.");
            return;
        }

        Transform[] allTransforms = carScript.GetComponentsInChildren <Transform>();

        foreach (Transform t in allTransforms)
        {
            t.gameObject.layer = LayerMask.NameToLayer(RCC_Settings.Instance.RCCLayer);
            if (!carScript.AIController)
            {
                if (RCC_Settings.Instance.tagAllChildrenGameobjects)
                {
                    t.gameObject.transform.tag = RCC_Settings.Instance.RCCTag;
                }
                else
                {
                    carScript.transform.gameObject.tag = RCC_Settings.Instance.RCCTag;
                }
            }
            else
            {
                t.gameObject.transform.tag = "Untagged";
            }
        }
    }
Esempio n. 13
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        carScript          = (RCC_CarControllerV3)target;
        defBackgroundColor = GUI.backgroundColor;

        if (!carScript.GetComponent <RCC_AICarController>())
        {
            carScript.AIController = false;
        }

        if (firstInit)
        {
            SetDefaultSettings();
            SetDefaultPrefabs();
        }

        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.Space();

        EditorGUILayout.BeginHorizontal();

        if (WheelSettings)
        {
            GUI.backgroundColor = Color.gray;
        }
        else
        {
            GUI.backgroundColor = defBackgroundColor;
        }

        if (GUILayout.Button(wheelIcon))
        {
            WheelSettings = EnableCategory();
        }

        if (SteerSettings)
        {
            GUI.backgroundColor = Color.gray;
        }
        else
        {
            GUI.backgroundColor = defBackgroundColor;
        }

        if (GUILayout.Button(steerIcon))
        {
            SteerSettings = EnableCategory();
        }

        if (SuspensionSettings)
        {
            GUI.backgroundColor = Color.gray;
        }
        else
        {
            GUI.backgroundColor = defBackgroundColor;
        }

        if (GUILayout.Button(suspensionIcon))
        {
            SuspensionSettings = EnableCategory();
        }

        if (Configurations)
        {
            GUI.backgroundColor = Color.gray;
        }
        else
        {
            GUI.backgroundColor = defBackgroundColor;
        }

        if (GUILayout.Button(configIcon))
        {
            Configurations = EnableCategory();
        }

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();

        if (StabilitySettings)
        {
            GUI.backgroundColor = Color.gray;
        }
        else
        {
            GUI.backgroundColor = defBackgroundColor;
        }

        if (GUILayout.Button(stabilityIcon))
        {
            StabilitySettings = EnableCategory();
        }

        if (LightSettings)
        {
            GUI.backgroundColor = Color.gray;
        }
        else
        {
            GUI.backgroundColor = defBackgroundColor;
        }

        if (GUILayout.Button(lightIcon))
        {
            LightSettings = EnableCategory();
        }

        if (SoundSettings)
        {
            GUI.backgroundColor = Color.gray;
        }
        else
        {
            GUI.backgroundColor = defBackgroundColor;
        }

        if (GUILayout.Button(soundIcon))
        {
            SoundSettings = EnableCategory();
        }

        if (DamageSettings)
        {
            GUI.backgroundColor = Color.gray;
        }
        else
        {
            GUI.backgroundColor = defBackgroundColor;
        }

        if (GUILayout.Button(damageIcon))
        {
            DamageSettings = EnableCategory();
        }

        GUI.backgroundColor = defBackgroundColor;
        EditorGUILayout.EndHorizontal();

        if (WheelSettings)
        {
            EditorGUILayout.Space();
            GUI.color = Color.cyan;
            EditorGUILayout.HelpBox("Wheel Settings", MessageType.None);
            GUI.color = defBackgroundColor;
            EditorGUILayout.Space();

            EditorGUILayout.Space();
            if (GUILayout.Button("Create Necessary Gameobject Groups"))
            {
                Transform[] objects             = carScript.gameObject.GetComponentsInChildren <Transform>();
                bool        didWeHaveThisObject = false;

                foreach (Transform g in objects)
                {
                    if (g.name == "Chassis")
                    {
                        didWeHaveThisObject = true;
                    }
                }

                if (!didWeHaveThisObject)
                {
                    GameObject chassis = new GameObject("Chassis");
                    chassis.transform.parent        = carScript.transform;
                    chassis.transform.localPosition = Vector3.zero;
                    chassis.transform.localScale    = Vector3.one;
                    chassis.transform.rotation      = carScript.transform.rotation;
                    carScript.chassis = chassis;
                    GameObject wheelModels = new GameObject("Wheel Models");
                    wheelModels.transform.parent        = chassis.transform;
                    wheelModels.transform.localPosition = Vector3.zero;
                    wheelModels.transform.localScale    = Vector3.one;
                    wheelModels.transform.rotation      = carScript.transform.rotation;
                    GameObject COM = new GameObject("COM");
                    COM.transform.parent        = carScript.transform;
                    COM.transform.localPosition = Vector3.zero;
                    COM.transform.localScale    = Vector3.one;
                    COM.transform.rotation      = carScript.transform.rotation;
                    carScript.COM = COM.transform;
                }
                else
                {
                    EditorUtility.DisplayDialog("Vehicle has these groups already!", "Vehicle has these groups already!", "Ok");
                }
            }

            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("FrontLeftWheelTransform"), new GUIContent("Front Left Wheel Model", "Select front left wheel of your car."), false);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("FrontRightWheelTransform"), new GUIContent("Front Right Wheel Model", "Select front right wheel of your car."), false);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("RearLeftWheelTransform"), new GUIContent("Rear Left Wheel Model", "Select rear left wheel of your car."), false);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("RearRightWheelTransform"), new GUIContent("Rear Right Wheel Model", "Select rear right wheel of your car."), false);
            EditorGUILayout.Space();

            if (GUILayout.Button("Create Wheel Colliders"))
            {
                WheelCollider[] wheelColliders = carScript.gameObject.GetComponentsInChildren <WheelCollider>();

                if (wheelColliders.Length >= 1)
                {
                    EditorUtility.DisplayDialog("Vehicle has Wheel Colliders already!", "Vehicle has Wheel Colliders already!", "Ok");
                }
                else
                {
                    carScript.CreateWheelColliders();
                }
            }

            if (carScript.FrontLeftWheelTransform == null || carScript.FrontRightWheelTransform == null || carScript.RearLeftWheelTransform == null || carScript.RearRightWheelTransform == null)
            {
                EditorGUILayout.HelpBox("Select all of your Wheel Models before creating Wheel Colliders", MessageType.Error);
            }

            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("FrontLeftWheelCollider"), new GUIContent("Front Left WheelCollider", "WheelColliders are generated when you click ''Create WheelColliders'' button. But if you want to create your WheelCollider yourself, select corresponding WheelCollider for each wheel after you created."), false);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("FrontRightWheelCollider"), new GUIContent("Front Right WheelCollider", "WheelColliders are generated when you click ''Create WheelColliders'' button. But if you want to create your WheelCollider yourself, select corresponding WheelCollider for each wheel after you created."), false);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("RearLeftWheelCollider"), new GUIContent("Rear Left WheelCollider", "WheelColliders are generated when you click ''Create WheelColliders'' button. But if you want to create your WheelCollider yourself, select corresponding WheelCollider for each wheel after you created."), false);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("RearRightWheelCollider"), new GUIContent("Rear Right WheelCollider", "WheelColliders are generated when you click ''Create WheelColliders'' button. But if you want to create your WheelCollider yourself, select corresponding WheelCollider for each wheel after you created."), false);
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("ExtraRearWheelsTransform"), new GUIContent("Extra Rear Wheel Models", "In case of if your vehicle has extra wheels."), true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("ExtraRearWheelsCollider"), new GUIContent("Extra Rear Wheel Colliders", "In case of if your vehicle has extra wheels."), true);
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("applyEngineTorqueToExtraRearWheelColliders"), new GUIContent("Apply Engine Torque To Extra Rear Wheels", "Applies Engine Torque To Extra Rear Wheels."), false);
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("SteeringWheel"), new GUIContent("Interior Steering Wheel Model", "In case of if your vehicle has individual steering wheel model in interior."), false);
            EditorGUILayout.Space();
        }

        if (SteerSettings)
        {
            EditorGUILayout.Space();
            GUI.color = Color.cyan;
            EditorGUILayout.HelpBox("Steer Settings", MessageType.None);
            GUI.color = defBackgroundColor;
            EditorGUILayout.Space();

            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("steerAngle"), new GUIContent("Maximum Steer Angle", "Maximum steer angle for your vehicle."), false);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("highspeedsteerAngle"), new GUIContent("Maximum Steer Angle At ''X'' Speed", "Maximum steer angle at highest speed."), false);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("highspeedsteerAngleAtspeed"), new GUIContent("''X'' Speed", "Steer Angle At Highest Speed."), false);
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("antiRollFrontHorizontal"), new GUIContent("Anti Roll Front Horizontal", "Anti Roll Force for prevents flip overs."));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("antiRollRearHorizontal"), new GUIContent("Anti Roll Rear Horizontal", "Anti Roll Force for prevents flip overs."));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("antiRollVertical"), new GUIContent("Anti Roll Forward", "Anti Roll Force for preventing flip overs."));
        }

        if (SuspensionSettings)
        {
            EditorGUILayout.Space();
            GUI.color = Color.cyan;
            EditorGUILayout.HelpBox("Suspension Settings", MessageType.None);
            GUI.color = defBackgroundColor;
            EditorGUILayout.Space();

            if (!carScript.FrontLeftWheelCollider || !carScript.FrontRightWheelCollider || !carScript.RearLeftWheelCollider || !carScript.RearRightWheelCollider)
            {
                EditorGUILayout.HelpBox("Vehicle Missing Wheel Colliders. Be Sure You Have Created Wheel Colliders Before Adjusting Suspensions", MessageType.Error);
                return;
            }

            if (Selection.gameObjects.Length > 1)
            {
                EditorGUILayout.HelpBox("Multiple Editing Suspensions Is Not Allowed", MessageType.Error);
                return;
            }

            JointSpring frontSspring = carScript.FrontLeftWheelCollider.wheelCollider.suspensionSpring;
            JointSpring rearSpring   = carScript.RearLeftWheelCollider.wheelCollider.suspensionSpring;

            GUILayout.BeginHorizontal();

            if (FrontSuspension)
            {
                GUI.backgroundColor = Color.gray;
            }
            else
            {
                GUI.backgroundColor = defBackgroundColor;
            }

            if (GUILayout.Button("Front Suspensions"))
            {
                FrontSuspension = true;
                RearSuspension  = false;
            }

            if (RearSuspension)
            {
                GUI.backgroundColor = Color.gray;
            }
            else
            {
                GUI.backgroundColor = defBackgroundColor;
            }

            if (GUILayout.Button("Rear Suspensions"))
            {
                FrontSuspension = false;
                RearSuspension  = true;
            }

            GUI.backgroundColor = defBackgroundColor;

            GUILayout.EndHorizontal();

            if (FrontSuspension)
            {
                EditorGUILayout.Space();
                //carScript.FrontLeftWheelCollider.wheelCollider.mass = carScript.FrontRightWheelCollider.wheelCollider.mass = EditorGUILayout.FloatField("Front Wheels Mass", carScript.FrontLeftWheelCollider.wheelCollider.mass);
                carScript.FrontLeftWheelCollider.wheelCollider.suspensionDistance    = carScript.FrontRightWheelCollider.wheelCollider.suspensionDistance = EditorGUILayout.FloatField("Front Suspensions Distance", carScript.FrontLeftWheelCollider.wheelCollider.suspensionDistance);
                carScript.FrontLeftWheelCollider.wheelCollider.forceAppPointDistance = carScript.FrontRightWheelCollider.wheelCollider.forceAppPointDistance = EditorGUILayout.FloatField("Front Force App Distance", carScript.FrontLeftWheelCollider.wheelCollider.forceAppPointDistance);
                EditorGUILayout.PropertyField(serializedObject.FindProperty("frontCamber"), new GUIContent("Front Camber Angle"));
                EditorGUILayout.Space();
                frontSspring.spring         = EditorGUILayout.FloatField("Front Suspensions Spring", frontSspring.spring);
                frontSspring.damper         = EditorGUILayout.FloatField("Front Suspensions Damping", frontSspring.damper);
                frontSspring.targetPosition = EditorGUILayout.FloatField("Front Suspensions Target Position", frontSspring.targetPosition);
                EditorGUILayout.Space();
            }

            if (RearSuspension)
            {
                EditorGUILayout.Space();
                //carScript.RearLeftWheelCollider.wheelCollider.mass = carScript.RearRightWheelCollider.wheelCollider.mass = EditorGUILayout.FloatField("Rear Wheels Mass", carScript.RearLeftWheelCollider.wheelCollider.mass);
                carScript.RearLeftWheelCollider.wheelCollider.suspensionDistance    = carScript.RearRightWheelCollider.wheelCollider.suspensionDistance = EditorGUILayout.FloatField("Rear Suspensions Distance", carScript.RearLeftWheelCollider.wheelCollider.suspensionDistance);
                carScript.RearLeftWheelCollider.wheelCollider.forceAppPointDistance = carScript.RearRightWheelCollider.wheelCollider.forceAppPointDistance = EditorGUILayout.FloatField("Rear Force App Distance", carScript.RearLeftWheelCollider.wheelCollider.forceAppPointDistance);
                EditorGUILayout.PropertyField(serializedObject.FindProperty("rearCamber"), new GUIContent("Rear Camber Angle"));
                EditorGUILayout.Space();
                rearSpring.spring         = EditorGUILayout.FloatField("Rear Suspensions Spring", rearSpring.spring);
                rearSpring.damper         = EditorGUILayout.FloatField("Rear Suspensions Damping", rearSpring.damper);
                rearSpring.targetPosition = EditorGUILayout.FloatField("Rear Suspensions Target Position", rearSpring.targetPosition);
                EditorGUILayout.Space();
            }

            carScript.FrontLeftWheelCollider.wheelCollider.suspensionSpring  = frontSspring;
            carScript.FrontRightWheelCollider.wheelCollider.suspensionSpring = frontSspring;
            carScript.RearLeftWheelCollider.wheelCollider.suspensionSpring   = rearSpring;
            carScript.RearRightWheelCollider.wheelCollider.suspensionSpring  = rearSpring;

            EditorGUILayout.Space();
        }

        if (Configurations)
        {
            EditorGUILayout.Space();
            GUI.color = Color.cyan;
            EditorGUILayout.HelpBox("Configurations", MessageType.None);
            GUI.color = defBackgroundColor;
            EditorGUILayout.Space();

            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("canControl"), new GUIContent("Can Be Controllable Now", "Enables/Disables controlling the vehicle."));
            EditorGUILayout.Space();
//			EditorGUILayout.PropertyField(serializedObject.FindProperty("runEngineAtAwake"), new GUIContent("Engine Is Running At Awake", "Engine is running defaultly at start of the game."));
            EditorGUILayout.LabelField("Engine Is Running Now", carScript.engineRunning.ToString());
//			EditorGUILayout.PropertyField(serializedObject.FindProperty("canEngineStall"), new GUIContent("Engine Can Be Stalled?", "Stalled Engine due to low RPM."));
            EditorGUILayout.Space();
//			EditorGUILayout.PropertyField(serializedObject.FindProperty("autoReverse"), new GUIContent("Auto Reverse", "Enables/Disables auto reversing when player press brake button. Useful for if you are making parking style game."));
            //EditorGUILayout.PropertyField(serializedObject.FindProperty("automaticGear"), new GUIContent("Automatic Gear Shifting", "Enables/Disables automatic gear shifting of the vehicle."));

            EditorGUILayout.PropertyField(serializedObject.FindProperty("_wheelTypeChoise"));

            if (carScript._wheelTypeChoise == RCC_CarControllerV3.WheelType.BIASED)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(serializedObject.FindProperty("biasedWheelTorque"), new GUIContent("Front / Rear"));
                //EditorGUILayout.BeginHorizontal();
                EditorGUILayout.FloatField("Front", 100 - carScript.biasedWheelTorque);
                EditorGUILayout.FloatField("Rear", carScript.biasedWheelTorque);
                //EditorGUILayout.EndHorizontal();
                EditorGUI.indentLevel--;
            }

            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("COM"), new GUIContent("Center Of Mass (''COM'')", "Center of Mass of the vehicle. Usually, COM is below around front driver seat."));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("totalGears"), new GUIContent("Total Gears Count", "How Many Gears Your Vehicle Has?"), false);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("gearShiftingDelay"), new GUIContent("Gear Shifting Delay", "Gear Shifting Delay"), false);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("currentGear"), new GUIContent("Current Gear"), false);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("engineTorque"), new GUIContent("Maximum Engine Torque"), false);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("brakeTorque"), new GUIContent("Maximum Brake Torque"), false);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("maxspeed"), new GUIContent("Maximum Speed"), false);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("downForce"), new GUIContent("DownForce"), false);

            EditorGUILayout.PropertyField(serializedObject.FindProperty("minEngineRPM"), new GUIContent("Lowest Engine RPM"), false);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("maxEngineRPM"), new GUIContent("Highest Engine RPM"), false);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("engineInertia"), new GUIContent("Engine Inertia"), false);

            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("useRevLimiter"), new GUIContent("Rev Limiter"), false);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("useNOS"), new GUIContent("Use NOS"), false);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("useTurbo"), new GUIContent("Use Turbo"), false);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("useExhaustFlame"), new GUIContent("Use Exhaust Flame"), false);

            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("chassis"), new GUIContent("Chassis", "Script will simulate chassis movement based on vehicle rigidbody situation."), false);

            if (RCC_Settings.Instance.dontUseChassisJoint)
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("chassisVerticalLean"), new GUIContent("Chassis Vertical Sensitivity", "Script will simulate chassis movement based on vehicle rigidbody situation."), false);
                EditorGUILayout.PropertyField(serializedObject.FindProperty("chassisHorizontalLean"), new GUIContent("Chassis Horizontal Sensitivity", "Script will simulate chassis movement based on vehicle rigidbody situation."), false);
            }

            EditorGUILayout.Space();

            EditorGUILayout.PropertyField(serializedObject.FindProperty("autoGenerateGearCurves"), new GUIContent("Generate All Gear Torque Curves"), false);

            if (!carScript.autoGenerateGearCurves)
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("engineTorqueCurve"), new GUIContent("All Gear Torque Curves"), true);
            }

            EditorGUILayout.PropertyField(serializedObject.FindProperty("autoGenerateTargetSpeedsForChangingGear"), new GUIContent("Generate All Target Speeds For Changing Gears"), false);

            if (!carScript.autoGenerateTargetSpeedsForChangingGear)
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("gearSpeed"), new GUIContent("Target Speeds For Changing Gears"), true);
            }

            EditorGUILayout.Space();
        }

        if (StabilitySettings)
        {
            EditorGUILayout.Space();
            GUI.color = Color.cyan;
            EditorGUILayout.HelpBox("Stability System Settings", MessageType.None);
            GUI.color = defBackgroundColor;
            EditorGUILayout.Space();

            EditorGUILayout.PropertyField(serializedObject.FindProperty("ABS"), new GUIContent("ABS"), false);

            if (carScript.ABS)
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("ABSThreshold"), new GUIContent("ABS Threshold"), false);
            }

            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("TCS"), new GUIContent("TCS"), false);

            if (carScript.TCS)
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("TCSThreshold"), new GUIContent("TCS Threshold"), false);
                EditorGUILayout.PropertyField(serializedObject.FindProperty("TCSStrength"), new GUIContent("TCS Strength"), false);
            }

            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("ESP"), new GUIContent("ESP"), false);

            if (carScript.ESP)
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("ESPThreshold"), new GUIContent("ESP Threshold"), false);
                EditorGUILayout.PropertyField(serializedObject.FindProperty("ESPStrength"), new GUIContent("ESP Strength"), false);
            }

            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("steeringHelper"), new GUIContent("Steering Helper"), false);

            if (carScript.steeringHelper)
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("steerHelperLinearVelStrength"), new GUIContent("Steering Helper Linear Velocity Strength"), false);
                EditorGUILayout.PropertyField(serializedObject.FindProperty("steerHelperAngularVelStrength"), new GUIContent("Steering Helper Angular Velocity Strength"), false);
            }

            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("tractionHelper"), new GUIContent("Traction Helper"), false);

            if (carScript.tractionHelper)
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("tractionHelperStrength"), new GUIContent("Traction Helper Strength"), false);
            }

            EditorGUILayout.Space();
        }

        if (SoundSettings)
        {
            EditorGUILayout.Space();
            GUI.color = Color.cyan;
            EditorGUILayout.HelpBox("Sound Settings", MessageType.None);
            GUI.color = defBackgroundColor;

            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("engineClipOn"), new GUIContent("Engine Sound On"), false);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("engineClipOff"), new GUIContent("Engine Sound Off"), false);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("engineClipIdle"), new GUIContent("Engine Sound Idle"), false);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("engineStartClip"), new GUIContent("Engine Starting Sound", "Optional"), false);

            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("minEngineSoundPitch"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("maxEngineSoundPitch"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("minEngineSoundVolume"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("maxEngineSoundVolume"));
            EditorGUILayout.Space();
        }

        if (LightSettings)
        {
            EditorGUILayout.Space();
            GUI.color = Color.cyan;
            EditorGUILayout.HelpBox("Light Settings", MessageType.None);
            GUI.color = defBackgroundColor;
            EditorGUILayout.Space();

            EditorGUILayout.PropertyField(serializedObject.FindProperty("lowBeamHeadLightsOn"), new GUIContent("Head Lights On"));
            EditorGUILayout.Space();

            RCC_Light[] lights = carScript.GetComponentsInChildren <RCC_Light>();

            EditorGUILayout.LabelField("Head Lights", EditorStyles.boldLabel);
            EditorGUILayout.Space();
            EditorGUI.indentLevel++;

            for (int i = 0; i < lights.Length; i++)
            {
                EditorGUILayout.BeginHorizontal();
                if (lights[i].lightType == RCC_Light.LightType.HeadLight)
                {
                    EditorGUILayout.ObjectField("Head Light", lights[i].GetComponent <Light>(), typeof(Light), true);
                    GUI.color = Color.red;
                    if (GUILayout.Button("X", GUILayout.Width(25f)))
                    {
                        DestroyImmediate(lights[i].gameObject);
                    }
                    GUI.color = defBackgroundColor;
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.Space();
            EditorGUI.indentLevel--;
            EditorGUILayout.LabelField("Brake Lights", EditorStyles.boldLabel);
            EditorGUILayout.Space();
            EditorGUI.indentLevel++;

            for (int i = 0; i < lights.Length; i++)
            {
                EditorGUILayout.BeginHorizontal();
                if (lights[i].lightType == RCC_Light.LightType.BrakeLight)
                {
                    EditorGUILayout.ObjectField("Brake Light", lights[i].GetComponent <Light>(), typeof(Light), true);
                    GUI.color = Color.red;
                    if (GUILayout.Button("X", GUILayout.Width(25f)))
                    {
                        DestroyImmediate(lights[i].gameObject);
                    }
                    GUI.color = defBackgroundColor;
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.Space();
            EditorGUI.indentLevel--;
            EditorGUILayout.LabelField("Reverse Lights", EditorStyles.boldLabel);
            EditorGUILayout.Space();
            EditorGUI.indentLevel++;

            for (int i = 0; i < lights.Length; i++)
            {
                EditorGUILayout.BeginHorizontal();
                if (lights[i].lightType == RCC_Light.LightType.ReverseLight)
                {
                    EditorGUILayout.ObjectField("Reverse Light", lights[i].GetComponent <Light>(), typeof(Light), true);
                    GUI.color = Color.red;
                    if (GUILayout.Button("X", GUILayout.Width(25f)))
                    {
                        DestroyImmediate(lights[i].gameObject);
                    }
                    GUI.color = defBackgroundColor;
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.Space();
            EditorGUI.indentLevel--;
            EditorGUILayout.LabelField("Indicator Lights", EditorStyles.boldLabel);
            EditorGUILayout.Space();
            EditorGUI.indentLevel++;

            for (int i = 0; i < lights.Length; i++)
            {
                EditorGUILayout.BeginHorizontal();
                if (lights[i].lightType == RCC_Light.LightType.Indicator)
                {
                    EditorGUILayout.ObjectField("Indicator Light", lights[i].GetComponent <Light>(), typeof(Light), true);
                    GUI.color = Color.red;
                    if (GUILayout.Button("X", GUILayout.Width(25f)))
                    {
                        DestroyImmediate(lights[i].gameObject);
                    }
                    GUI.color = defBackgroundColor;
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUI.indentLevel--;
            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("+ Head Light"))
            {
                RCC_EditorWindows.CreateHeadLight();
            }
            if (GUILayout.Button("+ Brake Light"))
            {
                RCC_EditorWindows.CreateBrakeLight();
            }
            if (GUILayout.Button("+ Reverse Light"))
            {
                RCC_EditorWindows.CreateReverseLight();
            }
            if (GUILayout.Button("+ Indicator Light"))
            {
                RCC_EditorWindows.CreateIndicatorLight();
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();
        }

        if (DamageSettings)
        {
            EditorGUILayout.Space();
            GUI.color = Color.cyan;
            EditorGUILayout.HelpBox("Damage Settings", MessageType.None);
            GUI.color = defBackgroundColor;
            EditorGUILayout.Space();

            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("useDamage"), new GUIContent("Use Damage"), false);
            EditorGUILayout.Space();

            if (carScript.useDamage)
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("deformableMeshFilters"), new GUIContent("Deformable Mesh Filters", "If no mesh filters selected, will collect all mesh filters in children except wheel models."), true);
                EditorGUILayout.PropertyField(serializedObject.FindProperty("randomizeVertices"), new GUIContent("Randomize Vertices", "Randomizes vertices movement angle."), false);
                EditorGUILayout.PropertyField(serializedObject.FindProperty("damageRadius"), new GUIContent("Damage Radius on Contact", "Damage radius on contact."), false);
                EditorGUILayout.PropertyField(serializedObject.FindProperty("maximumDamage"), new GUIContent("Maximum Damage", "Maximum deformable damage."), false);
                EditorGUILayout.PropertyField(serializedObject.FindProperty("damageMultiplier"), new GUIContent("Damage Multiplier", "Damage mutliplier."), false);
                EditorGUILayout.PropertyField(serializedObject.FindProperty("maximumContactSparkle"), new GUIContent("Maximum Contact Sparkle Count", "Script is re-using existing collision particles. 3 is good for mobile, 5 and above is good for PC."), false);

                if (carScript.repaired)
                {
                    GUI.color = Color.gray;
                    GUILayout.Button("Repaired");
                }
                else
                {
                    GUI.color = Color.green;
                    if (GUILayout.Button("Repair Now"))
                    {
                        carScript.repairNow = true;
                    }
                }
            }

            EditorGUILayout.Space();
        }

        if (carScript.GetComponent <RCC_AICarController>())
        {
            EditorGUILayout.Space();
            EditorGUILayout.HelpBox("This Vehicle Is Controlling By AI. Therefore, All Player Controllers Are Disabled For This Vehicle.", MessageType.Info);
            EditorGUILayout.Space();

            if (GUILayout.Button("Remove AI Controller From Vehicle"))
            {
                carScript.AIController = false;
                DestroyImmediate(carScript.GetComponent <RCC_AICarController>());
            }
        }

        EditorGUILayout.Space();
        GUI.color = Color.cyan;
        EditorGUILayout.HelpBox("System Overall Check", MessageType.None);
        GUI.color = defBackgroundColor;
        EditorGUILayout.Space();

        EditorGUILayout.BeginHorizontal();

        if (carScript.FrontLeftWheelCollider == null || carScript.FrontRightWheelCollider == null || carScript.RearLeftWheelCollider == null || carScript.RearRightWheelCollider == null)
        {
            EditorGUILayout.HelpBox("Wheel Colliders = NOT OK", MessageType.Error);
        }

        if (carScript.FrontLeftWheelTransform == null || carScript.FrontRightWheelTransform == null || carScript.RearLeftWheelTransform == null || carScript.RearRightWheelTransform == null)
        {
            EditorGUILayout.HelpBox("Wheel Models = NOT OK", MessageType.Error);
        }

        if (carScript.COM == null)
        {
            EditorGUILayout.HelpBox("COM = NOT OK", MessageType.Error);
        }

        Collider[] cols = carScript.gameObject.GetComponentsInChildren <Collider>();
        int        totalCountsOfWheelColliders = carScript.GetComponentsInChildren <WheelCollider>().Length;

        if (cols.Length - totalCountsOfWheelColliders <= 0)
        {
            EditorGUILayout.HelpBox("Your vehicle MUST have any type of body Collider.", MessageType.Error);
        }

        EditorGUILayout.EndHorizontal();

        if (carScript.COM)
        {
            if (Mathf.Approximately(carScript.COM.transform.localPosition.y, 0f))
            {
                EditorGUILayout.HelpBox("You haven't changed COM position of the vehicle yet. Keep in that your mind, COM is most extremely important for realistic behavior.", MessageType.Warning);
            }
        }
        else
        {
            EditorGUILayout.HelpBox("You haven't created COM of the vehicle yet. Just hit ''Create Necessary Gameobject Groups'' under ''Wheel'' tab for creating this too.", MessageType.Error);
        }

        if (carScript.chassis != null)
        {
            if (!carScript.chassis.GetComponent <RCC_Chassis> ())
            {
                carScript.chassis.AddComponent <RCC_Chassis> ();
            }
        }

        serializedObject.ApplyModifiedProperties();

        if (GUI.changed && !EditorApplication.isPlaying)
        {
            SetLayerMask();
            carScript.defMaxSpeed = 0f;
            if (carScript.autoGenerateGearCurves)
            {
                carScript.TorqueCurve();
            }
        }
    }
Esempio n. 14
0
    void Start()
    {
        carController  = GetComponentInParent <RCC_CarControllerV3>();
        _light         = GetComponent <Light>();
        _light.enabled = true;
        lensFlare      = GetComponent <LensFlare> ();

        if (lensFlare)
        {
            if (_light.flare != null)
            {
                _light.flare = null;
            }
        }

        if (RCCSettings.useLightProjectorForLightingEffect)
        {
            projector = GetComponent <Projector>();
            if (projector == null)
            {
                projector = ((GameObject)Instantiate(RCCSettings.projector, transform.position, transform.rotation)).GetComponent <Projector>();
                projector.transform.SetParent(transform, true);
            }
            projector.ignoreLayers = RCCSettings.projectorIgnoreLayer;
            if (lightType != LightType.HeadLight)
            {
                projector.transform.localRotation = Quaternion.Euler(20f, transform.localPosition.z > 0f ? 0f : 180f, 0f);
            }
            Material newMaterial = new Material(projector.material);
            projector.material = newMaterial;
        }

        if (RCCSettings.useLightsAsVertexLights)
        {
            _light.renderMode  = LightRenderMode.ForceVertex;
            _light.cullingMask = 0;
        }
        else
        {
            _light.renderMode = LightRenderMode.ForcePixel;
        }

        if (lightType == LightType.Indicator)
        {
            if (!carController.transform.Find("All Audio Sources/Indicator Sound AudioSource"))
            {
                indicatorSound = RCC_CreateAudioSource.NewAudioSource(carController.gameObject, "Indicator Sound AudioSource", 1f, 3f, 1, indicatorClip, false, false, false);
            }
            else
            {
                indicatorSound = carController.transform.Find("All Audio Sources/Indicator Sound AudioSource").GetComponent <AudioSource>();
            }
        }

        RCC_Light[] allLights = carController.GetComponentsInChildren <RCC_Light> ();

        for (int i = 0; i < allLights.Length; i++)
        {
            if (allLights [i].lightType == LightType.ParkLight)
            {
                parkLightFound = true;
            }

            if (allLights [i].lightType == LightType.HighBeamHeadLight)
            {
                highBeamLightFound = true;
            }
        }

        CheckRotation();
        CheckLensFlare();
    }
    void Start()
    {
        carController = GetComponentInParent <RCC_CarControllerV3>();
        rigid         = carController.GetComponent <Rigidbody> ();

        // Getting all WheelColliders attached to this vehicle (Except this).
        allWheelColliders = carController.GetComponentsInChildren <RCC_WheelCollider>().ToList();
//		allWheelColliders.Remove(this);
        GetTerrainData();

        // Are we going to use skidmarks? If we do, get or create SkidmarksManager on scene.
        if (!RCCSettings.dontUseSkidmarks)
        {
            if (GameObject.FindObjectOfType(typeof(RCC_Skidmarks)))
            {
                skidmarks = GameObject.FindObjectOfType(typeof(RCC_Skidmarks)) as RCC_Skidmarks;
            }
            else
            {
                skidmarks = (RCC_Skidmarks)Instantiate(RCCSettings.skidmarksManager, Vector3.zero, Quaternion.identity);
            }
        }

        // Increasing WheelCollider mass for avoiding unstable behavior. Only in Unity 5.
        if (RCCSettings.useFixedWheelColliders)
        {
            wheelCollider.mass = rigid.mass / 20f;
//			wheelCollider.ConfigureVehicleSubsteps(1000f, 10, 10);
        }

        // Getting friction curves.
        forwardFrictionCurve  = wheelCollider.forwardFriction;
        sidewaysFrictionCurve = wheelCollider.sidewaysFriction;

        // Proper settings for selected behavior type.
        switch (RCCSettings.behaviorType)
        {
        case RCC_Settings.BehaviorType.SemiArcade:
            forwardFrictionCurve  = SetFrictionCurves(forwardFrictionCurve, .2f, 2f, 2f, 2f);
            sidewaysFrictionCurve = SetFrictionCurves(sidewaysFrictionCurve, .25f, 2f, 2f, 2f);
            wheelCollider.forceAppPointDistance = Mathf.Clamp(wheelCollider.forceAppPointDistance, .35f, 1f);
            break;

        case RCC_Settings.BehaviorType.Drift:
            forwardFrictionCurve  = SetFrictionCurves(forwardFrictionCurve, .3f, 1f, .8f, 1f);
            sidewaysFrictionCurve = SetFrictionCurves(sidewaysFrictionCurve, .3f, 1f, .5f, 1f);
            wheelCollider.forceAppPointDistance = Mathf.Clamp(wheelCollider.forceAppPointDistance, .1f, 1f);
            if (carController._wheelTypeChoise == RCC_CarControllerV3.WheelType.FWD)
            {
                Debug.LogWarning("Current behavior mode is ''Drift'', but your vehicle named " + carController.name + " was FWD. You have to use RWD, AWD, or BIASED to rear wheels. Setting it to *RWD* now. ");
                carController._wheelTypeChoise = RCC_CarControllerV3.WheelType.RWD;
            }
            break;

        case RCC_Settings.BehaviorType.Fun:
            forwardFrictionCurve  = SetFrictionCurves(forwardFrictionCurve, .2f, 2f, 2f, 2f);
            sidewaysFrictionCurve = SetFrictionCurves(sidewaysFrictionCurve, .25f, 2f, 2f, 2f);
            wheelCollider.forceAppPointDistance = Mathf.Clamp(wheelCollider.forceAppPointDistance, .35f, 1f);
            break;

        case RCC_Settings.BehaviorType.Racing:
            forwardFrictionCurve  = SetFrictionCurves(forwardFrictionCurve, .2f, 1f, .8f, .75f);
            sidewaysFrictionCurve = SetFrictionCurves(sidewaysFrictionCurve, .3f, 1f, .25f, .75f);
            wheelCollider.forceAppPointDistance = Mathf.Clamp(wheelCollider.forceAppPointDistance, .25f, 1f);
            break;

        case RCC_Settings.BehaviorType.Simulator:
            forwardFrictionCurve  = SetFrictionCurves(forwardFrictionCurve, .2f, 1f, .8f, .75f);
            sidewaysFrictionCurve = SetFrictionCurves(sidewaysFrictionCurve, .25f, 1f, .5f, .75f);
            wheelCollider.forceAppPointDistance = Mathf.Clamp(wheelCollider.forceAppPointDistance, 0f, 1f);
            break;
        }

        // Assigning new frictons if one of the behavior preset selected above.
        wheelCollider.forwardFriction  = forwardFrictionCurve;
        wheelCollider.sidewaysFriction = sidewaysFrictionCurve;

        // Creating audiosource for skid SFX.
        if (RCCSettings.useSharedAudioSources)
        {
            if (!carController.transform.Find("All Audio Sources/Skid Sound AudioSource"))
            {
                audioSource = RCC_CreateAudioSource.NewAudioSource(carController.gameObject, "Skid Sound AudioSource", 5f, 50f, 0f, audioClip, true, true, false);
            }
            else
            {
                audioSource = carController.transform.Find("All Audio Sources/Skid Sound AudioSource").GetComponent <AudioSource>();
            }
        }
        else
        {
            audioSource = RCC_CreateAudioSource.NewAudioSource(carController.gameObject, "Skid Sound AudioSource", 5f, 50f, 0f, audioClip, true, true, false);
            audioSource.transform.position = transform.position;
        }

        // Creating all ground particles, and adding them to list.
        if (!RCCSettings.dontUseAnyParticleEffects)
        {
            for (int i = 0; i < RCCGroundMaterials.frictions.Length; i++)
            {
                GameObject ps = (GameObject)Instantiate(RCCGroundMaterials.frictions [i].groundParticles, transform.position, transform.rotation) as GameObject;
                emission         = ps.GetComponent <ParticleSystem> ().emission;
                emission.enabled = false;
                ps.transform.SetParent(transform, false);
                ps.transform.localPosition = Vector3.zero;
                ps.transform.localRotation = Quaternion.identity;
                allWheelParticles.Add(ps.GetComponent <ParticleSystem> ());
            }
        }

        GameObject newPivot = new GameObject("Pivot_" + wheelModel.transform.name);

        newPivot.transform.position = RCC_GetBounds.GetBoundsCenter(wheelModel.transform);
        newPivot.transform.rotation = transform.rotation;
        newPivot.transform.SetParent(wheelModel.transform.parent, true);
        wheelModel.SetParent(newPivot.transform, true);
        wheelModel = newPivot.transform;
    }
Esempio n. 16
0
	void Start (){

		//	Getting essentials.
		carController = GetComponentInParent<RCC_CarControllerV3>();
		rigid = carController.GetComponent<Rigidbody> ();

		// Getting all WheelColliders attached to this vehicle (Except this).
		allWheelColliders = carController.GetComponentsInChildren<RCC_WheelCollider>().ToList();

		GetTerrainData ();		//	Getting terrain datas on scene.
		CheckBehavior ();		//	Checks selected behavior in RCC Settings.

		// Are we going to use skidmarks? If we do, get or create SkidmarksManager on scene.
		if (!RCCSettings.dontUseSkidmarks) {

			if (GameObject.FindObjectOfType<RCC_SkidmarksManager> ())
				skidmarksManager = GameObject.FindObjectOfType<RCC_SkidmarksManager> ();
			else
				skidmarksManager = GameObject.Instantiate (RCCSettings.skidmarksManager, Vector3.zero, Quaternion.identity);

		}

		// Increasing WheelCollider mass for avoiding unstable behavior.
		if (RCCSettings.useFixedWheelColliders)
			wheelCollider.mass = rigid.mass / 15f;

		// Creating audiosource for skid SFX.
		audioSource = NewAudioSource(RCCSettings.audioMixer, carController.gameObject, "Skid Sound AudioSource", 5f, 50f, 0f, audioClip, true, true, false);
		audioSource.transform.position = transform.position;

		// Creating all ground particles, and adding them to list.
		if (!RCCSettings.dontUseAnyParticleEffects) {

			for (int i = 0; i < RCCGroundMaterials.frictions.Length; i++) {

				GameObject ps = (GameObject)Instantiate (RCCGroundMaterials.frictions [i].groundParticles, transform.position, transform.rotation) as GameObject;
				emission = ps.GetComponent<ParticleSystem> ().emission;
				emission.enabled = false;
				ps.transform.SetParent (transform, false);
				ps.transform.localPosition = Vector3.zero;
				ps.transform.localRotation = Quaternion.identity;
				allWheelParticles.Add (ps.GetComponent<ParticleSystem> ());

			}

		}

		//	Creating pivot position of the wheel at correct position and rotation.
		GameObject newPivot = new GameObject ("Pivot_" + wheelModel.transform.name);
		newPivot.transform.position = RCC_GetBounds.GetBoundsCenter (wheelModel.transform);
		newPivot.transform.rotation = transform.rotation;
		newPivot.transform.SetParent (wheelModel.transform.parent, true);

		//	Settings offsets.
		if (newPivot.transform.localPosition.x > 0)
			wheelModel.transform.position += transform.right * offset;
		else
			wheelModel.transform.position -= transform.right * offset;

		//	Assigning temporary created wheel to actual wheel.
		wheelModel.SetParent (newPivot.transform, true);
		wheelModel = newPivot.transform;

		// Override wheels automatically if enabled.
		if (carController.overrideWheels) {

			// Overriding canPower, canSteer, canBrake, canHandbrake.
			if (this == carController.FrontLeftWheelCollider || this == carController.FrontRightWheelCollider) {

				canSteer = true;
				canBrake = true;
				brakingMultiplier = 1f;

			}

			if (this == carController.RearLeftWheelCollider || this == carController.RearRightWheelCollider) {

				canHandbrake = true;
				canBrake = true;
				brakingMultiplier = .5f;

			}

		}

	}