Created
March 29, 2018 00:30
-
-
Save kevinw/14dec05e9ac9ab99a5596423d94f7468 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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