mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-11-11 08:38:45 +00:00
临时提交
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9855eda2b13a0084ab0def6f7ca74141
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,91 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityToolbarExtender;
|
||||
|
||||
namespace SHFrame
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public class EditorResourceMode
|
||||
{
|
||||
static class ToolbarStyles
|
||||
{
|
||||
public static readonly GUIStyle ToolBarExtenderBtnStyle;
|
||||
|
||||
public static readonly GUIStyle ToolBarTextStyle;
|
||||
|
||||
public static readonly GUIStyle ToolBarButtonGuiStyle;
|
||||
|
||||
static ToolbarStyles()
|
||||
{
|
||||
ToolBarExtenderBtnStyle = new GUIStyle("Command")
|
||||
{
|
||||
fontSize = 12,
|
||||
alignment = TextAnchor.MiddleCenter,
|
||||
imagePosition = ImagePosition.ImageAbove,
|
||||
fontStyle = FontStyle.Normal,
|
||||
fixedWidth = 60
|
||||
};
|
||||
|
||||
ToolBarTextStyle = new GUIStyle(ButtonStyleName)
|
||||
{
|
||||
padding = new RectOffset(2, 8, 2, 2),
|
||||
alignment = TextAnchor.MiddleCenter,
|
||||
fontStyle = FontStyle.Bold
|
||||
};
|
||||
|
||||
ToolBarButtonGuiStyle = new GUIStyle(ButtonStyleName)
|
||||
{
|
||||
padding = new RectOffset(2, 8, 2, 2),
|
||||
alignment = TextAnchor.MiddleCenter,
|
||||
fontStyle = FontStyle.Bold
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
static EditorResourceMode()
|
||||
{
|
||||
ToolbarExtender.RightToolbarGUI.Add(OnToolbarGUI);
|
||||
_resourceModeIndex = EditorPrefs.GetInt("EditorResourceMode", 0);
|
||||
}
|
||||
|
||||
private const string ButtonStyleName = "Tab middle";
|
||||
static GUIStyle _buttonGuiStyle;
|
||||
|
||||
private static readonly string[] _resourceModeNames =
|
||||
{ "EditorMode (编辑器下的模拟模式)",
|
||||
"OfflinePlayMode (单机模式)",
|
||||
"HostPlayMode (联机运行模式)",
|
||||
"WebPlayMode (WebGL运行模式)"
|
||||
};
|
||||
|
||||
private static int _resourceModeIndex = 0;
|
||||
public static int ResourceModeIndex => _resourceModeIndex;
|
||||
|
||||
static void OnToolbarGUI()
|
||||
{
|
||||
EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
|
||||
{
|
||||
// GUILayout.Label("资源加载模式:",ToolbarStyles.ToolBarTextStyle);
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
// 资源模式
|
||||
int selectedIndex = EditorGUILayout.Popup("", _resourceModeIndex, _resourceModeNames, ToolbarStyles.ToolBarButtonGuiStyle);
|
||||
// ReSharper disable once RedundantCheckBeforeAssignment
|
||||
if (selectedIndex != _resourceModeIndex)
|
||||
{
|
||||
Debug.Log($"更改编辑器资源运行模式 : {_resourceModeNames[selectedIndex]}");
|
||||
_resourceModeIndex = selectedIndex;
|
||||
EditorPrefs.SetInt("EditorResourceMode", selectedIndex);
|
||||
}
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
GUILayout.Space(400);
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce74293562bfebc45856ef1b22eb41b8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,91 @@
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityToolbarExtender;
|
||||
|
||||
namespace SHFrame
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public class SceneSwitchLeftButton
|
||||
{
|
||||
private static readonly string SceneMain = "Boot";
|
||||
|
||||
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))
|
||||
{
|
||||
if (EditorApplication.isPlaying)
|
||||
{
|
||||
EditorApplication.isPlaying = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
SceneHelper.StartScene(SceneMain);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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: f015ac6f30edc48409abd5eaeb7de23b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
#if UNITY_2019_1_OR_NEWER
|
||||
using UnityEngine.UIElements;
|
||||
#else
|
||||
using UnityEngine.Experimental.UIElements;
|
||||
#endif
|
||||
|
||||
namespace UnityToolbarExtender
|
||||
{
|
||||
public static class ToolbarCallback
|
||||
{
|
||||
static Type m_toolbarType = typeof(Editor).Assembly.GetType("UnityEditor.Toolbar");
|
||||
static Type m_guiViewType = typeof(Editor).Assembly.GetType("UnityEditor.GUIView");
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
static Type m_iWindowBackendType = typeof(Editor).Assembly.GetType("UnityEditor.IWindowBackend");
|
||||
static PropertyInfo m_windowBackend = m_guiViewType.GetProperty("windowBackend",
|
||||
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
static PropertyInfo m_viewVisualTree = m_iWindowBackendType.GetProperty("visualTree",
|
||||
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
#else
|
||||
static PropertyInfo m_viewVisualTree = m_guiViewType.GetProperty("visualTree",
|
||||
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
#endif
|
||||
static FieldInfo m_imguiContainerOnGui = typeof(IMGUIContainer).GetField("m_OnGUIHandler",
|
||||
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
static ScriptableObject m_currentToolbar;
|
||||
|
||||
/// <summary>
|
||||
/// Callback for toolbar OnGUI method.
|
||||
/// </summary>
|
||||
public static Action OnToolbarGUI;
|
||||
public static Action OnToolbarGUILeft;
|
||||
public static Action OnToolbarGUIRight;
|
||||
|
||||
static ToolbarCallback()
|
||||
{
|
||||
EditorApplication.update -= OnUpdate;
|
||||
EditorApplication.update += OnUpdate;
|
||||
}
|
||||
|
||||
static void OnUpdate()
|
||||
{
|
||||
// Relying on the fact that toolbar is ScriptableObject and gets deleted when layout changes
|
||||
if (m_currentToolbar == null)
|
||||
{
|
||||
// Find toolbar
|
||||
var toolbars = Resources.FindObjectsOfTypeAll(m_toolbarType);
|
||||
m_currentToolbar = toolbars.Length > 0 ? (ScriptableObject) toolbars[0] : null;
|
||||
if (m_currentToolbar != null)
|
||||
{
|
||||
#if UNITY_2021_1_OR_NEWER
|
||||
var root = m_currentToolbar.GetType().GetField("m_Root", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
var rawRoot = root.GetValue(m_currentToolbar);
|
||||
var mRoot = rawRoot as VisualElement;
|
||||
RegisterCallback("ToolbarZoneLeftAlign", OnToolbarGUILeft);
|
||||
RegisterCallback("ToolbarZoneRightAlign", OnToolbarGUIRight);
|
||||
|
||||
void RegisterCallback(string root, Action cb) {
|
||||
var toolbarZone = mRoot.Q(root);
|
||||
|
||||
var parent = new VisualElement()
|
||||
{
|
||||
style = {
|
||||
flexGrow = 1,
|
||||
flexDirection = FlexDirection.Row,
|
||||
}
|
||||
};
|
||||
var container = new IMGUIContainer();
|
||||
container.style.flexGrow = 1;
|
||||
container.onGUIHandler += () => {
|
||||
cb?.Invoke();
|
||||
};
|
||||
parent.Add(container);
|
||||
toolbarZone.Add(parent);
|
||||
}
|
||||
#else
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
var windowBackend = m_windowBackend.GetValue(m_currentToolbar);
|
||||
|
||||
// Get it's visual tree
|
||||
var visualTree = (VisualElement) m_viewVisualTree.GetValue(windowBackend, null);
|
||||
#else
|
||||
// Get it's visual tree
|
||||
var visualTree = (VisualElement) m_viewVisualTree.GetValue(m_currentToolbar, null);
|
||||
#endif
|
||||
|
||||
// Get first child which 'happens' to be toolbar IMGUIContainer
|
||||
var container = (IMGUIContainer) visualTree[0];
|
||||
|
||||
// (Re)attach handler
|
||||
var handler = (Action) m_imguiContainerOnGui.GetValue(container);
|
||||
handler -= OnGUI;
|
||||
handler += OnGUI;
|
||||
m_imguiContainerOnGui.SetValue(container, handler);
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void OnGUI()
|
||||
{
|
||||
var handler = OnToolbarGUI;
|
||||
if (handler != null) handler();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a4fbfa229ee894b478fb21c046afa6d4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,169 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityToolbarExtender
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public static class ToolbarExtender
|
||||
{
|
||||
static int m_toolCount;
|
||||
static GUIStyle m_commandStyle = null;
|
||||
|
||||
public static readonly List<Action> LeftToolbarGUI = new List<Action>();
|
||||
public static readonly List<Action> RightToolbarGUI = new List<Action>();
|
||||
|
||||
static ToolbarExtender()
|
||||
{
|
||||
Type toolbarType = typeof(Editor).Assembly.GetType("UnityEditor.Toolbar");
|
||||
|
||||
#if UNITY_2019_1_OR_NEWER
|
||||
string fieldName = "k_ToolCount";
|
||||
#else
|
||||
string fieldName = "s_ShownToolIcons";
|
||||
#endif
|
||||
|
||||
FieldInfo toolIcons = toolbarType.GetField(fieldName,
|
||||
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
|
||||
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
m_toolCount = toolIcons != null ? ((int) toolIcons.GetValue(null)) : 8;
|
||||
#elif UNITY_2019_1_OR_NEWER
|
||||
m_toolCount = toolIcons != null ? ((int) toolIcons.GetValue(null)) : 7;
|
||||
#elif UNITY_2018_1_OR_NEWER
|
||||
m_toolCount = toolIcons != null ? ((Array) toolIcons.GetValue(null)).Length : 6;
|
||||
#else
|
||||
m_toolCount = toolIcons != null ? ((Array) toolIcons.GetValue(null)).Length : 5;
|
||||
#endif
|
||||
|
||||
ToolbarCallback.OnToolbarGUI = OnGUI;
|
||||
ToolbarCallback.OnToolbarGUILeft = GUILeft;
|
||||
ToolbarCallback.OnToolbarGUIRight = GUIRight;
|
||||
}
|
||||
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
public const float space = 8;
|
||||
#else
|
||||
public const float space = 10;
|
||||
#endif
|
||||
public const float largeSpace = 20;
|
||||
public const float buttonWidth = 32;
|
||||
public const float dropdownWidth = 80;
|
||||
#if UNITY_2019_1_OR_NEWER
|
||||
public const float playPauseStopWidth = 140;
|
||||
#else
|
||||
public const float playPauseStopWidth = 100;
|
||||
#endif
|
||||
|
||||
static void OnGUI()
|
||||
{
|
||||
// Create two containers, left and right
|
||||
// Screen is whole toolbar
|
||||
|
||||
if (m_commandStyle == null)
|
||||
{
|
||||
m_commandStyle = new GUIStyle("CommandLeft");
|
||||
}
|
||||
|
||||
var screenWidth = EditorGUIUtility.currentViewWidth;
|
||||
|
||||
// Following calculations match code reflected from Toolbar.OldOnGUI()
|
||||
float playButtonsPosition = Mathf.RoundToInt ((screenWidth - playPauseStopWidth) / 2);
|
||||
|
||||
Rect leftRect = new Rect(0, 0, screenWidth, Screen.height);
|
||||
leftRect.xMin += space; // Spacing left
|
||||
leftRect.xMin += buttonWidth * m_toolCount; // Tool buttons
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
leftRect.xMin += space; // Spacing between tools and pivot
|
||||
#else
|
||||
leftRect.xMin += largeSpace; // Spacing between tools and pivot
|
||||
#endif
|
||||
leftRect.xMin += 64 * 2; // Pivot buttons
|
||||
leftRect.xMax = playButtonsPosition;
|
||||
|
||||
Rect rightRect = new Rect(0, 0, screenWidth, Screen.height);
|
||||
rightRect.xMin = playButtonsPosition;
|
||||
rightRect.xMin += m_commandStyle.fixedWidth * 3; // Play buttons
|
||||
rightRect.xMax = screenWidth;
|
||||
rightRect.xMax -= space; // Spacing right
|
||||
rightRect.xMax -= dropdownWidth; // Layout
|
||||
rightRect.xMax -= space; // Spacing between layout and layers
|
||||
rightRect.xMax -= dropdownWidth; // Layers
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
rightRect.xMax -= space; // Spacing between layers and account
|
||||
#else
|
||||
rightRect.xMax -= largeSpace; // Spacing between layers and account
|
||||
#endif
|
||||
rightRect.xMax -= dropdownWidth; // Account
|
||||
rightRect.xMax -= space; // Spacing between account and cloud
|
||||
rightRect.xMax -= buttonWidth; // Cloud
|
||||
rightRect.xMax -= space; // Spacing between cloud and collab
|
||||
rightRect.xMax -= 78; // Colab
|
||||
|
||||
// Add spacing around existing controls
|
||||
leftRect.xMin += space;
|
||||
leftRect.xMax -= space;
|
||||
rightRect.xMin += space;
|
||||
rightRect.xMax -= space;
|
||||
|
||||
// Add top and bottom margins
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
leftRect.y = 4;
|
||||
leftRect.height = 22;
|
||||
rightRect.y = 4;
|
||||
rightRect.height = 22;
|
||||
#else
|
||||
leftRect.y = 5;
|
||||
leftRect.height = 24;
|
||||
rightRect.y = 5;
|
||||
rightRect.height = 24;
|
||||
#endif
|
||||
|
||||
if (leftRect.width > 0)
|
||||
{
|
||||
GUILayout.BeginArea(leftRect);
|
||||
GUILayout.BeginHorizontal();
|
||||
foreach (var handler in LeftToolbarGUI)
|
||||
{
|
||||
handler();
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
|
||||
if (rightRect.width > 0)
|
||||
{
|
||||
GUILayout.BeginArea(rightRect);
|
||||
GUILayout.BeginHorizontal();
|
||||
foreach (var handler in RightToolbarGUI)
|
||||
{
|
||||
handler();
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
}
|
||||
|
||||
public static void GUILeft() {
|
||||
GUILayout.BeginHorizontal();
|
||||
foreach (var handler in LeftToolbarGUI)
|
||||
{
|
||||
handler();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
public static void GUIRight() {
|
||||
GUILayout.BeginHorizontal();
|
||||
foreach (var handler in RightToolbarGUI)
|
||||
{
|
||||
handler();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8e582c227e3bb4498b2703b86ca00d7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user