/// <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);
 public FromScalableSetting(
     ScalableSetting <T> value,
     HDRenderPipelineAsset source)
 {
     m_Value  = value;
     m_Source = source;
 }
 /// <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;
        public void SchemaPropertyWorks()
        {
            var setting = new ScalableSetting <int>(new[] { 1, 2, 3 }, ScalableSettingSchemaId.With3Levels);

            Assert.AreEqual(ScalableSettingSchemaId.With3Levels, setting.schemaId);

            setting.schemaId = ScalableSettingSchemaId.With4Levels;
            Assert.AreEqual(ScalableSettingSchemaId.With4Levels, setting.schemaId);
        }
 public void CustomGUI(
     Rect fieldRect,
     SerializedScalableSettingValue self,
     GUIContent label,
     ScalableSetting <bool> sourceValue,
     string sourceName
     )
 {
     [email protected] = EditorGUI.Toggle(fieldRect, [email protected]);
 }
 public void LevelValueDescriptionGUI(
     Rect fieldRect,
     SerializedScalableSettingValue self,
     GUIContent label,
     ScalableSetting <int> sourceValue,
     string sourceName
     )
 {
     EditorGUI.LabelField(fieldRect, $"{(sourceValue != null ? sourceValue[self.level.intValue] : 0)} ({sourceName})");
 }
 public void CustomGUI(
     Rect fieldRect,
     SerializedScalableSettingValue self,
     GUIContent label,
     ScalableSetting <int> sourceValue,
     string sourceName
     )
 {
     [email protected] = EditorGUI.IntField(fieldRect, [email protected]);
 }
 public void MixedValueDescriptionGUI(
     Rect fieldRect,
     SerializedScalableSettingValue self,
     GUIContent label,
     ScalableSetting <bool> sourceValue,
     string sourceName
     )
 {
     EditorGUI.LabelField(fieldRect, $"---");
 }
        public void IndexValuesWorks()
        {
            var setting = new ScalableSetting <int>(new[] { 1, 2, 3 }, ScalableSettingSchemaId.With3Levels);

            Assert.AreEqual(1, setting[0]);
            Assert.AreEqual(2, setting[1]);
            Assert.AreEqual(3, setting[2]);
            Assert.AreEqual(0, setting[3]);
            Assert.AreEqual(0, setting[4]);
        }
        public void ValueWorkWithOverride()
        {
            var setting = new ScalableSetting <int>(new[] { 1, 2, 3 }, ScalableSettingSchemaId.With3Levels);
            var value   = new ScalableSettingValue <int>
            {
                useOverride = true,
                @override   = 4
            };

            Assert.AreEqual(4, value.Value(setting));
        }
        public void ValueWorkWithLevel()
        {
            var setting = new ScalableSetting <int>(new[] { 1, 2, 3 }, ScalableSettingSchemaId.With3Levels);
            var value   = new ScalableSettingValue <int>
            {
                useOverride = false,
                @override   = 4,
                level       = 1,
            };

            Assert.AreEqual(2, value.Value(setting));
        }
            public void CustomGUI(
                Rect fieldRect,
                SerializedScalableSettingValue self,
                GUIContent label,
                ScalableSetting <H> sourceValue,
                string sourceName
                )
            {
                // Due to a constraint in the scalability setting, we cannot simply precise the H type as an Enum in the struct declaration.
                // this shenanigans are not pretty, but we do not fall into a high complexity everytime we want to support a new enum.
                Enum data = (Enum)Enum.Parse(typeof(H), [email protected]());

                [email protected] = (int)(object)EditorGUI.EnumPopup(fieldRect, data);
            }
Exemplo n.º 13
0
        public void TryGetWorks()
        {
            var setting = new ScalableSetting <int>(new[] { 1, 2, 3 }, ScalableSettingSchemaId.With3Levels);

            Assert.True(setting.TryGet(0, out var v));
            Assert.AreEqual(1, v);

            Assert.False(setting.TryGet(-1, out v));
            Assert.AreEqual(default(int), v);

            Assert.True(setting.TryGet(2, out v));
            Assert.AreEqual(3, v);

            Assert.False(setting.TryGet(3, out v));
            Assert.AreEqual(default(int), v);
        }
            public void LevelValueDescriptionGUI(
                Rect fieldRect,
                SerializedScalableSettingValue self,
                GUIContent label,
                ScalableSetting <bool> sourceValue,
                string sourceName
                )
            {
                var enabled = GUI.enabled;

                GUI.enabled = false;
                EditorGUI.Toggle(fieldRect, sourceValue != null ? sourceValue[self.level.intValue] : false);
                fieldRect.x     += 25;
                fieldRect.width -= 25;
                EditorGUI.LabelField(fieldRect, $"({sourceName})");
                GUI.enabled = enabled;
            }
            public void LevelValueDescriptionGUI(
                Rect fieldRect,
                SerializedScalableSettingValue self,
                GUIContent label,
                ScalableSetting <H> sourceValue,
                string sourceName
                )
            {
                var enabled = GUI.enabled;

                GUI.enabled = false;
                // See the comment in the function above.
                var defaultValue = (Enum)(Enum.GetValues(typeof(H)).GetValue(0));

                EditorGUI.EnumPopup(fieldRect, sourceValue != null ? (Enum)(object)(sourceValue[self.level.intValue]) : defaultValue);
                fieldRect.x     += 25;
                fieldRect.width -= 25;
                GUI.enabled      = enabled;
            }
        /// <summary>
        /// Evaluate the value of the scalable setting value.
        /// </summary>
        /// <typeparam name="T">The type of the scalable setting.</typeparam>
        /// <param name="setting">The scalable setting to use to evaluate levels.</param>
        /// <param name="value">The evaluated value.</param>
        /// <returns><c>true</c> when the value was evaluated, <c>false</c> when the value could not be evaluated.</returns>
        public bool TryGetValue <T>(ScalableSetting <T> setting, out T value)
            where T : struct
        {
            if (hasMultipleValues)
            {
                value = default;
                return(false);
            }

            if (useOverride.boolValue)
            {
                value = @override.GetInline <T>();
                return(true);
            }
            else
            {
                var actualLevel = level.intValue;
                return(setting.TryGet(actualLevel, out value));
            }
        }
 /// <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);
 /// <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);