Beispiel #1
0
        public override bool OnInspectorNUI()
        {
            if (!base.OnInspectorNUI())
            {
                return(false);
            }

            _surfacePreset = (SurfacePreset)target;

            drawer.BeginSubsection("General");
            drawer.Field("name");
            drawer.EndSubsection();

            drawer.BeginSubsection("Friction Settings");
            drawer.Field("frictionPreset");
            drawer.EndSubsection();

            drawer.BeginSubsection("Skidmark Settings");
            if (drawer.Field("drawSkidmarks").boolValue)
            {
                drawer.Field("skidmarkMaterial");
                drawer.Field("slipFactor");
            }
            drawer.EndSubsection();

            drawer.BeginSubsection("Dust/Smoke Particle Settings");
            if (drawer.Field("emitParticles").boolValue)
            {
                drawer.Field("particleType");
                drawer.Field("particleSize");
                drawer.Field("particleColor");
                drawer.Field("particleMaxAlpha");
                drawer.Field("maxParticleEmissionRateOverDistance");
                drawer.Field("particleLifeDistance");
                drawer.Field("maxParticleLifetime");
            }

            drawer.EndSubsection();

            drawer.BeginSubsection("Chunk Particle Settings");
            if (drawer.Field("emitChunks").boolValue)
            {
                drawer.Field("maxChunkEmissionRateOverDistance");
                drawer.Field("chunkLifeDistance");
                drawer.Field("maxChunkLifetime");
            }
            drawer.EndSubsection();

            drawer.BeginSubsection("Sound Settings");
            drawer.BeginSubsection("Skid Sounds");
            if (drawer.Field("playSkidSounds").boolValue)
            {
                drawer.Field("skidSoundVolume");
                drawer.Field("skidSoundPitch");
                drawer.Field("skidSoundClip");
            }
            drawer.EndSubsection();
            drawer.BeginSubsection("Surface Sounds");
            if (drawer.Field("playSurfaceSounds").boolValue)
            {
                drawer.Field("slipSensitiveSurfaceSound");
                drawer.Field("surfaceSoundVolume");
                drawer.Field("surfaceSoundPitch");
                drawer.Field("surfaceSoundClip");
            }

            drawer.EndSubsection();
            drawer.EndSubsection();

            drawer.EndEditor(this);
            return(true);
        }
Beispiel #2
0
        /// <summary>
        ///     Gets the surface map the wheel is currently on.
        /// </summary>
        public bool GetCurrentSurfaceMap(WheelController wheelController, ref int surfaceIndex,
                                         ref SurfacePreset outSurfacePreset)
        {
            surfaceIndex     = -1;
            outSurfacePreset = null;

            if (!IsEnabled)
            {
                return(false);
            }

            if (groundDetectionPreset == null)
            {
                Debug.LogError("GroundDetectionPreset is required but is null. Go to VehicleController > FX > Grnd. Det. and " +
                               "assign a GroundDetectionPreset.");
                return(false);
            }

            hitTransform = wheelController.wheelHit?.raycastHit.transform;
            if (wheelController.isGrounded && hitTransform != null)
            {
                wheelController.GetGroundHit(out WheelHit hit);

                // Check for tags
                int mapCount = groundDetectionPreset.surfaceMaps.Count;
                for (int e = 0; e < mapCount; e++)
                {
                    SurfaceMap map      = groundDetectionPreset.surfaceMaps[e];
                    int        tagCount = map.tags.Count;

                    for (int i = 0; i < tagCount; i++)
                    {
                        if (hitTransform.CompareTag(map.tags[i]))
                        {
                            outSurfacePreset = map.surfacePreset;
                            surfaceIndex     = e;
                            return(true);
                        }
                    }
                }

                // Find active terrain
                activeTerrain = hitTransform.GetComponent <Terrain>();

                if (activeTerrain)
                {
                    // Check for terrain textures
                    int dominantTerrainIndex = GetDominantTerrainTexture(hit.point, activeTerrain);
                    if (dominantTerrainIndex != -1)
                    {
                        for (int e = 0; e < groundDetectionPreset.surfaceMaps.Count; e++)
                        {
                            SurfaceMap map = groundDetectionPreset.surfaceMaps[e];

                            int n = map.terrainTextureIndices.Count;
                            for (int i = 0; i < n; i++)
                            {
                                if (map.terrainTextureIndices[i] == dominantTerrainIndex)
                                {
                                    outSurfacePreset = map.surfacePreset;
                                    surfaceIndex     = e;
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }
            if (groundDetectionPreset.fallbackSurfacePreset != null)
            {
                outSurfacePreset = groundDetectionPreset.fallbackSurfacePreset;
                surfaceIndex     = -1;
                return(true);
            }

            Debug.LogError(
                $"Fallback surface map of ground detection preset {groundDetectionPreset.name} not assigned.");
            outSurfacePreset = null;
            surfaceIndex     = -1;
            return(false);
        }