Created
September 10, 2024 09:47
-
-
Save json-m/96ab917fc8d88b5e938dd59eabf91dbf to your computer and use it in GitHub Desktop.
adds button to scene view in unity to return to gamemode and select whatever gameobject you want every time
This file contains 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
using UnityEngine; | |
using UnityEditor; | |
public static class SceneViewButton | |
{ | |
[InitializeOnLoadMethod] | |
static void RegisterCallback() | |
{ | |
SceneView.duringSceneGui += OnSceneGUI; | |
} | |
static void OnSceneGUI(SceneView sceneView) | |
{ | |
Handles.BeginGUI(); | |
Rect sceneViewRect = sceneView.position; | |
float buttonWidth = 150; | |
float buttonHeight = 40; | |
float padding = 40; | |
Rect buttonRect = new Rect( | |
padding, | |
sceneViewRect.height - buttonHeight - padding, | |
buttonWidth, | |
buttonHeight | |
); | |
if (GUI.Button(buttonRect, "Set Game View")) | |
{ | |
SelectGameObjectAndSetView(); | |
} | |
Handles.EndGUI(); | |
} | |
static void SelectGameObjectAndSetView() | |
{ | |
GameObject targetObject = GameObject.Find("GestureManager"); | |
if (targetObject != null) | |
{ | |
Selection.activeGameObject = targetObject; | |
} | |
System.Type gameViewType = System.Type.GetType("UnityEditor.GameView,UnityEditor"); | |
if (gameViewType != null) | |
{ | |
EditorWindow.GetWindow(gameViewType).Focus(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment