Пример #1
0
	void OnPress(bool isPressed)
	{
		// Filter for touches or selected mouse button.
		
		if (UICamera.currentTouchID >= 0 || UICamera.currentTouchID == (-1 - mouseButton))
		{
			// We show the menu on the up-press not the down-press. Otherwise NGUI would steal
			// the selection state from the context menu on the up-press, causing the menu to
			// close immediately.
			
			if (! isPressed)
			{
				current = this;
				EventDelegate.Execute(onShow);
	
				Vector3 menuPosition = CtxHelper.ComputeMenuPosition(contextMenu, gameObject);
				
				CtxMenu.Item[] items = MenuItems;
				
				if (items != null || contextMenu.onShow.Count > 0)
				{
					EventDelegate.Add(contextMenu.onSelection, OnMenuSelection);
					EventDelegate.Add(contextMenu.onHide, OnHide, true);
				
					if (menuItems != null && menuItems.Length > 0)
						contextMenu.Show(menuPosition, menuItems);
					else
						contextMenu.Show(menuPosition);
				}
			}
		}
	}
Пример #2
0
 void OnMenuSelection()
 {
     // Dispatch selection events.
     current      = this;
     selectedItem = CtxMenu.current.selectedItem;
     EventDelegate.Execute(onSelection);
 }
Пример #3
0
    public override void OnInspectorGUI()
    {
        popup = target as CtxPopup;

        EditorGUIUtility.labelWidth = 120f;

        CtxMenu contextMenu = (CtxMenu)EditorGUILayout.ObjectField("Context Menu", popup.contextMenu,
                                                                   typeof(CtxMenu), true);

        if (popup.contextMenu != contextMenu)
        {
            RegisterUndo();
            popup.contextMenu = contextMenu;
        }

        int mouseButton = EditorGUILayout.IntField("Mouse Button", popup.mouseButton);

        if (popup.mouseButton != mouseButton)
        {
            RegisterUndo();
            popup.mouseButton = mouseButton;
        }

        popup.placeAtTouchPosition = EditorGUILayout.Toggle("Place at Touch Pos", popup.placeAtTouchPosition);

        NGUIEditorTools.DrawEvents("On Selection", popup, popup.onSelection);
        NGUIEditorTools.DrawEvents("On Show", popup, popup.onShow);
        NGUIEditorTools.DrawEvents("On Hide", popup, popup.onHide);

        if (popup.contextMenu != null)
        {
            EditMenuItemList(ref popup.menuItems, popup.contextMenu.atlas, true, ref popup.isEditingItems);
        }
        else
        {
            EditorGUILayout.HelpBox("You need to reference a context menu for this component to work properly.", MessageType.Warning);
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
Пример #4
0
	public override void OnInspectorGUI()
	{
		popup = target as CtxPopup;
		
		EditorGUIUtility.labelWidth = 120f;
		
		CtxMenu contextMenu = (CtxMenu)EditorGUILayout.ObjectField("Context Menu", popup.contextMenu, 
			typeof(CtxMenu), true);
		
		if (popup.contextMenu != contextMenu)
		{
			RegisterUndo();
			popup.contextMenu = contextMenu;
		}
		
		int mouseButton = EditorGUILayout.IntField("Mouse Button", popup.mouseButton);
		if (popup.mouseButton != mouseButton)
		{
			RegisterUndo();
			popup.mouseButton = mouseButton;
		}

		NGUIEditorTools.DrawEvents("On Selection", popup, popup.onSelection);
		NGUIEditorTools.DrawEvents("On Show", popup, popup.onShow);
		NGUIEditorTools.DrawEvents("On Hide", popup, popup.onHide);
		
		if (popup.contextMenu != null)
		{
			EditMenuItemList(ref popup.menuItems, popup.contextMenu.atlas, true, ref popup.isEditingItems);
		}
		else
		{
			EditorGUILayout.HelpBox("You need to reference a context menu for this component to work properly.",MessageType.Warning);
		}
		
		if (GUI.changed)
			EditorUtility.SetDirty(target);
	}
Пример #5
0
    void OnPress(bool isPressed)
    {
        // Filter for touches or selected mouse button.

        if (UICamera.currentTouchID >= 0 || UICamera.currentTouchID == (-1 - mouseButton))
        {
            // We show the menu on the up-press not the down-press. Otherwise NGUI would steal
            // the selection state from the context menu on the up-press, causing the menu to
            // close immediately.

            if (!isPressed)
            {
                current = this;
                EventDelegate.Execute(onShow);

                Vector3 menuPosition = placeAtTouchPosition ? new Vector3(UICamera.currentTouch.pos.x, UICamera.currentTouch.pos.y, 0f) :
                                       CtxHelper.ComputeMenuPosition(contextMenu, gameObject);

                CtxMenu.Item[] items = MenuItems;

                if (items != null || contextMenu.onShow.Count > 0)
                {
                    EventDelegate.Add(contextMenu.onSelection, OnMenuSelection);
                    EventDelegate.Add(contextMenu.onHide, OnHide, true);

                    if (menuItems != null && menuItems.Length > 0)
                    {
                        contextMenu.Show(menuPosition, menuItems);
                    }
                    else
                    {
                        contextMenu.Show(menuPosition);
                    }
                }
            }
        }
    }
Пример #6
0
 void OnHide()
 {
     current = this;
     EventDelegate.Execute(onHide);
     EventDelegate.Remove(contextMenu.onSelection, OnMenuSelection);         // <-- In case the menu was hidden with no selection made
 }
Пример #7
0
 void OnMenuSelection() {
     // Dispatch selection events.
     current = this;
     selectedItem = CtxMenu.current.selectedItem;
     EventDelegate.Execute(onSelection);
 }
Пример #8
0
 void OnHide() {
     current = this;
     EventDelegate.Execute(onHide);
     EventDelegate.Remove(contextMenu.onSelection, OnMenuSelection); // <-- In case the menu was hidden with no selection made
 }