예제 #1
0
        void DisableVehicle(VehicleController vehicle)
        {
            if (vehicle == null) return;

            SetupVehicleComponents(vehicle, false);
            vehicle.throttleInput = 0.0f;
            vehicle.brakeInput = 1.0f;
        }
예제 #2
0
	void OnEnable ()
		{
		m_vehicle = GetComponent<VehicleController>();
		m_vehicle.processContacts = true;
		m_vehicle.onImpact += ProcessImpact;

		// Store original vertices of the meshes

		m_originalMeshes = new Vector3[meshes.Length][];
		for (int i = 0; i < meshes.Length; i++)
			{
			Mesh mesh = meshes[i].mesh;

			m_originalMeshes[i] = mesh.vertices;
			mesh.MarkDynamic();
			}

		// Store original vertices of the colliders

		m_originalColliders = new Vector3[colliders.Length][];
		for (int i = 0; i < colliders.Length; i++)
			{
			Mesh mesh = colliders[i].sharedMesh;

			m_originalColliders[i] = mesh.vertices;
			mesh.MarkDynamic();
			}

		// Store original position and rotation of the nodes

		m_originalNodePositions = new Vector3[nodes.Length];
		m_originalNodeRotations = new Quaternion[nodes.Length];

		for (int i = 0; i < nodes.Length; i++)
			{
			m_originalNodePositions[i] = nodes[i].transform.localPosition;
			m_originalNodeRotations[i] = nodes[i].transform.localRotation;
			}

		// Initialize damage levels

		m_repairing = false;
		m_meshDamage = 0.0f;
		m_colliderDamage = 0.0f;
		m_nodeDamage = 0.0f;
		}
예제 #3
0
        public void SelectVehicle(int vehicleIdx)
        {
            if (vehicleIdx > vehicles.Length) return;

            // Disable current vehicle, if any

            if (m_currentVehicle != null)
            {
            DisableVehicle(m_currentVehicle);
            m_currentVehicle = null;
            }

            // Select new vhicle. Leave no vehicle selected if idx < 1.

            if (vehicleIdx >= 0)
            {
            m_currentVehicle = vehicles[vehicleIdx];
            EnableVehicle(m_currentVehicle);
            }

            m_currentVehicleIdx = vehicleIdx;
        }
예제 #4
0
        // Impact processing
        void HandleImpacts()
        {
            // Multiple impacts within an impact interval are accumulated and averaged later.

            if (Time.time-m_lastImpactTime >= impactInterval && m_sumImpactCount > 0)
            {
            // Prepare the impact parameters

            float invCount = 1.0f / m_sumImpactCount;

            m_sumImpactPosition *= invCount;
            m_sumImpactVelocity *= invCount;

            // Notify the listeners on the impact

            if (onImpact != null)
                {
                current = this;
                onImpact();
                current = null;
                }

            // debugText = string.Format("Count: {4}  Impact Pos: {0}  Impact Velocity: {1} ({2,5:0.00})  Impact Friction: {3,4:0.00}", localImpactPosition, localImpactVelocity, localImpactVelocity.magnitude, localImpactFriction, m_sumImpactCount);
            if (showContactGizmos && localImpactVelocity.sqrMagnitude > 0.001f)
                Debug.DrawLine(transform.TransformPoint(localImpactPosition), transform.TransformPoint(localImpactPosition) + CommonTools.Lin2Log(transform.TransformDirection(localImpactVelocity)), Color.red, 0.2f, false);

            // Reset impact data

            m_sumImpactCount = 0;
            m_sumImpactPosition = Vector3.zero;
            m_sumImpactVelocity = Vector3.zero;
            m_sumImpactHardness = 0;

            m_lastImpactTime = Time.time + impactInterval * UnityEngine.Random.Range(-impactIntervalRandom, impactIntervalRandom);	// Add a random variation for avoiding regularities
            }
        }
예제 #5
0
 void OnEnable()
 {
     m_rigidbody = GetComponent<Rigidbody>();
     m_vehicle = GetComponent<VehicleController>();
 }
	void OnEnable ()
		{
		// Configure the vehicle: report impacts, compute extended tire data (for skid)

		m_vehicle = GetComponent<VehicleController>();
		m_vehicle.processContacts = true;
		m_vehicle.onImpact += DoImpactAudio;
		m_vehicle.computeExtendedTireData = true;

		// Verify / configure parameters

		if (engine.gears < 2)
			engine.gears = 2;

		m_engineRpmDamp = engine.gearUpRpmRate;
		m_wheelsRpm = 0.0f;

		// Verify the audio sources to belong to the actual vehicle (editor only)

		VerifyAudioSources();
		}
	public override void OnInspectorGUI ()
		{
		serializedObject.Update();
		m_target = (VehicleController)target;

		BeginInspectorContent(120);

		EditorGUILayout.Space();
		EditorGUILayout.PropertyField(serializedObject.FindProperty("wheels"), true);

		// Handling

		EditorGUILayout.PropertyField(serializedObject.FindProperty("centerOfMass"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("tireFriction"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("antiRoll"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("maxSteerAngle"));

		SetInspectorMinLabelWidth(150);
		EditorGUILayout.PropertyField(serializedObject.FindProperty("aeroDrag"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("aeroDownforce"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("aeroAppPointOffset"));
		ResetInspectorMinLabelWidth();

		// Motor

		SetInspectorMinLabelWidth(150);
		EditorGUILayout.PropertyField(serializedObject.FindProperty("maxSpeedForward"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("maxSpeedReverse"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("maxDriveForce"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("maxDriveSlip"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("driveForceToMaxSlip"));
		ResetInspectorMinLabelWidth();
		EditorGUILayout.PropertyField(serializedObject.FindProperty("forceCurveShape"));

		Rect graphRect = AllocateRectForGraphic();

		// Brakes

		SetInspectorMinLabelWidth(150);
		EditorGUILayout.PropertyField(serializedObject.FindProperty("maxBrakeForce"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("brakeForceToMaxSlip"));
		ResetInspectorMinLabelWidth();

		EditorGUILayout.Space();
		SerializedProperty brakeMode = serializedObject.FindProperty("brakeMode");
		EditorGUILayout.PropertyField(brakeMode);
		if (brakeMode.enumValueIndex == 0)
			EditorGUILayout.PropertyField(serializedObject.FindProperty("maxBrakeSlip"));
		else
			EditorGUILayout.PropertyField(serializedObject.FindProperty("maxBrakeRatio"));

		EditorGUILayout.Space();
		SerializedProperty handbrakeMode = serializedObject.FindProperty("handbrakeMode");
		EditorGUILayout.PropertyField(handbrakeMode);
		if (handbrakeMode.enumValueIndex == 0)
			EditorGUILayout.PropertyField(serializedObject.FindProperty("maxHandbrakeSlip"));
		else
			EditorGUILayout.PropertyField(serializedObject.FindProperty("maxHandbrakeRatio"));

		// Aids

		EditorGUILayout.PropertyField(serializedObject.FindProperty("tcEnabled"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("tcRatio"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("absEnabled"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("absRatio"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("espEnabled"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("espRatio"));

		EditorGUILayout.PropertyField(serializedObject.FindProperty("steerInput"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("throttleInput"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("brakeInput"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("handbrakeInput"));

		EditorGUILayout.PropertyField(serializedObject.FindProperty("spinUpdateRate"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("wheelPositionMode"));

		SetInspectorMinLabelWidth(200);
		EditorGUILayout.PropertyField(serializedObject.FindProperty("disallowRuntimeChanges"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("disableWheelHitCorrection"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("disableSteerAngleCorrection"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("showContactGizmos"));
		ResetInspectorMinLabelWidth();
		EditorGUILayout.PropertyField(serializedObject.FindProperty("sleepVelocity"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("steeringOverdrive"));

		EditorGUILayout.PropertyField(serializedObject.FindProperty("defaultGroundGrip"));
		EditorGUILayout.PropertyField(serializedObject.FindProperty("defaultGroundDrag"));

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

		serializedObject.ApplyModifiedProperties();

		GUIDrawForceGraph(graphRect);
		EndInspectorContent();
		}
	void GUIDrawForceGraph (Rect graphRect)
		{
		if (m_canvas == null || Event.current.type != EventType.Ignore)
			{
			if (m_canvas == null)
				{
				m_canvas = new TextureCanvas(m_graphWidth, m_graphHeight);
				m_canvas.alpha = 0.75f;
				m_canvas.color = Color.black;
				m_canvas.Clear();
				m_canvas.Save();
				}
			else
				{
				m_canvas.Restore();
				}

			m_target = (VehicleController)serializedObject.targetObject;

			// Calculate the dimmensions of the speed graph

			float maxSpeed = Mathf.Max(m_target.maxSpeedForward * 1.1f, 1.0f);
			float maxForce = Mathf.Max(m_target.maxDriveForce * 1.1f, 1.0f);

			// Set dimensions and draw grids

			m_canvas.rect = new Rect(0.0f, 0.0f, maxSpeed, maxForce);
			m_canvas.color = Color.green*0.1f;
			m_canvas.Grid(1.0f, 100.0f);
			m_canvas.color = Color.green*0.4f;
			m_canvas.Grid(10.0f, 1000.0f);

			// Origin lines

			m_canvas.color = Color.grey;
			m_canvas.HorizontalLine(0.0f);
			m_canvas.VerticalLine(0.0f);

			// Force graph

			CommonTools.BiasLerpContext biasCtx = new CommonTools.BiasLerpContext();

			m_canvas.color = Color.green;
			m_canvas.Function(x => m_target.maxDriveForce
				* CommonTools.BiasedLerp(1.0f - x/m_target.maxSpeedForward, m_target.forceCurveShape, biasCtx));

			// Limit lines

			m_canvas.color = Color.white;
			m_canvas.lineType = TextureCanvas.LineType.Dashed;
			m_canvas.Line(m_target.maxSpeedForward, 0.0f, m_target.maxSpeedForward, m_target.maxDriveForce);
			m_canvas.lineType = TextureCanvas.LineType.Solid;

			}

		// Non-scaled, horizontally centered, bottom-aligned, shadow effect

		m_canvas.EditorGUIDraw(graphRect);
		}
예제 #9
0
        //----------------------------------------------------------------------------------------------
        void EnableVehicle(VehicleController vehicle)
        {
            if (vehicle == null) return;

            SetupVehicleComponents(vehicle, true);

            if (cameraController != null)
            {
            VehicleViewConfig viewConfig = vehicle.GetComponent<VehicleViewConfig>();

            if (viewConfig != null)
                {
                // Get the view configuration of the new vehicle and configure the controller

                cameraController.target =
                    viewConfig.lookAtPoint != null? viewConfig.lookAtPoint : vehicle.transform;

                cameraController.targetFixedPosition = viewConfig.driverView;

                cameraController.smoothFollowSettings.distance = viewConfig.viewDistance;
                cameraController.smoothFollowSettings.height = viewConfig.viewHeight;
                cameraController.smoothFollowSettings.rotationDamping = viewConfig.viewDamping;

                cameraController.orbitSettings.distance = viewConfig.viewDistance;
                cameraController.orbitSettings.minDistance = viewConfig.viewMinDistance;
                cameraController.orbitSettings.minVerticalAngle = viewConfig.viewMinHeight;
                }
            else
                {
                cameraController.target = vehicle.transform;
                }

            cameraController.ResetCamera();
            }
        }
예제 #10
0
        void SetupVehicleComponents(VehicleController vehicle, bool enabled)
        {
            VehicleTelemetry vehicleTelemetry = vehicle.GetComponent<VehicleTelemetry>();
            VehicleStandardInput vehicleInput = vehicle.GetComponent<VehicleStandardInput>();
            VehicleDamage vehicleDamage = vehicle.GetComponent<VehicleDamage>();

            if (vehicleInput != null)
            {
            if (m_commonInput != null)
                {
                if (overrideVehicleComponents)
                    {
                    vehicleInput.enabled = false;
                    m_commonInput.enabled = true;
                    m_commonInput.target = enabled? vehicle : null;
                    }
                else
                    {
                    vehicleInput.enabled = enabled;
                    m_commonInput.enabled = false;
                    }
                }
            else
                {
                vehicleInput.enabled = enabled;
                }
            }
            else
            {
            if (m_commonInput != null)
                {
                m_commonInput.enabled = true;
                m_commonInput.target = enabled? vehicle : null;
                }
            }

            if (vehicleTelemetry != null)
            {
            if (m_commonTelemetry != null)
                {
                if (overrideVehicleComponents)
                    {
                    vehicleTelemetry.enabled = false;
                    m_commonTelemetry.enabled = true;
                    m_commonTelemetry.target = enabled? vehicle : null;
                    }
                else
                    {
                    vehicleTelemetry.enabled = enabled;
                    m_commonTelemetry.enabled = false;
                    }
                }
            else
                {
                vehicleTelemetry.enabled = enabled;
                }
            }
            else
            {
            if (m_commonTelemetry != null)
                {
                m_commonTelemetry.enabled = true;
                m_commonTelemetry.target = enabled? vehicle : null;
                }
            }

            if (vehicleDamage != null)
            {
            vehicleDamage.enableRepairKey = enabled;
            }
        }
예제 #11
0
 void OnEnable()
 {
     m_vehicle = GetComponent<VehicleController>();
     m_vehicle.computeExtendedTireData = true;
 }
        void OnEnable()
        {
            // Cache vehicle

            if (target == null)
            target = GetComponent<VehicleController>();
        }
예제 #13
0
 void OnEnable()
 {
     m_vehicle = GetComponent<VehicleController>();
 }
예제 #14
0
        void OnEnable()
        {
            // Default font settings

            if (style.font == null)
            {
                style.font = defaultFont;
            style.normal.textColor = Color.white;
            }

            // Cache data

            if (target == null)
            target = GetComponent<VehicleController>();
        }