Search Unity

GraphView: Cannot get ManipulatorActivationFilter to work

Discussion in 'UI Toolkit' started by daschatten, Apr 3, 2019.

  1. daschatten

    daschatten

    Joined:
    Jul 16, 2015
    Posts:
    208
    Hi,

    i try to remap showing a context menu from RMB to LMB, seems to be easy but doesn't work :) Do i miss anything in this code snippet?

    Code (CSharp):
    1. node.blendModeButton = new Button();
    2. node.blendModeButton.AddManipulator(new ContextualMenuManipulator(node.ContextMenuDelegate));
    3. node.blendModeButton.clickable.activators.Clear();
    4. node.blendModeButton.clickable.activators.Add(new ManipulatorActivationFilter { button = MouseButton.LeftMouse });
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    By not working, do you mean that it still activates using RMB, or that it doesn't activate at all anymore?
     
  3. daschatten

    daschatten

    Joined:
    Jul 16, 2015
    Posts:
    208
    It still activates using RMB. And does not activate using LMB.
     
  4. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    Ah, I see now. You are changing the activators on the wrong manipulator. blendModeButton.clickable is not the manipulator you just added with AddManipulator(). clickable is the button's built-in Click manipulator. This is more what you need to do:


    Code (CSharp):
    1. node.blendModeButton = new Button();
    2.  
    3. var manip = new ContextualMenuManipulator(node.ContextMenuDelegate);
    4. manip.activators.Clear();
    5. manip.activators.Add(new ManipulatorActivationFilter { button = MouseButton.LeftMouse });
    6.  
    7. node.blendModeButton.AddManipulator(manip);
     
    daschatten likes this.
  5. daschatten

    daschatten

    Joined:
    Jul 16, 2015
    Posts:
    208
    Worked, thanks! I really like this new GraphView :)