Skip to content

Instantly share code, notes, and snippets.

@kevinw
Created March 29, 2018 00:30
Show Gist options
  • Save kevinw/14dec05e9ac9ab99a5596423d94f7468 to your computer and use it in GitHub Desktop.
Save kevinw/14dec05e9ac9ab99a5596423d94f7468 to your computer and use it in GitHub Desktop.
static void DoScenePicking(SceneView sceneView)
{
var e = Event.current;
if (e.alt || e.control || e.command)
return;
var controlID = GUIUtility.GetControlID(FocusType.Passive);
switch (e.GetTypeForControl(controlID))
{
case EventType.Layout:
{
var selectedGameObject = PickSceneViewObject(sceneView.camera, e.mousePosition);
if (selectedGameObject)
HandleUtility.AddDefaultControl(controlID);
break;
}
case EventType.MouseDown:
{
if (e.button == 0 && HandleUtility.nearestControl == controlID && GUIUtility.hotControl == 0)
GUIUtility.hotControl = controlID;
break;
}
case EventType.MouseUp:
{
if (e.button == 0 && GUIUtility.hotControl == controlID)
{
GUIUtility.hotControl = 0;
Event.current.Use();
var selectedGameObject = PickSceneViewObject(sceneView.camera, e.mousePosition);
Selection.activeGameObject = selectedGameObject;
}
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment