1.4.0: Added build target picker and build button to toolbar
This commit is contained in:
parent
0b147a9144
commit
03200cc370
10 changed files with 254 additions and 7 deletions
77
Editor/Toolbar/Tools/ToolBuild.cs
Normal file
77
Editor/Toolbar/Tools/ToolBuild.cs
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
using JetBrains.Annotations;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UTools = UnityEditor.Tools;
|
||||
|
||||
namespace Module.NavigationTool.Editor.Toolbar
|
||||
{
|
||||
[UsedImplicitly]
|
||||
internal sealed class ToolBuild : AbstractToolbarDrawer
|
||||
{
|
||||
public override bool Visible => ToolbarSettings.IsBuildEnabled;
|
||||
public override bool Enabled => !Application.isPlaying;
|
||||
public override EToolbarPlacement Placement => EToolbarPlacement.Left;
|
||||
public override int Priority => (int)EToolbarPriority.Low;
|
||||
|
||||
private static bool IS_DIRTY = true;
|
||||
private static GUIContent[] BUTTON_LIST = new GUIContent[0];
|
||||
private static GUIContent[] CONTENT_LIST = new GUIContent[0];
|
||||
private static GUIContent DROPDOWN = new GUIContent();
|
||||
|
||||
private static void Initialize()
|
||||
{
|
||||
if (!IS_DIRTY)
|
||||
return;
|
||||
|
||||
BUTTON_LIST = new[]
|
||||
{
|
||||
new GUIContent("Build"),
|
||||
new GUIContent("Build & Run")
|
||||
};
|
||||
|
||||
CONTENT_LIST = new[]
|
||||
{
|
||||
new GUIContent("Build"),
|
||||
new GUIContent("Build and Run")
|
||||
};
|
||||
|
||||
DROPDOWN = EditorGUIUtility.IconContent("d_icon dropdown");
|
||||
|
||||
IS_DIRTY = false;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
protected override void Draw(Rect rect)
|
||||
{
|
||||
var rect0 = new Rect(rect.x, rect.y, rect.width - 16.0f, rect.height);
|
||||
var rect1 = new Rect(rect0.xMax, rect.y, 16.0f, rect.height);
|
||||
|
||||
int currentSelected = ToolbarSettings.IsBuildAndRunEnabled ? 1 : 0;
|
||||
|
||||
if (GUI.Button(rect0, BUTTON_LIST[currentSelected], styles.buttonNoPadding))
|
||||
{
|
||||
BuildPlayerOptions options = BuildPlayerWindow.DefaultBuildMethods.GetBuildPlayerOptions(new BuildPlayerOptions());
|
||||
options.options |= BuildOptions.AutoRunPlayer;
|
||||
BuildPlayerWindow.DefaultBuildMethods.BuildPlayer(options);
|
||||
}
|
||||
|
||||
if (GUI.Button(rect1, DROPDOWN, styles.button))
|
||||
{
|
||||
EditorUtility.DisplayCustomMenu(rect, CONTENT_LIST, currentSelected, (_, _, selected) =>
|
||||
{
|
||||
if (selected != -1)
|
||||
ToolbarSettings.IsBuildAndRunEnabled = selected == 1;
|
||||
}, null);
|
||||
}
|
||||
}
|
||||
|
||||
public override float CalculateWidth()
|
||||
{
|
||||
return 100.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue