Example #1
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            if (FoldableHeader.Begin(this, EditorStrings.DynOcclusion.HeaderCamera))
            {
                EditorGUILayout.PropertyField(layerMask, EditorStrings.DynOcclusion.LayerMask);

                if (Config.Instance.geometryOverrideLayer == false)
                {
                    EditorGUILayout.HelpBox(EditorStrings.DynOcclusion.HelpOverrideLayer, MessageType.Warning);
                }
                else if (m_Targets.HasAtLeastOneTargetWith((DynamicOcclusionDepthBuffer comp) => { return(comp.HasLayerMaskIssues()); }))
                {
                    EditorGUILayout.HelpBox(EditorStrings.DynOcclusion.HelpLayerMaskIssues, MessageType.Warning);
                }

                EditorGUILayout.PropertyField(useOcclusionCulling, EditorStrings.DynOcclusion.DepthBufferOcclusionCulling);
                EditorGUILayout.PropertyField(depthMapResolution, EditorStrings.DynOcclusion.DepthBufferDepthMapResolution);
            }
            FoldableHeader.End();

            if (FoldableHeader.Begin(this, EditorStrings.DynOcclusion.HeaderOccluderSurface))
            {
                EditorGUILayout.PropertyField(fadeDistanceToSurface, EditorStrings.DynOcclusion.FadeDistanceToSurface);
            }
            FoldableHeader.End();

            DisplayCommonInspector();

            serializedObject.ApplyModifiedProperties();
        }
        protected void DisplayCommonInspector()
        {
            if (FoldableHeader.Begin(this, EditorStrings.DynOcclusion.HeaderUpdateRate))
            {
                updateRate.CustomEnum <DynamicOcclusionUpdateRate>(EditorStrings.DynOcclusion.UpdateRate, EditorStrings.DynOcclusion.UpdateRateDescriptions);

                if (m_Targets.HasAtLeastOneTargetWith((T comp) => { return(comp.updateRate.HasFlag(DynamicOcclusionUpdateRate.EveryXFrames)); }))
                {
                    EditorGUILayout.PropertyField(waitXFrames, EditorStrings.DynOcclusion.WaitXFrames);
                }

                EditorGUILayout.HelpBox(
                    string.Format(EditorStrings.DynOcclusion.GetUpdateRateAdvice <T>(m_Targets[0].updateRate), m_Targets[0].waitXFrames),
                    MessageType.Info);
            }

            FoldableHeader.End();

            serializedObject.ApplyModifiedProperties();
        }
Example #3
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            EditorGUILayout.PropertyField(setIsTrigger, EditorStrings.TriggerZone.SetIsTrigger);
            EditorGUILayout.PropertyField(rangeMultiplier, EditorStrings.TriggerZone.RangeMultiplier);

            if (FoldableHeader.Begin(this, EditorStrings.TriggerZone.HeaderInfos))
            {
                EditorGUILayout.HelpBox(EditorStrings.TriggerZone.HelpDescription, MessageType.Info);

                if (m_Targets.HasAtLeastOneTargetWith((VolumetricLightBeam beam) => { return(beam.trackChangesDuringPlaytime); }))
                {
                    EditorGUILayout.HelpBox(EditorStrings.TriggerZone.HelpTrackChangesDuringPlaytimeEnabled, MessageType.Warning);
                }
            }
            FoldableHeader.End();

            serializedObject.ApplyModifiedProperties();
        }
Example #4
0
        bool DrawInfos()
        {
            var tips = GetInfoTips();
            var gpuInstancingReport = GetBatchingReport();

            if (tips.Count > 0 || !string.IsNullOrEmpty(gpuInstancingReport))
            {
                if (FoldableHeader.Begin(this, EditorStrings.Beam.HeaderInfos))
                {
                    foreach (var tip in tips)
                    {
                        EditorGUILayout.HelpBox(tip.message, tip.type);
                    }

                    if (!string.IsNullOrEmpty(gpuInstancingReport))
                    {
                        EditorGUILayout.HelpBox(gpuInstancingReport, MessageType.Warning);
                    }
                }
                FoldableHeader.End();
                return(true);
            }
            return(false);
        }
Example #5
0
 protected virtual void OnEnable()
 {
     FoldableHeader.OnEnable();
 }
Example #6
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            Debug.Assert(m_Targets.Count > 0);

#if DEBUG_SHOW_CUSTOM_MATERIAL_INFO
            if (m_Targets.Count == 1)
            {
                string msg  = "";
                var    geom = m_Targets[0].GetComponentInChildren <BeamGeometry>();
                if (geom == null)
                {
                    msg = "No BeamGeometry";
                }
                else
                {
                    msg = geom._EDITOR_IsUsingCustomMaterial ? "Custom Material" : "GPU Instanced Shared Material";
                }
                EditorGUILayout.HelpBox(msg, MessageType.Info);
            }
#endif

            bool hasLightSpot = false;
            var  light        = m_Targets[0].GetComponent <Light>();
            if (light)
            {
                hasLightSpot = light.type == LightType.Spot;
                if (!hasLightSpot)
                {
                    EditorGUILayout.HelpBox(EditorStrings.Beam.HelpNoSpotlight, MessageType.Warning);
                }
            }

            if (FoldableHeader.Begin(this, EditorStrings.Beam.HeaderBasic))
            {
                // Color
                using (ButtonToggleScopeFromLight(colorFromLight, hasLightSpot))
                {
                    if (!hasLightSpot)
                    {
                        EditorGUILayout.BeginHorizontal();                   // mandatory to have the color picker on the same line (when the button "from light" is not here)
                    }
                    {
                        if (Config.Instance.featureEnabledColorGradient == FeatureEnabledColorGradient.Off)
                        {
                            EditorGUILayout.PropertyField(color, EditorStrings.Beam.ColorMode);
                        }
                        else
                        {
                            EditorGUIUtility.fieldWidth = 65.0f;
                            EditorGUILayout.PropertyField(colorMode, EditorStrings.Beam.ColorMode);
                            EditorGUIUtility.fieldWidth = 0.0f;

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

                // Blending Mode
                EditorGUILayout.PropertyField(blendingMode, EditorStrings.Beam.BlendingMode);

                EditorGUILayout.Separator();

                // Intensity
                bool advancedModeEnabled = false;
                using (ButtonToggleScopeFromLight(intensityFromLight, hasLightSpot))
                {
                    bool advancedModeButton = !hasLightSpot || intensityFromLight.HasAtLeastOneValue(false);
                    using (ButtonToggleScopeAdvanced(intensityModeAdvanced, advancedModeButton))
                    {
                        advancedModeEnabled = intensityModeAdvanced.HasAtLeastOneValue(true);
                        EditorGUILayout.PropertyField(intensityOutside, advancedModeEnabled ? EditorStrings.Beam.IntensityOutside : EditorStrings.Beam.IntensityGlobal);
                    }
                }

                if (advancedModeEnabled)
                {
                    EditorGUILayout.PropertyField(intensityInside, EditorStrings.Beam.IntensityInside);
                }
                else
                {
                    intensityInside.floatValue = intensityOutside.floatValue;
                }

                EditorGUILayout.Separator();

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

                PropertyThickness(fresnelPow);

                EditorGUILayout.Separator();

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

                EditorGUILayout.Separator();

                if (Config.Instance.featureEnabledShaderAccuracyHigh)
                {
                    EditorGUILayout.PropertyField(shaderAccuracy, EditorStrings.Beam.ShaderAccuracy);
                    EditorGUILayout.Separator();
                }

                trackChangesDuringPlaytime.ToggleLeft(EditorStrings.Beam.TrackChanges);
                DrawAnimatorWarning();
            }
            FoldableHeader.End();

            if (FoldableHeader.Begin(this, EditorStrings.Beam.HeaderAttenuation))
            {
                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.PropertyField(attenuationEquation, EditorStrings.Beam.AttenuationEquation);
                    if (attenuationEquation.enumValueIndex == (int)AttenuationEquation.Blend)
                    {
                        EditorGUILayout.PropertyField(attenuationCustomBlending, EditorStrings.Beam.AttenuationCustomBlending);
                    }
                }
                EditorGUILayout.EndHorizontal();

                // Fade End
                using (ButtonToggleScopeFromLight(fallOffEndFromLight, hasLightSpot))
                {
                    EditorGUILayout.PropertyField(fallOffEnd, EditorStrings.Beam.FallOffEnd);
                }

                if (fallOffEnd.hasMultipleDifferentValues)
                {
                    EditorGUILayout.PropertyField(fallOffStart, EditorStrings.Beam.FallOffStart);
                }
                else
                {
                    fallOffStart.FloatSlider(EditorStrings.Beam.FallOffStart, 0f, fallOffEnd.floatValue - Consts.FallOffDistancesMinThreshold);
                }

                EditorGUILayout.Separator();

                // Tilt
                EditorGUILayout.PropertyField(tiltFactor, EditorStrings.Beam.TiltFactor);
                GlobalToggle(ref VolumetricLightBeam.editorShowTiltFactor, EditorStrings.Beam.EditorShowTiltDirection, "VLB_BEAM_SHOWTILTDIR");

                if (m_Targets.HasAtLeastOneTargetWith((VolumetricLightBeam beam) => { return(beam.isTilted && beam.shaderAccuracy != ShaderAccuracy.High); }))
                {
                    EditorGUILayout.HelpBox(EditorStrings.Beam.HelpTiltedWithShaderAccuracyFast, MessageType.Warning);
                }
            }
            FoldableHeader.End();

            if (Config.Instance.featureEnabledNoise3D)
            {
                if (FoldableHeader.Begin(this, EditorStrings.Beam.Header3DNoise))
                {
                    noiseMode.CustomEnum <NoiseMode>(EditorStrings.Beam.NoiseMode, EditorStrings.Beam.NoiseModeEnumDescriptions);

                    bool showNoiseProps = m_Targets.HasAtLeastOneTargetWith((VolumetricLightBeam beam) => { return(beam.isNoiseEnabled); });
                    if (showNoiseProps)
                    {
                        EditorGUILayout.PropertyField(noiseIntensity, EditorStrings.Beam.NoiseIntensity);

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

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

                        ButtonOpenConfig();

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

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

            if (FoldableHeader.Begin(this, EditorStrings.Beam.HeaderBlendingDistances))
            {
                {
                    var content = AddEnabledStatusToContentText(EditorStrings.Beam.CameraClippingDistance, cameraClippingDistance);
                    EditorGUILayout.PropertyField(cameraClippingDistance, content);
                }

                {
                    var content = AddEnabledStatusToContentText(EditorStrings.Beam.DepthBlendDistance, depthBlendDistance);
                    EditorGUILayout.PropertyField(depthBlendDistance, content);
                }
            }
            FoldableHeader.End();

            if (FoldableHeader.Begin(this, EditorStrings.Beam.HeaderGeometry))
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    EditorGUILayout.PropertyField(coneRadiusStart, EditorStrings.Beam.ConeRadiusStart);
                    EditorGUI.BeginChangeCheck();
                    {
                        geomCap.ToggleLeft(EditorStrings.Beam.GeomCap, GUILayout.MaxWidth(40.0f));
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        SetMeshesDirty();
                    }
                }

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

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

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

                    if (Config.Instance.featureEnabledMeshSkewing)
                    {
                        var vec3 = skewingLocalForwardDirection.vector3Value;
                        var vec2 = Vector2.zero;
                        EditorGUI.BeginChangeCheck();
                        {
                            vec2 = EditorGUILayout.Vector2Field(EditorStrings.Beam.SkewingLocalForwardDirection, vec3.xy());
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            vec3 = new Vector3(vec2.x, vec2.y, 1.0f);
                            skewingLocalForwardDirection.vector3Value = vec3;
                            SetMeshesDirty();
                        }
                    }

                    EditorGUI.indentLevel--;
                }

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

                EditorGUILayout.Separator();

                EditorGUILayout.PropertyField(clippingPlaneTransform, EditorStrings.Beam.ClippingPlane);

                if (m_Targets.HasAtLeastOneTargetWith((VolumetricLightBeam beam) => { return(beam.clippingPlaneTransform != null); }))
                {
                    GlobalToggle(ref VolumetricLightBeam.editorShowClippingPlane, EditorStrings.Beam.EditorShowClippingPlane, "VLB_BEAM_SHOWADDCLIPPINGPLANE");
                }
            }
            FoldableHeader.End();

            if (FoldableHeader.Begin(this, EditorStrings.Beam.HeaderFadeOut))
            {
                bool wasEnabled = fadeOutBegin.floatValue <= fadeOutEnd.floatValue;

                if (m_Targets.HasAtLeastOneTargetWith((VolumetricLightBeam beam) => { return((beam.fadeOutBegin <= beam.fadeOutEnd) != wasEnabled); }))
                {
                    wasEnabled = true;
                    EditorGUI.showMixedValue = true;
                }

                System.Action <float> setFadeOutBegin = value =>
                {
                    fadeOutBegin.floatValue = value;
                    m_Targets.RecordUndoAction("Change Fade Out Begin Distance",
                                               (VolumetricLightBeam beam) => { beam.fadeOutBegin = value; });
                };

                System.Action <float> setFadeOutEnd = value =>
                {
                    fadeOutEnd.floatValue = value;
                    m_Targets.RecordUndoAction("Change Fade Out End Distance",
                                               (VolumetricLightBeam beam) => { beam.fadeOutEnd = value; });
                };

                EditorGUI.BeginChangeCheck();
                bool isEnabled = EditorGUILayout.Toggle(EditorStrings.Beam.FadeOutEnabled, wasEnabled);
                EditorGUI.showMixedValue = false;
                if (EditorGUI.EndChangeCheck())
                {
                    float invValue = isEnabled ? 1 : -1;
                    float valueA   = Mathf.Abs(fadeOutBegin.floatValue);
                    float valueB   = Mathf.Abs(fadeOutEnd.floatValue);
                    setFadeOutBegin(invValue * Mathf.Min(valueA, valueB));
                    setFadeOutEnd(invValue * Mathf.Max(valueA, valueB));
                }

                if (isEnabled)
                {
                    const float kEpsilon = 0.1f;

                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.PropertyField(fadeOutBegin, EditorStrings.Beam.FadeOutBegin);
                    if (EditorGUI.EndChangeCheck())
                    {
                        setFadeOutBegin(Mathf.Clamp(fadeOutBegin.floatValue, 0, fadeOutEnd.floatValue - kEpsilon));
                    }

                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.PropertyField(fadeOutEnd, EditorStrings.Beam.FadeOutEnd);
                    if (EditorGUI.EndChangeCheck())
                    {
                        setFadeOutEnd(Mathf.Max(fadeOutBegin.floatValue + kEpsilon, fadeOutEnd.floatValue));
                    }

                    if (Application.isPlaying)
                    {
                        if (Config.Instance.fadeOutCameraTransform == null)
                        {
                            EditorGUILayout.HelpBox(EditorStrings.Beam.HelpFadeOutNoMainCamera, MessageType.Error);
                        }
                    }
                }
            }
            FoldableHeader.End();

            if (FoldableHeader.Begin(this, EditorStrings.Beam.Header2D))
            {
                dimensions.CustomEnum <Dimensions>(EditorStrings.Beam.Dimensions, EditorStrings.Common.DimensionsEnumDescriptions);
                DrawSortingLayer();
                DrawSortingOrder();
            }
            FoldableHeader.End();

            if (DrawInfos())
            {
                DrawLineSeparator();
            }

            DrawCustomActionButtons();
            DrawAdditionalFeatures();

            serializedObject.ApplyModifiedProperties();
        }
Example #7
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            Debug.Assert(m_TargetConfig != null);

            m_NeedToReloadNoise   = false;
            m_NeedToRefreshShader = false;
            m_IsUsedInstance      = m_TargetConfig.IsCurrentlyUsedInstance();

            // Config per plaftorm
#if UNITY_2018_1_OR_NEWER
            {
                bool hasValidName            = m_TargetConfig.HasValidAssetName();
                bool isCurrentPlatformSuffix = m_TargetConfig.GetAssetSuffix() == PlatformHelper.GetCurrentPlatformSuffix();

                var    platformSuffix = m_TargetConfig.GetAssetSuffix();
                string platformStr    = "Default Config asset";
                if (!string.IsNullOrEmpty(platformSuffix))
                {
                    platformStr = string.Format("Config asset for platform '{0}'", m_TargetConfig.GetAssetSuffix());
                }
                if (!hasValidName)
                {
                    platformStr += " (INVALID)";
                }
                EditorGUILayout.LabelField(platformStr, EditorStyles.boldLabel);

                if (GUILayout.Button(EditorStrings.Beam.ButtonCreateOverridePerPlatform, EditorStyles.miniButton))
                {
                    var menu = new GenericMenu();
                    foreach (var platform in System.Enum.GetValues(typeof(RuntimePlatform)))
                    {
                        menu.AddItem(new GUIContent(platform.ToString()), false, OnAddConfigPerPlatform, platform);
                    }
                    menu.ShowAsContext();
                }

                if (!hasValidName)
                {
                    EditorGUILayout.Separator();
                    EditorGUILayout.HelpBox(EditorStrings.Config.InvalidPlatformOverride, MessageType.Error);
                    ButtonOpenConfig();
                }
                else if (!m_IsUsedInstance)
                {
                    EditorGUILayout.Separator();

                    if (isCurrentPlatformSuffix)
                    {
                        EditorGUILayout.HelpBox(EditorStrings.Config.WrongAssetLocation, MessageType.Error);
                    }
                    else
                    {
                        EditorGUILayout.HelpBox(EditorStrings.Config.NotCurrentAssetInUse, MessageType.Warning);
                    }

                    ButtonOpenConfig();
                }

                DrawLineSeparator();
            }
#endif

            {
                EditorGUI.BeginChangeCheck();
                {
                    if (FoldableHeader.Begin(this, EditorStrings.Config.HeaderBeamGeometry))
                    {
                        using (new EditorGUILayout.HorizontalScope())
                        {
                            geometryOverrideLayer.boolValue = EditorGUILayout.Toggle(EditorStrings.Config.GeometryOverrideLayer, geometryOverrideLayer.boolValue);
                            using (new EditorGUI.DisabledGroupScope(!geometryOverrideLayer.boolValue))
                            {
                                geometryLayerID.intValue = EditorGUILayout.LayerField(geometryLayerID.intValue);
                            }
                        }

                        geometryTag.stringValue = EditorGUILayout.TagField(EditorStrings.Config.GeometryTag, geometryTag.stringValue);
                    }
                    FoldableHeader.End();

                    if (FoldableHeader.Begin(this, EditorStrings.Config.HeaderRendering))
                    {
                        RenderQueueGUIDraw();

                        if (BeamGeometry.isCustomRenderPipelineSupported)
                        {
                            EditorGUI.BeginChangeCheck();
                            {
                                renderPipeline.CustomEnum <RenderPipeline>(EditorStrings.Config.GeometryRenderPipeline, EditorStrings.Config.GeometryRenderPipelineEnumDescriptions);
                            }
                            if (EditorGUI.EndChangeCheck())
                            {
                                SetDirty(DirtyFlags.AllBeamGeom | DirtyFlags.Shader); // need to fully reset the BeamGeom to update the shader
                            }
                        }

                        if (m_TargetConfig.hasRenderPipelineMismatch)
                        {
                            EditorGUILayout.HelpBox(EditorStrings.Config.ErrorRenderPipelineMismatch, MessageType.Error);
                        }

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

                            if (renderPipeline.enumValueIndex == (int)RenderPipeline.BuiltIn)
                            {
                                if (renderingMode.enumValueIndex == (int)RenderingMode.SRPBatcher)
                                {
                                    EditorGUILayout.HelpBox(EditorStrings.Config.ErrorSrpBatcherOnlyCompatibleWithSrp, MessageType.Error);
                                }
                            }
                            else
                            {
                                if (renderingMode.enumValueIndex == (int)RenderingMode.SRPBatcher && SRPHelper.renderPipelineType == SRPHelper.RenderPipeline.LWRP)
                                {
                                    EditorGUILayout.HelpBox(EditorStrings.Config.ErrorSrpBatcherNotCompatibleWithLWRP, MessageType.Error);
                                }

                                if (renderingMode.enumValueIndex == (int)RenderingMode.MultiPass)
                                {
                                    EditorGUILayout.HelpBox(EditorStrings.Config.ErrorSrpAndMultiPassNotCompatible, MessageType.Error);
                                }
                            }

#pragma warning disable 0162 // warning CS0162: Unreachable code detected
                            if (renderingMode.enumValueIndex == (int)RenderingMode.GPUInstancing && !BatchingHelper.isGpuInstancingSupported)
                            {
                                EditorGUILayout.HelpBox(EditorStrings.Config.ErrorGeometryGpuInstancingNotSupported, MessageType.Error);
                            }
#pragma warning restore 0162
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            SetDirty(DirtyFlags.AllBeamGeom | DirtyFlags.GlobalMesh | DirtyFlags.Shader); // need to fully reset the BeamGeom to update the shader
                        }

                        if (m_TargetConfig.beamShader == null)
                        {
                            EditorGUILayout.HelpBox(EditorStrings.Config.GetErrorInvalidShader(), MessageType.Error);
                        }

                        if (ditheringFactor.FloatSlider(EditorStrings.Config.DitheringFactor, 0.0f, 1.0f))
                        {
                            SetDirty(DirtyFlags.Shader);
                        }
                    }
                    FoldableHeader.End();
                }
                if (EditorGUI.EndChangeCheck())
                {
                    VolumetricLightBeam._EditorSetAllMeshesDirty();
                }

                if (FoldableHeader.Begin(this, EditorStrings.Config.HeaderSharedMesh))
                {
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.PropertyField(sharedMeshSides, EditorStrings.Config.SharedMeshSides);
                    EditorGUILayout.PropertyField(sharedMeshSegments, EditorStrings.Config.SharedMeshSegments);
                    if (EditorGUI.EndChangeCheck())
                    {
                        SetDirty(DirtyFlags.GlobalMesh | DirtyFlags.AllMeshes);
                    }

                    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);
                }
                FoldableHeader.End();

                if (FoldableHeader.Begin(this, EditorStrings.Config.HeaderGlobal3DNoise))
                {
                    EditorGUILayout.PropertyField(globalNoiseScale, EditorStrings.Config.GlobalNoiseScale);
                    EditorGUILayout.PropertyField(globalNoiseVelocity, EditorStrings.Config.GlobalNoiseVelocity);
                }
                FoldableHeader.End();

                if (FoldableHeader.Begin(this, EditorStrings.Config.HeaderFadeOutCamera))
                {
                    EditorGUI.BeginChangeCheck();
                    fadeOutCameraTag.stringValue = EditorGUILayout.TagField(EditorStrings.Config.FadeOutCameraTag, fadeOutCameraTag.stringValue);
                    if (EditorGUI.EndChangeCheck() && Application.isPlaying)
                    {
                        m_TargetConfig.ForceUpdateFadeOutCamera();
                    }
                }
                FoldableHeader.End();

                if (FoldableHeader.Begin(this, EditorStrings.Config.HeaderFeaturesEnabled))
                {
                    EditorGUI.BeginChangeCheck();
                    {
                        EditorGUILayout.PropertyField(featureEnabledColorGradient, EditorStrings.Config.FeatureEnabledColorGradient);
                        EditorGUILayout.PropertyField(featureEnabledDepthBlend, EditorStrings.Config.FeatureEnabledDepthBlend);
                        EditorGUILayout.PropertyField(featureEnabledNoise3D, EditorStrings.Config.FeatureEnabledNoise3D);
                        EditorGUILayout.PropertyField(featureEnabledDynamicOcclusion, EditorStrings.Config.FeatureEnabledDynamicOcclusion);
                        EditorGUILayout.PropertyField(featureEnabledMeshSkewing, EditorStrings.Config.FeatureEnabledMeshSkewing);
                        EditorGUILayout.PropertyField(featureEnabledShaderAccuracyHigh, EditorStrings.Config.FeatureEnabledShaderAccuracyHigh);
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        SetDirty(DirtyFlags.Shader | DirtyFlags.AllBeamGeom);
                    }
                }
                FoldableHeader.End();

                if (FoldableHeader.Begin(this, EditorStrings.Config.HeaderInternalData))
                {
                    EditorGUILayout.PropertyField(dustParticlesPrefab, EditorStrings.Config.DustParticlesPrefab);

                    EditorGUILayout.PropertyField(ditheringNoiseTexture, EditorStrings.Config.DitheringNoiseTexture);

                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.PropertyField(noise3DData, EditorStrings.Config.Noise3DData);
                    EditorGUILayout.PropertyField(noise3DSize, EditorStrings.Config.Noise3DSize);
                    if (EditorGUI.EndChangeCheck())
                    {
                        SetDirty(DirtyFlags.Noise);
                    }

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

                if (GUILayout.Button(EditorStrings.Config.OpenDocumentation, EditorStyles.miniButton))
                {
                    UnityEditor.Help.BrowseURL(Consts.HelpUrlConfig);
                }

                using (new EditorGUILayout.HorizontalScope())
                {
                    if (GUILayout.Button(EditorStrings.Config.ResetToDefaultButton, EditorStyles.miniButton))
                    {
                        UnityEditor.Undo.RecordObject(target, "Reset Config Properties");
                        m_TargetConfig.Reset();
                        SetDirty(DirtyFlags.Target | DirtyFlags.Noise);
                    }

                    if (GUILayout.Button(EditorStrings.Config.ResetInternalDataButton, EditorStyles.miniButton))
                    {
                        UnityEditor.Undo.RecordObject(target, "Reset Internal Data");
                        m_TargetConfig.ResetInternalData();
                        SetDirty(DirtyFlags.Target | DirtyFlags.Noise);
                    }
                }
            }

            serializedObject.ApplyModifiedProperties();

            if (m_NeedToRefreshShader)
            {
                m_TargetConfig.RefreshShader(Config.RefreshShaderFlags.All); // need to be done AFTER ApplyModifiedProperties
            }
            if (m_NeedToReloadNoise)
            {
                Noise3D._EditorForceReloadData(); // Should be called AFTER ApplyModifiedProperties so the Config instance has the proper values when reloading data
            }
        }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            var particles = target as VolumetricDustParticles;

            if (!VolumetricDustParticles.isFeatureSupported)
            {
                EditorGUILayout.HelpBox(EditorStrings.DustParticles.HelpFeatureNotSupported, MessageType.Warning);
            }
            else if (particles.gameObject.activeSelf && particles.enabled && !particles.particlesAreInstantiated)
            {
                EditorGUILayout.HelpBox(EditorStrings.DustParticles.HelpFailToInstantiate, MessageType.Error);
                ButtonOpenConfig();
            }

            if (FoldableHeader.Begin(this, EditorStrings.DustParticles.HeaderRendering))
            {
                EditorGUILayout.PropertyField(alpha, EditorStrings.DustParticles.Alpha);
                EditorGUILayout.PropertyField(size, EditorStrings.DustParticles.Size);
            }
            FoldableHeader.End();

            if (FoldableHeader.Begin(this, EditorStrings.DustParticles.HeaderDirectionAndVelocity))
            {
                EditorGUILayout.PropertyField(direction, EditorStrings.DustParticles.Direction);

                if (particles.direction == ParticlesDirection.Random)
                {
                    var vec = velocity.vector3Value;
                    vec.z = EditorGUILayout.FloatField(EditorStrings.DustParticles.Velocity, vec.z);
                    velocity.vector3Value = vec;
                }
                else
                {
                    EditorGUILayout.PropertyField(velocity, EditorStrings.DustParticles.Velocity);
                }
            }
            FoldableHeader.End();

            if (FoldableHeader.Begin(this, EditorStrings.DustParticles.HeaderCulling))
            {
                EditorGUILayout.PropertyField(cullingEnabled, EditorStrings.DustParticles.CullingEnabled);
                if (cullingEnabled.boolValue)
                {
                    EditorGUILayout.PropertyField(cullingMaxDistance, EditorStrings.DustParticles.CullingMaxDistance);
                }
            }
            FoldableHeader.End();

            if (FoldableHeader.Begin(this, EditorStrings.DustParticles.HeaderSpawning))
            {
                EditorGUILayout.PropertyField(density, EditorStrings.DustParticles.Density);
                EditorGUILayout.PropertyField(spawnMinDistance, EditorStrings.DustParticles.SpawnMinDistance);
                EditorGUILayout.PropertyField(spawnMaxDistance, EditorStrings.DustParticles.SpawnMaxDistance);

                if (VolumetricDustParticles.isFeatureSupported)
                {
                    var infos = "Particles count:\nCurrent: ";
                    if (AreParticlesInfosUpdated())
                    {
                        infos += particles.particlesCurrentCount;
                    }
                    else
                    {
                        infos += "(playtime only)";
                    }
                    if (particles.isCulled)
                    {
                        infos += string.Format(" (culled by '{0}')", particles.mainCamera.name);
                    }
                    infos += string.Format("\nMax: {0}", particles.particlesMaxCount);
                    EditorGUILayout.HelpBox(infos, MessageType.Info);
                }
            }
            FoldableHeader.End();

            if (FoldableHeader.Begin(this, EditorStrings.DustParticles.HeaderInfos))
            {
                EditorGUILayout.HelpBox(EditorStrings.DustParticles.HelpRecommendation, MessageType.Info);
            }
            FoldableHeader.End();

            serializedObject.ApplyModifiedProperties();
        }
Example #9
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            bool reloadNoise = false;

            bool isUsedInstance = (Object)Config.Instance == this.target;

            if (!IsOverriddenInstance())
            {
                if (isUsedInstance)
                {
                    if (!Application.isPlaying)
                    {
                        if (GUILayout.Button(EditorStrings.Config.CreateOverrideAsset))
                        {
                            ConfigOverrideEditor.CreateAsset();
                        }
                    }
                }
                else
                {
                    ButtonOpenConfig(/*miniButton*/ false);
                }
                DrawLineSeparator();
            }

            if (IsOverriddenInstance() && !isUsedInstance)
            {
                EditorGUILayout.HelpBox(EditorStrings.Config.MultipleAssets, MessageType.Error);
                EditorGUILayout.Separator();
                ButtonOpenConfig();
            }
            else
            {
                EditorGUI.BeginDisabledGroup(IsDisabled());
                {
                    EditorGUI.BeginChangeCheck();
                    {
                        if (FoldableHeader.Begin(this, "Beam Geometry"))
                        {
                            using (new EditorGUILayout.HorizontalScope())
                            {
                                geometryOverrideLayer.boolValue = EditorGUILayout.Toggle(EditorStrings.Config.GeometryOverrideLayer, geometryOverrideLayer.boolValue);
                                using (new EditorGUI.DisabledGroupScope(!geometryOverrideLayer.boolValue))
                                {
                                    geometryLayerID.intValue = EditorGUILayout.LayerField(geometryLayerID.intValue);
                                }
                            }

                            geometryTag.stringValue = EditorGUILayout.TagField(EditorStrings.Config.GeometryTag, geometryTag.stringValue);
                        }
                        FoldableHeader.End();

                        if (FoldableHeader.Begin(this, "Rendering"))
                        {
                            RenderQueueGUIDraw();

                            if (BeamGeometry.isCustomRenderPipelineSupported)
                            {
                                EditorGUI.BeginChangeCheck();
                                {
                                    renderPipeline.CustomEnum <RenderPipeline>(EditorStrings.Config.GeometryRenderPipeline, EditorStrings.Config.GeometryRenderPipelineEnumDescriptions);
                                }
                                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.Config.GeometryRenderingMode);

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

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

                    if (FoldableHeader.Begin(this, "Shared Mesh"))
                    {
                        EditorGUI.BeginChangeCheck();
                        EditorGUILayout.PropertyField(sharedMeshSides, EditorStrings.Config.SharedMeshSides);
                        EditorGUILayout.PropertyField(sharedMeshSegments, EditorStrings.Config.SharedMeshSegments);
                        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);
                    }
                    FoldableHeader.End();

                    if (FoldableHeader.Begin(this, "Global 3D Noise"))
                    {
                        EditorGUILayout.PropertyField(globalNoiseScale, EditorStrings.Config.GlobalNoiseScale);
                        EditorGUILayout.PropertyField(globalNoiseVelocity, EditorStrings.Config.GlobalNoiseVelocity);
                    }
                    FoldableHeader.End();

                    if (FoldableHeader.Begin(this, "Camera to compute Fade Out"))
                    {
                        EditorGUI.BeginChangeCheck();
                        fadeOutCameraTag.stringValue = EditorGUILayout.TagField(EditorStrings.Config.FadeOutCameraTag, fadeOutCameraTag.stringValue);
                        if (EditorGUI.EndChangeCheck() && Application.isPlaying)
                        {
                            (target as Config).ForceUpdateFadeOutCamera();
                        }
                    }
                    FoldableHeader.End();

                    if (FoldableHeader.Begin(this, "Internal Data (do not change)"))
                    {
                        EditorGUILayout.PropertyField(beamShader1Pass, EditorStrings.Config.BeamShader1Pass);
                        EditorGUILayout.PropertyField(beamShader2Pass, EditorStrings.Config.BeamShader2Pass);
                        if (BeamGeometry.isCustomRenderPipelineSupported)
                        {
                            EditorGUILayout.PropertyField(beamShaderSRP, EditorStrings.Config.BeamShaderSRP);
                        }
                        EditorGUILayout.PropertyField(dustParticlesPrefab, EditorStrings.Config.DustParticlesPrefab);

                        EditorGUI.BeginChangeCheck();
                        EditorGUILayout.PropertyField(noise3DData, EditorStrings.Config.Noise3DData);
                        EditorGUILayout.PropertyField(noise3DSize, EditorStrings.Config.Noise3DSize);
                        if (EditorGUI.EndChangeCheck())
                        {
                            reloadNoise = true;
                        }

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

                    if (GUILayout.Button(EditorStrings.Config.OpenDocumentation, EditorStyles.miniButton))
                    {
                        UnityEditor.Help.BrowseURL(Consts.HelpUrlConfig);
                    }

                    using (new EditorGUILayout.HorizontalScope())
                    {
                        if (GUILayout.Button(EditorStrings.Config.ResetToDefaultButton, EditorStyles.miniButton))
                        {
                            UnityEditor.Undo.RecordObject(target, "Reset Config Properties");
                            (target as Config).Reset();
                            EditorUtility.SetDirty(target);
                        }

                        if (GUILayout.Button(EditorStrings.Config.ResetInternalDataButton, EditorStyles.miniButton))
                        {
                            UnityEditor.Undo.RecordObject(target, "Reset Internal Data");
                            (target as Config).ResetInternalData();
                            EditorUtility.SetDirty(target);
                        }
                    }
                }
                EditorGUI.EndDisabledGroup();
            }

            serializedObject.ApplyModifiedProperties();

            if (reloadNoise)
            {
                Noise3D._EditorForceReloadData(); // Should be called AFTER ApplyModifiedProperties so the Config instance has the proper values when reloading data
            }
        }
Example #10
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            if (FoldableHeader.Begin(this, EditorStrings.DynOcclusion.HeaderRaycasting))
            {
                dimensions.CustomEnum <OccluderDimensions>(EditorStrings.DynOcclusion.Dimensions, EditorStrings.DynOcclusion.DimensionsEnumDescriptions);
                EditorGUILayout.PropertyField(layerMask, EditorStrings.DynOcclusion.LayerMask);
                EditorGUILayout.PropertyField(considerTriggers, EditorStrings.DynOcclusion.ConsiderTriggers);

                if (Physics2D.queriesHitTriggers == false)
                {
                    if (m_Targets.HasAtLeastOneTargetWith((DynamicOcclusionRaycasting instance) => { return(instance.dimensions == OccluderDimensions.Occluders2D && instance.considerTriggers); }))
                    {
                        EditorGUILayout.HelpBox(EditorStrings.DynOcclusion.ConsiderTriggersNoPossible, MessageType.Error);
                    }
                }

                EditorGUILayout.PropertyField(minOccluderArea, EditorStrings.DynOcclusion.MinOccluderArea);
            }

            FoldableHeader.End();

            DisplayCommonInspector();

            if (FoldableHeader.Begin(this, EditorStrings.DynOcclusion.HeaderOccluderSurface))
            {
                minSurfaceRatio.FloatSlider(
                    EditorStrings.DynOcclusion.MinSurfaceRatio,
                    Consts.DynOcclusionRaycastingMinSurfaceRatioMin, Consts.DynOcclusionRaycastingMinSurfaceRatioMax,
                    (value) => value * 100f,  // conversion value to slider
                    (value) => value / 100f   // conversion slider to value
                    );

                maxSurfaceDot.FloatSlider(
                    EditorStrings.DynOcclusion.MaxSurfaceDot,
                    Consts.DynOcclusionRaycastingMaxSurfaceAngleMin, Consts.DynOcclusionRaycastingMaxSurfaceAngleMax,
                    (value) => Mathf.Acos(value) * Mathf.Rad2Deg,   // conversion value to slider
                    (value) => Mathf.Cos(value * Mathf.Deg2Rad)     // conversion slider to value
                    );
            }

            FoldableHeader.End();

            if (FoldableHeader.Begin(this, EditorStrings.DynOcclusion.HeaderClippingPlane))
            {
                EditorGUILayout.PropertyField(planeAlignment, EditorStrings.DynOcclusion.PlaneAlignment);
                EditorGUILayout.PropertyField(planeOffset, EditorStrings.DynOcclusion.PlaneOffset);
                EditorGUILayout.PropertyField(fadeDistanceToSurface, EditorStrings.DynOcclusion.FadeDistanceToSurface);
            }

            FoldableHeader.End();

            if (FoldableHeader.Begin(this, EditorStrings.DynOcclusion.HeaderEditorDebug))
            {
                EditorGUI.BeginChangeCheck();
                DynamicOcclusionRaycasting.editorShowDebugPlane = EditorGUILayout.Toggle(EditorStrings.DynOcclusion.EditorShowDebugPlane, DynamicOcclusionRaycasting.editorShowDebugPlane);
                if (EditorGUI.EndChangeCheck())
                {
                    EditorPrefs.SetBool("VLB_DYNOCCLUSION_SHOWDEBUGPLANE", DynamicOcclusionRaycasting.editorShowDebugPlane);
                    SceneView.RepaintAll();
                }

                EditorGUI.BeginChangeCheck();
                DynamicOcclusionRaycasting.editorRaycastAtEachFrame = EditorGUILayout.Toggle(EditorStrings.DynOcclusion.EditorRaycastAtEachFrame, DynamicOcclusionRaycasting.editorRaycastAtEachFrame);
                if (EditorGUI.EndChangeCheck())
                {
                    EditorPrefs.SetBool("VLB_DYNOCCLUSION_RAYCASTINEDITOR", DynamicOcclusionRaycasting.editorRaycastAtEachFrame);
                    SceneView.RepaintAll();
                }

                if (Application.isPlaying || DynamicOcclusionRaycasting.editorRaycastAtEachFrame)
                {
                    if (!serializedObject.isEditingMultipleObjects)
                    {
                        var instance = (target as DynamicOcclusionRaycasting);
                        Debug.Assert(instance);
                        var hit             = instance.currentHit;
                        var lastFrameUpdate = instance.editorDebugData.lastFrameUpdate;

                        var occluderInfo = string.Format("Last update {0} frame(s) ago\n", Time.frameCount - lastFrameUpdate);
                        occluderInfo += (hit != null) ? string.Format("Current occluder: '{0}'\nEstimated occluder area: {1} unitsĀ²", hit.name, hit.bounds.GetMaxArea2D()) : "No occluder found";
                        EditorGUILayout.HelpBox(occluderInfo, MessageType.Info);
                    }
                }
            }
            FoldableHeader.End();

            serializedObject.ApplyModifiedProperties();
        }