Files
2025-11-30 08:35:03 +02:00

86 lines
2.8 KiB
C#

using System;
using System.IO;
using JetBrains.Annotations;
using Needle.Engine.Core;
using Needle.Engine.Editors;
using Needle.Engine.Problems;
using Needle.Engine.Utils;
using UnityEditor;
using UnityEngine;
namespace Needle.Engine.Deployment
{
[UsedImplicitly]
internal class BuildPlatformFooterProvider : INeedleBuildPlatformFooterGUIProvider
{
public void OnBuildPlatformsFooterGUI(NeedleEngineBuildOptions buildOptions)
{
var license = LicenseCheck.HasLicense && LicenseCheck.LicenseIsActive;
using (new EditorGUI.DisabledScope(!license))
{
var canBuild = !Actions.IsRunningBuildTask;
if (ProjectValidation.CheckRequiredSoftwareIsInstalled() == false)
{
canBuild = false;
if (GUILayout.Button(new GUIContent("Project Validation", "Open the Project Validation window to check if all required software is installed.")))
{
ProjectValidationWindow.Open();
}
}
using (new EditorGUI.DisabledScope(!canBuild))
{
var exp = ExportInfo.Get();
if (!exp)
{
if (GUILayout.Button("Add Needle Engine Integration to current Scene"))
{
Actions.SetupSceneForNeedleEngineExport();
}
}
else
{
const float width = BuildPlatformConstants.LeftColumnWidth;
if (GUILayout.Button(new GUIContent("Build to Disk", "Perform a build of your web app for deployment. The resulting files can then be uploaded to your webserver.\n\nYou can also use any of our Deployment components listed above to directly build and deploy your scene to the web without any manual steps."), GUILayout.Width(width)))
{
MenuItems.BuildForDist(NeedleEngineBuildOptions.DevelopmentBuild ? BuildContext.Development : BuildContext.Production);
GUIUtility.ExitGUI();
}
if (GUILayout.Button(new GUIContent("Preview Build", "Build & Start preview server. This does disable gzip compression to work with vite preview and can be used to preview a build on your local machine.\n\nRun \"Build\" to make a final build for deployment."), GUILayout.Width(width)))
{
PreviewBuild();
GUIUtility.ExitGUI();
}
}
}
}
}
private static async void PreviewBuild()
{
var gzip = UseGizp.Enabled;
UseGizp.Enabled = false;
var ctx = NeedleEngineBuildOptions.DevelopmentBuild
? BuildContext.Development
: BuildContext.Production;
var res = await Actions.ExportAndBuild(ctx);
UseGizp.Enabled = gzip;
if (!res)
{
Debug.Log("Build failed, can not start preview server...");
return;
}
var exp = ExportInfo.Get();
if (!exp || !exp.Exists()) return;
await WebProjectUtils.StartPreviewServer(Path.GetFullPath(exp.GetProjectDirectory()));
}
private static async void RunInBrowser()
{
await Builder.Build(false, BuildContext.LocalDevelopment);
MenuItems.StartDevelopmentServer();
}
}
}