您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

46 行
1.2 KiB

using UnityEngine;
using UnityEditor;
public static class GameViewTracker
{
[MenuItem(k_MenuName, true)]
public static bool ToggleGameViewTrackingValidate()
{
Menu.SetChecked(k_MenuName, s_Enabled);
return true;
}
[MenuItem(k_MenuName)]
public static void ToggleGameViewTracking()
{
SetEnabled(!s_Enabled);
}
static void SetEnabled(bool enabled)
{
if (enabled && !s_Enabled)
{
SceneView.onSceneGUIDelegate += sceneGUICallback;
s_Enabled = true;
}
else if (!enabled && s_Enabled)
{
SceneView.onSceneGUIDelegate -= sceneGUICallback;
s_Enabled = false;
}
}
static void sceneGUICallback(SceneView s)
{
if (Camera.main == null)
return;
// Non ortho cams are placed slightly in front of scenecam to avoid seeing gizmo
if(!s.camera.orthographic)
Camera.main.transform.SetPositionAndRotation(s.camera.transform.position - 0.1f * s.camera.transform.forward, s.camera.transform.rotation);
}
static bool s_Enabled;
const string k_MenuName = "fps.sample/Hotkeys/Toggle game view tracking _%#K";
}