コード例 #1
0
        void DrawShadowsResolutionGUI()
        {
            int shadowResolutionTier;

            if (m_AdditionalLightDataSO == null)
            {
                shadowResolutionTier = UniversalAdditionalLightData.AdditionalLightsShadowDefaultResolutionTier;
            }
            else
            {
                m_AdditionalLightDataSO.Update();
                shadowResolutionTier = m_AdditionalLightData.additionalLightsShadowResolutionTier;
            }

            Rect controlRectAdditionalData = EditorGUILayout.GetControlRect(true);

            if (m_AdditionalLightDataSO != null)
            {
                EditorGUI.BeginProperty(controlRectAdditionalData, Styles.ShadowResolution, m_AdditionalLightsShadowResolutionTierProp);
            }

            EditorGUI.BeginChangeCheck();

            // UI code adapted from HDRP LevelFieldGUI in com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/SerializedScalableSettingValue.cs
            const int k_IndentPerLevel     = 15;
            const int k_PrefixPaddingRight = 2;
            const int k_ValueUnitSeparator = 2;
            const int k_EnumWidth          = 70;
            float     indent = k_IndentPerLevel * EditorGUI.indentLevel;

            Rect labelRect = controlRectAdditionalData;
            Rect levelRect = controlRectAdditionalData;
            Rect fieldRect = controlRectAdditionalData;

            labelRect.width = EditorGUIUtility.labelWidth;
            // Dealing with indentation add space before the actual drawing
            // Thus resize accordingly to have a coherent aspect
            levelRect.x     += labelRect.width - indent + k_PrefixPaddingRight;
            levelRect.width  = k_EnumWidth + indent;
            fieldRect.x      = levelRect.x + levelRect.width + k_ValueUnitSeparator - indent;
            fieldRect.width -= fieldRect.x - controlRectAdditionalData.x;

            EditorGUI.LabelField(labelRect, Styles.ShadowResolution);

            shadowResolutionTier = EditorGUI.IntPopup(levelRect, GUIContent.none, shadowResolutionTier, Styles.ShadowResolutionDefaultOptions, Styles.ShadowResolutionDefaultValues);

            bool hasResolutionTierChanged = EditorGUI.EndChangeCheck();

            if (m_AdditionalLightDataSO != null)
            {
                EditorGUI.EndProperty();
            }

            // Same logic as in DrawAdditionalShadowData
            if (shadowResolutionTier == UniversalAdditionalLightData.AdditionalLightsShadowResolutionTierCustom && m_AdditionalLightDataSO != null)
            {
                // show the custom value field GUI.
                var newResolution = EditorGUI.IntField(fieldRect, settings.shadowsResolution.intValue);
                settings.shadowsResolution.intValue = Mathf.Max(UniversalAdditionalLightData.AdditionalLightsShadowMinimumResolution, Mathf.NextPowerOfTwo(newResolution));

                m_AdditionalLightDataSO.ApplyModifiedProperties();
            }
            if (shadowResolutionTier != UniversalAdditionalLightData.AdditionalLightsShadowResolutionTierCustom)
            {
                // show resolution tier values defined in pipeline settings
                UniversalRenderPipelineAsset urpAsset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset;
                EditorGUI.LabelField(fieldRect, $"{urpAsset.GetAdditionalLightsShadowResolution(shadowResolutionTier)} ({urpAsset.name})");
            }

            if (hasResolutionTierChanged)
            {
                if (m_AdditionalLightDataSO == null)
                {
                    lightProperty.gameObject.AddComponent <UniversalAdditionalLightData>();
                    m_AdditionalLightData = lightProperty.gameObject.GetComponent <UniversalAdditionalLightData>();

                    UniversalRenderPipelineAsset asset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset;
                    settings.shadowsBias.floatValue       = asset.shadowDepthBias;
                    settings.shadowsNormalBias.floatValue = asset.shadowNormalBias;
                    settings.shadowsResolution.intValue   = UniversalAdditionalLightData.AdditionalLightsShadowDefaultCustomResolution;

                    init(m_AdditionalLightData);
                }

                m_AdditionalLightsShadowResolutionTierProp.intValue = shadowResolutionTier;
                m_AdditionalLightDataSO.ApplyModifiedProperties();
            }
        }