0.5.0: Added toolbar with scene picker
This commit is contained in:
parent
d35a79faf1
commit
27d7ecb2dd
19 changed files with 365 additions and 3 deletions
77
Editor/Toolbar/Tools/ToolScenePicker.cs
Normal file
77
Editor/Toolbar/Tools/ToolScenePicker.cs
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Game.NavigationTool.Editor.Toolbar;
|
||||
using JetBrains.Annotations;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Game.NavigationTool.Editor.Tools
|
||||
{
|
||||
[UsedImplicitly]
|
||||
internal sealed class ToolScenePicker : IToolbarDrawer
|
||||
{
|
||||
public bool Visible => true;
|
||||
public bool Enabled => !EditorApplication.isPlaying && !EditorApplication.isPlayingOrWillChangePlaymode;
|
||||
public EToolbarPlacement Placement => EToolbarPlacement.Right;
|
||||
|
||||
private static bool IS_DIRTY = true;
|
||||
private static int SELECTED_INDEX = -1;
|
||||
private static string[] OPTIONS = new string[0];
|
||||
private static string[] PATHS = new string[0];
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
if (!IS_DIRTY)
|
||||
return;
|
||||
|
||||
EditorBuildSettingsScene[] scenes = EditorBuildSettings.scenes;
|
||||
var listNames = new List<string>(scenes.Length);
|
||||
var listPaths = new List<string>(scenes.Length);
|
||||
|
||||
for (var i = 0; i < scenes.Length; i++)
|
||||
{
|
||||
if (string.IsNullOrEmpty(scenes[i].path))
|
||||
continue;
|
||||
|
||||
listNames.Add(Path.GetFileNameWithoutExtension(scenes[i].path));
|
||||
listPaths.Add(scenes[i].path);
|
||||
}
|
||||
|
||||
OPTIONS = listNames.ToArray();
|
||||
PATHS = listPaths.ToArray();
|
||||
|
||||
Scene activeScene = SceneManager.GetActiveScene();
|
||||
SELECTED_INDEX = listPaths.IndexOf(activeScene.path);
|
||||
IS_DIRTY = false;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public void Draw(Rect rect, Styles styles)
|
||||
{
|
||||
Initialize();
|
||||
int temp = EditorGUI.Popup(rect, SELECTED_INDEX, OPTIONS, styles.popup);
|
||||
|
||||
if (temp != -1 && temp != SELECTED_INDEX && OPTIONS.Length != 0)
|
||||
{
|
||||
SELECTED_INDEX = temp;
|
||||
EditorSceneManager.OpenScene(PATHS[SELECTED_INDEX], OpenSceneMode.Single);
|
||||
}
|
||||
}
|
||||
|
||||
public float CalculateWidth()
|
||||
{
|
||||
return 100.0f;
|
||||
}
|
||||
|
||||
public static void SetAsDirty()
|
||||
{
|
||||
IS_DIRTY = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Editor/Toolbar/Tools/ToolScenePicker.cs.meta
Normal file
3
Editor/Toolbar/Tools/ToolScenePicker.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 172702143ca2476994af66dff7f0c0f9
|
||||
timeCreated: 1615451718
|
||||
20
Editor/Toolbar/Tools/ToolScenePickerPostProcess.cs
Normal file
20
Editor/Toolbar/Tools/ToolScenePickerPostProcess.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using System.Linq;
|
||||
using Game.NavigationTool.Editor.Tools;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Game.NavigationTool.Editor.Toolbar
|
||||
{
|
||||
internal sealed class ToolbarPostProcess : AssetPostprocessor
|
||||
{
|
||||
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
|
||||
{
|
||||
if (HasChange(deletedAssets) || HasChange(movedAssets) || HasChange(importedAssets))
|
||||
ToolScenePicker.SetAsDirty();
|
||||
}
|
||||
|
||||
private static bool HasChange(string[] assets)
|
||||
{
|
||||
return assets.Any(s => s.EndsWith(".unity"));
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Editor/Toolbar/Tools/ToolScenePickerPostProcess.cs.meta
Normal file
3
Editor/Toolbar/Tools/ToolScenePickerPostProcess.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: aba187d5f2434c93b4104a1136897484
|
||||
timeCreated: 1615458676
|
||||
Loading…
Add table
Add a link
Reference in a new issue