예제 #1
0
        protected override void DrawPropertyLayout(GUIContent label)
        {
            var entry = Property.ValueEntry;
            // We need to find the standard SerializedProperty so that we can access
            // the isExpanded property, which we'll use to drive our foldout behaviour
            var serializedObject   = entry.Property.Tree.UnitySerializedObject;
            var serializedProperty = serializedObject.FindProperty(entry.Property.UnityPropertyPath);
            var lineHeight         = EditorGUIUtility.singleLineHeight;

            var rect = EditorGUILayout.BeginHorizontal(GUILayout.MinHeight(serializedProperty.isExpanded ? drawer.GetPropertyHeight(serializedProperty, label) : lineHeight)).Padding(lineHeight - 3, 0f, 0f, 0f);

            serializedProperty.isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(serializedProperty.isExpanded, new GUIContent(), "Foldout");
            if (serializedProperty.isExpanded)
            {
                drawer.OnGUI(rect, serializedProperty, label);
            }

            EditorGUILayout.EndFoldoutHeaderGroup();
            EditorGUILayout.EndHorizontal();

            // TODO: there something weird about this label positioning

            var lineRect = rect.SetHeight(lineHeight);

            if (Event.current.type == EventType.Repaint)
            {
                ((GUIStyle)"RL Header").Draw(lineRect, false, false, false, false);
            }
            GUI.Label(lineRect.Padding(5f, 0f, 0f, 0f), label.text);

            GUILayout.Space(5f);
        }
예제 #2
0
    public override void OnGUI(Rect position,
                               SerializedProperty property,
                               GUIContent label)
    {
        UnityEventDrawer eventDrawer = new UnityEventDrawer();

        if (GetPersistentCallCount(property) == 0)
        {
            Rect r = new Rect(position.x, position.y, position.width, 18);
            GUI.BeginGroup(r);
            eventDrawer.OnGUI(new Rect(0, 0, r.width, r.height), property, label);
            GUI.EndGroup();
            r = new Rect(position.x, position.y + 18, position.width, 15);
            GUI.BeginGroup(new Rect(r.x, r.y, r.width, r.height + 3));
            eventDrawer.OnGUI(new Rect(0, -67, r.width, r.height), property, label);
            GUI.EndGroup();
        }
        else
        {
            eventDrawer.OnGUI(position, property, new GUIContent(label));
        }
    }
예제 #3
0
        public static void PropertyField(SerializedProperty prop, string tooltip = null)
        {
            // TODO test this. thanks to unity this has to be very dirty and must be tested!

            var label = new GUIContent(_(prop.displayName), string.IsNullOrWhiteSpace(tooltip) ? null : _(tooltip));

            var headerAttribute = GetAttribute <HeaderAttribute>(prop);

            if (headerAttribute != null)
            {
                GUILayout.Label(_(headerAttribute.header), EditorStyles.boldLabel);
            }

            switch (prop.propertyType)
            {
            case SerializedPropertyType.Boolean:
                prop.boolValue = EditorGUILayout.Toggle(label, prop.boolValue);
                break;

            case SerializedPropertyType.Vector2:
                prop.vector2Value = EditorGUILayout.Vector2Field(label, prop.vector2Value);
                break;

            case SerializedPropertyType.Float:
                prop.floatValue = EditorGUILayout.FloatField(label, prop.floatValue);
                break;

            case SerializedPropertyType.Integer:
                prop.intValue = EditorGUILayout.IntField(label, prop.intValue);
                break;

            case SerializedPropertyType.Color:
                prop.colorValue = EditorGUILayout.ColorField(label, prop.colorValue);
                break;

            case SerializedPropertyType.String when GetAttribute <TextAreaAttribute>(prop) != null:
                EditorGUILayout.PrefixLabel(label);

                prop.stringValue = EditorGUILayout.TextArea(prop.stringValue);
                break;

            case SerializedPropertyType.String:
                prop.stringValue = EditorGUILayout.TextField(label, prop.stringValue);
                break;

            case SerializedPropertyType.Enum:
                var displayedOptions = Enum.GetNames(GetFieldType(prop)).Select(_).ToArray();
                prop.enumValueIndex = EditorGUILayout.Popup(label, prop.enumValueIndex, displayedOptions);
                break;

            case SerializedPropertyType.ObjectReference:
                prop.objectReferenceValue =
                    EditorGUILayout.ObjectField(label, prop.objectReferenceValue, GetFieldType(prop), true);
                break;

            case SerializedPropertyType.Generic when GetFieldType(prop) == typeof(UnityEvent):
                var rect = EditorGUILayout.BeginHorizontal();

                Drawer.OnGUI(rect, prop, label);
                EditorGUILayout.EndHorizontal();
                break;

            default:
                Debug.LogWarning("Unknown property type: " + prop.propertyType);
                break;
            }
        }