Пример #1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            int index;

            if (_array == null)
            {
                _array = GetParentArray(property, out index);
            }
            else
            {
                index = GetArrayIndex(property);
            }
            _elementIndexes[property] = index;

            if (_attr == null)
            {
                _attr = attribute as SRAttribute;
            }

            var typeName        = GetTypeName(property.managedReferenceFullTypename);
            var typeNameContent = new GUIContent(typeName + (_array != null ? ("[" + index + "]") : ""));

            float buttonWidth  = 10f + GUI.skin.button.CalcSize(typeNameContent).x;
            float buttonHeight = EditorGUI.GetPropertyHeight(property, label, false);

            EditorGUI.BeginChangeCheck();

            var bgColor = GUI.backgroundColor;

            GUI.backgroundColor = Color.green;
            var buttonRect = new Rect(position.x + position.width - buttonWidth, position.y, buttonWidth, buttonHeight);

            if (EditorGUI.DropdownButton(buttonRect, typeNameContent, FocusType.Passive))
            {
                ShowMenu(property, true);
                Event.current.Use();
            }
            GUI.backgroundColor = bgColor;

            var propertyRect = position;

            EditorGUI.PropertyField(propertyRect, property, label, true);

            if (EditorGUI.EndChangeCheck() && _attr != null)
            {
                //TODO _attr.OnChange(_element.managedReferenceValue);
            }
        }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        if (!property.isArray)
        {
            if (_element == null)
            {
                _element = property;
                _array   = GetParentArray(property, out _elementIndex);
            }

            if (_attr == null)
            {
                _attr = attribute as SRAttribute;
            }

            Event e             = Event.current;
            var   labelPosition = position;
            labelPosition.height = 20f;
            if (e.type == EventType.ContextClick && e.button == 1 && labelPosition.Contains(e.mousePosition) && !e.control)
            {
                GenericMenu context = new GenericMenu();

                if (_array != null)
                {
                    context.AddItem(new GUIContent("Delete"), false, OnMenuItemClick, "Delete");
                    context.AddItem(new GUIContent("Insert"), false, OnMenuItemClick, "Insert");
                    //context.AddItem(new GUIContent("Add"), false, OnMenuItemClick, "Add");
                    context.AddSeparator("");
                }
                if (_attr != null && _attr.Types != null)
                {
                    context.AddItem(new GUIContent("Erase"), false, OnMenuItemClick, "Erase");
                    context.AddSeparator("");
                    for (int i = 0; i < _attr.Types.Length; ++i)
                    {
                        context.AddItem(new GUIContent(_attr.Types[i].Path), false, OnMenuItemClick, _attr.Types[i].Path);
                    }
                }

                context.ShowAsContext();

                e.Use();
            }
        }

        EditorGUI.PropertyField(position, property, label, true);
    }