NLDClient-yudde/ProjectNLD/Assets/Editor/Common/BuildWindow.cs

226 lines
6.6 KiB
C#
Raw Normal View History

2023-11-08 17:33:46 +08:00
using System;
2024-05-15 17:15:25 +08:00
using UnityEditor;
using UnityEngine;
2023-10-19 15:00:19 +08:00
using Sirenix.Utilities;
2024-05-15 17:15:25 +08:00
using Sirenix.OdinInspector;
2023-10-19 15:00:19 +08:00
using Sirenix.Utilities.Editor;
2024-05-15 17:15:25 +08:00
using Sirenix.OdinInspector.Editor;
2025-11-05 13:09:30 +08:00
using Obfuz.Settings;
2023-10-19 15:00:19 +08:00
public class BuildWindow : OdinEditorWindow
{
private static BuildWindow thisWindow;
2025-02-27 13:31:47 +08:00
[MenuItem("Tools/*打包工具", false, (int)NLDMenuID.BuildTools)]
2023-10-19 15:00:19 +08:00
public static void ShowWindow()
{
thisWindow = GetWindow<BuildWindow>();
thisWindow.position = GUIHelper.GetEditorWindowRect().AlignCenter(600, 300);
2023-11-08 17:33:46 +08:00
}
2024-05-15 17:15:25 +08:00
2024-11-21 18:56:50 +08:00
#region MainLife
2023-11-08 17:33:46 +08:00
protected override void OnEnable()
{
2024-11-21 18:56:50 +08:00
var buildTargetString = PlayerPrefs.GetString("BuildTarget");
2023-11-08 17:33:46 +08:00
if (Enum.TryParse<BuildTarget>(buildTargetString, out BuildTarget parsedBuildTarget))
{
2024-05-15 17:15:25 +08:00
buildTarget = parsedBuildTarget;
2023-11-08 17:33:46 +08:00
}
2024-05-15 17:15:25 +08:00
2023-11-08 17:33:46 +08:00
version = PlayerPrefs.GetString("Version");
2024-05-15 17:15:25 +08:00
workSpace = PlayerPrefs.GetString("WorkSpace");
2024-11-21 18:56:50 +08:00
localBuild = BuildUtils.ConvertBool(PlayerPrefs.GetString("LocalBuild"));
remoteBuild = BuildUtils.ConvertBool(PlayerPrefs.GetString("RemoteBuild"));
enableHotUpdateDll = BuildUtils.ConvertBool(PlayerPrefs.GetString("IgnoreHotUpdateDll"));
2023-11-08 17:33:46 +08:00
}
2023-10-19 15:00:19 +08:00
2023-11-08 17:33:46 +08:00
protected override void OnDisable()
{
2024-11-21 18:56:50 +08:00
PlayerPrefs.SetString("LocalBuild", localBuild.ToString());
PlayerPrefs.SetString("RemoteBuild", remoteBuild.ToString());
2024-05-15 17:15:25 +08:00
PlayerPrefs.SetString("BuildTarget", buildTarget.ToString());
2023-11-08 17:33:46 +08:00
PlayerPrefs.SetString("Version", version);
2024-05-15 17:15:25 +08:00
PlayerPrefs.SetString("WorkSpace", workSpace);
PlayerPrefs.SetString("IgnoreHotUpdateDll", enableHotUpdateDll.ToString());
2023-11-08 17:33:46 +08:00
PlayerPrefs.Save();
}
2024-05-15 17:15:25 +08:00
2024-11-21 18:56:50 +08:00
#endregion
2023-10-19 15:00:19 +08:00
2024-11-21 18:56:50 +08:00
#region Build Param
2023-10-19 15:00:19 +08:00
2024-11-21 18:56:50 +08:00
[InfoBox("远程包需要在OSS服务器中上传对应AppConfig例如server.渠道.0.1.0.xml ")]
[InfoBox("上传资源需要先配置服务器SSH密钥终端输入[ssh-copy-id -i ~/.ssh/密钥 root@1.14.62.163]")]
[InfoBox("请勿提交任何打包修改")]
[VerticalGroup("TargetParam")]
[LabelText("打包平台"), LabelWidth(150)]
2024-05-15 17:15:25 +08:00
public BuildTarget buildTarget = BuildTarget.Android;
2023-10-19 15:00:19 +08:00
2024-05-15 17:15:25 +08:00
[VerticalGroup("Version")] [LabelText("版本号"), LabelWidth(150)]
2023-10-19 15:00:19 +08:00
public string version;
2024-11-21 18:56:50 +08:00
[VerticalGroup("developmentBuild")] [LabelText("Development Build"), LabelWidth(150)]
public bool developmentBuild;
2023-10-19 15:00:19 +08:00
2024-11-21 18:56:50 +08:00
[HorizontalGroup("PackageMode")] [LabelText("本地包")] [OnValueChanged("OnLocalBuildChanged")]
public bool localBuild;
2023-10-19 15:00:19 +08:00
2024-11-21 18:56:50 +08:00
[HorizontalGroup("PackageMode")] [LabelText("远程包")] [OnValueChanged("OnRemoteBuildChanged")]
public bool remoteBuild;
2023-10-19 15:00:19 +08:00
2024-11-21 18:56:50 +08:00
[VerticalGroup("WorkSpace")]
[InfoBox("远程包需要创建一个对应渠道的AppConfig")]
[LabelText("渠道"), LabelWidth(150), ShowIf("remoteBuild")]
public string workSpace = "Dev";
[VerticalGroup("HotUpdate")] [LabelText("开启热更新"), LabelWidth(150), ShowIf("remoteBuild")]
2024-05-15 17:15:25 +08:00
public bool enableHotUpdateDll;
2023-10-19 15:00:19 +08:00
2024-11-21 18:56:50 +08:00
[HideInInspector] public string profileName = "AllLocal";
2023-10-19 15:00:19 +08:00
2024-11-21 18:56:50 +08:00
#endregion
#region OnValuChanged
private void OnLocalBuildChanged()
2023-10-19 15:00:19 +08:00
{
2024-11-21 18:56:50 +08:00
if (localBuild && remoteBuild)
remoteBuild = false;
if (localBuild)
{
workSpace = "Dev";
profileName = "AllLocal";
}
enableHotUpdateDll = !localBuild;
2023-10-19 15:00:19 +08:00
}
2024-11-19 14:12:28 +08:00
2024-11-21 18:56:50 +08:00
private void OnRemoteBuildChanged()
2024-05-21 17:04:32 +08:00
{
2024-11-21 18:56:50 +08:00
if (localBuild && remoteBuild)
localBuild = false;
if (remoteBuild)
{
enableHotUpdateDll = true;
profileName = "Debug";
workSpace = "";
}
2024-05-21 17:04:32 +08:00
}
2023-10-19 15:00:19 +08:00
2024-11-21 18:56:50 +08:00
#endregion
#region Build
[PropertySpace(10)]
2023-10-19 15:00:19 +08:00
[HorizontalGroup("package")]
2024-11-21 18:56:50 +08:00
[Button("构建资源和包体")]
2024-05-15 17:15:25 +08:00
private void BuildResourceAndPlayer()
2023-10-19 15:00:19 +08:00
{
2024-11-21 18:56:50 +08:00
if (!CheckParam()) return;
2024-05-15 17:15:25 +08:00
BuildLauncher.Init(buildTarget, workSpace, version, profileName, developmentBuild, enableHotUpdateDll);
2024-11-19 14:12:28 +08:00
BuildLauncher.BuildResourceAndPlayer();
AssetDatabase.SaveAssets();
2023-10-19 15:00:19 +08:00
}
2024-11-21 18:56:50 +08:00
[PropertySpace(10)]
[HorizontalGroup("package/2")]
[Button("热更")]
private void UpdatePreviousBuild()
{
if (!CheckParam()) return;
BuildLauncher.Init(buildTarget, workSpace, version, profileName, developmentBuild, enableHotUpdateDll);
BuildLauncher.UpdatePreviousBuild(workSpace, version, buildTarget);
}
[HorizontalGroup("package2")]
[PropertySpace(10)]
[Button("单独构建资源")]
private void BuildResource()
{
if (!CheckParam()) return;
BuildLauncher.Init(buildTarget, workSpace, version, profileName, developmentBuild, enableHotUpdateDll);
BuildLauncher.BuildResource();
}
[PropertySpace(10)]
[HorizontalGroup("package2/1")]
2024-11-21 14:16:06 +08:00
[Button("上传资源")]
private void UploadResource()
{
2024-11-21 18:56:50 +08:00
if (!CheckParam()) return;
2024-11-21 14:16:06 +08:00
BuildLauncher.UploadToServer(workSpace, version, buildTarget);
}
2023-10-19 15:00:19 +08:00
2024-11-21 18:56:50 +08:00
[HorizontalGroup("package3")]
[PropertySpace(10)]
[Button("单独构建热更")]
private void BuildHotUpdateDlls()
2023-10-19 15:00:19 +08:00
{
2024-11-21 18:56:50 +08:00
BuildLauncher.BuildHotUpdateDlls();
}
2023-10-19 15:00:19 +08:00
2023-11-08 17:33:46 +08:00
[PropertySpace(10)]
2024-11-21 18:56:50 +08:00
[HorizontalGroup("package3/1")]
[Button("单独构建包体")]
2023-10-19 15:00:19 +08:00
private void OnBuildPlayer()
{
2024-11-21 18:56:50 +08:00
if (!CheckParam()) return;
2024-05-15 17:15:25 +08:00
BuildLauncher.Init(buildTarget, workSpace, version, profileName, developmentBuild, enableHotUpdateDll);
2024-11-19 14:12:28 +08:00
BuildLauncher.BuildPlayer();
2023-10-19 15:00:19 +08:00
}
2024-05-15 17:15:25 +08:00
2024-11-21 18:56:50 +08:00
#endregion
#region API
2023-11-08 17:33:46 +08:00
[PropertySpace(10)]
[HorizontalGroup("Clean")]
[Button("还原设置")]
private void RevertSettings()
{
2024-05-15 17:15:25 +08:00
buildTarget = BuildTarget.Android;
2023-11-08 17:33:46 +08:00
version = PlayerSettings.bundleVersion;
2024-11-21 18:56:50 +08:00
workSpace = "Dev";
enableHotUpdateDll = true;
2024-01-22 17:51:43 +08:00
developmentBuild = true;
2024-11-21 18:56:50 +08:00
localBuild = false;
remoteBuild = false;
2023-11-08 17:33:46 +08:00
}
2024-05-15 18:38:52 +08:00
2024-11-21 18:56:50 +08:00
private bool CheckParam()
2024-05-15 17:15:25 +08:00
{
2024-11-21 18:56:50 +08:00
if (!localBuild && !remoteBuild)
2024-05-15 17:15:25 +08:00
{
2024-11-21 18:56:50 +08:00
DebugUtil.LogError("请选择打包方式");
return false;
2024-05-15 17:15:25 +08:00
}
2024-11-21 18:56:50 +08:00
if (!profileName.Equals("Debug") && !profileName.Equals("AllLocal"))
{
return false;
}
2024-05-15 17:15:25 +08:00
2024-11-21 18:56:50 +08:00
if (string.IsNullOrEmpty(workSpace))
{
DebugUtil.LogError("渠道不能为空");
return false;
}
2024-05-15 17:15:25 +08:00
2024-11-21 18:56:50 +08:00
if (localBuild && !workSpace.Equals("Dev"))
2024-05-15 17:15:25 +08:00
{
2024-11-21 18:56:50 +08:00
DebugUtil.LogError("打本地包渠道需要设置为Dev");
return false;
2024-05-15 17:15:25 +08:00
}
2024-11-21 18:56:50 +08:00
if (string.IsNullOrEmpty(version))
2024-05-15 17:15:25 +08:00
{
2024-11-21 18:56:50 +08:00
DebugUtil.LogError("版本号不能为空");
return false;
2024-05-15 17:15:25 +08:00
}
2024-11-21 18:56:50 +08:00
return true;
2024-05-15 17:15:25 +08:00
}
2024-11-21 18:56:50 +08:00
#endregion
2024-05-15 17:15:25 +08:00
}