From dee6a8e2eb9bb69eee01544e387c43f3a1f3dbd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20Barczy=C5=84ski?= Date: Fri, 28 Aug 2020 22:52:15 +0200 Subject: [PATCH] Release 1.1.0 (#6) * Release 1.1.0 * Support for 2020.1. --- CHANGELOG.md | 12 +- Editor/SceneInspector.cs | 541 ++++++++++-------- ...ity.Daancode.SceneInspector.Editor.asmdef} | 5 +- ...aancode.SceneInspector.Editor.asmdef.meta} | 0 package.json | 8 +- 5 files changed, 320 insertions(+), 246 deletions(-) rename Editor/{Unity.DCSceneInspector.Editor.asmdef => Unity.Daancode.SceneInspector.Editor.asmdef} (72%) rename Editor/{Unity.DCSceneInspector.Editor.asmdef.meta => Unity.Daancode.SceneInspector.Editor.asmdef.meta} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a5ac45..04adb32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,12 +3,20 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) +## [1.1.0] - 2020-08-29 +## Added +- Restore scene after exit play mode. +- Support for Unity 2020.1. + +## Changed +- Shortcut name is now displayed as tooltip. + ## [1.0.1] - 2019-06-12 This is the first release of *Scene Inspector* package via Unity Package Manager. ### Added -- Create new scene option -- Pin scene shortcut to toolbar +- Create new scene option. +- Pin scene shortcut to toolbar. ### Changed - UX tweaks \ No newline at end of file diff --git a/Editor/SceneInspector.cs b/Editor/SceneInspector.cs index 66db3a0..834e51d 100644 --- a/Editor/SceneInspector.cs +++ b/Editor/SceneInspector.cs @@ -1,6 +1,6 @@ // MIT License -// Copyright(c) 2018 Damian Barczynski +// Copyright(c) 2020 Damian Barczynski // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -37,29 +37,32 @@ using UnityEngine.Experimental.UIElements; #endif -namespace DCTools +namespace Daancode.Utils { - [Serializable] - public class SceneInspectorSettings - { - public bool OnlyIncludedScenes = false; - public bool RestoreAfterPlay = true; - public string[] scenePaths; - } - + // https://github.com/marijnz/unity-toolbar-extender. [InitializeOnLoad] public static class ToolbarExtender { - static BindingFlags m_flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance; - - static Assembly m_assembly = typeof( Editor ).Assembly; - static Type m_toolbarType = m_assembly.GetType( "UnityEditor.Toolbar" ); - static PropertyInfo m_viewVisualTree = m_assembly.GetType( "UnityEditor.GUIView" ).GetProperty( "visualTree", m_flags ); - static FieldInfo m_imguiContainerOnGui = typeof( IMGUIContainer ).GetField( "m_OnGUIHandler", m_flags ); - static ScriptableObject m_currentToolbar; - - static int m_toolCount = GetToolsCount(); - static GUIStyle m_commandStyle = null; + private const BindingFlags FLAGS = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance; + + private static readonly Assembly m_assembly = typeof( Editor ).Assembly; + private static readonly Type m_toolbarType = m_assembly.GetType( "UnityEditor.Toolbar" ); + private static readonly FieldInfo m_imguiContainerOnGui = typeof( IMGUIContainer ).GetField( "m_OnGUIHandler", FLAGS ); + private static ScriptableObject m_currentToolbar; + +#if UNITY_2020_1_OR_NEWER + static Type m_iWindowBackendType = typeof(Editor).Assembly.GetType("UnityEditor.IWindowBackend"); + static PropertyInfo m_windowBackend = m_assembly.GetType( "UnityEditor.GUIView" ) + .GetProperty("windowBackend", FLAGS); + static PropertyInfo m_viewVisualTree = m_iWindowBackendType.GetProperty("visualTree", FLAGS); +#else + private static readonly PropertyInfo m_viewVisualTree = m_assembly + .GetType( "UnityEditor.GUIView" ) + .GetProperty( "visualTree", FLAGS ); +#endif + + private static readonly int m_toolCount = GetToolsCount(); + private static GUIStyle m_commandStyle = null; public static readonly List LeftToolbarGUI = new List(); public static readonly List RightToolbarGUI = new List(); @@ -70,78 +73,90 @@ static ToolbarExtender() EditorApplication.update += OnUpdate; } - static void OnUpdate() + private static void OnUpdate() { if (m_currentToolbar == null) { var toolbars = Resources.FindObjectsOfTypeAll( m_toolbarType ); m_currentToolbar = toolbars.Length > 0 ? (ScriptableObject) toolbars[0] : null; - if (m_currentToolbar != null) - { - var element = m_viewVisualTree.GetValue( m_currentToolbar, null ) as VisualElement; - var container = element[0] as IMGUIContainer; - var handler = m_imguiContainerOnGui.GetValue( container ) as Action; - handler -= OnGUI; - handler += OnGUI; - m_imguiContainerOnGui.SetValue( container, handler ); - } } + +#if UNITY_2020_1_OR_NEWER + var windowBackend = m_windowBackend.GetValue(m_currentToolbar); + var visualTree = (VisualElement) m_viewVisualTree.GetValue(windowBackend, null); +#else + var visualTree = (VisualElement) m_viewVisualTree.GetValue(m_currentToolbar, null); +#endif + + var container = visualTree[0] as IMGUIContainer; + var handler = m_imguiContainerOnGui.GetValue( container ) as Action; + handler -= OnGUI; + handler += OnGUI; + m_imguiContainerOnGui.SetValue( container, handler ); } - static void OnGUI() + private static void OnGUI() { if (m_commandStyle == null) { - m_commandStyle = new GUIStyle( "CommandLeft" ); + m_commandStyle = new GUIStyle( "Command" ); } var screenWidth = EditorGUIUtility.currentViewWidth; #if UNITY_2019_1_OR_NEWER - float playButtonsPosition = ( screenWidth - 140 ) / 2; + var playButtonsPosition = ( screenWidth - 140 ) / 2; #else - float playButtonsPosition = (screenWidth - 100) / 2; + var playButtonsPosition = (screenWidth - 100) / 2; #endif - Rect leftToolbarRect = new Rect( 0, 4, screenWidth, 24 ); + var leftToolbarRect = new Rect( 0, 4, screenWidth, 24 ); leftToolbarRect.xMin += 170 + 32 * m_toolCount; leftToolbarRect.xMax = playButtonsPosition - 10; - Rect rightToolbarRect = new Rect( 0, 4, screenWidth, 24 ); - rightToolbarRect.xMin = playButtonsPosition + 10 + ( m_commandStyle.fixedWidth * 3 ); - rightToolbarRect.xMax = screenWidth - 420; + var rightToolbarRect = new Rect(0, 4, screenWidth, 24) + { + xMin = playButtonsPosition + 10 + m_commandStyle.fixedWidth * 3, + xMax = screenWidth - 420 + }; HandleCustomToolbar( LeftToolbarGUI, leftToolbarRect ); HandleCustomToolbar( RightToolbarGUI, rightToolbarRect ); } - static void HandleCustomToolbar( List toolbar, Rect rect ) + private static void HandleCustomToolbar( IEnumerable toolbar, Rect rect ) { - if (rect.width > 0) + if (!(rect.width > 0)) + { + return; + } + + using (new GUILayout.AreaScope(rect)) { - GUILayout.BeginArea( rect ); - GUILayout.BeginHorizontal(); - foreach (var handler in toolbar) + using (new GUILayout.HorizontalScope()) { - handler(); + foreach (var handler in toolbar) + { + handler(); + } } - GUILayout.EndHorizontal(); - GUILayout.EndArea(); } } - static int GetToolsCount() + private static int GetToolsCount() { #if UNITY_2019_1_OR_NEWER - string fieldName = "k_ToolCount"; + const string fieldName = "k_ToolCount"; #else - string fieldName = "s_ShownToolIcons"; + const string fieldName = "s_ShownToolIcons"; #endif var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static; - var toolIcons = m_toolbarType.GetField( fieldName, flags ) as FieldInfo; + var toolIcons = m_toolbarType.GetField( fieldName, flags ); -#if UNITY_2019_1_OR_NEWER +#if UNITY_2019_3_OR_NEWER + return toolIcons != null ? ( (int) toolIcons.GetValue( null ) ) : 8; +#elif UNITY_2019_1_OR_NEWER return toolIcons != null ? ( (int) toolIcons.GetValue( null ) ) : 7; #elif UNITY_2018_1_OR_NEWER return toolIcons != null ? ( (Array) toolIcons.GetValue( null ) ).Length : 6; @@ -154,298 +169,348 @@ static int GetToolsCount() [InitializeOnLoad] public class SceneInspector { - static float Height = 22f; - static SceneInspectorSettings Settings; - static HashSet Shortcuts; - - static SceneInspector() + [Serializable] + public class Settings { - LoadSettings(); - if (Settings == null) + public bool OnlyIncludedScenes = false; + public bool EnableShortcuts = false; + public bool ShowShortcutNames = false; + public bool RestoreAfterPlay = true; + public List Shortcuts; + public string LastOpenedScene; + + public static string Key => $"DCTools:{Application.productName}:Settings"; + public bool ShortcutsValid => EnableShortcuts && Shortcuts != null && Shortcuts.Count > 0; + + public void Save() { - Settings = new SceneInspectorSettings(); + EditorPrefs.SetString(Key, EditorJsonUtility.ToJson(this)); } - ToolbarExtender.LeftToolbarGUI.Add( OnToolbarGUI ); - ToolbarExtender.RightToolbarGUI.Add( OnShortcutsGUI ); + public void Load() + { + if (!EditorPrefs.HasKey(Key)) + { + return; + } + + JsonUtility.FromJsonOverwrite( EditorPrefs.GetString( Key ), this ); + } } - static void SaveSettings() + private static class Styles + { + private static GUIContent _playButtonContent; + private static GUIContent _addSceneContent; + private static GUIContent _settingsContent; + + public static GUILayoutOption ShortWidth => GUILayout.Width(25f); + public static GUILayoutOption Height => GUILayout.Height(22f); + + public static GUIContent PlaySceneContent => _playButtonContent ?? (_playButtonContent = new GUIContent + { + image = EditorGUIUtility.IconContent("Animation.Play").image, + tooltip = "Enter play mode from first scene defined in build settings." + }); + + public static GUIContent ChangeSceneContent => new GUIContent + { + text = " " + SceneManager.GetActiveScene().name, + image = EditorGUIUtility.IconContent("BuildSettings.Editor.Small").image, + tooltip = "Change active scene" + }; + + public static GUIContent AddSceneContent => _addSceneContent ?? (_addSceneContent = new GUIContent + { + image = EditorGUIUtility.IconContent("Toolbar Plus More").image, + tooltip = "Open scene in additive mode" + }); + + public static GUIContent SettingsContent => _settingsContent ?? (_settingsContent = new GUIContent + { + image = EditorGUIUtility.IconContent("_Popup").image, + tooltip = "Scene inspector settings" + }); + } + + private static Settings s_settings; + private static Settings CurrentSettings => s_settings ?? (s_settings = new Settings()); + + static SceneInspector() { - EditorPrefs.SetString( GetEditorSettingsKey(), JsonUtility.ToJson( Settings ) ); + CurrentSettings.Load(); + ToolbarExtender.LeftToolbarGUI.Add( OnToolbarGUI ); + ToolbarExtender.RightToolbarGUI.Add( OnShortcutsGUI ); + EditorApplication.playModeStateChanged += OnModeChanged; } - static void LoadSettings() + private static void OnModeChanged(PlayModeStateChange playModeState) { - if (Settings == null) + CurrentSettings.Load(); + + if (!CurrentSettings.RestoreAfterPlay) { - Settings = new SceneInspectorSettings(); + return; } - var settingsKeyData = EditorPrefs.GetString( GetEditorSettingsKey() ); - if (settingsKeyData == "") + if (playModeState == PlayModeStateChange.EnteredEditMode) { - SaveSettings(); + EditorSceneManager.OpenScene(CurrentSettings.LastOpenedScene); } - - JsonUtility.FromJsonOverwrite( EditorPrefs.GetString( GetEditorSettingsKey() ), Settings ); - Shortcuts = new HashSet( Settings.scenePaths.ToList() ); } - - static void OnToolbarGUI() + + private static void OnToolbarGUI() { GUILayout.FlexibleSpace(); - EditorGUILayout.BeginHorizontal(); - - EditorGUI.BeginDisabledGroup( EditorApplication.isPlaying ); - CreatePlayButton(); - CreateSceneChangeButton(); - EditorGUI.EndDisabledGroup(); - - CreateSceneAddButton(); + using (new GUILayout.HorizontalScope()) + { + using (new EditorGUI.DisabledScope(EditorApplication.isPlaying)) + { + CreatePlayButton(); + CreateSceneChangeButton(); + } - EditorGUI.BeginDisabledGroup( EditorApplication.isPlaying ); - CreateSettingsButton(); - EditorGUI.EndDisabledGroup(); + CreateSceneAddButton(); - EditorGUILayout.EndHorizontal(); + using (new EditorGUI.DisabledScope(EditorApplication.isPlaying)) + { + CreateSettingsButton(); + } + } } - static void OnShortcutsGUI() + private static void OnShortcutsGUI() { - if (!EditorApplication.isPlaying && Shortcuts.Count > 0) + if (EditorApplication.isPlaying || !CurrentSettings.ShortcutsValid) { - var scenes = Shortcuts.ToArray(); - string[] sceneNames = scenes.ToArray(); + return; + } - for (int i = 0; i < sceneNames.Length; ++i) - { - sceneNames[i] = GetSceneNameFromPath( sceneNames[i] ); - } + for (var i = 0; i < CurrentSettings.Shortcuts.Count; ++i) + { + var isActiveScene = IsActiveScene(CurrentSettings.Shortcuts[i]); + var sceneName = GetSceneNameFromPath(CurrentSettings.Shortcuts[i]); - int selection = GUILayout.Toolbar( -1, sceneNames, GUILayout.Height( Height ) ); - if (selection != -1) + var oldColor = GUI.backgroundColor; + GUI.backgroundColor = isActiveScene ? Color.cyan : oldColor; + + using (new EditorGUI.DisabledScope(isActiveScene)) { - SwitchScene( scenes[selection] ); + if (CurrentSettings.ShowShortcutNames) + { + if (GUILayout.Button(SceneButtonContent(i, sceneName), Styles.Height)) + { + SwitchScene(CurrentSettings.Shortcuts[i]); + } + } + else + { + if (GUILayout.Button(SceneButtonContent(i, sceneName), Styles.ShortWidth, Styles.Height)) + { + SwitchScene(CurrentSettings.Shortcuts[i]); + } + } } + + GUI.backgroundColor = oldColor; + } - GUILayout.FlexibleSpace(); + GUIContent SceneButtonContent(int index, string sceneName) + { + return new GUIContent + { + text = CurrentSettings.ShowShortcutNames ? sceneName : $"{index + 1}", + tooltip = GetSceneNameFromPath(CurrentSettings.Shortcuts[index]) + }; } + + GUILayout.FlexibleSpace(); } - static void SwitchScene( object scene ) + private static void SwitchScene( object scene ) { if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) { - EditorSceneManager.OpenScene( (string) scene ); + EditorSceneManager.OpenScene( scene as string ); } } - static void AddScene( object scene ) + private static void AddScene( object scene ) { if (EditorApplication.isPlaying) { - EditorSceneManager.LoadScene( (string) scene, LoadSceneMode.Additive ); + SceneManager.LoadScene( scene as string, LoadSceneMode.Additive ); } else { - EditorSceneManager.OpenScene( (string) scene, OpenSceneMode.Additive ); + EditorSceneManager.OpenScene( scene as string, OpenSceneMode.Additive ); } } - static void CreatePlayButton() + private static void CreatePlayButton() { var oldColor = GUI.backgroundColor; GUI.backgroundColor = EditorApplication.isPlaying ? Color.red : Color.green; - - GUIContent playContent = new GUIContent(); - - if (EditorApplication.isPlaying) - { - playContent.text = "Play Mode"; - } - else - { - playContent.image = EditorGUIUtility.IconContent( "Animation.Play" ).image; - } - - playContent.tooltip = "Play game from first scene"; - - if (GUILayout.Button( playContent, GUILayout.Height( Height ) )) + + if (GUILayout.Button( Styles.PlaySceneContent, Styles.Height ) && EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) { - if (!EditorApplication.isPlaying) - { - if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) - { - EditorSceneManager.OpenScene( EditorBuildSettings.scenes[0].path ); - EditorApplication.isPlaying = true; - } - } + CurrentSettings.LastOpenedScene = SceneManager.GetActiveScene().path; + CurrentSettings.Save(); + EditorSceneManager.OpenScene( EditorBuildSettings.scenes[0].path ); + EditorApplication.isPlaying = true; } GUI.backgroundColor = oldColor; } - static void CreateSceneChangeButton() + private static void CreateSceneChangeButton() { - GUIContent changeSceneContent = new GUIContent(); - changeSceneContent.text = " " + SceneManager.GetActiveScene().name; - changeSceneContent.image = EditorGUIUtility.IconContent( "BuildSettings.Editor.Small" ).image; - changeSceneContent.tooltip = "Change active scene"; - - if (GUILayout.Button( changeSceneContent, GUILayout.Height( Height ) ) && !EditorApplication.isPlaying) + if (GUILayout.Button( Styles.ChangeSceneContent, Styles.Height ) && !EditorApplication.isPlaying) { - GenericMenu menu = new GenericMenu(); + var menu = new GenericMenu(); FillScenesMenu( menu, SwitchScene ); menu.ShowAsContext(); } } - static void CreateSceneAddButton() + private static void CreateSceneAddButton() { - GUIContent changeSceneContent = new GUIContent(); - changeSceneContent.image = EditorGUIUtility.IconContent( "Toolbar Plus More" ).image; - changeSceneContent.tooltip = "Open scene in additive mode"; - - if (GUILayout.Button( changeSceneContent, GUILayout.Height( Height ) )) + if (GUILayout.Button( Styles.AddSceneContent, Styles.Height )) { - GenericMenu menu = new GenericMenu(); + var menu = new GenericMenu(); FillScenesMenu( menu, AddScene, false ); menu.ShowAsContext(); } } - static void FillScenesMenu( GenericMenu menu, GenericMenu.MenuFunction2 callback, bool showActiveScene = true ) + private static void FillScenesMenu( GenericMenu menu, GenericMenu.MenuFunction2 callback, bool showActiveScene = true ) { - if (Settings.OnlyIncludedScenes) + var scenePaths = GetScenes(); + + foreach (var path in scenePaths) { - if (EditorBuildSettings.scenes.Length == 0) - { - Debug.LogWarning( "[DCTools:SceneInspector] There is no scenes defined in build settings." ); - } - else foreach (var scene in EditorBuildSettings.scenes) - { - menu.AddItem( new GUIContent( GetSceneNameFromPath( scene.path ) ), - scene.path == SceneManager.GetActiveScene().path && showActiveScene, - callback, - scene.path ); - } + menu.AddItem(SceneNameContent(path), IsActiveScene(path) && showActiveScene, callback, path); } - else + + GUIContent SceneNameContent(string path) { - var scenes = AssetDatabase.FindAssets( "t:Scene" ); - foreach (var t in scenes) - { - var path = AssetDatabase.GUIDToAssetPath( t ); - menu.AddItem( new GUIContent( GetSceneNameFromPath( path ) ), - path == SceneManager.GetActiveScene().path && showActiveScene, - callback, - path ); - } + return new GUIContent(GetSceneNameFromPath(path)); } } - static void CreateSettingsButton() + private static string[] GetScenes() { - GUIContent settingsContent = new GUIContent(); - settingsContent.image = EditorGUIUtility.IconContent( "_Popup" ).image; - settingsContent.tooltip = "Scene inspector settings"; - - if (GUILayout.Button( settingsContent, GUILayout.Height( Height ) )) + if (CurrentSettings.OnlyIncludedScenes && EditorBuildSettings.scenes.Length != 0) { - GenericMenu menu = new GenericMenu(); - - menu.AddItem( new GUIContent( "Create new scene/Empty" ), false, () => - { - EditorSceneManager.NewScene( NewSceneSetup.EmptyScene, NewSceneMode.Single ); - } ); - - menu.AddItem( new GUIContent( "Create new scene/Empty - Additive" ), false, () => + return EditorBuildSettings.scenes.Select(s => s.path).ToArray(); + } + + var scenes = AssetDatabase.FindAssets("t:Scene"); + return scenes.Select(AssetDatabase.GUIDToAssetPath).ToArray(); + } + + private static void CreateSettingsButton() + { + if (GUILayout.Button( Styles.SettingsContent, Styles.Height )) + { + var menu = new GenericMenu(); + + AddNewScene(menu, "Empty", NewSceneSetup.EmptyScene, NewSceneMode.Single); + AddNewScene(menu, "Empty (Additive)", NewSceneSetup.EmptyScene, NewSceneMode.Additive); + AddNewScene(menu, "Default", NewSceneSetup.DefaultGameObjects, NewSceneMode.Single); + AddNewScene(menu, "Default (Additive)", NewSceneSetup.DefaultGameObjects, NewSceneMode.Additive); + + if (CurrentSettings.EnableShortcuts) { - EditorSceneManager.NewScene( NewSceneSetup.EmptyScene, NewSceneMode.Additive ); - } ); + FetchShortcutScenes(menu); + menu.AddSeparator("Shortcuts/"); + menu.AddItem(new GUIContent("Shortcuts/Show Names"), CurrentSettings.ShowShortcutNames, () => + { + CurrentSettings.ShowShortcutNames = !CurrentSettings.ShowShortcutNames; + CurrentSettings.Save(); + }); + + menu.AddItem(new GUIContent("Shortcuts/Clear"), false, () => + { + CurrentSettings.Shortcuts.Clear(); + CurrentSettings.Save(); + }); + } - menu.AddItem( new GUIContent( "Create new scene/Default" ), false, () => + menu.AddSeparator(""); + menu.AddDisabledItem(new GUIContent("Settings")); + menu.AddItem(new GUIContent("Only build scenes"), CurrentSettings.OnlyIncludedScenes, + () => { - EditorSceneManager.NewScene( NewSceneSetup.DefaultGameObjects, NewSceneMode.Single ); - } ); - - menu.AddItem( new GUIContent( "Create new scene/Default - Additive" ), false, () => + CurrentSettings.OnlyIncludedScenes = !CurrentSettings.OnlyIncludedScenes; + CurrentSettings.Save(); + }); + + menu.AddItem(new GUIContent("Shortcuts enabled"), CurrentSettings.EnableShortcuts, + () => { - EditorSceneManager.NewScene( NewSceneSetup.DefaultGameObjects, NewSceneMode.Additive ); - } ); - - menu.AddItem( new GUIContent( "Show only scenes included in build" ), Settings.OnlyIncludedScenes, () => + CurrentSettings.EnableShortcuts = !CurrentSettings.EnableShortcuts; + CurrentSettings.Save(); + }); + + menu.AddItem(new GUIContent("Restore scene on play mode exit"), CurrentSettings.RestoreAfterPlay, + () => { - Settings.OnlyIncludedScenes = !Settings.OnlyIncludedScenes; - SaveSettings(); - } ); - - menu.AddSeparator( "/" ); - FetchShortcutScenes( menu ); - menu.AddSeparator( "Pin scene to toolbar/" ); + CurrentSettings.RestoreAfterPlay = !CurrentSettings.RestoreAfterPlay; + CurrentSettings.Save(); + }); - menu.AddItem( new GUIContent( "Pin scene to toolbar/Clear" ), false, () => + menu.ShowAsContext(); + } + + void AddNewScene(GenericMenu menu, string label, NewSceneSetup setup, NewSceneMode mode) + { + menu.AddItem( new GUIContent( $"Create Scene/{label}" ), false, () => { - Shortcuts.Clear(); - Settings.scenePaths = Shortcuts.ToArray(); - SaveSettings(); + EditorSceneManager.NewScene( setup, mode ); } ); - - menu.ShowAsContext(); } } - static public void FetchShortcutScenes( GenericMenu menu ) + private static void FetchShortcutScenes( GenericMenu menu ) { - if (Settings.OnlyIncludedScenes) + if (CurrentSettings.Shortcuts == null) { - foreach (var scene in EditorBuildSettings.scenes) - { - var path = scene.path; - var sceneName = System.IO.Path.GetFileNameWithoutExtension( path.Split( '/' ).Last() ); - menu.AddItem( new GUIContent( "Pin scene to toolbar/" + sceneName ), Shortcuts.Contains( path ), () => - { - if (!Shortcuts.Add( path )) - { - Shortcuts.Remove( path ); - } - - Settings.scenePaths = Shortcuts.ToArray(); - SaveSettings(); - } ); - } + CurrentSettings.Shortcuts = new List(); + CurrentSettings.Save(); } - else + + var scenes = GetScenes(); + foreach (var path in scenes) { - var scenes = AssetDatabase.FindAssets( "t:Scene" ); - foreach (var t in scenes) + var sceneName = GetSceneNameFromPath(path); + var isShortcut = CurrentSettings.Shortcuts.Contains(path); + + menu.AddItem(new GUIContent("Shortcuts/" + sceneName), isShortcut, () => { - var path = AssetDatabase.GUIDToAssetPath( t ); - var sceneName = System.IO.Path.GetFileNameWithoutExtension( path.Split( '/' ).Last() ); - menu.AddItem( new GUIContent( "Pin scene to toolbar/" + sceneName ), Shortcuts.Contains( path ), () => + if (isShortcut) { - if (!Shortcuts.Add( path )) - { - Shortcuts.Remove( path ); - } + CurrentSettings.Shortcuts.Remove(path); + } + else + { + CurrentSettings.Shortcuts.Add(path); + } - Settings.scenePaths = Shortcuts.ToArray(); - SaveSettings(); - } ); - } + CurrentSettings.Save(); + }); } } - static public string GetSceneNameFromPath( string path ) + private static string GetSceneNameFromPath( string path ) { return System.IO.Path.GetFileNameWithoutExtension( path.Split( '/' ).Last() ); } - - public static string GetEditorSettingsKey() + + private static bool IsActiveScene(string scenePath) { - return "DCTools:" + Application.productName + ":Settings"; + return scenePath == SceneManager.GetActiveScene().path; } } } diff --git a/Editor/Unity.DCSceneInspector.Editor.asmdef b/Editor/Unity.Daancode.SceneInspector.Editor.asmdef similarity index 72% rename from Editor/Unity.DCSceneInspector.Editor.asmdef rename to Editor/Unity.Daancode.SceneInspector.Editor.asmdef index 66cb74b..8ed98a7 100644 --- a/Editor/Unity.DCSceneInspector.Editor.asmdef +++ b/Editor/Unity.Daancode.SceneInspector.Editor.asmdef @@ -1,5 +1,5 @@ { - "name": "Unity.DCSceneInspector.Editor", + "name": "Unity.Daancode.SceneInspector.Editor", "references": [], "optionalUnityReferences": [], "includePlatforms": [ @@ -10,6 +10,5 @@ "overrideReferences": false, "precompiledReferences": [], "autoReferenced": true, - "defineConstraints": [], - "versionDefines": [] + "defineConstraints": [] } \ No newline at end of file diff --git a/Editor/Unity.DCSceneInspector.Editor.asmdef.meta b/Editor/Unity.Daancode.SceneInspector.Editor.asmdef.meta similarity index 100% rename from Editor/Unity.DCSceneInspector.Editor.asmdef.meta rename to Editor/Unity.Daancode.SceneInspector.Editor.asmdef.meta diff --git a/package.json b/package.json index af5679a..458c613 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,17 @@ { "name": "com.daancode.scene-inspector", - "version": "1.0.1", + "version": "1.1.0", "displayName": "Scene Inspector", "description": "Helper package which extends default toolbar with scene utilities.\n\nThis tool allows you to switch fast between scenes in your project, play first scene even if isn't active and pin selected scenes to toolbar.", "unity": "2018.1", "keywords": [ "scene", "inspector", - "DCTools", "daancode", - "scene-inspector" + "scene-inspector", + "unity", + "scenes", + "shortcuts" ], "author": { "name": "Damian Barczy\u0144ski",