Exemple #1
0
        protected virtual void EmitPropertyField(Rect position, RuntimeSerializedProperty runtimeSerializedProperty, GUIContent label)
        {
            var multiline = GetMultilineAttribute();

            if (multiline == null)
            {
                var range = GetRangeAttribute();
                if (range == null)
                {
                    RuntimeEasyGUI.PropertyField(position, runtimeSerializedProperty, label, true, null);
                }
                else
                {
                    if (runtimeSerializedProperty.PropertyType == RuntimeSerializedPropertyType.Float)
                    {
                        RuntimeEasyGUI.Slider(position, runtimeSerializedProperty, range.Min, range.Max, label);
                    }
                    else if (runtimeSerializedProperty.PropertyType == RuntimeSerializedPropertyType.Integer)
                    {
                        RuntimeEasyGUI.IntSlider(position, runtimeSerializedProperty, (int)range.Min, (int)range.Max, label);
                    }
                    else
                    {
                        EditorGUI.LabelField(position, label.text, "Use Range with float or int.");
                    }
                }
            }
            else
            {
                var property = runtimeSerializedProperty;

                label = RuntimeEasyGUI.BeginProperty(position, label, property);
                var method = typeof(EditorGUI).GetMethod("MultiFieldPrefixLabel", BindingFlags.Static | BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.NonPublic);
                position = (Rect)method.Invoke(null, new object[] { position, 0, label, 1 });

                EditorGUI.BeginChangeCheck();
                int indentLevel = EditorGUI.indentLevel;
                EditorGUI.indentLevel = 0;
                var stringValue = EditorGUI.TextArea(position, property.StringValue);
                EditorGUI.indentLevel = indentLevel;
                if (EditorGUI.EndChangeCheck())
                {
                    property.StringValue = stringValue;
                }
                RuntimeEasyGUI.EndProperty();
            }
        }
        public override void OnGUI(Rect position, RuntimeSerializedProperty property, GUIContent label)
        {
            RangeAttribute rangeAttribute = Attribute as RangeAttribute;

            if (property.PropertyType == RuntimeSerializedPropertyType.Float)
            {
                RuntimeEasyGUI.Slider(position, property, rangeAttribute.min, rangeAttribute.max, label);
            }
            else if (property.PropertyType == RuntimeSerializedPropertyType.Integer)
            {
                RuntimeEasyGUI.IntSlider(position, property, (int)rangeAttribute.min, (int)rangeAttribute.max, label);
            }
            else
            {
                EditorGUI.LabelField(position, label.text, "Use Range with float or int.");
            }
        }