/// <summary>Draws the level popup and the associated value in a field style GUI with an Enum field.</summary>
 /// <param name="self">The scalable setting value to draw.</param>
 /// <param name="label">The label to use for the field.</param>
 /// <param name="sourceValue">The associated scalable setting. This one defines the levels for this value.</param>
 /// <param name="sourceName">A string describing the source of the scalable settings. Usually the name of the containing asset.</param>
 public static void LevelAndEnumGUILayout <H>
 (
     this SerializedScalableSettingValue self,
     GUIContent label,
     ScalableSetting <H> sourceValue,
     string sourceName
 ) where H : Enum => LevelAndGUILayout <H, EnumFieldGUI <H> >(self, label, sourceValue, sourceName);
예제 #2
0
        internal SerializedProbeSettings(SerializedProperty root)
        {
            this.root = root;

            type                                 = root.Find((ProbeSettings p) => p.type);
            mode                                 = root.Find((ProbeSettings p) => p.mode);
            realtimeMode                         = root.Find((ProbeSettings p) => p.realtimeMode);
            lightingMultiplier                   = root.FindPropertyRelative("lighting.multiplier");
            lightingWeight                       = root.FindPropertyRelative("lighting.weight");
            lightingFadeDistance                 = root.FindPropertyRelative("lighting.fadeDistance");
            lightingLightLayer                   = root.FindPropertyRelative("lighting.lightLayer");
            lightingRangeCompressionFactor       = root.FindPropertyRelative("lighting.rangeCompressionFactor");
            proxyUseInfluenceVolumeAsProxyVolume = root.FindPropertyRelative("proxySettings.useInfluenceVolumeAsProxyVolume");
            proxyCapturePositionProxySpace       = root.FindPropertyRelative("proxySettings.capturePositionProxySpace");
            proxyCaptureRotationProxySpace       = root.FindPropertyRelative("proxySettings.captureRotationProxySpace");
            proxyMirrorPositionProxySpace        = root.FindPropertyRelative("proxySettings.mirrorPositionProxySpace");
            proxyMirrorRotationProxySpace        = root.FindPropertyRelative("proxySettings.mirrorRotationProxySpace");
            resolutionScalable                   = new SerializedScalableSettingValue(root.Find((ProbeSettings p) => p.resolutionScalable));
            roughReflections                     = root.FindPropertyRelative("roughReflections");
            distanceBasedRoughness               = root.FindPropertyRelative("distanceBasedRoughness");
            frustumFieldOfViewMode               = root.FindPropertyRelative("frustum.fieldOfViewMode");
            frustumFixedValue                    = root.FindPropertyRelative("frustum.fixedValue");
            frustumViewerScale                   = root.FindPropertyRelative("frustum.viewerScale");
            frustumAutomaticScale                = root.FindPropertyRelative("frustum.automaticScale");

            cameraSettings = new SerializedCameraSettings(root.Find((ProbeSettings p) => p.cameraSettings));
            influence      = new SerializedInfluenceVolume(root.Find((ProbeSettings p) => p.influence));
            proxy          = new SerializedProxyVolume(root.Find((ProbeSettings p) => p.proxy));
        }
        static Rect DoGUILayout(SerializedScalableSettingValue self, GUIContent label)
        {
            var rect = GUILayoutUtility.GetRect(0, float.Epsilon, 0, EditorGUIUtility.singleLineHeight);

            var contentRect = EditorGUI.PrefixLabel(rect, label);

            // Render the enum popup
            const int k_EnumWidth = 70;
            // Magic number??
            const int k_EnumOffset = 30;
            var       enumRect     = new Rect(contentRect);

            enumRect.x    -= k_EnumOffset;
            enumRect.width = k_EnumWidth + k_EnumOffset;

            var(level, isOverride) =
                LevelFieldGUI(enumRect, GUIContent.none, (ScalableSetting.Level)self.level.intValue, self.useOverride.boolValue);
            self.useOverride.boolValue = isOverride;
            if (!self.useOverride.boolValue)
            {
                self.level.intValue = (int)level;
            }

            // Return the rect fo user can render the field there
            var fieldRect = new Rect(contentRect);

            fieldRect.x     = enumRect.x + enumRect.width + 2 - k_EnumOffset;
            fieldRect.width = contentRect.width - (fieldRect.x - enumRect.x) + k_EnumOffset;

            return(fieldRect);
        }
 /// <summary>
 /// Draw the scalable setting as a popup and field GUI in a single line.
 ///
 /// This helper statically dispatch the appropriate GUI call depending
 /// on the multiselection state of the serialized properties.
 /// </summary>
 /// <typeparam name="T">The type of the scalable property.</typeparam>
 /// <typeparam name="FieldGUI">The renderer of the property. It must implements <see cref="IFieldGUI{T}"/></typeparam>
 /// <param name="self">The scalable property to render.</param>
 /// <param name="label">The label of the scalable property field.</param>
 /// <param name="sourceValue">The source of the scalable setting.</param>
 /// <param name="sourceName">A description of the scalable setting, usually the name of its containing asset.</param>
 /// <param name="defaultSchema">
 /// The id of the schema to use when the scalable setting is null.
 /// Defaults to <see cref="ScalableSettingSchemaId.With3Levels"/>.
 /// </param>
 static void LevelAndGUILayout <T, FieldGUI>(
     this SerializedScalableSettingValue self,
     GUIContent label,
     ScalableSetting <T> sourceValue,
     string sourceName,
     ScalableSettingSchemaId defaultSchema = default
     ) where FieldGUI : IFieldGUI <T>, new()
 {
     var resolvedDefaultSchema = defaultSchema.Equals(default) ? ScalableSettingSchemaId.With3Levels : defaultSchema;
        /// <summary>
        /// Draw the level enum popup for a scalable setting value.
        ///
        /// The popup displays the level available and a `custom` entry to provide an explicit value.
        /// </summary>
        /// <param name = "rect" > The rect to use to draw the popup.</param>
        /// <param name="label">The label to use for the popup.</param>
        /// <param name="schema">The schema of the scalable setting. This provides the number of levels availables.</param>
        /// <returns>The rect to use to render the value of the field. (Either the custom value or the level value).</returns>
        static Rect LevelFieldGUILayout(
            SerializedScalableSettingValue self,
            GUIContent label,
            ScalableSettingSchema schema
            )
        {
            Assert.IsNotNull(schema);

            var rect = GUILayoutUtility.GetRect(0, float.Epsilon, 0, EditorGUIUtility.singleLineHeight);

            var contentRect = EditorGUI.PrefixLabel(rect, label);

            // Render the enum popup
            const int k_EnumWidth = 70;
            // Magic number??
            const int k_EnumOffset = 30;
            var       enumRect     = new Rect(contentRect);

            enumRect.x    -= k_EnumOffset;
            enumRect.width = k_EnumWidth + k_EnumOffset;

            var oldShowMixedValue = EditorGUI.showMixedValue;

            EditorGUI.showMixedValue |= self.level.hasMultipleDifferentValues || self.useOverride.hasMultipleDifferentValues;
            EditorGUI.BeginChangeCheck();
            var(level, useOverride) = LevelFieldGUI(
                enumRect,
                GUIContent.none,
                schema,
                self.level.intValue,
                self.useOverride.boolValue
                );
            EditorGUI.showMixedValue = oldShowMixedValue;
            if (EditorGUI.EndChangeCheck())
            {
                self.useOverride.boolValue = useOverride;
                if (!self.useOverride.boolValue)
                {
                    self.level.intValue = level;
                }
            }

            // Return the rect fo user can render the field there
            var fieldRect = new Rect(contentRect);

            fieldRect.x     = enumRect.x + enumRect.width + 2 - k_EnumOffset;
            fieldRect.width = contentRect.width - (fieldRect.x - enumRect.x) + k_EnumOffset;

            return(fieldRect);
        }
        public static void LevelAndIntGUILayout <T>(this SerializedScalableSettingValue self, GUIContent label, T @default)
            where T : struct, IValueGetter <int>
        {
            var fieldRect = DoGUILayout(self, label);

            if (self.useOverride.boolValue)
            {
                [email protected] = EditorGUI.IntField(fieldRect, [email protected]);
            }
            else
            {
                EditorGUI.LabelField(fieldRect, $"{@default.GetValue((ScalableSetting.Level)self.level.intValue)} ({@default.sourceDescription})");
            }
        }
        public static void LevelAndToggleGUILayout <T>(this SerializedScalableSettingValue self, GUIContent label, T @default)
            where T : struct, IValueGetter <bool>
        {
            var fieldRect = DoGUILayout(self, label);

            if (self.useOverride.boolValue)
            {
                [email protected] = EditorGUI.Toggle(fieldRect, [email protected]);
            }
            else
            {
                var enabled = GUI.enabled;
                GUI.enabled = false;
                EditorGUI.Toggle(fieldRect, @default.GetValue((ScalableSetting.Level)self.level.intValue));
                fieldRect.x     += 25;
                fieldRect.width -= 25;
                EditorGUI.LabelField(fieldRect, $"({@default.sourceDescription})");
                GUI.enabled = enabled;
            }
        }
        /// <summary>
        /// Draw the level enum popup for a scalable setting value.
        ///
        /// The popup displays the level available and a `custom` entry to provide an explicit value.
        /// </summary>
        /// <param name = "rect" > The rect to use to draw the popup.</param>
        /// <param name="label">The label to use for the popup.</param>
        /// <param name="schema">The schema of the scalable setting. This provides the number of levels availables.</param>
        /// <returns>The rect to use to render the value of the field. (Either the custom value or the level value).</returns>
        static Rect LevelFieldGUILayout(
            SerializedScalableSettingValue self,
            GUIContent label,
            ScalableSettingSchema schema
            )
        {
            Assert.IsNotNull(schema);

            // Match const defined in EditorGUI.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 lineRect  = EditorGUILayout.GetControlRect();
            Rect labelRect = lineRect;
            Rect levelRect = lineRect;
            Rect fieldRect = lineRect;

            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 - lineRect.x;

            label = EditorGUI.BeginProperty(labelRect, label, self.level);
            label = EditorGUI.BeginProperty(labelRect, label, self.@override);
            label = EditorGUI.BeginProperty(labelRect, label, self.useOverride);
            {
                EditorGUI.LabelField(labelRect, label);
            }
            EditorGUI.EndProperty();
            EditorGUI.EndProperty();
            EditorGUI.EndProperty();

            EditorGUI.BeginProperty(levelRect, label, self.level);
            EditorGUI.BeginProperty(levelRect, label, self.useOverride);
            {
                EditorGUI.BeginChangeCheck();
                var(level, useOverride) = LevelFieldGUI(
                    levelRect,
                    GUIContent.none,
                    schema,
                    self.level.intValue,
                    self.useOverride.boolValue
                    );
                if (EditorGUI.EndChangeCheck())
                {
                    self.useOverride.boolValue = useOverride;
                    if (!self.useOverride.boolValue)
                    {
                        self.level.intValue = level;
                    }
                }
            }
            EditorGUI.EndProperty();
            EditorGUI.EndProperty();

            return(fieldRect);
        }
 /// <summary>Draws the level popup and the associated value in a field style GUI with an toggle field.</summary>
 /// <param name="self">The scalable setting value to draw.</param>
 /// <param name="label">The label to use for the field.</param>
 /// <param name="sourceValue">The associated scalable setting. This one defines the levels for this value.</param>
 /// <param name="sourceName">A string describing the source of the scalable settings. Usually the name of the containing asset.</param>
 public static void LevelAndToggleGUILayout(
     this SerializedScalableSettingValue self,
     GUIContent label,
     ScalableSetting <bool> sourceValue,
     string sourceName
     ) => LevelAndGUILayout <bool, ToggleFieldGUI>(self, label, sourceValue, sourceName);
 /// <summary>Draws the level popup and the associated value in a field style GUI with an int field.</summary>
 /// <param name="self">The scalable setting value to draw.</param>
 /// <param name="label">The label to use for the field.</param>
 /// <param name="sourceValue">The associated scalable setting. This one defines the levels for this value.</param>
 /// <param name="sourceName">A string describing the source of the scalable settings. Usually the name of the containing asset.</param>
 public static void LevelAndIntGUILayout(
     this SerializedScalableSettingValue self,
     GUIContent label,
     ScalableSetting <int> sourceValue,
     string sourceName
     ) => LevelAndGUILayout <int, IntFieldGUI>(self, label, sourceValue, sourceName);
 public static void LevelAndToggleGUILayout(this SerializedScalableSettingValue self, GUIContent label)
 {
     LevelAndToggleGUILayout(self, label, new NoopGetter <bool>());
 }