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);
            }
        }
Ejemplo n.º 2
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;
            }
        }