mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
[+] EditorToolbar
[+] EditorToolbar
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 20dbf6614352aaf488de29690deeab68
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb0502859d7561142a3408d0ce2a19d8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,84 @@
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityToolbarExtender
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public class SceneSwitchLeftButton
|
||||
{
|
||||
private static readonly string SceneName1 = "main";
|
||||
private static readonly string SceneName2 = "main2";
|
||||
|
||||
static SceneSwitchLeftButton()
|
||||
{
|
||||
ToolbarExtender.LeftToolbarGUI.Add(OnToolbarGUI);
|
||||
}
|
||||
|
||||
static readonly string ButtonStyleName = "Tab middle";
|
||||
static GUIStyle _buttonGuiStyle;
|
||||
|
||||
static void OnToolbarGUI()
|
||||
{
|
||||
_buttonGuiStyle ??= new GUIStyle(ButtonStyleName)
|
||||
{
|
||||
padding = new RectOffset(2, 8, 2, 2),
|
||||
alignment = TextAnchor.MiddleCenter,
|
||||
fontStyle = FontStyle.Bold
|
||||
};
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
if (GUILayout.Button(
|
||||
new GUIContent("Launcher", EditorGUIUtility.FindTexture("PlayButton"), $"Start Scene Launcher"),
|
||||
_buttonGuiStyle))
|
||||
{
|
||||
SceneHelper.StartScene(SceneName1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class SceneHelper
|
||||
{
|
||||
static string _sceneToOpen;
|
||||
|
||||
public static void StartScene(string sceneName)
|
||||
{
|
||||
if (EditorApplication.isPlaying)
|
||||
{
|
||||
EditorApplication.isPlaying = false;
|
||||
}
|
||||
|
||||
_sceneToOpen = sceneName;
|
||||
EditorApplication.update += OnUpdate;
|
||||
}
|
||||
|
||||
static void OnUpdate()
|
||||
{
|
||||
if (_sceneToOpen == null ||
|
||||
EditorApplication.isPlaying || EditorApplication.isPaused ||
|
||||
EditorApplication.isCompiling || EditorApplication.isPlayingOrWillChangePlaymode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EditorApplication.update -= OnUpdate;
|
||||
|
||||
if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
|
||||
{
|
||||
string[] guids = AssetDatabase.FindAssets("t:scene " + _sceneToOpen, null);
|
||||
if (guids.Length == 0)
|
||||
{
|
||||
Debug.LogWarning("Couldn't find scene file");
|
||||
}
|
||||
else
|
||||
{
|
||||
string scenePath = AssetDatabase.GUIDToAssetPath(guids[0]);
|
||||
EditorSceneManager.OpenScene(scenePath);
|
||||
EditorApplication.isPlaying = true;
|
||||
}
|
||||
}
|
||||
|
||||
_sceneToOpen = null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 45017e4df12424c4fb16db4708d239f0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: acd9403857c068f4792b1a536a7b89f6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 252cc3ce82f9548b99943bfdadc9d4c0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,58 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityToolbarExtender.Examples
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public static class SceneViewFocuser
|
||||
{
|
||||
static bool m_enabled;
|
||||
|
||||
static bool Enabled
|
||||
{
|
||||
get { return m_enabled; }
|
||||
set
|
||||
{
|
||||
m_enabled = value;
|
||||
EditorPrefs.SetBool("SceneViewFocuser", value);
|
||||
}
|
||||
}
|
||||
|
||||
static SceneViewFocuser()
|
||||
{
|
||||
m_enabled = EditorPrefs.GetBool("SceneViewFocuser", false);
|
||||
EditorApplication.playModeStateChanged += OnPlayModeChanged;
|
||||
EditorApplication.pauseStateChanged += OnPauseChanged;
|
||||
|
||||
ToolbarExtender.RightToolbarGUI.Add(OnToolbarGUI);
|
||||
}
|
||||
|
||||
static void OnPauseChanged(PauseState obj)
|
||||
{
|
||||
if (Enabled && obj == PauseState.Unpaused)
|
||||
{
|
||||
// Not sure why, but this must be delayed
|
||||
EditorApplication.delayCall += EditorWindow.FocusWindowIfItsOpen<SceneView>;
|
||||
}
|
||||
}
|
||||
|
||||
static void OnPlayModeChanged(PlayModeStateChange obj)
|
||||
{
|
||||
if (Enabled && obj == PlayModeStateChange.EnteredPlayMode)
|
||||
{
|
||||
EditorWindow.FocusWindowIfItsOpen<SceneView>();
|
||||
}
|
||||
}
|
||||
|
||||
static void OnToolbarGUI()
|
||||
{
|
||||
var tex = EditorGUIUtility.IconContent(@"UnityEditor.SceneView").image;
|
||||
GUI.changed = false;
|
||||
GUILayout.Toggle(m_enabled, new GUIContent(null, tex, "Focus SceneView when entering play mode"), "Command");
|
||||
if (GUI.changed)
|
||||
{
|
||||
Enabled = !Enabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8ddf5f9fafe5734dbae1d30d51bb2a6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user