123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using UnityEditor;
- using UnityEngine;
- using UnityToolbarExtender;
- using XGame.Framework.Asset;
- namespace XGame.Editor.Asset
- {
- [InitializeOnLoad]
- class AssetModeNavigation : INavigation
- {
- static readonly string[,] AssetModeContent =
- { { "AssetBundle", "当前模式:AssetBundle\n运行时不可切换" }, { "AssetDatabase", "当前模式:AssetDatabase\n运行时不可切换" } };
- bool _assetMode;
- public int Order => 200;
- public void OnGUI()
- {
- GUILayout.Space(50);
- _assetMode = EditorPrefs.GetBool(Define.SIMULATE_ASSETBUNDLE_EDITOR_KEY, true);
- EditorGUI.BeginDisabledGroup(Application.isPlaying);
- if (GUILayout.Button(new GUIContent(AssetModeContent[_assetMode ? 1 : 0, 0], AssetModeContent[_assetMode ? 1 : 0, 1]), ToolbarStyles.assetModeButtonStyle))
- {
- _assetMode = !_assetMode;
- Debug.Log($"切换资源模式成功,当前模式:{AssetModeContent[_assetMode ? 1 : 0, 0]}");
- EditorSettings.spritePackerMode = _assetMode ? UnityEditor.SpritePackerMode.AlwaysOnAtlas : UnityEditor.SpritePackerMode.BuildTimeOnlyAtlas;
- EditorPrefs.SetBool(Define.SIMULATE_ASSETBUNDLE_EDITOR_KEY, _assetMode);
- }
- EditorGUI.EndDisabledGroup();
- }
- static AssetModeNavigation()
- {
- ToolbarExtender.AddToLeft(new AssetModeNavigation());
- }
- static class ToolbarStyles
- {
- public static readonly GUIStyle assetModeButtonStyle;
- static ToolbarStyles()
- {
- assetModeButtonStyle = new GUIStyle("Command")
- {
- fixedWidth = 100,
- fontSize = 13,
- alignment = TextAnchor.MiddleCenter,
- imagePosition = ImagePosition.ImageAbove,
- fontStyle = FontStyle.Bold
- };
- }
- }
- }
- }
|