Ejemplo n.º 1
0
 private bool HasValidInstanceReference()
 {
     return(targetInstance.HasValidInstanceReference());
 }
Ejemplo n.º 2
0
        private static void OpenContextMenu()
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(openingMenu != null);
                        #endif

            if (OnMenuOpening != null)
            {
                OnMenuOpening(openingMenu, openingMenuInspector, openingMenuSubject.Target);
            }

            // new test
            if (!ApplicationUtility.HasFocus)
            {
                                #if DEV_MODE
                Debug.LogWarning("Aborting display of context menu because Unity application does not have focus any longer.");
                                #endif

                if (disposeMenuAfterOpening)
                {
                    openingMenu.Dispose();
                }

                openingMenu = null;

                if (onMenuClosed != null)
                {
                    var invoke = onMenuClosed;
                    onMenuClosed = null;
                    invoke(openingMenuPart);
                }
                return;
            }

            var genericMenu = new GenericMenu();

            if (openingMenuSubject.HasValidInstanceReference())
            {
                var linkedMember = openingMenuSubject.Target.MemberInfo;
                if (linkedMember != null)
                {
                    var serializedProperty = linkedMember.SerializedProperty;
                    if (serializedProperty != null)
                    {
                        var editorGUI = typeof(EditorGUI);
                        var addUnityInternalPropertyMenuItems = editorGUI.GetMethod("FillPropertyContextMenu", BindingFlags.Static | BindingFlags.NonPublic);
                        if (addUnityInternalPropertyMenuItems != null)
                        {
                            var parameters = ArrayPool <object> .Create(3);

                            parameters[0] = serializedProperty;
                            parameters[1] = null;
                            parameters[2] = genericMenu;
                            addUnityInternalPropertyMenuItems.Invoke(null, parameters);
                        }
                                                #if DEV_MODE
                        else
                        {
                            Debug.LogError("Could not find method EditorGUI.FillPropertyContextMenu!");
                        }
                                                #endif
                    }
                }
            }

            openingMenu.AddToGenericMenu(ref genericMenu, false);

            if (disposeMenuAfterOpening)
            {
                openingMenu.Dispose();
            }

            openingMenu = null;

            if (openingMenuPosition.HasValue)
            {
                var openMenuAtPosition = openingMenuPosition.Value;
                openingMenuPosition = null;

                var openAtScreenPoint = openMenuAtPosition.position;
                var openAtLocalPoint  = GUIUtility.ScreenToGUIPoint(openAtScreenPoint);
                openMenuAtPosition.position = openAtLocalPoint;

                                #if DEV_MODE && DEBUG_OPEN_MENU
                Debug.Log("Opening context menu @ " + openMenuAtPosition + " now.");
                                #endif

                genericMenu.DropDown(openMenuAtPosition);
            }
            else
            {
                                #if DEV_MODE && DEBUG_OPEN_MENU
                Debug.Log("Opening context menu at cursor position now.");
                                #endif

                genericMenu.ShowAsContext();
            }

            if (onMenuClosed != null)
            {
                var invoke = onMenuClosed;
                onMenuClosed = null;
                invoke(openingMenuPart);
            }
        }