module-navigation-tool/Editor/Toolbar/Tools/ToolBuild.cs
Anders Ejlersen dd80d46ebb Scene Picker: Modified scene groups to contain LoadAsGroup, SortAsGroup and SortInSubmenuAsGroup
### Changed
-  Scene groups to contain three different types of behaviours for grouping:
   - Load As Group: Groups all scenes into a single entry
   - Sort As Group: Sorts all scenes into entries close to each other in the dropdown
   - Sort In Submenu As Group: Sorts all scenes into entries in a submenu

### Removed
- Removed "Scene sorting by Asset label" groups
2025-03-29 11:12:03 +01:00

82 lines
3.1 KiB
C#

using JetBrains.Annotations;
using UnityEditor;
using UnityEngine;
namespace Module.NavigationTool.Editor.Toolbar
{
[UsedImplicitly]
internal sealed class ToolBuild : AbstractToolbarDrawer
{
public override bool Visible => ToolbarBuildSettings.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;
const string TOOLTIP = "Build project with current EditorBuildSettings and target platform";
const string TOOLTIP_RUN = "Build & Run project with current EditorBuildSettings and target platform";
const string TOOLTIP_PLATFORM = "Select build or build & run options";
BUTTON_LIST = new[]
{
new GUIContent("Build", TOOLTIP),
new GUIContent("Build & Run", TOOLTIP_RUN)
};
CONTENT_LIST = new[]
{
new GUIContent("Build"),
new GUIContent("Build and Run")
};
GUIContent iconContent = EditorGUIUtility.IconContent("d_icon dropdown");
DROPDOWN = new GUIContent(iconContent.image, TOOLTIP_PLATFORM);
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 = ToolbarBuildSettings.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.buttonNoPadding))
{
// Note: Do not discard the parameters: userData and options, since they throw an error in 2019, if there are two of them
EditorUtility.DisplayCustomMenu(rect, CONTENT_LIST, currentSelected, (userData, options, selected) =>
{
if (selected != -1)
ToolbarBuildSettings.IsBuildAndRunEnabled = selected == 1;
}, null);
}
}
public override float CalculateWidth()
{
return 100.0f;
}
}
}