Beispiel #1
0
 void AddComponentToTargets <T>() where T : MonoBehaviour
 {
     foreach (var target in m_Targets)
     {
         EditorExtensions.AddComponentFromEditor <T>(target);
     }
 }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            bool reloadNoise = false;

            if ((Object)Config.Instance != this.target)
            {
                EditorGUILayout.HelpBox(EditorStrings.ConfigMultipleAssets, MessageType.Error);
                EditorGUILayout.Separator();
                ButtonOpenConfig();
            }
            else
            {
                Header("Beam Geometry");
                EditorGUI.BeginChangeCheck();
                {
                    using (new EditorGUILayout.HorizontalScope())
                    {
                        geometryOverrideLayer.boolValue = EditorGUILayout.Toggle(EditorStrings.ConfigGeometryOverrideLayer, geometryOverrideLayer.boolValue);
                        using (new EditorGUI.DisabledGroupScope(!geometryOverrideLayer.boolValue))
                        {
                            geometryLayerID.intValue = EditorGUILayout.LayerField(geometryLayerID.intValue);
                        }
                    }

                    geometryTag.stringValue = EditorGUILayout.TagField(EditorStrings.ConfigGeometryTag, geometryTag.stringValue);
                }

                Header("Rendering");
                {
                    RenderQueueGUIDraw();

                    if (BeamGeometry.isCustomRenderPipelineSupported)
                    {
                        EditorGUI.BeginChangeCheck();
                        {
                            renderPipeline.CustomEnum <RenderPipeline>(EditorStrings.ConfigGeometryRenderPipeline, EditorStrings.ConfigGeometryRenderPipelineEnumDescriptions);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            Config.OnRenderPipelineChanged((RenderPipeline)renderPipeline.enumValueIndex);
                            VolumetricLightBeam._EditorSetAllBeamGeomDirty(); // need to fully reset the BeamGeom to update the shader
                            ReimportShaders();
                        }
                    }

                    EditorGUI.BeginChangeCheck();
                    {
                        EditorGUILayout.PropertyField(renderingMode, EditorStrings.ConfigGeometryRenderingMode);

                        if (renderPipeline.enumValueIndex == (int)RenderPipeline.SRP_4_0_0_or_higher && renderingMode.enumValueIndex == (int)RenderingMode.MultiPass)
                        {
                            EditorGUILayout.HelpBox(EditorStrings.ConfigSrpAndMultiPassNoCompatible, MessageType.Error);
                        }

#pragma warning disable 0162 // warning CS0162: Unreachable code detected
                        if (renderingMode.enumValueIndex == (int)RenderingMode.GPUInstancing && !GpuInstancing.isSupported)
                        {
                            EditorGUILayout.HelpBox(EditorStrings.ConfigGeometryGpuInstancingNotSupported, MessageType.Warning);
                        }
#pragma warning restore 0162
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        VolumetricLightBeam._EditorSetAllBeamGeomDirty(); // need to fully reset the BeamGeom to update the shader
                        GlobalMesh.Destroy();
                        ReimportShaders();
                    }
                }
                if (EditorGUI.EndChangeCheck())
                {
                    VolumetricLightBeam._EditorSetAllMeshesDirty();
                }

                Header("Shared Mesh");
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(sharedMeshSides, EditorStrings.ConfigSharedMeshSides);
                EditorGUILayout.PropertyField(sharedMeshSegments, EditorStrings.ConfigSharedMeshSegments);
                if (EditorGUI.EndChangeCheck())
                {
                    GlobalMesh.Destroy();
                    VolumetricLightBeam._EditorSetAllMeshesDirty();
                }

                var meshInfo = "These properties will change the mesh tessellation of each Volumetric Light Beam with 'Shared' MeshType.\nAdjust them carefully since they could impact performance.";
                meshInfo += string.Format("\nShared Mesh stats: {0} vertices, {1} triangles", MeshGenerator.GetSharedMeshVertexCount(), MeshGenerator.GetSharedMeshIndicesCount() / 3);
                EditorGUILayout.HelpBox(meshInfo, MessageType.Info);

                Header("Global 3D Noise");
                EditorGUILayout.PropertyField(globalNoiseScale, EditorStrings.ConfigGlobalNoiseScale);
                EditorGUILayout.PropertyField(globalNoiseVelocity, EditorStrings.ConfigGlobalNoiseVelocity);

                EditorGUILayout.Separator();
                EditorExtensions.HorizontalLineSeparator();

                Header("Internal Data (do not change)");
                EditorGUILayout.PropertyField(beamShader1Pass, EditorStrings.ConfigBeamShader1Pass);
                EditorGUILayout.PropertyField(beamShader2Pass, EditorStrings.ConfigBeamShader2Pass);
                EditorGUILayout.PropertyField(dustParticlesPrefab, EditorStrings.ConfigDustParticlesPrefab);

                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(noise3DData, EditorStrings.ConfigNoise3DData);
                EditorGUILayout.PropertyField(noise3DSize, EditorStrings.ConfigNoise3DSize);
                if (EditorGUI.EndChangeCheck())
                {
                    reloadNoise = true;
                }

                if (Noise3D.isSupported && !Noise3D.isProperlyLoaded)
                {
                    EditorGUILayout.HelpBox(EditorStrings.HelpNoiseLoadingFailed, MessageType.Error);
                }


                EditorGUILayout.Separator();
                EditorExtensions.HorizontalLineSeparator();
                EditorGUILayout.Separator();

                using (new EditorGUILayout.HorizontalScope())
                {
                    if (GUILayout.Button(EditorStrings.ConfigOpenDocumentation, EditorStyles.miniButton))
                    {
                        UnityEditor.Help.BrowseURL(Consts.HelpUrlConfig);
                    }

                    if (GUILayout.Button(EditorStrings.ConfigResetToDefaultButton, EditorStyles.miniButton))
                    {
                        UnityEditor.Undo.RecordObject(target, "Reset Config Properties");
                        (target as Config).Reset();
                    }
                }
            }

            serializedObject.ApplyModifiedProperties();

            if (reloadNoise)
            {
                Noise3D._EditorForceReloadData(); // Should be called AFTER ApplyModifiedProperties so the Config instance has the proper values when reloading data
            }
        }
Beispiel #3
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            Debug.Assert(m_Entities.Count > 0);

            bool hasLightSpot = false;
            var  light        = m_Entities[0].GetComponent <Light>();

            if (light)
            {
                hasLightSpot = light.type == LightType.Spot;
                if (!hasLightSpot)
                {
                    EditorGUILayout.HelpBox(EditorStrings.HelpNoSpotlight, MessageType.Warning);
                }
            }

            Header("Basic");
            {
                // Color
                using (new FromLightComponentScope(colorFromLight, hasLightSpot))
                    using (new EditorGUILayout.HorizontalScope())
                    {
                        EditorGUILayout.PropertyField(colorMode, EditorStrings.ColorMode);

                        if (colorMode.enumValueIndex == (int)ColorMode.Gradient)
                        {
                            EditorGUILayout.PropertyField(colorGradient, EditorStrings.ColorGradient);
                        }
                        else
                        {
                            EditorGUILayout.PropertyField(color, EditorStrings.ColorFlat);
                        }
                    }

                EditorGUILayout.PropertyField(alphaInside, EditorStrings.AlphaInside);
                EditorGUILayout.PropertyField(alphaOutside, EditorStrings.AlphaOutside);
                EditorGUILayout.PropertyField(blendingMode, EditorStrings.BlendingMode);

                EditorGUILayout.Separator();

                // Spot Angle
                using (new FromLightComponentScope(spotAngleFromLight, hasLightSpot))
                {
                    EditorGUILayout.PropertyField(spotAngle, EditorStrings.SpotAngle);
                }

                PropertyThickness(fresnelPow);

                EditorGUILayout.Separator();

                EditorGUILayout.PropertyField(glareFrontal, EditorStrings.GlareFrontal);
                EditorGUILayout.PropertyField(glareBehind, EditorStrings.GlareBehind);

                EditorGUILayout.Separator();

                trackChangesDuringPlaytime.ToggleLeft(EditorStrings.TrackChanges);
                DrawAnimatorWarning();
            }

            Header("Attenuation");
            {
                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.PropertyField(attenuationEquation, EditorStrings.AttenuationEquation);
                    if (attenuationEquation.enumValueIndex == (int)AttenuationEquation.Blend)
                    {
                        EditorGUILayout.PropertyField(attenuationCustomBlending, EditorStrings.AttenuationCustomBlending);
                    }
                }
                EditorGUILayout.EndHorizontal();

                // Fade End
                using (new FromLightComponentScope(fadeEndFromLight, hasLightSpot))
                {
                    EditorGUILayout.PropertyField(fadeEnd, EditorStrings.FadeEnd);
                }

                if (fadeEnd.hasMultipleDifferentValues)
                {
                    EditorGUILayout.PropertyField(fadeStart, EditorStrings.FadeStart);
                }
                else
                {
                    fadeStart.FloatSlider(EditorStrings.FadeStart, 0f, fadeEnd.floatValue - Consts.FadeMinThreshold);
                }
            }

            Header("3D Noise");
            {
                EditorGUILayout.PropertyField(noiseEnabled, EditorStrings.NoiseEnabled);

                if (noiseEnabled.boolValue)
                {
                    EditorGUILayout.PropertyField(noiseIntensity, EditorStrings.NoiseIntensity);

                    using (new EditorGUILayout.HorizontalScope())
                    {
                        using (new EditorGUI.DisabledGroupScope(noiseScaleUseGlobal.boolValue))
                        {
                            EditorGUILayout.PropertyField(noiseScaleLocal, EditorStrings.NoiseScale);
                        }
                        noiseScaleUseGlobal.ToggleUseGlobalNoise();
                    }

                    using (new EditorGUILayout.HorizontalScope())
                    {
                        using (new EditorGUI.DisabledGroupScope(noiseVelocityUseGlobal.boolValue))
                        {
                            EditorGUILayout.PropertyField(noiseVelocityLocal, EditorStrings.NoiseVelocity);
                        }
                        noiseVelocityUseGlobal.ToggleUseGlobalNoise();
                    }

                    ButtonOpenConfig();

                    if (Noise3D.isSupported && !Noise3D.isProperlyLoaded)
                    {
                        EditorGUILayout.HelpBox(EditorStrings.HelpNoiseLoadingFailed, MessageType.Error);
                    }

                    if (!Noise3D.isSupported)
                    {
                        EditorGUILayout.HelpBox(Noise3D.isNotSupportedString, MessageType.Info);
                    }
                }
            }

            Header("Soft Intersections Blending Distances");
            {
                EditorGUILayout.PropertyField(cameraClippingDistance, EditorStrings.CameraClippingDistance);
                EditorGUILayout.PropertyField(depthBlendDistance, EditorStrings.DepthBlendDistance);
            }

            Header("Cone Geometry");
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    EditorGUILayout.PropertyField(coneRadiusStart, EditorStrings.ConeRadiusStart);
                    EditorGUI.BeginChangeCheck();
                    {
                        geomCap.ToggleLeft(EditorStrings.GeomCap, GUILayout.MaxWidth(40.0f));
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        SetMeshesDirty();
                    }
                }

                EditorGUI.BeginChangeCheck();
                {
                    EditorGUILayout.PropertyField(geomMeshType, EditorStrings.GeomMeshType);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    SetMeshesDirty();
                }

                if (geomMeshType.intValue == (int)MeshType.Custom)
                {
                    EditorGUI.indentLevel++;

                    EditorGUI.BeginChangeCheck();
                    {
                        EditorGUILayout.PropertyField(geomCustomSides, EditorStrings.GeomSides);
                        EditorGUILayout.PropertyField(geomCustomSegments, EditorStrings.GeomSegments);
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        SetMeshesDirty();
                    }

                    EditorGUI.indentLevel--;
                }

                if (m_Entities.Count == 1)
                {
                    EditorGUILayout.HelpBox(m_Entities[0].meshStats, MessageType.Info);
                }
            }

            Header("2D");
            {
                DrawSortingLayer();
                DrawSortingOrder();
            }

            EditorGUILayout.Separator();
            EditorExtensions.HorizontalLineSeparator();
            EditorGUILayout.Separator();

            DrawCustomActionButtons();
            DrawAdditionalFeatures();
            DrawTips();

            serializedObject.ApplyModifiedProperties();
        }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            Header("Beam Geometry");
            EditorGUI.BeginChangeCheck();
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    geometryOverrideLayer.boolValue = EditorGUILayout.Toggle(EditorStrings.ConfigGeometryOverrideLayer, geometryOverrideLayer.boolValue);
                    using (new EditorGUI.DisabledGroupScope(!geometryOverrideLayer.boolValue))
                    {
                        geometryLayerID.intValue = EditorGUILayout.LayerField(geometryLayerID.intValue);
                    }
                }

                geometryTag.stringValue = EditorGUILayout.TagField(EditorStrings.ConfigGeometryTag, geometryTag.stringValue);
            }

            Header("Rendering");
            {
                RenderQueueGUIDraw();

                EditorGUI.BeginChangeCheck();
                {
                    forceSinglePass.boolValue = EditorGUILayout.Toggle(EditorStrings.ConfigGeometryForceSinglePass, forceSinglePass.boolValue);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    VolumetricLightBeam._EditorSetAllBeamGeomDirty(); // need to fully reset the BeamGeom to update the shader
                    GlobalMesh.Destroy();
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                VolumetricLightBeam._EditorSetAllMeshesDirty();
            }

            EditorGUILayout.PropertyField(beamShader1Pass, EditorStrings.ConfigBeamShader1Pass);
            EditorGUILayout.PropertyField(beamShader2Pass, EditorStrings.ConfigBeamShader2Pass);

            Header("Shared Mesh");
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(sharedMeshSides, EditorStrings.ConfigSharedMeshSides);
            EditorGUILayout.PropertyField(sharedMeshSegments, EditorStrings.ConfigSharedMeshSegments);
            if (EditorGUI.EndChangeCheck())
            {
                GlobalMesh.Destroy();
                VolumetricLightBeam._EditorSetAllMeshesDirty();
            }

            var meshInfo = "These properties will change the mesh tessellation of each Volumetric Light Beam with 'Shared' MeshType.\nAdjust them carefully since they could impact performance.";

            meshInfo += string.Format("\nShared Mesh stats: {0} vertices, {1} triangles", MeshGenerator.GetSharedMeshVertexCount(), MeshGenerator.GetSharedMeshIndicesCount() / 3);
            EditorGUILayout.HelpBox(meshInfo, MessageType.Info);

            Header("Global 3D Noise");
            EditorGUILayout.PropertyField(globalNoiseScale, EditorStrings.ConfigGlobalNoiseScale);
            EditorGUILayout.PropertyField(globalNoiseVelocity, EditorStrings.ConfigGlobalNoiseVelocity);

            Header("3D Noise Texture Data");
            bool reloadNoise = false;

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(noise3DData, EditorStrings.ConfigNoise3DData);
            EditorGUILayout.PropertyField(noise3DSize, EditorStrings.ConfigNoise3DSize);
            if (EditorGUI.EndChangeCheck())
            {
                reloadNoise = true;
            }

            if (Noise3D.isSupported && !Noise3D.isProperlyLoaded)
            {
                EditorGUILayout.HelpBox(EditorStrings.HelpNoiseLoadingFailed, MessageType.Error);
            }

            Header("Volumetric Dust Particles");
            EditorGUILayout.PropertyField(dustParticlesPrefab, EditorStrings.ConfigDustParticlesPrefab);

            EditorGUILayout.Separator();
            EditorExtensions.HorizontalLineSeparator();
            EditorGUILayout.Separator();

            if (GUILayout.Button(EditorStrings.ConfigResetToDefaultButton, EditorStyles.miniButton))
            {
                UnityEditor.Undo.RecordObject(target, "Reset Config Properties");
                (target as Config).Reset();
            }

            serializedObject.ApplyModifiedProperties();

            if (reloadNoise)
            {
                Noise3D._EditorForceReloadData(); // Should be called AFTER ApplyModifiedProperties so the Config instance has the proper values when reloading data
            }
        }