Exemple #1
0
        public override void OpenContextual(ToolControl control)
        {
            activatorControl = control;
            var menu = new GenericMenu();

            menu.allowDuplicateNames = true;
            GameObjectContextMenu.Fill(targets, menu, activatorControl.activatorScreenPosition, null);
            menu.DropDown(activatorControl.activatorGuiPosition);
        }
        protected override void ContextClickedItem(int id)
        {
            var item = FindItem(id, rootItem);

            if (item is GameObjectItem gameObjectItem)
            {
                var selection = selectedGameObjects;

                GenericMenu.MenuFunction rename = null;

                if (selection.Length == 1)
                {
                    rename = () => BeginRename(gameObjectItem);
                }

                var activatorPosition = LudiqGUIUtility.GUIToScreenRect(GetItemRect(id));

                var menu = new GenericMenu();
                menu.allowDuplicateNames = true;
                GameObjectContextMenu.Fill(selection, menu, activatorPosition, rename);
                menu.ShowAsContext();
            }
        }
Exemple #3
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (PeekPlugin.Configuration.enableReferenceInspector && !property.hasMultipleDifferentValues && property.objectReferenceValue != null)
            {
                Rect buttonPosition, fieldPosition;

                if (label != GUIContent.none)
                {
                    buttonPosition = new Rect
                                     (
                        position.x + EditorGUIUtility.labelWidth - IconSize.Small - 1,
                        position.y,
                        IconSize.Small,
                        IconSize.Small
                                     );

                    fieldPosition = position;
                }
                else
                {
                    buttonPosition = new Rect
                                     (
                        position.xMax - IconSize.Small,
                        position.y + 1,
                        IconSize.Small,
                        IconSize.Small
                                     );

                    fieldPosition = new Rect
                                    (
                        position.x,
                        position.y,
                        position.width - buttonPosition.width - 2,
                        position.height
                                    );
                }

                DefaultField(property, label, fieldPosition);

                var isActive = PopupWatcher.IsOpenOrJustClosed(lastPopup);

                var activatedButton = LudiqGUI.DropdownToggle(buttonPosition, isActive, LudiqGUIUtility.TempContent(PeekPlugin.Icons.propertyDrawer?[IconSize.Small]), GUIStyle.none);

                if (activatedButton && !isActive)
                {
                    PopupWatcher.Release(lastPopup);
                    lastPopup = null;

                    var targets = new[] { property.objectReferenceValue };
                    var activatorGuiPosition    = buttonPosition;
                    var activatorScreenPosition = LudiqGUIUtility.GUIToScreenRect(activatorGuiPosition);

                    if (e.IsContextMouseButton())
                    {
                        if (property.objectReferenceValue is GameObject go)
                        {
                            GameObjectContextMenu.Open(new[] { go }, activatorScreenPosition);
                        }
                        else
                        {
                            UnityObjectContextMenu.Open(targets, activatorGuiPosition);
                        }
                    }
                    else
                    {
                        lastPopup = EditorPopup.Open(targets, activatorScreenPosition);
                        PopupWatcher.Watch(lastPopup);
                    }
                }
            }
            else
            {
                DefaultField(property, label, position);
            }
        }