Пример #1
0
        static void LevelValuesFieldGUI <T>(
            Rect rect,
            SerializedScalableSetting scalableSetting,
            int count,
            ScalableSettingSchema schema
            )
            where T : struct
        {
            var labels = new GUIContent[count];

            Array.Copy(schema.levelNames, labels, count);
            var values = new T[count];

            for (var i = 0; i < count; ++i)
            {
                values[i] = scalableSetting.values.GetArrayElementAtIndex(i).GetInline <T>();
            }
            EditorGUI.BeginChangeCheck();
            MultiField(rect, labels, values);
            if (EditorGUI.EndChangeCheck())
            {
                for (var i = 0; i < count; ++i)
                {
                    scalableSetting.values.GetArrayElementAtIndex(i).SetInline(values[i]);
                }
            }
        }
Пример #2
0
        public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
        {
            var value = parameter.value;

            if (value.propertyType != SerializedPropertyType.Integer)
            {
                return(false);
            }

            var o = parameter.GetObjectRef <ScalableSettingLevelParameter>();

            var(level, useOverride) = o.levelAndOverride;

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

            // Magic number for padding
            rect.x     += 3;
            rect.y     += 2;
            rect.width -= 3;

            o.levelAndOverride = SerializedScalableSettingValueUI.LevelFieldGUI(
                rect,
                title,
                ScalableSettingSchema.GetSchemaOrNull(ScalableSettingSchemaId.With3Levels),
                level,
                useOverride
                );
            return(true);
        }
Пример #3
0
        public int GetSchemaLevelCount()
        {
            var schema = ScalableSettingSchema.GetSchemaOrNull(new ScalableSettingSchemaId(schemaId.stringValue))
                         ?? ScalableSettingSchema.GetSchemaOrNull(ScalableSettingSchemaId.With3Levels);

            return(schema.levelCount);
        }
Пример #4
0
        static void LevelValuesFieldGUI <T>(
            GUIContent label,
            SerializedScalableSetting scalableSetting,
            int count,
            ScalableSettingSchema schema
            )
            where T : struct
        {
            var labels = new GUIContent[count];

            Array.Copy(schema.levelNames, labels, count);
            var values = new T[count];

            for (var i = 0; i < count; ++i)
            {
                values[i] = scalableSetting.values.GetArrayElementAtIndex(i).GetInline <T>();
            }

            using (var scope = new EditorGUI.ChangeCheckScope())
            {
                CoreEditorUtils.DrawMultipleFields(label, labels, values);
                if (scope.changed)
                {
                    for (var i = 0; i < count; ++i)
                    {
                        scalableSetting.values.GetArrayElementAtIndex(i).SetInline(values[i]);
                    }
                }
            }
        }
        public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
        {
            var value = parameter.value;

            if (value.propertyType != SerializedPropertyType.Integer)
            {
                return(false);
            }

            var o = parameter.GetObjectRef <ScalableSettingLevelParameter>();

            var(level, useOverride) = o.levelAndOverride;

            var rect = EditorGUILayout.GetControlRect();

            var levelAndOverride = SerializedScalableSettingValueUI.LevelFieldGUI(
                rect,
                title,
                ScalableSettingSchema.GetSchemaOrNull(ScalableSettingSchemaId.With3Levels),
                level,
                useOverride
                );

            value.intValue = ScalableSettingLevelParameter.GetScalableSettingLevelParameterValue(levelAndOverride.level, levelAndOverride.useOverride);
            return(true);
        }
Пример #6
0
        public void LevelNamesWorks()
        {
            var schema = ScalableSettingSchema.GetSchemaOrNull(ScalableSettingSchemaId.With3Levels);

            Assert.AreEqual(3, schema.levelCount);
            Assert.AreEqual(3, schema.levelNames.Length);
            Assert.AreEqual("Low", schema.levelNames[0].text);
            Assert.AreEqual("Medium", schema.levelNames[1].text);
            Assert.AreEqual("High", schema.levelNames[2].text);
        }
        /// <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);
        }
Пример #8
0
        public void GetSchemaOrNullWorks()
        {
            {
                var schema = ScalableSettingSchema.GetSchemaOrNull(ScalableSettingSchemaId.With3Levels);

                Assert.IsNotNull(schema);
                Assert.AreEqual(3, schema.levelCount);
                Assert.AreEqual(3, schema.levelNames.Length);
            }
            {
                ScalableSettingSchemaId?id = ScalableSettingSchemaId.With3Levels;
                var schema = ScalableSettingSchema.GetSchemaOrNull(id);

                Assert.IsNotNull(schema);
                Assert.AreEqual(3, schema.levelCount);
                Assert.AreEqual(3, schema.levelNames.Length);
            }
        }
        /// <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>
        /// <param name="level">The level to use, when <paramref name="useOverride"/> is <c>false</c>.</param>
        /// <param name="useOverride">Whether to use the custom value or the level's value.</param>
        /// <returns>
        /// If the field uses a level value, then <c>(level, true)</c> is returned, where <c>level</c> is the level used.
        /// Otherwise, <c>(-1, 0)</c> is returned.
        /// </returns>
        public static (int level, bool useOverride) LevelFieldGUI(
            Rect rect,
            GUIContent label,
            ScalableSettingSchema schema,
            int level,
            bool useOverride
            )
        {
            var enumValue  = useOverride ? 0 : level + 1;
            var levelCount = schema.levelCount;
            var options    = new GUIContent[levelCount + 1];

            options[0] = new GUIContent("Custom");
            Array.Copy(schema.levelNames, 0, options, 1, levelCount);

            var newValue = EditorGUI.Popup(rect, label, enumValue, options);

            return(newValue - 1, newValue == 0);
        }
Пример #10
0
        /// <summary>
        /// Draw the scalable setting as a single line field with multiple values.
        ///
        /// There will be one value per level.
        /// </summary>
        /// <typeparam name="T">The type of the scalable setting.</typeparam>
        /// <param name="self">The scalable setting to draw.</param>
        /// <param name="label">The label of the field.</param>
        public static void ValueGUI <T>(this SerializedScalableSetting self, GUIContent label)
            where T : struct
        {
            var schema = ScalableSettingSchema.GetSchemaOrNull(new ScalableSettingSchemaId(self.schemaId.stringValue))
                         ?? ScalableSettingSchema.GetSchemaOrNull(ScalableSettingSchemaId.With3Levels);

            EditorGUI.showMixedValue = self.values.hasMultipleDifferentValues;

            var count = schema.levelCount;

            if (self.values.arraySize != count)
            {
                self.values.arraySize = count;
            }

            LevelValuesFieldGUI <T>(label, self, count, schema);

            EditorGUI.showMixedValue = false;
        }
        /// <summary>
        /// Draw the scalable setting as a single line field with multiple values.
        ///
        /// There will be one value per level.
        /// </summary>
        /// <typeparam name="T">The type of the scalable setting.</typeparam>
        /// <param name="self">The scalable setting to draw.</param>
        /// <param name="label">The label of the field.</param>
        public static void ValueGUI <T>(this SerializedScalableSetting self, GUIContent label)
            where T : struct
        {
            var schema = ScalableSettingSchema.GetSchemaOrNull(new ScalableSettingSchemaId(self.schemaId.stringValue))
                         ?? ScalableSettingSchema.GetSchemaOrNull(ScalableSettingSchemaId.With3Levels);

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

            // Magic Number !!
            rect.x     += 3;
            rect.width -= 6;
            // Magic Number !!

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

            EditorGUI.showMixedValue = self.values.hasMultipleDifferentValues;

            var count = schema.levelCount;

            if (self.values.arraySize != count)
            {
                self.values.arraySize = count;
            }

            if (typeof(T) == typeof(bool))
            {
                LevelValuesFieldGUI <bool>(contentRect, self, count, schema);
            }
            else if (typeof(T) == typeof(int))
            {
                LevelValuesFieldGUI <int>(contentRect, self, count, schema);
            }
            else if (typeof(T) == typeof(float))
            {
                LevelValuesFieldGUI <float>(contentRect, self, count, schema);
            }
            else if (typeof(T).IsEnum)
            {
                LevelValuesFieldGUI <T>(contentRect, self, count, schema);
            }
            EditorGUI.showMixedValue = false;
        }
Пример #12
0
        int GetMinimumMaxLoDValue(HDRenderPipelineAsset asset)
        {
            int minimumMaxLoD = int.MaxValue;
            var maxLoDs       = asset.currentPlatformRenderPipelineSettings.maximumLODLevel;
            var schema        = ScalableSettingSchema.GetSchemaOrNull(maxLoDs.schemaId);

            for (int lod = 0; lod < schema.levelCount; ++lod)
            {
                if (maxLoDs.TryGet(lod, out int maxLoD))
                {
                    minimumMaxLoD = Mathf.Min(minimumMaxLoD, maxLoD);
                }
            }

            if (minimumMaxLoD != int.MaxValue)
            {
                return(minimumMaxLoD);
            }
            else
            {
                return(0);
            }
        }
        /// <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);
        }