public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
        {
            var value = parameter.value;

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

            var o = parameter.GetObjectRef <FloatRangeParameter>();
            var v = value.vector2Value;

            // The layout system breaks alignement when mixing inspector fields with custom layouted
            // fields as soon as a scrollbar is needed in the inspector, so we'll do the layout
            // manually instead
            const int kFloatFieldWidth = 50;
            const int kSeparatorWidth  = 5;
            float     indentOffset     = EditorGUI.indentLevel * 15f;
            var       lineRect         = GUILayoutUtility.GetRect(1, EditorGUIUtility.singleLineHeight);

            lineRect.xMin += 4f;
            lineRect.y    += 2f;
            var labelRect       = new Rect(lineRect.x, lineRect.y, EditorGUIUtility.labelWidth - indentOffset, lineRect.height);
            var floatFieldLeft  = new Rect(labelRect.xMax, lineRect.y, kFloatFieldWidth + indentOffset, lineRect.height);
            var sliderRect      = new Rect(floatFieldLeft.xMax + kSeparatorWidth - indentOffset, lineRect.y, lineRect.width - labelRect.width - kFloatFieldWidth * 2 - kSeparatorWidth * 2, lineRect.height);
            var floatFieldRight = new Rect(sliderRect.xMax + kSeparatorWidth - indentOffset, lineRect.y, kFloatFieldWidth + indentOffset, lineRect.height);

            EditorGUI.PrefixLabel(labelRect, title);
            v.x = EditorGUI.FloatField(floatFieldLeft, v.x);
            EditorGUI.MinMaxSlider(sliderRect, ref v.x, ref v.y, o.min, o.max);
            v.y = EditorGUI.FloatField(floatFieldRight, v.y);

            value.vector2Value = v;
            return(true);
        }
        public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
        {
            var value = parameter.value;

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

            value.vector4Value = EditorGUILayout.Vector4Field(title, value.vector4Value);
            return(true);
        }
示例#3
0
        protected void DrawOverrideCheckbox(SerializedDataParameter property)
        {
            var overrideRect = GUILayoutUtility.GetRect(17f, 17f, GUILayout.ExpandWidth(false));

            overrideRect.yMin += 4f;

            var oldColor = GUI.color;

            GUI.color = new Color(0.6f, 0.6f, 0.6f, 0.75f);
            property.overrideState.boolValue = GUI.Toggle(overrideRect, property.overrideState.boolValue, CoreEditorUtils.GetContent("|Override this setting for this volume."), CoreEditorStyles.smallTickbox);
            GUI.color = oldColor;
        }
        public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
        {
            var value = parameter.value;

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

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

            value.colorValue = EditorGUILayout.ColorField(title, value.colorValue, o.showEyeDropper, o.showAlpha, o.hdr);
            return(true);
        }
示例#5
0
        public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
        {
            var value = parameter.value;

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

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

            EditorGUILayout.Slider(value, o.min, o.max, title);
            value.floatValue = Mathf.Clamp(value.floatValue, o.min, o.max);
            return(true);
        }
示例#6
0
        public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
        {
            var value = parameter.value;

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

            var   o = parameter.GetObjectRef <MinFloatParameter>();
            float v = EditorGUILayout.FloatField(title, value.floatValue);

            value.floatValue = Mathf.Max(v, o.min);
            return(true);
        }
        public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
        {
            var value = parameter.value;

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

            var o = parameter.GetObjectRef <NoInterpMaxIntParameter>();
            int v = EditorGUILayout.IntField(title, value.intValue);

            value.intValue = Mathf.Min(v, o.max);
            return(true);
        }
        public virtual void OnEnable()
        {
            m_Parameters = new List <SerializedDataParameter>();

            // Grab all valid serializable field on the VolumeComponent
            var fields = target.GetType()
                         .GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                         .Where(t => t.FieldType.IsSubclassOf(typeof(VolumeParameter)))
                         .Where(t =>
                                (t.IsPublic && t.GetCustomAttributes(typeof(NonSerializedAttribute), false).Length == 0) ||
                                (t.GetCustomAttributes(typeof(SerializeField), false).Length > 0)
                                )
                         .Where(t => t.GetCustomAttributes(typeof(HideInInspector), false).Length == 0)
                         .ToList();

            // Prepare all serialized objects for this editor
            foreach (var field in fields)
            {
                var property  = serializedObject.FindProperty(field.Name);
                var parameter = new SerializedDataParameter(property);
                m_Parameters.Add(parameter);
            }
        }
示例#9
0
 // Return false is the input parameter is invalid - unity will display the default editor
 // for this control then
 public abstract bool OnGUI(SerializedDataParameter parameter, GUIContent title);
        protected void PropertyField(SerializedDataParameter property, GUIContent title)
        {
            // Handle unity built-in decorators (Space, Header, Tooltip etc)
            foreach (var attr in property.attributes)
            {
                if (attr is PropertyAttribute)
                {
                    if (attr is SpaceAttribute)
                    {
                        EditorGUILayout.GetControlRect(false, (attr as SpaceAttribute).height);
                    }
                    else if (attr is HeaderAttribute)
                    {
                        var rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight);
                        rect.y += 0f;
                        rect    = EditorGUI.IndentedRect(rect);
                        EditorGUI.LabelField(rect, (attr as HeaderAttribute).header, EditorStyles.miniLabel);
                    }
                    else if (attr is TooltipAttribute)
                    {
                        if (string.IsNullOrEmpty(title.tooltip))
                        {
                            title.tooltip = (attr as TooltipAttribute).tooltip;
                        }
                    }
                }
            }

            // Custom parameter drawer
            VolumeParameterDrawer drawer;

            s_ParameterDrawers.TryGetValue(property.referenceType, out drawer);

            bool invalidProp = false;

            if (drawer != null && !drawer.IsAutoProperty())
            {
                if (drawer.OnGUI(property, title))
                {
                    return;
                }

                invalidProp = true;
            }

            // ObjectParameter<T> is a special case
            if (VolumeParameter.IsObjectParameter(property.referenceType))
            {
                bool expanded = property.value.isExpanded;
                expanded = EditorGUILayout.Foldout(expanded, title, true);

                if (expanded)
                {
                    EditorGUI.indentLevel++;

                    // Not the fastest way to do it but that'll do just fine for now
                    var  it    = property.value.Copy();
                    var  end   = it.GetEndProperty();
                    bool first = true;

                    while (it.Next(first) && !SerializedProperty.EqualContents(it, end))
                    {
                        PropertyField(Unpack(it));
                        first = false;
                    }

                    EditorGUI.indentLevel--;
                }

                property.value.isExpanded = expanded;
                return;
            }

            using (new EditorGUILayout.HorizontalScope())
            {
                // Override checkbox
                DrawOverrideCheckbox(property);

                // Property
                using (new EditorGUI.DisabledScope(!property.overrideState.boolValue))
                {
                    if (drawer != null && !invalidProp)
                    {
                        if (drawer.OnGUI(property, title))
                        {
                            return;
                        }
                    }

                    // Default unity field
                    EditorGUILayout.PropertyField(property.value, title);
                }
            }
        }
        protected void PropertyField(SerializedDataParameter property)
        {
            var title = CoreEditorUtils.GetContent(property.displayName);

            PropertyField(property, title);
        }