Search Unity

Question Disable select/unselect with mouse and shif/crtl in GUI

Discussion in 'Code Editors & IDEs' started by jkmgroup1979, Feb 15, 2024.

  1. jkmgroup1979

    jkmgroup1979

    Joined:
    Oct 6, 2018
    Posts:
    2
    I make my editor on game object. I'd like to have possibility to select few points, lines etc. at same time, by holding shif/crtl. But when I hold shift and press mouse button my game object are deselected. How can I block shift press event at this situation.
    Code (CSharp):
    1.         void MouseCheck()
    2.         {
    3.             var currentEvent = Event.current;
    4.  
    5.             if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0)
    6.             {
    7.                 var ray = HandleUtility.GUIPointToWorldRay(currentEvent.mousePosition);
    8.                 var shift = currentEvent.shift;
    9.                 var foundObject = owenr.FindClosestPoint(ray.origin, shift, currentEvent.control);
    10.                 if (!foundObject)
    11.                     foundObject = owenr.FindClosestLine(ray.origin, shift, currentEvent.control);
    12.                 if (foundObject)
    13.                 {
    14.                     if (shift)
    15.                         DisableShift();
    16.                 }
    17.             }
    18.         }
    19.         void DisableShift()
    20.         {
    21.             ??????????????????????
    22.         }
    23.  
     
  2. jkmgroup1979

    jkmgroup1979

    Joined:
    Oct 6, 2018
    Posts:
    2
    I found solution. Not best for me but can be useful for others.
    Code (CSharp):
    1.         int controlIDSafeOffset = 100; // its hack, maybe is better way to get first id
    2.         void EventManagement()
    3.         {
    4.             switch (Event.current.type)
    5.             {
    6.                 case EventType.Repaint:
    7.                     DrawPoints(EventType.Repaint);
    8.                     break;
    9.                 case EventType.Layout:
    10.                     DrawPoints(EventType.Layout); break;
    11.                 case EventType.MouseDown:
    12.                     {
    13.                         if (Event.current.button == 0)
    14.                         {
    15.                             var id = HandleUtility.nearestControl - controlIDSafeOffset;
    16.                             AddPointToSelectedList(id, Event.current.shift);
    17.                         }
    18.                     }; break;
    19.             };
    20.  
    21.         }
    22.  
    23.         private void DrawPoints(EventType layout)
    24.         {
    25.             for (var i = 0; i < points.Length; i++)
    26.                 Handles.DotHandleCap(i + controlIDSafeOffset, points[i], Quaternion.identity, 0.5f, layout);
    27.         }
    28.  
    29.