Skip to content

Instantly share code, notes, and snippets.

@json-m
Created September 10, 2024 09:47
Show Gist options
  • Save json-m/96ab917fc8d88b5e938dd59eabf91dbf to your computer and use it in GitHub Desktop.
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
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