public override void OnInspectorGUI()
    {
        GroundSurfaceMaster surfaceMaster = FindObjectOfType<GroundSurfaceMaster>();
        GroundSurfaceInstance targetScript = (GroundSurfaceInstance)target;
        GroundSurfaceInstance[] allTargets = new GroundSurfaceInstance[targets.Length];

        for (int i = 0; i < targets.Length; i++)
        {
            Undo.RecordObject(targets[i], "Ground Surface Change");
            allTargets[i] = targets[i] as GroundSurfaceInstance;
        }

        string[] surfaceNames = new string[surfaceMaster.surfaceTypes.Length];

        for (int i = 0; i < surfaceNames.Length; i++)
        {
            surfaceNames[i] = surfaceMaster.surfaceTypes[i].name;
        }

        foreach (GroundSurfaceInstance curTarget in allTargets)
        {
            curTarget.surfaceType = EditorGUILayout.Popup("Surface Type", curTarget.surfaceType, surfaceNames);
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(targetScript);
        }
    }
    public override void OnInspectorGUI()
    {
        GroundSurfaceMaster   surfaceMaster = FindObjectOfType <GroundSurfaceMaster>();
        GroundSurfaceInstance targetScript  = (GroundSurfaceInstance)target;

        GroundSurfaceInstance[] allTargets = new GroundSurfaceInstance[targets.Length];

        for (int i = 0; i < targets.Length; i++)
        {
            Undo.RecordObject(targets[i], "Ground Surface Change");
            allTargets[i] = targets[i] as GroundSurfaceInstance;
        }

        string[] surfaceNames = new string[surfaceMaster.surfaceTypes.Length];

        for (int i = 0; i < surfaceNames.Length; i++)
        {
            surfaceNames[i] = surfaceMaster.surfaceTypes[i].name;
        }

        foreach (GroundSurfaceInstance curTarget in allTargets)
        {
            curTarget.surfaceType = EditorGUILayout.Popup("Surface Type", curTarget.surfaceType, surfaceNames);
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(targetScript);
        }
    }
예제 #3
0
    void Update()
    {
        //Check for continuous marking
        if (w.grounded)
        {
            curSurfaceInstance = w.contactPoint.col.GetComponent <GroundSurfaceInstance>();
            if (curSurfaceInstance)
            {
                alwaysScrape = GroundSurfaceMaster.surfaceTypesStatic[curSurfaceInstance.surfaceType].alwaysScrape ? slipThreshold + Mathf.Min(0.5f, Mathf.Abs(w.rawRPM * 0.001f)) : 0;
            }
            else
            {
                alwaysScrape = 0;
            }
        }

        //Create mark
        if (w.grounded && (Mathf.Abs(F.MaxAbs(w.sidewaysSlip, w.forwardSlip)) > slipThreshold || alwaysScrape > 0) && w.connected)
        {
            prevSurface = curSurface;
            curSurface  = curSurfaceInstance ? w.contactPoint.surfaceType : -1;

            if (!creatingMark)
            {
                prevSurface = curSurface;
                StartMark();
            }
            else if (curSurface != prevSurface)
            {
                EndMark();
            }

            //Calculate segment points
            if (curMark)
            {
                Vector3 pointDir = Quaternion.AngleAxis(90, w.contactPoint.normal) * tr.right * (w.popped ? w.rimWidth : w.tireWidth);
                leftPoint  = curMarkTr.InverseTransformPoint(w.contactPoint.point + pointDir * w.suspensionParent.flippedSideFactor * Mathf.Sign(w.rawRPM) + w.contactPoint.normal * GlobalControl.tireMarkHeightStatic);
                rightPoint = curMarkTr.InverseTransformPoint(w.contactPoint.point - pointDir * w.suspensionParent.flippedSideFactor * Mathf.Sign(w.rawRPM) + w.contactPoint.normal * GlobalControl.tireMarkHeightStatic);
            }
        }
        else if (creatingMark)
        {
            EndMark();
        }

        //Update mark if it's short enough, otherwise end it
        if (curEdge < GlobalControl.tireMarkLengthStatic && creatingMark)
        {
            UpdateMark();
        }
        else if (creatingMark)
        {
            EndMark();
        }

        for (int i = 0; i < debrisParticles.Length; i++)
        {
            if (w.connected)
            {
                if (i == w.contactPoint.surfaceType)
                {
                    if (GroundSurfaceMaster.surfaceTypesStatic[w.contactPoint.surfaceType].leaveSparks && w.popped)
                    {
                        debrisParticles[i].emissionRate = 0;

                        if (sparks)
                        {
                            sparks.emissionRate = initialEmissionRates[debrisParticles.Length] * Mathf.Clamp01(Mathf.Abs(F.MaxAbs(w.sidewaysSlip, w.forwardSlip, alwaysScrape)) - slipThreshold);
                        }
                    }
                    else
                    {
                        debrisParticles[i].emissionRate = initialEmissionRates[i] * Mathf.Clamp01(Mathf.Abs(F.MaxAbs(w.sidewaysSlip, w.forwardSlip, alwaysScrape)) - slipThreshold);

                        if (sparks)
                        {
                            sparks.emissionRate = 0;
                        }
                    }
                }
                else
                {
                    debrisParticles[i].emissionRate = 0;
                }
            }
            else
            {
                debrisParticles[i].emissionRate = 0;

                if (sparks)
                {
                    sparks.emissionRate = 0;
                }
            }
        }
    }
예제 #4
0
	void Update()
	{
		//Check for continuous marking
		if (w.grounded)
		{
			curSurfaceInstance = w.contactPoint.col.GetComponent<GroundSurfaceInstance>();
			if (curSurfaceInstance)
			{
				alwaysScrape = GroundSurfaceMaster.surfaceTypesStatic[curSurfaceInstance.surfaceType].alwaysScrape ? slipThreshold + Mathf.Min(0.5f, Mathf.Abs(w.rawRPM * 0.001f)) : 0;
			}
			else
			{
				alwaysScrape = 0;
			}
		}

		//Create mark
		if (w.grounded && (Mathf.Abs(F.MaxAbs(w.sidewaysSlip, w.forwardSlip)) > slipThreshold || alwaysScrape > 0) && w.connected)
		{
			prevSurface = curSurface;
			curSurface = curSurfaceInstance ? w.contactPoint.surfaceType : -1;

			if (!creatingMark)
			{
				prevSurface = curSurface;
				StartMark();
			}
			else if (curSurface != prevSurface)
			{
				EndMark();
			}

			//Calculate segment points
			if (curMark)
			{
				Vector3 pointDir = Quaternion.AngleAxis(90, w.contactPoint.normal) * tr.right * (w.popped ? w.rimWidth : w.tireWidth);
				leftPoint = curMarkTr.InverseTransformPoint(w.contactPoint.point + pointDir * w.suspensionParent.flippedSideFactor * Mathf.Sign(w.rawRPM) + w.contactPoint.normal * GlobalControl.tireMarkHeightStatic);
				rightPoint = curMarkTr.InverseTransformPoint(w.contactPoint.point - pointDir * w.suspensionParent.flippedSideFactor * Mathf.Sign(w.rawRPM) + w.contactPoint.normal * GlobalControl.tireMarkHeightStatic);
			}
		}
		else if (creatingMark)
		{
			EndMark();
		}

		//Update mark if it's short enough, otherwise end it
		if (curEdge < GlobalControl.tireMarkLengthStatic && creatingMark)
		{
			UpdateMark();
		}
		else if (creatingMark)
		{
			EndMark();
		}

		for (int i = 0; i < debrisParticles.Length; i++)
		{
			if (w.connected)
			{
				if (i == w.contactPoint.surfaceType)
				{
					if (GroundSurfaceMaster.surfaceTypesStatic[w.contactPoint.surfaceType].leaveSparks && w.popped)
					{
						debrisParticles[i].emissionRate = 0;

						if (sparks)
						{
							sparks.emissionRate = initialEmissionRates[debrisParticles.Length] * Mathf.Clamp01(Mathf.Abs(F.MaxAbs(w.sidewaysSlip, w.forwardSlip, alwaysScrape)) - slipThreshold);
						}
					}
					else
					{
						debrisParticles[i].emissionRate = initialEmissionRates[i] * Mathf.Clamp01(Mathf.Abs(F.MaxAbs(w.sidewaysSlip, w.forwardSlip, alwaysScrape)) - slipThreshold);

						if (sparks)
						{
							sparks.emissionRate = 0;
						}
					}
				}
				else
				{
					debrisParticles[i].emissionRate = 0;
				}
			}
			else
			{
				debrisParticles[i].emissionRate = 0;

				if (sparks)
				{
					sparks.emissionRate = 0;
				}
			}
		}
	}
예제 #5
0
    void GetWheelContact()
    {
        float castDist = Mathf.Max(suspensionParent.suspensionDistance * Mathf.Max(0.001f, suspensionParent.targetCompression) + actualRadius, 0.001f);

        RaycastHit[] wheelHits = Physics.RaycastAll(suspensionParent.maxCompressPoint, suspensionParent.springDirection, castDist, GlobalControl.wheelCastMaskStatic);
        RaycastHit   hit;
        int          hitIndex = 0;
        bool         validHit = false;
        float        hitDist  = Mathf.Infinity;

        if (connected)
        {
            //Loop through raycast hits to find closest one
            for (int i = 0; i < wheelHits.Length; i++)
            {
                if (!wheelHits[i].transform.IsChildOf(vp.tr) && wheelHits[i].distance < hitDist)
                {
                    hitIndex = i;
                    hitDist  = wheelHits[i].distance;
                    validHit = true;
                }
            }
        }
        else
        {
            validHit = false;
        }

        //Set contact point variables
        if (validHit)
        {
            hit = wheelHits[hitIndex];

            if (!grounded && impactSnd && ((tireHitClips.Length > 0 && !popped) || (rimHitClip && popped)))
            {
                impactSnd.PlayOneShot(popped ? rimHitClip : tireHitClips[Mathf.RoundToInt(Random.Range(0, tireHitClips.Length - 1))], Mathf.Clamp01(airTime * airTime));
                impactSnd.pitch = Mathf.Clamp(airTime * 0.2f + 0.8f, 0.8f, 1);
            }

            grounded = true;
            contactPoint.distance         = hit.distance - actualRadius;
            contactPoint.point            = hit.point + localVel * Time.fixedDeltaTime;
            contactPoint.grounded         = true;
            contactPoint.normal           = hit.normal;
            contactPoint.relativeVelocity = tr.InverseTransformDirection(localVel);
            contactPoint.col = hit.collider;

            if (hit.collider.attachedRigidbody)
            {
                contactVelocity = hit.collider.attachedRigidbody.GetPointVelocity(contactPoint.point);
                contactPoint.relativeVelocity -= tr.InverseTransformDirection(contactVelocity);
            }
            else
            {
                contactVelocity = Vector3.zero;
            }

            GroundSurfaceInstance curSurface = hit.collider.GetComponent <GroundSurfaceInstance>();
            TerrainSurface        curTerrain = hit.collider.GetComponent <TerrainSurface>();

            if (curSurface)
            {
                contactPoint.surfaceFriction = curSurface.friction;
                contactPoint.surfaceType     = curSurface.surfaceType;
            }
            else if (curTerrain)
            {
                contactPoint.surfaceType     = curTerrain.GetDominantSurfaceTypeAtPoint(contactPoint.point);
                contactPoint.surfaceFriction = curTerrain.GetFriction(contactPoint.surfaceType);
            }
            else
            {
                contactPoint.surfaceFriction = hit.collider.material.dynamicFriction * 2;
                contactPoint.surfaceType     = 0;
            }

            if (contactPoint.col.CompareTag("Pop Tire") && canPop && airLeakTime == -1 && !popped)
            {
                Deflate();
            }
        }
        else
        {
            grounded = false;
            contactPoint.distance         = suspensionParent.suspensionDistance;
            contactPoint.point            = Vector3.zero;
            contactPoint.grounded         = false;
            contactPoint.normal           = upDir;
            contactPoint.relativeVelocity = Vector3.zero;
            contactPoint.col             = null;
            contactVelocity              = Vector3.zero;
            contactPoint.surfaceFriction = 0;
            contactPoint.surfaceType     = 0;
        }
    }