コード例 #1
0
        protected override void OnEnable()
        {
            base.OnEnable();

            // Get & automatically add additional HD data if not present
            m_AdditionalLightDatas           = CoreEditorUtils.GetAdditionalData <HDAdditionalLightData>(targets, HDAdditionalLightData.InitDefaultHDAdditionalLightData);
            m_AdditionalShadowDatas          = CoreEditorUtils.GetAdditionalData <AdditionalShadowData>(targets, HDAdditionalShadowData.InitDefaultHDAdditionalShadowData);
            m_SerializedAdditionalLightData  = new SerializedObject(m_AdditionalLightDatas);
            m_SerializedAdditionalShadowData = new SerializedObject(m_AdditionalShadowDatas);

            using (var o = new PropertyFetcher <HDAdditionalLightData>(m_SerializedAdditionalLightData))
                m_AdditionalLightData = new SerializedLightData
                {
                    directionalIntensity         = o.Find(x => x.directionalIntensity),
                    punctualIntensity            = o.Find(x => x.punctualIntensity),
                    areaIntensity                = o.Find(x => x.areaIntensity),
                    enableSpotReflector          = o.Find(x => x.enableSpotReflector),
                    spotInnerPercent             = o.Find(x => x.m_InnerSpotPercent),
                    lightDimmer                  = o.Find(x => x.lightDimmer),
                    volumetricDimmer             = o.Find(x => x.volumetricDimmer),
                    displayAreaLightEmissiveMesh = o.Find(x => x.displayAreaLightEmissiveMesh),
                    fadeDistance                 = o.Find(x => x.fadeDistance),
                    affectDiffuse                = o.Find(x => x.affectDiffuse),
                    affectSpecular               = o.Find(x => x.affectSpecular),
                    nonLightmappedOnly           = o.Find(x => x.nonLightmappedOnly),
                    lightTypeExtent              = o.Find(x => x.lightTypeExtent),
                    spotLightShape               = o.Find(x => x.spotLightShape),
                    shapeWidth            = o.Find(x => x.shapeWidth),
                    shapeHeight           = o.Find(x => x.shapeHeight),
                    aspectRatio           = o.Find(x => x.aspectRatio),
                    shapeRadius           = o.Find(x => x.shapeRadius),
                    maxSmoothness         = o.Find(x => x.maxSmoothness),
                    applyRangeAttenuation = o.Find(x => x.applyRangeAttenuation),

                    // Editor stuff
                    useOldInspector        = o.Find(x => x.useOldInspector),
                    showFeatures           = o.Find(x => x.featuresFoldout),
                    showAdditionalSettings = o.Find(x => x.showAdditionalSettings)
                };

            // TODO: Review this once AdditionalShadowData is refactored
            using (var o = new PropertyFetcher <AdditionalShadowData>(m_SerializedAdditionalShadowData))
                m_AdditionalShadowData = new SerializedShadowData
                {
                    dimmer         = o.Find(x => x.shadowDimmer),
                    fadeDistance   = o.Find(x => x.shadowFadeDistance),
                    resolution     = o.Find(x => x.shadowResolution),
                    contactShadows = o.Find(x => x.contactShadows),

                    viewBiasMin         = o.Find(x => x.viewBiasMin),
                    viewBiasMax         = o.Find(x => x.viewBiasMax),
                    viewBiasScale       = o.Find(x => x.viewBiasScale),
                    normalBiasMin       = o.Find(x => x.normalBiasMin),
                    normalBiasMax       = o.Find(x => x.normalBiasMax),
                    normalBiasScale     = o.Find(x => x.normalBiasScale),
                    sampleBiasScale     = o.Find(x => x.sampleBiasScale),
                    edgeLeakFixup       = o.Find(x => x.edgeLeakFixup),
                    edgeToleranceNormal = o.Find(x => x.edgeToleranceNormal),
                    edgeTolerance       = o.Find(x => x.edgeTolerance)
                };
        }
コード例 #2
0
 void OnPostprocessModel(GameObject go)
 {
     CoreEditorUtils.AddAdditionalData <Camera, UniversalAdditionalCameraData>(go);
     CoreEditorUtils.AddAdditionalData <Light, UniversalAdditionalLightData>(go);
 }
コード例 #3
0
        //[MenuItem("Internal/HDRenderPipeline/Update/Update Height Maps parametrization")]
        static void UpdateHeightMapParametrization()
        {
            try
            {
                var matIds = AssetDatabase.FindAssets("t:Material");

                for (int i = 0, length = matIds.Length; i < length; i++)
                {
                    var path = AssetDatabase.GUIDToAssetPath(matIds[i]);
                    var mat  = AssetDatabase.LoadAssetAtPath <Material>(path);

                    EditorUtility.DisplayProgressBar(
                        "Updating Materials...",
                        string.Format("{0} / {1} materials updated.", i, length),
                        i / (float)(length - 1));

                    bool VCSEnabled = (UnityEditor.VersionControl.Provider.enabled && UnityEditor.VersionControl.Provider.isActive);

                    if (mat.shader.name == "HDRenderPipeline/LitTessellation" ||
                        mat.shader.name == "HDRenderPipeline/Lit")
                    {
                        // Need only test one of the new properties
                        if (mat.HasProperty("_HeightPoMAmplitude"))
                        {
                            CoreEditorUtils.CheckOutFile(VCSEnabled, mat);

                            float valueMax  = mat.GetFloat("_HeightMax");
                            float valueMin  = mat.GetFloat("_HeightMin");
                            float center    = mat.GetFloat("_HeightCenter");
                            float amplitude = valueMax - valueMin;
                            mat.SetInt("_HeightMapParametrization", 1);
                            mat.SetFloat("_HeightPoMAmplitude", amplitude);
                            mat.SetFloat("_HeightTessAmplitude", amplitude);
                            mat.SetFloat("_HeightOffset", 0.0f);
                            mat.SetFloat("_HeightTessCenter", center);

                            BaseLitGUI.DisplacementMode displaceMode = (BaseLitGUI.DisplacementMode)mat.GetInt("_DisplacementMode");
                            if (displaceMode == BaseLitGUI.DisplacementMode.Pixel)
                            {
                                mat.SetFloat("_HeightCenter", 1.0f); // With PoM this is always 1.0f. We set it here to avoid having to open the UI to update it.
                            }

                            EditorUtility.SetDirty(mat);
                        }
                    }
                    else if (mat.shader.name == "HDRenderPipeline/LayeredLit" ||
                             mat.shader.name == "HDRenderPipeline/LayeredLitTessellation")
                    {
                        int numLayer = (int)mat.GetFloat("_LayerCount");

                        if (mat.HasProperty("_HeightPoMAmplitude0"))
                        {
                            CoreEditorUtils.CheckOutFile(VCSEnabled, mat);

                            for (int x = 0; x < numLayer; ++x)
                            {
                                float valueMax  = mat.GetFloat("_HeightMax" + x);
                                float valueMin  = mat.GetFloat("_HeightMin" + x);
                                float center    = mat.GetFloat("_HeightCenter" + x);
                                float amplitude = valueMax - valueMin;
                                mat.SetInt("_HeightMapParametrization" + x, 1);
                                mat.SetFloat("_HeightPoMAmplitude" + x, amplitude);
                                mat.SetFloat("_HeightTessAmplitude" + x, amplitude);
                                mat.SetFloat("_HeightOffset" + x, 0.0f);
                                mat.SetFloat("_HeightTessCenter" + x, center);

                                BaseLitGUI.DisplacementMode displaceMode = (BaseLitGUI.DisplacementMode)mat.GetInt("_DisplacementMode");
                                if (displaceMode == BaseLitGUI.DisplacementMode.Pixel)
                                {
                                    mat.SetFloat("_HeightCenter" + x, 1.0f); // With PoM this is always 1.0f. We set it here to avoid having to open the UI to update it.
                                }
                            }

                            EditorUtility.SetDirty(mat);
                        }
                    }
                }
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }
        }
コード例 #4
0
 void OnPostprocessModel(GameObject go)
 {
     CoreEditorUtils.AddAdditionalData <Camera, HDAdditionalCameraData>(go, HDAdditionalCameraData.InitDefaultHDAdditionalCameraData);
     CoreEditorUtils.AddAdditionalData <Light, HDAdditionalLightData>(go, HDAdditionalLightData.InitDefaultHDAdditionalLightData);
     CoreEditorUtils.AddAdditionalData <ReflectionProbe, HDAdditionalReflectionData>(go);
 }
コード例 #5
0
        static void UpdateMaterialToNewerVersion(string caption, float scriptVersion, UpdateMaterial updateMaterial, UpdateMaterialFile updateMaterialFile = null)
        {
            bool          VCSEnabled    = (UnityEditor.VersionControl.Provider.enabled && UnityEditor.VersionControl.Provider.isActive);
            var           matIds        = AssetDatabase.FindAssets("t:Material");
            List <string> materialFiles = new List <string>(); // Contain the list dirty files

            try
            {
                for (int i = 0, length = matIds.Length; i < length; i++)
                {
                    var path = AssetDatabase.GUIDToAssetPath(matIds[i]);
                    var mat  = AssetDatabase.LoadAssetAtPath <Material>(path);

                    EditorUtility.DisplayProgressBar(
                        "Update material to new version " + caption + "...",
                        string.Format("{0} / {1} materials updated.", i, length),
                        i / (float)(length - 1));

                    if (mat.shader.name == "HDRenderPipeline/LitTessellation" ||
                        mat.shader.name == "HDRenderPipeline/Lit" ||
                        mat.shader.name == "HDRenderPipeline/LayeredLit" ||
                        mat.shader.name == "HDRenderPipeline/LayeredLitTessellation" ||
                        mat.shader.name == "HDRenderPipeline/StackLit" ||
                        mat.shader.name == "HDRenderPipeline/Unlit" ||
                        mat.shader.name == "HDRenderPipeline/Fabric" ||
                        mat.shader.name == "HDRenderPipeline/Decal" ||
                        mat.shader.name == "HDRenderPipeline/TerrainLit"
                        )
                    {
                        // We don't handle embed material as we can't rewrite fbx files
                        if (Path.GetExtension(path).ToLower() == ".fbx")
                        {
                            continue;
                        }

                        // Get current version
                        float materialVersion = UpdateMaterial_GetVersion(path, mat);

                        if (materialVersion < scriptVersion)
                        {
                            updateMaterial(path, mat);

                            // Update version number to script number (so next script can upgrade correctly)
                            mat.SetFloat("_HdrpVersion", scriptVersion);


                            // Checkout the file and tag it as dirty
                            CoreEditorUtils.CheckOutFile(VCSEnabled, mat);
                            EditorUtility.SetDirty(mat);
                            materialFiles.Add(path);
                        }
                    }
                }
            }
            finally
            {
                EditorUtility.ClearProgressBar();
                // Save all dirty assets
                AssetDatabase.SaveAssets();
            }

            if (updateMaterialFile == null)
            {
                return;
            }

            // Now that all the asset have been modified and save, we can safely update the .mat file and remove removed property
            try
            {
                for (int i = 0, length = materialFiles.Count; i < length; i++)
                {
                    string path = materialFiles[i];

                    EditorUtility.DisplayProgressBar(
                        "Update .mat files...",
                        string.Format("{0} / {1} materials .mat file updated.", i, length),
                        i / (float)(length - 1));

                    // Note: The file is supposed to be checkout by the previous loop
                    updateMaterialFile(path);
                }
            }
            finally
            {
                EditorUtility.ClearProgressBar();
                // No need to save in this case
            }
        }
コード例 #6
0
        protected override void OnEnable()
        {
            base.OnEnable();

            // Get & automatically add additional HD data if not present
            m_AdditionalLightDatas           = CoreEditorUtils.GetAdditionalData <HDAdditionalLightData>(targets, HDAdditionalLightData.InitDefaultHDAdditionalLightData);
            m_AdditionalShadowDatas          = CoreEditorUtils.GetAdditionalData <AdditionalShadowData>(targets, HDAdditionalShadowData.InitDefaultHDAdditionalShadowData);
            m_SerializedAdditionalLightData  = new SerializedObject(m_AdditionalLightDatas);
            m_SerializedAdditionalShadowData = new SerializedObject(m_AdditionalShadowDatas);

            using (var o = new PropertyFetcher <HDAdditionalLightData>(m_SerializedAdditionalLightData))
                m_AdditionalLightData = new SerializedLightData
                {
                    intensity                    = o.Find(x => x.displayLightIntensity),
                    enableSpotReflector          = o.Find(x => x.enableSpotReflector),
                    spotInnerPercent             = o.Find(x => x.m_InnerSpotPercent),
                    lightDimmer                  = o.Find(x => x.lightDimmer),
                    volumetricDimmer             = o.Find(x => x.volumetricDimmer),
                    lightUnit                    = o.Find(x => x.lightUnit),
                    displayAreaLightEmissiveMesh = o.Find(x => x.displayAreaLightEmissiveMesh),
                    lightLayers                  = o.Find(x => x.lightLayers),
                    fadeDistance                 = o.Find(x => x.fadeDistance),
                    affectDiffuse                = o.Find(x => x.affectDiffuse),
                    affectSpecular               = o.Find(x => x.affectSpecular),
                    nonLightmappedOnly           = o.Find(x => x.nonLightmappedOnly),
                    lightTypeExtent              = o.Find(x => x.lightTypeExtent),
                    spotLightShape               = o.Find(x => x.spotLightShape),
                    shapeWidth                   = o.Find(x => x.shapeWidth),
                    shapeHeight                  = o.Find(x => x.shapeHeight),
                    aspectRatio                  = o.Find(x => x.aspectRatio),
                    shapeRadius                  = o.Find(x => x.shapeRadius),
                    maxSmoothness                = o.Find(x => x.maxSmoothness),
                    applyRangeAttenuation        = o.Find(x => x.applyRangeAttenuation),

                    // Editor stuff
                    useOldInspector        = o.Find(x => x.useOldInspector),
                    showFeatures           = o.Find(x => x.featuresFoldout),
                    showAdditionalSettings = o.Find(x => x.showAdditionalSettings)
                };

            // TODO: Review this once AdditionalShadowData is refactored
            using (var o = new PropertyFetcher <AdditionalShadowData>(m_SerializedAdditionalShadowData))
                m_AdditionalShadowData = new SerializedShadowData
                {
                    dimmer         = o.Find(x => x.shadowDimmer),
                    fadeDistance   = o.Find(x => x.shadowFadeDistance),
                    resolution     = o.Find(x => x.shadowResolution),
                    contactShadows = o.Find(x => x.contactShadows),

                    viewBiasMin         = o.Find(x => x.viewBiasMin),
                    viewBiasMax         = o.Find(x => x.viewBiasMax),
                    viewBiasScale       = o.Find(x => x.viewBiasScale),
                    normalBiasMin       = o.Find(x => x.normalBiasMin),
                    normalBiasMax       = o.Find(x => x.normalBiasMax),
                    normalBiasScale     = o.Find(x => x.normalBiasScale),
                    sampleBiasScale     = o.Find(x => x.sampleBiasScale),
                    edgeLeakFixup       = o.Find(x => x.edgeLeakFixup),
                    edgeToleranceNormal = o.Find(x => x.edgeToleranceNormal),
                    edgeTolerance       = o.Find(x => x.edgeTolerance)
                };

            // Update emissive mesh and light intensity when undo/redo
            Undo.undoRedoPerformed += () => {
                m_SerializedAdditionalLightData.ApplyModifiedProperties();
                foreach (var hdLightData in m_AdditionalLightDatas)
                {
                    if (hdLightData != null)
                    {
                        hdLightData.UpdateAreaLightEmissiveMesh();
                    }
                }
            };

            // If the light is disabled in the editor we force the light upgrade from his inspector
            foreach (var additionalLightData in m_AdditionalLightDatas)
            {
                additionalLightData.UpgradeLight();
            }
        }
コード例 #7
0
        static void Drawer_VolumeContent(SerializedDensityVolume serialized, Editor owner)
        {
            //keep previous data as value are stored in percent
            Vector3 previousSize         = serialized.size.vector3Value;
            float   previousUniformFade  = serialized.editorUniformFade.floatValue;
            Vector3 previousPositiveFade = serialized.editorPositiveFade.vector3Value;
            Vector3 previousNegativeFade = serialized.editorNegativeFade.vector3Value;

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(serialized.size, Styles.s_Size);
            if (EditorGUI.EndChangeCheck())
            {
                Vector3 newSize = serialized.size.vector3Value;
                newSize.x = Mathf.Max(0f, newSize.x);
                newSize.y = Mathf.Max(0f, newSize.y);
                newSize.z = Mathf.Max(0f, newSize.z);
                serialized.size.vector3Value = newSize;

                //update advanced mode blend
                Vector3 newPositiveFade = new Vector3(
                    newSize.x < 0.00001 ? 0 : previousPositiveFade.x * previousSize.x / newSize.x,
                    newSize.y < 0.00001 ? 0 : previousPositiveFade.y * previousSize.y / newSize.y,
                    newSize.z < 0.00001 ? 0 : previousPositiveFade.z * previousSize.z / newSize.z
                    );
                Vector3 newNegativeFade = new Vector3(
                    newSize.x < 0.00001 ? 0 : previousNegativeFade.x * previousSize.x / newSize.x,
                    newSize.y < 0.00001 ? 0 : previousNegativeFade.y * previousSize.y / newSize.y,
                    newSize.z < 0.00001 ? 0 : previousNegativeFade.z * previousSize.z / newSize.z
                    );
                for (int axeIndex = 0; axeIndex < 3; ++axeIndex)
                {
                    if (newPositiveFade[axeIndex] + newNegativeFade[axeIndex] > 1)
                    {
                        float overValue = (newPositiveFade[axeIndex] + newNegativeFade[axeIndex] - 1f) * 0.5f;
                        newPositiveFade[axeIndex] -= overValue;
                        newNegativeFade[axeIndex] -= overValue;

                        if (newPositiveFade[axeIndex] < 0)
                        {
                            newNegativeFade[axeIndex] += newPositiveFade[axeIndex];
                            newPositiveFade[axeIndex]  = 0f;
                        }
                        if (newNegativeFade[axeIndex] < 0)
                        {
                            newPositiveFade[axeIndex] += newNegativeFade[axeIndex];
                            newNegativeFade[axeIndex]  = 0f;
                        }
                    }
                }
                serialized.editorPositiveFade.vector3Value = newPositiveFade;
                serialized.editorNegativeFade.vector3Value = newNegativeFade;

                //update normal mode blend
                float max = Mathf.Min(newSize.x, newSize.y, newSize.z) * 0.5f;
                serialized.editorUniformFade.floatValue = Mathf.Clamp(serialized.editorUniformFade.floatValue, 0f, max);
            }

            Vector3 serializedSize = serialized.size.vector3Value;

            EditorGUI.BeginChangeCheck();
            if (serialized.editorAdvancedFade.hasMultipleDifferentValues)
            {
                using (new EditorGUI.DisabledScope(true))
                    EditorGUILayout.LabelField(Styles.s_BlendLabel, EditorGUIUtility.TrTextContent("Multiple values for Advanced mode"));
            }
            else if (serialized.editorAdvancedFade.boolValue)
            {
                EditorGUI.BeginChangeCheck();
                CoreEditorUtils.DrawVector6(Styles.s_BlendLabel, serialized.editorPositiveFade, serialized.editorNegativeFade, Vector3.zero, serializedSize, InfluenceVolumeUI.k_HandlesColor, serialized.size);
                if (EditorGUI.EndChangeCheck())
                {
                    //forbid positive/negative box that doesn't intersect in inspector too
                    Vector3 positive = serialized.editorPositiveFade.vector3Value;
                    Vector3 negative = serialized.editorNegativeFade.vector3Value;
                    for (int axis = 0; axis < 3; ++axis)
                    {
                        if (positive[axis] > 1f - negative[axis])
                        {
                            if (positive == serialized.editorPositiveFade.vector3Value)
                            {
                                negative[axis] = 1f - positive[axis];
                            }
                            else
                            {
                                positive[axis] = 1f - negative[axis];
                            }
                        }
                    }
                    serialized.editorPositiveFade.vector3Value = positive;
                    serialized.editorNegativeFade.vector3Value = negative;
                }
            }
            else
            {
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(serialized.editorUniformFade, Styles.s_BlendLabel);
                if (EditorGUI.EndChangeCheck())
                {
                    float max = Mathf.Min(serializedSize.x, serializedSize.y, serializedSize.z) * 0.5f;
                    serialized.editorUniformFade.floatValue = Mathf.Clamp(serialized.editorUniformFade.floatValue, 0f, max);
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                Vector3 posFade = new Vector3();
                posFade.x = Mathf.Clamp01(serialized.editorPositiveFade.vector3Value.x);
                posFade.y = Mathf.Clamp01(serialized.editorPositiveFade.vector3Value.y);
                posFade.z = Mathf.Clamp01(serialized.editorPositiveFade.vector3Value.z);

                Vector3 negFade = new Vector3();
                negFade.x = Mathf.Clamp01(serialized.editorNegativeFade.vector3Value.x);
                negFade.y = Mathf.Clamp01(serialized.editorNegativeFade.vector3Value.y);
                negFade.z = Mathf.Clamp01(serialized.editorNegativeFade.vector3Value.z);

                serialized.editorPositiveFade.vector3Value = posFade;
                serialized.editorNegativeFade.vector3Value = negFade;
            }

            EditorGUILayout.PropertyField(serialized.invertFade, Styles.s_InvertFadeLabel);

            // Distance fade.
            {
                EditorGUI.BeginChangeCheck();

                float distanceFadeStart = EditorGUILayout.FloatField(Styles.s_DistanceFadeStartLabel, serialized.distanceFadeStart.floatValue);
                float distanceFadeEnd   = EditorGUILayout.FloatField(Styles.s_DistanceFadeEndLabel, serialized.distanceFadeEnd.floatValue);

                if (EditorGUI.EndChangeCheck())
                {
                    distanceFadeStart = Mathf.Max(0, distanceFadeStart);
                    distanceFadeEnd   = Mathf.Max(distanceFadeStart, distanceFadeEnd);

                    serialized.distanceFadeStart.floatValue = distanceFadeStart;
                    serialized.distanceFadeEnd.floatValue   = distanceFadeEnd;
                }
            }
        }
コード例 #8
0
 static void Drawer_IntensityMultiplier(HDReflectionProbeUI s, SerializedHDReflectionProbe p, Editor owner)
 {
     EditorGUILayout.PropertyField(p.intensityMultiplier, CoreEditorUtils.GetContent("Intensity"));
 }
コード例 #9
0
 static void Drawer_ModeSettingsRealtime(HDReflectionProbeUI s, SerializedHDReflectionProbe p, Editor owner)
 {
     EditorGUILayout.PropertyField(p.refreshMode, CoreEditorUtils.GetContent("Refresh Mode|Controls how this probe refreshes in the Player"));
     EditorGUILayout.PropertyField(p.timeSlicingMode, CoreEditorUtils.GetContent("Time Slicing|If enabled this probe will update over several frames, to help reduce the impact on the frame rate"));
 }
コード例 #10
0
 static void Drawer_ReflectionProbeMode(HDReflectionProbeUI s, SerializedHDReflectionProbe p, Editor owner)
 {
     EditorGUI.BeginChangeCheck();
     EditorGUI.showMixedValue = p.mode.hasMultipleDifferentValues;
     EditorGUILayout.IntPopup(p.mode, k_Content_ReflectionProbeMode, k_Content_ReflectionProbeModeValues, CoreEditorUtils.GetContent("Type|'Baked Cubemap' uses the 'Auto Baking' mode from the Lighting window. If it is enabled then baking is automatic otherwise manual bake is needed (use the bake button below). \n'Custom' can be used if a custom cubemap is wanted. \n'Realtime' can be used to dynamically re-render the cubemap during runtime (via scripting)."));
     EditorGUI.showMixedValue = false;
     if (EditorGUI.EndChangeCheck())
     {
         s.SetModeTarget(p.mode.intValue);
     }
 }
コード例 #11
0
 static void Drawer_ProjectionSettings(HDReflectionProbeUI s, SerializedHDReflectionProbe p, Editor owner)
 {
     EditorGUILayout.PropertyField(p.boxProjection, CoreEditorUtils.GetContent("Parallax Correction|Parallax Correction causes reflections to appear to change based on the object's position within the probe's box, while still using a single probe as the source of the reflection. This works well for reflections on objects that are moving through enclosed spaces such as corridors and rooms. Setting Parallax Correction to False and the cubemap reflection will be treated as coming from infinitely far away. Note that this feature can be globally disabled from Graphics Settings -> Tier Settings"));
 }
コード例 #12
0
		public override void OnInspectorGUI()
		{
			serializedObject.Update();

			if ( _Properties == null )
			{
				_Properties = serializedObject.FindProperty( "Properties" );
			}

			if ( _Properties != null && _Shader != null )
			{
				if ( _Properties.arraySize > 0 )
				{
					List<SerializedProperty> finalProps = new List<SerializedProperty>();
					for ( int i = 0; i < _Properties.arraySize; i++ )
					{
						SerializedProperty prop = _Properties.GetArrayElementAtIndex( i );

						if ( prop != null && prop.FindPropertyRelative( "Name" ) != null )
						{
							if ( ShaderUtilExtensions.HasShaderProperty( _Shader, prop.FindPropertyRelative( "Name" ).stringValue ) )
							{
								finalProps.Add( prop );
							}
						}
					}
					finalProps = finalProps.OrderBy( x => ShaderUtilExtensions.GetShaderPropertyNames( _Shader ).IndexOf( x.FindPropertyRelative( "Name" ).stringValue ) ).ToList();

					EditorGUILayout.Space();

					for ( int j = 0; j < finalProps.Count; j++ )
					{
						SerializedProperty prop = finalProps[j];
						string name = prop.FindPropertyRelative( "Name" ).stringValue;
						string desc = prop.FindPropertyRelative( "Desc" ).stringValue;
						string type = prop.FindPropertyRelative( "Type" ).stringValue;
						bool change = prop.FindPropertyRelative( "Change" ).boolValue;
						string[] attrs = ShaderUtilExtensions.GetShaderPropertyAttributes( _Shader, name ) ?? new string[0];
						SerializedProperty p = prop.FindPropertyRelative( $"{type}Value" );
						GUIContent label = new GUIContent( desc, name );

						EditorGUILayout.BeginHorizontal();

						EditorGUI.BeginChangeCheck();
						var overrideRect = GUILayoutUtility.GetRect( 17f, 17f, GUILayout.ExpandWidth( false ) );
						overrideRect.yMin += 4f;
						bool chnge = GUI.Toggle( overrideRect, change, CoreEditorUtils.GetContent( "|Override this property for this object." ), CoreEditorStyles.smallTickbox );
						if ( EditorGUI.EndChangeCheck() )
						{
							prop.FindPropertyRelative( "Change" ).boolValue = chnge;
						}

						EditorGUI.BeginDisabledGroup( !change );

						switch ( type )
						{
							case "Color":
								EditorGUI.BeginChangeCheck();
								Color valColor = EditorGUILayout.ColorField( label, p.colorValue, true, true, true );
								if ( EditorGUI.EndChangeCheck() )
								{
									p.colorValue = valColor;
								}
								break;

							case "Texture":
								EditorGUI.BeginChangeCheck();
								Texture valTexture = (Texture) EditorGUILayout.ObjectField( label, p.objectReferenceValue, typeof( Texture ), false );
								if ( EditorGUI.EndChangeCheck() )
								{
									p.objectReferenceValue = valTexture;
								}
								break;

							case "Float":
								EditorGUI.BeginChangeCheck();
								float valFloat = attrs.Contains( "Toggle", StringComparer.OrdinalIgnoreCase ) ? Convert.ToSingle( EditorGUILayout.Toggle( label,
								                 Convert.ToBoolean( Mathf.Clamp01( p.floatValue ) ) ) ) : EditorGUILayout.FloatField( label, p.floatValue );
								if ( EditorGUI.EndChangeCheck() )
								{
									p.floatValue = valFloat;
								}
								break;

							case "Vector":
								EditorGUI.BeginChangeCheck();
								Vector4 valVector = EditorGUILayout.Vector4Field( label, p.vector4Value );
								if ( EditorGUI.EndChangeCheck() )
								{
									p.vector4Value = valVector;
								}
								break;
						}

						EditorGUI.EndDisabledGroup();

						EditorGUILayout.EndHorizontal();
					}
				}
			}

			serializedObject.ApplyModifiedProperties();
		}
コード例 #13
0
 /// <summary> Create an IDrawer foldout header using an ExpandedState </summary>
 /// <param name="title">Title wanted for this foldout header</param>
 /// <param name="mask">Bit mask (enum) used to define the boolean saving the state in ExpandedState</param>
 /// <param name="state">The ExpandedState describing the component</param>
 /// <param name="contentDrawers">The content of the foldout header</param>
 public static IDrawer FoldoutGroup <TEnum, TState>(string title, TEnum mask, ExpandedState <TEnum, TState> state, FoldoutOption options, params ActionDrawer[] contentDrawers)
     where TEnum : struct, IConvertible
 {
     return(FoldoutGroup(CoreEditorUtils.GetContent(title), mask, state, options, contentDrawers));
 }
 public override void OnInspectorGUI()
 {
     PropertyField(m_IndirectDiffuseIntensity, CoreEditorUtils.GetContent("Indirect Diffuse Intensity|Multiplier for the baked diffuse lighting."));
     PropertyField(m_IndirectSpecularIntensity, CoreEditorUtils.GetContent("Indirect Specular Intensity|Multiplier for the reflected specular light."));
 }
コード例 #15
0
        void DrawStackSettings()
        {
            m_StackSettingsFoldout.value = EditorGUILayout.BeginFoldoutHeaderGroup(m_StackSettingsFoldout.value, Styles.stackSettingsText);
            if (m_SerializedCamera.cameras.hasMultipleDifferentValues)
            {
                EditorGUILayout.HelpBox("Cannot multi edit stack of multiple cameras.", MessageType.Info);
                EditorGUILayout.EndFoldoutHeaderGroup();
                return;
            }

            bool cameraStackingAvailable = m_SerializedCamera
                                           .camerasAdditionalData
                                           .All(c => c.scriptableRenderer?.supportedRenderingFeatures?.cameraStacking ?? false);

            if (!cameraStackingAvailable)
            {
                EditorGUILayout.HelpBox("The renderer used by this camera doesn't support camera stacking. Only Base camera will render.", MessageType.Warning);
                return;
            }

            if (m_StackSettingsFoldout.value)
            {
                m_LayerList.DoLayoutList();
                m_SerializedCamera.Apply();

                EditorGUI.indentLevel--;
                if (m_TypeErrorCameras.Any())
                {
                    var message = new StringBuilder();
                    message.Append("The type of the following Cameras must be Overlay render type: ");
                    foreach (var camera in m_TypeErrorCameras)
                    {
                        message.Append(camera.name);
                        if (camera != m_TypeErrorCameras.Last())
                        {
                            message.Append(", ");
                        }
                        else
                        {
                            message.Append(".");
                        }
                    }

                    CoreEditorUtils.DrawFixMeBox(message.ToString(), MessageType.Error, () => UpdateStackCemerasToOverlay());
                }

                if (m_OutputWarningCameras.Any())
                {
                    var message = new StringBuilder();
                    message.Append("The output properties of this Camera do not match the output properties of the following Cameras: ");
                    foreach (var camera in m_OutputWarningCameras)
                    {
                        message.Append(camera.name);
                        if (camera != m_OutputWarningCameras.Last())
                        {
                            message.Append(", ");
                        }
                        else
                        {
                            message.Append(".");
                        }
                    }

                    CoreEditorUtils.DrawFixMeBox(message.ToString(), MessageType.Warning, () => UpdateStackCamerasOutput());
                }
                EditorGUI.indentLevel++;

                EditorGUILayout.Space();
                EditorGUILayout.Space();
            }
            EditorGUILayout.EndFoldoutHeaderGroup();
        }
コード例 #16
0
 protected virtual void OnCommonInspectorGUI()
 {
     EditorGUILayout.LabelField(CoreEditorUtils.GetContent("Common Settings"));
     PropertyField(m_ScreenWeightDistance, CoreEditorUtils.GetContent("Screen Weight Distance"));
 }
コード例 #17
0
 public override void OnInspectorGUI()
 {
     PropertyField(m_ScreenFadeDistance, CoreEditorUtils.GetContent("Screen Weight Distance"));
 }
コード例 #18
0
        //[MenuItem("Internal/HDRenderPipeline/Update/Update material for subsurface")]
        static void UpdateMaterialForSubsurface()
        {
            try
            {
                var matIds = AssetDatabase.FindAssets("t:Material");

                for (int i = 0, length = matIds.Length; i < length; i++)
                {
                    var path = AssetDatabase.GUIDToAssetPath(matIds[i]);
                    var mat  = AssetDatabase.LoadAssetAtPath <Material>(path);

                    EditorUtility.DisplayProgressBar(
                        "Setup materials Keywords...",
                        string.Format("{0} / {1} materials subsurface updated.", i, length),
                        i / (float)(length - 1));

                    bool VCSEnabled = (UnityEditor.VersionControl.Provider.enabled && UnityEditor.VersionControl.Provider.isActive);

                    if (mat.shader.name == "HDRenderPipeline/LitTessellation" ||
                        mat.shader.name == "HDRenderPipeline/Lit" ||
                        mat.shader.name == "HDRenderPipeline/LayeredLit" ||
                        mat.shader.name == "HDRenderPipeline/LayeredLitTessellation")
                    {
                        float materialID = mat.GetInt("_MaterialID");
                        if (materialID != 0.0)
                        {
                            continue;
                        }

                        if (mat.HasProperty("_SSSAndTransmissionType"))
                        {
                            CoreEditorUtils.CheckOutFile(VCSEnabled, mat);

                            int materialSSSAndTransmissionID = mat.GetInt("_SSSAndTransmissionType");

                            // Both;, SSS only, Transmission only
                            if (materialSSSAndTransmissionID == 2.0)
                            {
                                mat.SetInt("_MaterialID", 5);
                            }
                            else
                            {
                                if (materialSSSAndTransmissionID == 0.0)
                                {
                                    mat.SetFloat("_TransmissionEnable", 1.0f);
                                }
                                else
                                {
                                    mat.SetFloat("_TransmissionEnable", 0.0f);
                                }
                            }

                            EditorUtility.SetDirty(mat);
                        }
                    }
                }
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }
        }
コード例 #19
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            Drawer_ToolBar();

            EditorGUILayout.PropertyField(albedo, Styles.s_AlbedoLabel);
            EditorGUILayout.PropertyField(meanFreePath, Styles.s_MeanFreePathLabel);
            EditorGUILayout.Space();

            CoreEditorUtils.DrawSplitter();
            EditorGUI.BeginChangeCheck();
            bool expendedVolume = CoreEditorUtils.DrawHeaderFoldout(Styles.k_VolumeHeader, GetExpendedAreas((uint)Expandable.Volume));

            if (EditorGUI.EndChangeCheck())
            {
                SetExpendedAreas((uint)Expandable.Volume, expendedVolume);
            }
            if (expendedVolume)
            {
                Drawer_AdvancedSwitch();

                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(size, Styles.s_Size);
                if (EditorGUI.EndChangeCheck())
                {
                    Vector3 tmpClamp = size.vector3Value;
                    tmpClamp.x        = Mathf.Max(0f, tmpClamp.x);
                    tmpClamp.y        = Mathf.Max(0f, tmpClamp.y);
                    tmpClamp.z        = Mathf.Max(0f, tmpClamp.z);
                    size.vector3Value = tmpClamp;
                }

                Vector3 s = size.vector3Value;
                EditorGUI.BeginChangeCheck();
                if (advancedFade.boolValue)
                {
                    Vector3 positive = positiveFade.vector3Value;
                    positive.x *= s.x;
                    positive.y *= s.y;
                    positive.z *= s.z;
                    Vector3 negative = negativeFade.vector3Value;
                    negative.x *= s.x;
                    negative.y *= s.y;
                    negative.z *= s.z;
                    EditorGUI.BeginChangeCheck();
                    CoreEditorUtils.DrawVector6(Styles.s_BlendLabel, ref positive, ref negative, Vector3.zero, s, InfluenceVolumeUI.k_HandlesColor);
                    if (EditorGUI.EndChangeCheck())
                    {
                        positive.x /= s.x;
                        positive.y /= s.y;
                        positive.z /= s.z;
                        negative.x /= s.x;
                        negative.y /= s.y;
                        negative.z /= s.z;

                        //forbid positive/negative box that doesn't intersect in inspector too
                        for (int axis = 0; axis < 3; ++axis)
                        {
                            if (positive[axis] > 1f - negative[axis])
                            {
                                if (positive == positiveFade.vector3Value)
                                {
                                    negative[axis] = 1f - positive[axis];
                                }
                                else
                                {
                                    positive[axis] = 1f - negative[axis];
                                }
                            }
                        }

                        positiveFade.vector3Value = positive;
                        negativeFade.vector3Value = negative;
                    }
                }
                else
                {
                    EditorGUI.BeginChangeCheck();
                    float distanceMax         = Mathf.Min(s.x, s.y, s.z);
                    float uniformFadeDistance = uniformFade.floatValue * distanceMax;
                    uniformFadeDistance = EditorGUILayout.FloatField(Styles.s_BlendLabel, uniformFadeDistance);
                    if (EditorGUI.EndChangeCheck())
                    {
                        uniformFade.floatValue = Mathf.Clamp(uniformFadeDistance / distanceMax, 0f, 0.5f);
                    }
                }
                if (EditorGUI.EndChangeCheck())
                {
                    Vector3 posFade = new Vector3();
                    posFade.x = Mathf.Clamp01(positiveFade.vector3Value.x);
                    posFade.y = Mathf.Clamp01(positiveFade.vector3Value.y);
                    posFade.z = Mathf.Clamp01(positiveFade.vector3Value.z);

                    Vector3 negFade = new Vector3();
                    negFade.x = Mathf.Clamp01(negativeFade.vector3Value.x);
                    negFade.y = Mathf.Clamp01(negativeFade.vector3Value.y);
                    negFade.z = Mathf.Clamp01(negativeFade.vector3Value.z);

                    positiveFade.vector3Value = posFade;
                    negativeFade.vector3Value = negFade;
                }

                EditorGUILayout.PropertyField(invertFade, Styles.s_InvertFadeLabel);
                EditorGUILayout.Space();
            }

            CoreEditorUtils.DrawSplitter();
            EditorGUI.BeginChangeCheck();
            bool expendedDensityMaskTexture = CoreEditorUtils.DrawHeaderFoldout(Styles.k_DensityMaskTextureHeader, GetExpendedAreas((uint)Expandable.DensityMaskTexture));

            if (EditorGUI.EndChangeCheck())
            {
                SetExpendedAreas((uint)Expandable.DensityMaskTexture, expendedDensityMaskTexture);
            }
            if (expendedDensityMaskTexture)
            {
                EditorGUILayout.PropertyField(volumeTexture, Styles.s_VolumeTextureLabel);
                EditorGUILayout.PropertyField(textureScroll, Styles.s_TextureScrollLabel);
                EditorGUILayout.PropertyField(textureTile, Styles.s_TextureTileLabel);
            }

            serializedObject.ApplyModifiedProperties();
        }
コード例 #20
0
 public static bool DrawSectionFoldout(string title, bool isExpanded)
 {
     CoreEditorUtils.DrawSplitter(false);
     return(CoreEditorUtils.DrawHeaderFoldout(title, isExpanded, false));
 }
コード例 #21
0
        static void Drawer_VolumeContent(SerializedProbeVolume serialized, Editor owner)
        {
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(serialized.size, Styles.s_Size);
            if (EditorGUI.EndChangeCheck())
            {
                Vector3 tmpClamp = serialized.size.vector3Value;
                tmpClamp.x = Mathf.Max(0f, tmpClamp.x);
                tmpClamp.y = Mathf.Max(0f, tmpClamp.y);
                tmpClamp.z = Mathf.Max(0f, tmpClamp.z);
                serialized.size.vector3Value = tmpClamp;
            }

            Vector3 s = serialized.size.vector3Value;

            EditorGUI.BeginChangeCheck();
            if (serialized.advancedFade.boolValue)
            {
                EditorGUI.BeginChangeCheck();
                CoreEditorUtils.DrawVector6(Styles.s_BlendLabel, serialized.positiveFade, serialized.negativeFade, Vector3.zero, s, InfluenceVolumeUI.k_HandlesColor, serialized.size);
                if (EditorGUI.EndChangeCheck())
                {
                    //forbid positive/negative box that doesn't intersect in inspector too
                    Vector3 positive = serialized.positiveFade.vector3Value;
                    Vector3 negative = serialized.negativeFade.vector3Value;
                    for (int axis = 0; axis < 3; ++axis)
                    {
                        if (positive[axis] > 1f - negative[axis])
                        {
                            if (positive == serialized.positiveFade.vector3Value)
                            {
                                negative[axis] = 1f - positive[axis];
                            }
                            else
                            {
                                positive[axis] = 1f - negative[axis];
                            }
                        }
                    }

                    serialized.positiveFade.vector3Value = positive;
                    serialized.negativeFade.vector3Value = negative;
                }
            }
            else
            {
                EditorGUI.BeginChangeCheck();
                float distanceMax         = Mathf.Min(s.x, s.y, s.z);
                float uniformFadeDistance = serialized.uniformFade.floatValue * distanceMax;
                uniformFadeDistance = EditorGUILayout.FloatField(Styles.s_BlendLabel, uniformFadeDistance);
                if (EditorGUI.EndChangeCheck())
                {
                    serialized.uniformFade.floatValue = Mathf.Clamp(uniformFadeDistance / distanceMax, 0f, 0.5f);
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                Vector3 posFade = new Vector3();
                posFade.x = Mathf.Clamp01(serialized.positiveFade.vector3Value.x);
                posFade.y = Mathf.Clamp01(serialized.positiveFade.vector3Value.y);
                posFade.z = Mathf.Clamp01(serialized.positiveFade.vector3Value.z);

                Vector3 negFade = new Vector3();
                negFade.x = Mathf.Clamp01(serialized.negativeFade.vector3Value.x);
                negFade.y = Mathf.Clamp01(serialized.negativeFade.vector3Value.y);
                negFade.z = Mathf.Clamp01(serialized.negativeFade.vector3Value.z);

                serialized.positiveFade.vector3Value = posFade;
                serialized.negativeFade.vector3Value = negFade;
            }

            // Distance fade.
            {
                EditorGUI.BeginChangeCheck();

                float distanceFadeStart = EditorGUILayout.FloatField(Styles.s_DistanceFadeStartLabel, serialized.distanceFadeStart.floatValue);
                float distanceFadeEnd   = EditorGUILayout.FloatField(Styles.s_DistanceFadeEndLabel, serialized.distanceFadeEnd.floatValue);

                if (EditorGUI.EndChangeCheck())
                {
                    distanceFadeStart = Mathf.Max(0, distanceFadeStart);
                    distanceFadeEnd   = Mathf.Max(distanceFadeStart, distanceFadeEnd);

                    serialized.distanceFadeStart.floatValue = distanceFadeStart;
                    serialized.distanceFadeEnd.floatValue   = distanceFadeEnd;
                }
            }

            EditorGUILayout.PropertyField(serialized.lightLayers);
            EditorGUILayout.PropertyField(serialized.volumeBlendMode, Styles.s_VolumeBlendModeLabel);
            EditorGUILayout.Slider(serialized.weight, 0.0f, 1.0f, Styles.s_WeightLabel);
            EditorGUILayout.PropertyField(serialized.debugColor, Styles.s_DebugColorLabel);
        }
        public override void OnInspectorGUI()
        {
            CheckStyles();

            // Display a warning if this settings asset is not currently in use
            if (m_HDPipeline == null || m_HDPipeline.diffusionProfileSettings != m_Target)
            {
                EditorGUILayout.HelpBox("These profiles aren't currently in use, assign this asset to the HD render pipeline asset to use them.", MessageType.Warning);
            }

            serializedObject.Update();

            EditorGUILayout.Space();

            if (m_Profiles == null || m_Profiles.Count == 0)
            {
                return;
            }

            for (int i = 0; i < m_Profiles.Count; i++)
            {
                var profile = m_Profiles[i];

                CoreEditorUtils.DrawSplitter();

                bool state = profile.self.isExpanded;
                state = CoreEditorUtils.DrawHeaderFoldout(profile.name.stringValue, state);

                if (state)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(profile.name);

                    using (var scope = new EditorGUI.ChangeCheckScope())
                    {
                        EditorGUILayout.PropertyField(profile.scatteringDistance, s_Styles.profileScatteringDistance);

                        using (new EditorGUI.DisabledScope(true))
                            EditorGUILayout.FloatField(s_Styles.profileMaxRadius, profile.objReference.maxRadius);

                        EditorGUILayout.Slider(profile.ior, 1.0f, 2.0f, s_Styles.profileIor);
                        EditorGUILayout.PropertyField(profile.worldScale, s_Styles.profileWorldScale);

                        EditorGUILayout.Space();
                        EditorGUILayout.LabelField(s_Styles.SubsurfaceScatteringLabel, EditorStyles.boldLabel);

                        profile.texturingMode.intValue = EditorGUILayout.Popup(s_Styles.texturingMode, profile.texturingMode.intValue, s_Styles.texturingModeOptions);

                        EditorGUILayout.Space();
                        EditorGUILayout.LabelField(s_Styles.TransmissionLabel, EditorStyles.boldLabel);

                        profile.transmissionMode.intValue = EditorGUILayout.Popup(s_Styles.profileTransmissionMode, profile.transmissionMode.intValue, s_Styles.transmissionModeOptions);

                        EditorGUILayout.PropertyField(profile.transmissionTint, s_Styles.profileTransmissionTint);
                        EditorGUILayout.PropertyField(profile.thicknessRemap, s_Styles.profileMinMaxThickness);
                        var thicknessRemap = profile.thicknessRemap.vector2Value;
                        EditorGUILayout.MinMaxSlider(s_Styles.profileThicknessRemap, ref thicknessRemap.x, ref thicknessRemap.y, 0f, 50f);
                        profile.thicknessRemap.vector2Value = thicknessRemap;

                        EditorGUILayout.Space();
                        EditorGUILayout.LabelField(s_Styles.profilePreview0, s_Styles.centeredMiniBoldLabel);
                        EditorGUILayout.LabelField(s_Styles.profilePreview1, EditorStyles.centeredGreyMiniLabel);
                        EditorGUILayout.LabelField(s_Styles.profilePreview2, EditorStyles.centeredGreyMiniLabel);
                        EditorGUILayout.LabelField(s_Styles.profilePreview3, EditorStyles.centeredGreyMiniLabel);
                        EditorGUILayout.Space();

                        serializedObject.ApplyModifiedProperties();

                        if (scope.changed)
                        {
                            // Validate and update the cache for this profile only
                            profile.objReference.Validate();
                            m_Target.UpdateCache(i);
                        }
                    }

                    RenderPreview(profile);

                    EditorGUILayout.Space();
                    EditorGUI.indentLevel--;
                }

                profile.self.isExpanded = state;
            }

            CoreEditorUtils.DrawSplitter();

            serializedObject.ApplyModifiedProperties();
        }
コード例 #23
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            bool materialChanged      = false;
            bool isDefaultMaterial    = false;
            bool isValidDecalMaterial = true;

            bool isDecalSupported = DecalProjector.isSupported;

            if (!isDecalSupported)
            {
                EditorUtils.FeatureHelpBox("The current renderer has no Decal Renderer Feature added.", MessageType.Warning);
            }

            EditorGUI.BeginChangeCheck();
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                DoInspectorToolbar(k_EditVolumeModes, editVolumeLabels, GetBoundsGetter(target as DecalProjector), this);
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Space();

                // Info box for tools
                GUIStyle style = new GUIStyle(EditorStyles.miniLabel);
                style.richText = true;
                GUILayout.BeginVertical(EditorStyles.helpBox);
                string helpText = k_BaseSceneEditingToolText;
                if (EditMode.editMode == k_EditShapeWithoutPreservingUV && EditMode.IsOwner(this))
                {
                    helpText = k_EditShapeWithoutPreservingUVName;
                }
                if (EditMode.editMode == k_EditShapePreservingUV && EditMode.IsOwner(this))
                {
                    helpText = k_EditShapePreservingUVName;
                }
                if (EditMode.editMode == k_EditUVAndPivot && EditMode.IsOwner(this))
                {
                    helpText = k_EditUVAndPivotName;
                }
                GUILayout.Label(helpText, style);
                GUILayout.EndVertical();
                EditorGUILayout.Space();

                EditorGUILayout.PropertyField(m_ScaleMode, k_ScaleMode);

                bool negativeScale = false;
                foreach (var target in targets)
                {
                    var decalProjector = target as DecalProjector;

                    float combinedScale = decalProjector.transform.lossyScale.x * decalProjector.transform.lossyScale.y * decalProjector.transform.lossyScale.z;
                    negativeScale |= combinedScale < 0 && decalProjector.scaleMode == DecalScaleMode.InheritFromHierarchy;
                }
                if (negativeScale)
                {
                    EditorGUILayout.HelpBox("Does not work with negative odd scaling (When there are odd number of scale components)", MessageType.Warning);
                }

                var widthRect = EditorGUILayout.GetControlRect();
                EditorGUI.BeginProperty(widthRect, k_WidthContent, m_SizeValues[0]);
                EditorGUI.BeginChangeCheck();
                float newSizeX = EditorGUI.FloatField(widthRect, k_WidthContent, m_SizeValues[0].floatValue);
                if (EditorGUI.EndChangeCheck())
                {
                    UpdateSize(0, Mathf.Max(0, newSizeX));
                }
                EditorGUI.EndProperty();

                var heightRect = EditorGUILayout.GetControlRect();
                EditorGUI.BeginProperty(heightRect, k_HeightContent, m_SizeValues[1]);
                EditorGUI.BeginChangeCheck();
                float newSizeY = EditorGUI.FloatField(heightRect, k_HeightContent, m_SizeValues[1].floatValue);
                if (EditorGUI.EndChangeCheck())
                {
                    UpdateSize(1, Mathf.Max(0, newSizeY));
                }
                EditorGUI.EndProperty();

                var projectionRect = EditorGUILayout.GetControlRect();
                EditorGUI.BeginProperty(projectionRect, k_ProjectionDepthContent, m_SizeValues[2]);
                EditorGUI.BeginChangeCheck();
                float newSizeZ = EditorGUI.FloatField(projectionRect, k_ProjectionDepthContent, m_SizeValues[2].floatValue);
                if (EditorGUI.EndChangeCheck())
                {
                    UpdateSize(2, Mathf.Max(0, newSizeZ));
                }
                EditorGUI.EndProperty();

                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(m_Offset, k_Offset);
                if (EditorGUI.EndChangeCheck())
                {
                    ReinitSavedRatioSizePivotPosition();
                }

                EditorGUILayout.Space();

                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(m_MaterialProperty, k_MaterialContent);
                materialChanged = EditorGUI.EndChangeCheck();

                foreach (var target in targets)
                {
                    var decalProjector = target as DecalProjector;
                    var mat            = decalProjector.material;

                    isDefaultMaterial    |= decalProjector.material == DecalProjector.defaultMaterial;
                    isValidDecalMaterial &= decalProjector.IsValid();
                }

                if (m_MaterialEditor && !isValidDecalMaterial)
                {
                    CoreEditorUtils.DrawFixMeBox("Decal only work with Decal Material. Use default material or create from decal shader graph sub target.", () =>
                    {
                        m_MaterialProperty.objectReferenceValue = DecalProjector.defaultMaterial;
                        materialChanged = true;
                    });
                }

                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(m_UVScaleProperty, k_UVScaleContent);
                EditorGUILayout.PropertyField(m_UVBiasProperty, k_UVBiasContent);
                EditorGUILayout.PropertyField(m_FadeFactor, k_OpacityContent);
                EditorGUI.indentLevel--;

                bool angleFadeSupport = false;
                foreach (var decalProjector in targets)
                {
                    var mat = (decalProjector as DecalProjector).material;
                    if (mat == null)
                    {
                        continue;
                    }
                    angleFadeSupport = mat.HasProperty("_DecalAngleFadeSupported");
                }

                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(m_DrawDistanceProperty, k_DistanceContent);
                if (EditorGUI.EndChangeCheck() && m_DrawDistanceProperty.floatValue < 0f)
                {
                    m_DrawDistanceProperty.floatValue = 0f;
                }

                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(m_FadeScaleProperty, k_FadeScaleContent);
                EditorGUI.indentLevel--;

                using (new EditorGUI.DisabledScope(!angleFadeSupport))
                {
                    float angleFadeMinValue = m_StartAngleFadeProperty.floatValue;
                    float angleFadeMaxValue = m_EndAngleFadeProperty.floatValue;
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.MinMaxSlider(k_AngleFadeContent, ref angleFadeMinValue, ref angleFadeMaxValue, 0.0f, 180.0f);
                    if (EditorGUI.EndChangeCheck())
                    {
                        m_StartAngleFadeProperty.floatValue = angleFadeMinValue;
                        m_EndAngleFadeProperty.floatValue   = angleFadeMaxValue;
                    }
                }

                if (!angleFadeSupport && isValidDecalMaterial)
                {
                    EditorGUILayout.HelpBox($"Decal Angle Fade is not enabled in Shader. In ShaderGraph enable Angle Fade option.", MessageType.Info);
                }

                EditorGUILayout.Space();
            }
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
            }

            if (materialChanged)
            {
                UpdateMaterialEditor();
            }

            if (layerMaskHasMultipleValues || layerMask != (target as Component).gameObject.layer)
            {
                foreach (var decalProjector in targets)
                {
                    (decalProjector as DecalProjector).OnValidate();
                }
            }

            if (m_MaterialEditor != null)
            {
                // We need to prevent the user to edit default decal materials
                if (isValidDecalMaterial)
                {
                    using (new DecalProjectorScope())
                    {
                        using (new EditorGUI.DisabledGroupScope(isDefaultMaterial))
                        {
                            // Draw the material's foldout and the material shader field
                            // Required to call m_MaterialEditor.OnInspectorGUI ();
                            m_MaterialEditor.DrawHeader();

                            // Draw the material properties
                            // Works only if the foldout of m_MaterialEditor.DrawHeader () is open
                            m_MaterialEditor.OnInspectorGUI();
                        }
                    }
                }
            }
        }
コード例 #24
0
        private void DrawRendererFeature(int index, ref SerializedProperty renderFeatureProperty)
        {
            Object rendererFeatureObjRef = renderFeatureProperty.objectReferenceValue;

            if (rendererFeatureObjRef != null)
            {
                bool   hasChangedProperties = false;
                string title = ObjectNames.GetInspectorTitle(rendererFeatureObjRef);

                // Get the serialized object for the editor script & update it
                Editor           rendererFeatureEditor            = m_Editors[index];
                SerializedObject serializedRendererFeaturesEditor = rendererFeatureEditor.serializedObject;
                serializedRendererFeaturesEditor.Update();

                // Foldout header
                EditorGUI.BeginChangeCheck();
                SerializedProperty activeProperty = serializedRendererFeaturesEditor.FindProperty("m_Active");
                bool displayContent = CoreEditorUtils.DrawHeaderToggle(title, renderFeatureProperty, activeProperty, pos => OnContextClick(pos, index));
                hasChangedProperties |= EditorGUI.EndChangeCheck();

                // ObjectEditor
                if (displayContent)
                {
                    EditorGUI.BeginChangeCheck();
                    SerializedProperty nameProperty = serializedRendererFeaturesEditor.FindProperty("m_Name");
                    nameProperty.stringValue = ValidateName(EditorGUILayout.DelayedTextField(Styles.PassNameField, nameProperty.stringValue));
                    if (EditorGUI.EndChangeCheck())
                    {
                        hasChangedProperties = true;

                        // We need to update sub-asset name
                        rendererFeatureObjRef.name = nameProperty.stringValue;
                        AssetDatabase.SaveAssets();

                        // Triggers update for sub-asset name change
                        ProjectWindowUtil.ShowCreatedAsset(target);
                    }

                    EditorGUI.BeginChangeCheck();
                    rendererFeatureEditor.OnInspectorGUI();
                    hasChangedProperties |= EditorGUI.EndChangeCheck();

                    EditorGUILayout.Space(EditorGUIUtility.singleLineHeight);
                }

                // Apply changes and save if the user has modified any settings
                if (hasChangedProperties)
                {
                    serializedRendererFeaturesEditor.ApplyModifiedProperties();
                    serializedObject.ApplyModifiedProperties();
                    ForceSave();
                }
            }
            else
            {
                CoreEditorUtils.DrawHeaderToggle(Styles.MissingFeature, renderFeatureProperty, m_FalseBool, pos => OnContextClick(pos, index));
                m_FalseBool.boolValue = false; // always make sure false bool is false
                EditorGUILayout.HelpBox(Styles.MissingFeature.tooltip, MessageType.Error);
                if (GUILayout.Button("Attempt Fix", EditorStyles.miniButton))
                {
                    ScriptableRendererData data = target as ScriptableRendererData;
                    data.ValidateRendererFeatures();
                }
            }
        }
コード例 #25
0
        public SerializedHDCamera(SerializedObject serializedObject)
        {
            this.serializedObject = serializedObject;

            projectionMatrixMode = serializedObject.FindProperty("m_projectionMatrixMode");

            var additionals = CoreEditorUtils.GetAdditionalData <HDAdditionalCameraData>(serializedObject.targetObjects, HDAdditionalCameraData.InitDefaultHDAdditionalCameraData);

            serializedAdditionalDataObject = new SerializedObject(additionals);

            var hideFlags = serializedAdditionalDataObject.FindProperty("m_ObjectHideFlags");

            // We don't hide additional camera data anymore on UX team request. To be compatible with already author scene we force to be visible
            if ((hideFlags.intValue & (int)HideFlags.HideInInspector) > 0)
            {
                hideFlags.intValue = (int)HideFlags.None;
            }
            serializedAdditionalDataObject.ApplyModifiedProperties();

            // Common properties
            dithering = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.dithering);
            stopNaNs  = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.stopNaNs);
            allowDynamicResolution = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.allowDynamicResolution);
            volumeLayerMask        = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.volumeLayerMask);
            clearDepth             = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.clearDepth);
            antialiasing           = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.antialiasing);

            // HDRP specific properties
            iso            = serializedAdditionalDataObject.FindProperty("physicalParameters.m_Iso");
            shutterSpeed   = serializedAdditionalDataObject.FindProperty("physicalParameters.m_ShutterSpeed");
            aperture       = serializedAdditionalDataObject.FindProperty("physicalParameters.m_Aperture");
            bladeCount     = serializedAdditionalDataObject.FindProperty("physicalParameters.m_BladeCount");
            curvature      = serializedAdditionalDataObject.FindProperty("physicalParameters.m_Curvature");
            barrelClipping = serializedAdditionalDataObject.FindProperty("physicalParameters.m_BarrelClipping");
            anamorphism    = serializedAdditionalDataObject.FindProperty("physicalParameters.m_Anamorphism");

            exposureTarget = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.exposureTarget);

            allowDeepLearningSuperSampling = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.allowDeepLearningSuperSampling);
            deepLearningSuperSamplingUseCustomQualitySettings = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.deepLearningSuperSamplingUseCustomQualitySettings);
            deepLearningSuperSamplingQuality             = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.deepLearningSuperSamplingQuality);
            deepLearningSuperSamplingUseCustomAttributes = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.deepLearningSuperSamplingUseCustomAttributes);
            deepLearningSuperSamplingUseOptimalSettings  = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.deepLearningSuperSamplingUseOptimalSettings);
            deepLearningSuperSamplingSharpening          = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.deepLearningSuperSamplingSharpening);

            SMAAQuality              = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.SMAAQuality);
            taaSharpenStrength       = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.taaSharpenStrength);
            taaQualityLevel          = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.TAAQuality);
            taaHistorySharpening     = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.taaHistorySharpening);
            taaAntiFlicker           = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.taaAntiFlicker);
            taaMotionVectorRejection = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.taaMotionVectorRejection);
            taaAntiRinging           = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.taaAntiHistoryRinging);
            taaQualityLevel          = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.TAAQuality);

            clearColorMode          = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.clearColorMode);
            backgroundColorHDR      = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.backgroundColorHDR);
            xrRendering             = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.xrRendering);
            passThrough             = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.fullscreenPassthrough);
            customRenderingSettings = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.customRenderingSettings);
            volumeAnchorOverride    = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.volumeAnchorOverride);
            probeLayerMask          = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.probeLayerMask);
            frameSettings           = new SerializedFrameSettings(
                serializedAdditionalDataObject.FindProperty("m_RenderingPathCustomFrameSettings"),
                serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.renderingPathCustomFrameSettingsOverrideMask)
                );

            baseCameraSettings = new CameraEditor.Settings(serializedObject);
            baseCameraSettings.OnEnable();
        }
コード例 #26
0
        public override void OnInspectorGUI()
        {
            HDRenderPipelineAsset currentAsset = HDRenderPipeline.currentAsset;

            if (!currentAsset?.currentPlatformRenderPipelineSettings.supportRayTracing ?? false)
            {
                EditorGUILayout.Space();
                EditorGUILayout.HelpBox("The current HDRP Asset does not support Ray Tracing.", MessageType.Error, wide: true);
                return;
            }

            // If ray tracing is supported display the content of the volume component
            if (HDRenderPipeline.assetSupportsRayTracing)
            {
                PropertyField(m_Enable);

                if (m_Enable.overrideState.boolValue && m_Enable.value.boolValue)
                {
                    using (new IndentLevelScope())
                    {
                        PropertyField(m_LayerMask);
                        PropertyField(m_MaxSamples);
                        PropertyField(m_MinDepth);
                        PropertyField(m_MaxDepth);
                        PropertyField(m_MaxIntensity);
                        PropertyField(m_SkyImportanceSampling);
#if ENABLE_UNITY_DENOISING_PLUGIN
                        PropertyField(m_Denoising);
                        var  denoiserType = m_Denoising.value.GetEnumValue <DenoiserType>();
                        bool supported    = Denoiser.IsDenoiserTypeSupported(denoiserType);

                        if (m_Denoising.value.intValue != (int)DenoiserType.None)
                        {
                            using (new IndentLevelScope())
                            {
                                if (supported)
                                {
                                    PropertyField(m_UseAOV);
                                    if (m_Denoising.value.intValue == (int)DenoiserType.Optix)
                                    {
                                        PropertyField(m_Temporal);
                                    }
                                }
                                else
                                {
                                    EditorGUILayout.HelpBox($"The denoiser selected is not supported by this hardware configuration.", MessageType.Error, wide: true);
                                }
                            }
                        }
#else
                        CoreEditorUtils.DrawFixMeBox("Path Tracing Denoising is not active in this project. To activate it, install the Unity Denoising Plugin package.", MessageType.Info, () =>
                        {
                            PackageManager.Client.Add("com.unity.rendering.denoising");
                        });
#endif
                    }

                    // Make sure MaxDepth is always greater or equal than MinDepth
                    m_MaxDepth.value.intValue = Math.Max(m_MinDepth.value.intValue, m_MaxDepth.value.intValue);
                }
            }
        }
コード例 #27
0
        static void Drawer_SectionShapeBox(SerializedInfluenceVolume serialized, Editor owner, bool drawOffset, bool drawNormal, bool drawFace)
        {
            bool advanced        = serialized.editorAdvancedModeEnabled.boolValue;
            var  maxFadeDistance = serialized.boxSize.vector3Value * 0.5f;
            var  minFadeDistance = Vector3.zero;

            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(serialized.boxSize, boxSizeContent);
            if (EditorGUI.EndChangeCheck())
            {
                Vector3 blendPositive       = serialized.boxBlendDistancePositive.vector3Value;
                Vector3 blendNegative       = serialized.boxBlendDistanceNegative.vector3Value;
                Vector3 blendNormalPositive = serialized.boxBlendNormalDistancePositive.vector3Value;
                Vector3 blendNormalNegative = serialized.boxBlendNormalDistanceNegative.vector3Value;
                Vector3 size = serialized.boxSize.vector3Value;
                for (int i = 0; i < 3; ++i)
                {
                    size[i] = Mathf.Max(0f, size[i]);
                }
                serialized.boxSize.vector3Value = size;
                Vector3 halfSize = size * .5f;
                for (int i = 0; i < 3; ++i)
                {
                    blendPositive[i]       = Mathf.Clamp(blendPositive[i], 0f, halfSize[i]);
                    blendNegative[i]       = Mathf.Clamp(blendNegative[i], 0f, halfSize[i]);
                    blendNormalPositive[i] = Mathf.Clamp(blendNormalPositive[i], 0f, halfSize[i]);
                    blendNormalNegative[i] = Mathf.Clamp(blendNormalNegative[i], 0f, halfSize[i]);
                }
                serialized.boxBlendDistancePositive.vector3Value       = blendPositive;
                serialized.boxBlendDistanceNegative.vector3Value       = blendNegative;
                serialized.boxBlendNormalDistancePositive.vector3Value = blendNormalPositive;
                serialized.boxBlendNormalDistanceNegative.vector3Value = blendNormalNegative;
                if (serialized.editorAdvancedModeEnabled.boolValue)
                {
                    serialized.editorAdvancedModeBlendDistancePositive.vector3Value       = serialized.boxBlendDistancePositive.vector3Value;
                    serialized.editorAdvancedModeBlendDistanceNegative.vector3Value       = serialized.boxBlendDistanceNegative.vector3Value;
                    serialized.editorAdvancedModeBlendNormalDistancePositive.vector3Value = serialized.boxBlendNormalDistancePositive.vector3Value;
                    serialized.editorAdvancedModeBlendNormalDistanceNegative.vector3Value = serialized.boxBlendNormalDistanceNegative.vector3Value;
                }
                else
                {
                    serialized.editorSimplifiedModeBlendDistance.floatValue       = Mathf.Max(blendPositive.x, blendPositive.y, blendPositive.z, blendNegative.x, blendNegative.y, blendNegative.z);
                    serialized.boxBlendDistancePositive.vector3Value              = serialized.boxBlendDistanceNegative.vector3Value = Vector3.one * serialized.editorSimplifiedModeBlendDistance.floatValue;
                    serialized.editorSimplifiedModeBlendNormalDistance.floatValue = Mathf.Max(blendNormalPositive.x, blendNormalPositive.y, blendNormalPositive.z, blendNormalNegative.x, blendNormalNegative.y, blendNormalNegative.z);
                    serialized.boxBlendNormalDistancePositive.vector3Value        = serialized.boxBlendNormalDistanceNegative.vector3Value = Vector3.one * serialized.editorSimplifiedModeBlendNormalDistance.floatValue;
                }
            }
            HDProbeUI.Drawer_ToolBarButton(HDProbeUI.ToolBar.InfluenceShape, owner, GUILayout.Width(28f), GUILayout.MinHeight(22f));
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);

            EditorGUILayout.BeginHorizontal();
            Drawer_AdvancedBlendDistance(serialized, false, maxFadeDistance, blendDistanceContent);
            HDProbeUI.Drawer_ToolBarButton(HDProbeUI.ToolBar.Blend, owner, GUILayout.ExpandHeight(true), GUILayout.Width(28f), GUILayout.MinHeight(22f), GUILayout.MaxHeight((advanced ? 2 : 1) * (EditorGUIUtility.singleLineHeight + 3)));
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(EditorGUIUtility.standardVerticalSpacing * 2f);

            if (drawNormal)
            {
                EditorGUILayout.BeginHorizontal();
                Drawer_AdvancedBlendDistance(serialized, true, maxFadeDistance, blendNormalDistanceContent);
                HDProbeUI.Drawer_ToolBarButton(HDProbeUI.ToolBar.NormalBlend, owner, GUILayout.ExpandHeight(true), GUILayout.Width(28f), GUILayout.MinHeight(22f), GUILayout.MaxHeight((advanced ? 2 : 1) * (EditorGUIUtility.singleLineHeight + 3)));
                EditorGUILayout.EndHorizontal();

                GUILayout.Space(EditorGUIUtility.standardVerticalSpacing * 2f);
            }

            if (advanced && drawFace)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUI.BeginChangeCheck();
                var positive = serialized.editorAdvancedModeFaceFadePositive.vector3Value;
                var negative = serialized.editorAdvancedModeFaceFadeNegative.vector3Value;
                CoreEditorUtils.DrawVector6(faceFadeContent, ref positive, ref negative, Vector3.zero, Vector3.one, k_HandlesColor);
                serialized.editorAdvancedModeFaceFadePositive.vector3Value = positive;
                serialized.editorAdvancedModeFaceFadeNegative.vector3Value = negative;
                if (EditorGUI.EndChangeCheck())
                {
                    serialized.boxSideFadePositive.vector3Value = serialized.editorAdvancedModeFaceFadePositive.vector3Value;
                    serialized.boxSideFadeNegative.vector3Value = serialized.editorAdvancedModeFaceFadeNegative.vector3Value;
                }
                GUILayout.Space(28f + 9f); //add right margin for alignment
                EditorGUILayout.EndHorizontal();

                GUILayout.Space(EditorGUIUtility.standardVerticalSpacing * 2f);
            }
        }
        static void Drawer_AdvancedBlendDistance(SerializedInfluenceVolume serialized, bool isNormal, Vector3 maxBlendDistance, GUIContent content)
        {
            SerializedProperty blendDistancePositive = isNormal ? serialized.boxBlendNormalDistancePositive : serialized.boxBlendDistancePositive;
            SerializedProperty blendDistanceNegative = isNormal ? serialized.boxBlendNormalDistanceNegative : serialized.boxBlendDistanceNegative;
            SerializedProperty editorAdvancedModeBlendDistancePositive = isNormal ? serialized.editorAdvancedModeBlendNormalDistancePositive : serialized.editorAdvancedModeBlendDistancePositive;
            SerializedProperty editorAdvancedModeBlendDistanceNegative = isNormal ? serialized.editorAdvancedModeBlendNormalDistanceNegative : serialized.editorAdvancedModeBlendDistanceNegative;
            SerializedProperty editorSimplifiedModeBlendDistance       = isNormal ? serialized.editorSimplifiedModeBlendNormalDistance : serialized.editorSimplifiedModeBlendDistance;
            Vector3            bdp = blendDistancePositive.vector3Value;
            Vector3            bdn = blendDistanceNegative.vector3Value;

            //resync to be sure prefab revert will keep syncs
            if (serialized.editorAdvancedModeEnabled.boolValue)
            {
                if (!(Mathf.Approximately(Vector3.SqrMagnitude(blendDistancePositive.vector3Value - editorAdvancedModeBlendDistancePositive.vector3Value), 0f) &&
                      Mathf.Approximately(Vector3.SqrMagnitude(blendDistanceNegative.vector3Value - editorAdvancedModeBlendDistanceNegative.vector3Value), 0f)))
                {
                    blendDistancePositive.vector3Value = editorAdvancedModeBlendDistancePositive.vector3Value;
                    blendDistanceNegative.vector3Value = editorAdvancedModeBlendDistanceNegative.vector3Value;
                    serialized.Apply();
                    SceneView.RepaintAll(); //update gizmo
                }
            }
            else
            {
                float scalar = editorSimplifiedModeBlendDistance.floatValue;
                if (!(Mathf.Approximately(blendDistancePositive.vector3Value.x, scalar) &&
                      Mathf.Approximately(blendDistancePositive.vector3Value.y, scalar) &&
                      Mathf.Approximately(blendDistancePositive.vector3Value.z, scalar) &&
                      Mathf.Approximately(blendDistanceNegative.vector3Value.x, scalar) &&
                      Mathf.Approximately(blendDistanceNegative.vector3Value.y, scalar) &&
                      Mathf.Approximately(blendDistanceNegative.vector3Value.z, scalar)))
                {
                    blendDistancePositive.vector3Value = blendDistanceNegative.vector3Value = new Vector3(scalar, scalar, scalar);
                    serialized.Apply();
                    SceneView.RepaintAll(); //update gizmo
                }
            }

            if (serialized.editorAdvancedModeEnabled.boolValue)
            {
                EditorGUI.BeginChangeCheck();
                CoreEditorUtils.DrawVector6(content, editorAdvancedModeBlendDistancePositive, editorAdvancedModeBlendDistanceNegative, Vector3.zero, maxBlendDistance, k_HandlesColor);
                if (EditorGUI.EndChangeCheck())
                {
                    blendDistancePositive.vector3Value = editorAdvancedModeBlendDistancePositive.vector3Value;
                    blendDistanceNegative.vector3Value = editorAdvancedModeBlendDistanceNegative.vector3Value;
                }
            }
            else
            {
                Rect lineRect = EditorGUILayout.GetControlRect();
                EditorGUI.BeginProperty(lineRect, content, editorSimplifiedModeBlendDistance);
                float distance = editorSimplifiedModeBlendDistance.floatValue;
                EditorGUI.BeginChangeCheck();
                distance = EditorGUI.FloatField(lineRect, content, distance);
                if (EditorGUI.EndChangeCheck())
                {
                    distance = Mathf.Clamp(distance, 0f, Mathf.Max(maxBlendDistance.x, maxBlendDistance.y, maxBlendDistance.z));
                    Vector3 decal = Vector3.one * distance;
                    bdp.x = Mathf.Clamp(decal.x, 0f, maxBlendDistance.x);
                    bdp.y = Mathf.Clamp(decal.y, 0f, maxBlendDistance.y);
                    bdp.z = Mathf.Clamp(decal.z, 0f, maxBlendDistance.z);
                    bdn.x = Mathf.Clamp(decal.x, 0f, maxBlendDistance.x);
                    bdn.y = Mathf.Clamp(decal.y, 0f, maxBlendDistance.y);
                    bdn.z = Mathf.Clamp(decal.z, 0f, maxBlendDistance.z);
                    blendDistancePositive.vector3Value           = bdp;
                    blendDistanceNegative.vector3Value           = bdn;
                    editorSimplifiedModeBlendDistance.floatValue = distance;
                }
                EditorGUI.EndProperty();
            }
        }
コード例 #29
0
        static void UpdateMaterialToNewerVersion(string caption, UpdateMaterial updateMaterial, UpdateMaterialFile updateMaterialFile = null)
        {
            bool          VCSEnabled    = (UnityEditor.VersionControl.Provider.enabled && UnityEditor.VersionControl.Provider.isActive);
            var           matIds        = AssetDatabase.FindAssets("t:Material");
            List <string> materialFiles = new List <string>(); // Contain the list dirty files

            try
            {
                for (int i = 0, length = matIds.Length; i < length; i++)
                {
                    var path = AssetDatabase.GUIDToAssetPath(matIds[i]);
                    var mat  = AssetDatabase.LoadAssetAtPath <Material>(path);

                    EditorUtility.DisplayProgressBar(
                        "Update material to new version " + caption + "...",
                        string.Format("{0} / {1} materials updated.", i, length),
                        i / (float)(length - 1));

                    if (mat.shader.name == "HDRenderPipeline/LitTessellation" ||
                        mat.shader.name == "HDRenderPipeline/Lit" ||
                        mat.shader.name == "HDRenderPipeline/LayeredLit" ||
                        mat.shader.name == "HDRenderPipeline/LayeredLitTessellation" ||
                        mat.shader.name == "HDRenderPipeline/StackLit" ||
                        mat.shader.name == "HDRenderPipeline/Unlit"
                        )
                    {
                        // Need to be processed in order - All function here should be re-entrant (i.e after upgrade it can be recall)
                        bool dirty = updateMaterial(path, mat);

                        if (dirty)
                        {
                            // Checkout the file and tag it as dirty
                            CoreEditorUtils.CheckOutFile(VCSEnabled, mat);
                            EditorUtility.SetDirty(mat);
                            materialFiles.Add(path);
                        }
                    }
                }
            }
            finally
            {
                EditorUtility.ClearProgressBar();
                // Save all dirty assets
                AssetDatabase.SaveAssets();
            }

            if (updateMaterialFile == null)
            {
                return;
            }

            // Now that all the asset have been modified and save, we can safely update the .mat file and remove removed property
            try
            {
                for (int i = 0, length = materialFiles.Count; i < length; i++)
                {
                    string path = materialFiles[i];

                    EditorUtility.DisplayProgressBar(
                        "Update .mat files...",
                        string.Format("{0} / {1} materials .mat file updated.", i, length),
                        i / (float)(length - 1));

                    // Note: The file is supposed to be checkout by the previous loop
                    updateMaterialFile(path);
                }
            }
            finally
            {
                EditorUtility.ClearProgressBar();
                // No need to save in this case
            }
        }
コード例 #30
0
        public VisualElement GetDefaultInspector()
        {
            VisualElement inspector = new VisualElement()
            {
                name = "inspector"
            };

            VisualElement header = new VisualElement()
            {
                name = "inspector-header"
            };

            header.Add(new Image()
            {
                image = CoreEditorUtils.LoadIcon(@"Packages/com.unity.render-pipelines.core/Editor/LookDev/Icons/", "LookDev_EnvironmentHDR", forceLowRes: true)
            });
            environmentName           = new TextField();
            environmentName.isDelayed = true;
            environmentName.RegisterValueChangedCallback(evt =>
            {
                string path      = AssetDatabase.GetAssetPath(environment);
                environment.name = evt.newValue;
                AssetDatabase.SetLabels(environment, new string[] { evt.newValue });
                EditorUtility.SetDirty(environment);
                AssetDatabase.ImportAsset(path);
                environmentName.name = environment.name;
            });
            header.Add(environmentName);
            inspector.Add(header);

            Foldout foldout = new Foldout()
            {
                text = "Environment Settings"
            };

            skyCubemapField = new ObjectField("Sky with Sun")
            {
                tooltip = "A cubemap that will be used as the sky."
            };
            skyCubemapField.allowSceneObjects = false;
            skyCubemapField.objectType        = typeof(Cubemap);
            skyCubemapField.RegisterValueChangedCallback(evt =>
            {
                var tmp = environment.sky.cubemap;
                RegisterChange(ref tmp, evt.newValue as Cubemap);
                environment.sky.cubemap = tmp;
                latlong.image           = GetLatLongThumbnailTexture(environment, k_SkyThumbnailWidth);
            });
            foldout.Add(skyCubemapField);

            shadowCubemapField = new ObjectField("Sky without Sun")
            {
                tooltip = "[Optional] A cubemap that will be used to compute self shadowing.\nIt should be the same sky without the sun.\nIf nothing is provided, the sky with sun will be used with lower intensity."
            };
            shadowCubemapField.allowSceneObjects = false;
            shadowCubemapField.objectType        = typeof(Cubemap);
            shadowCubemapField.RegisterValueChangedCallback(evt =>
            {
                var tmp = environment.shadow.cubemap;
                RegisterChange(ref tmp, evt.newValue as Cubemap);
                environment.shadow.cubemap = tmp;
                latlong.image = GetLatLongThumbnailTexture(environment, k_SkyThumbnailWidth);
            });
            foldout.Add(shadowCubemapField);

            skyRotationOffset = new FloatField("Rotation")
            {
                tooltip = "Rotation offset on the longitude of the sky."
            };
            skyRotationOffset.RegisterValueChangedCallback(evt
                                                           => RegisterChange(ref environment.sky.rotation, Environment.Shadow.ClampLongitude(evt.newValue), skyRotationOffset, updatePreview: true));
            foldout.Add(skyRotationOffset);

            skyExposureField = new FloatField("Exposure")
            {
                tooltip = "The exposure to apply with this sky."
            };
            skyExposureField.RegisterValueChangedCallback(evt
                                                          => RegisterChange(ref environment.sky.exposure, evt.newValue));
            foldout.Add(skyExposureField);
            var style = foldout.Q <Toggle>().style;

            style.marginLeft = 3;
            style.unityFontStyleAndWeight = FontStyle.Bold;
            inspector.Add(foldout);

            sunPosition = new Vector2Field("Sun Position")
            {
                tooltip = "The sun position as (Longitude, Latitude)\nThe button compute brightest position in the sky with sun."
            };
            sunPosition.Q("unity-x-input").Q <FloatField>().formatString = "n1";
            sunPosition.Q("unity-y-input").Q <FloatField>().formatString = "n1";
            sunPosition.RegisterValueChangedCallback(evt =>
            {
                var tmpContainer = new Vector2(
                    environment.shadow.sunLongitude,
                    environment.shadow.sunLatitude);
                var tmpNewValue = new Vector2(
                    Environment.Shadow.ClampLongitude(evt.newValue.x),
                    Environment.Shadow.ClampLatitude(evt.newValue.y));
                RegisterChange(ref tmpContainer, tmpNewValue, sunPosition);
                environment.shadow.sunLongitude = tmpContainer.x;
                environment.shadow.sunLatitude  = tmpContainer.y;
            });
            foldout.Add(sunPosition);

            Button sunToBrightess = new Button(() =>
            {
                ResetToBrightestSpot(environment);
                sunPosition.SetValueWithoutNotify(new Vector2(
                                                      Environment.Shadow.ClampLongitude(environment.shadow.sunLongitude),
                                                      Environment.Shadow.ClampLatitude(environment.shadow.sunLatitude)));
            })
            {
                name = "sunToBrightestButton"
            };

            sunToBrightess.Add(new Image()
            {
                image = CoreEditorUtils.LoadIcon(@"Packages/com.unity.render-pipelines.core/Editor/LookDev/Icons/", "LookDev_SunPosition", forceLowRes: true)
            });
            sunToBrightess.AddToClassList("sun-to-brightest-button");
            var vector2Input = sunPosition.Q(className: "unity-vector2-field__input");

            vector2Input.Remove(sunPosition.Q(className: "unity-composite-field__field-spacer"));
            vector2Input.Add(sunToBrightess);

            shadowColor = new ColorField("Shadow Tint")
            {
                tooltip = "The wanted shadow tint to be used when computing shadow."
            };
            shadowColor.RegisterValueChangedCallback(evt
                                                     => RegisterChange(ref environment.shadow.color, evt.newValue));
            foldout.Add(shadowColor);

            style            = foldout.Q <Toggle>().style;
            style.marginLeft = 3;
            style.unityFontStyleAndWeight = FontStyle.Bold;
            inspector.Add(foldout);

            return(inspector);
        }