225 lines
6.6 KiB
C#
225 lines
6.6 KiB
C#
using System;
|
||
using UnityEditor;
|
||
using UnityEngine;
|
||
using Sirenix.Utilities;
|
||
using Sirenix.OdinInspector;
|
||
using Sirenix.Utilities.Editor;
|
||
using Sirenix.OdinInspector.Editor;
|
||
|
||
public class BuildWindow : OdinEditorWindow
|
||
{
|
||
private static BuildWindow thisWindow;
|
||
|
||
[MenuItem("Tools/*打包工具", false, (int)NLDMenuID.BuildTools)]
|
||
public static void ShowWindow()
|
||
{
|
||
thisWindow = GetWindow<BuildWindow>();
|
||
thisWindow.position = GUIHelper.GetEditorWindowRect().AlignCenter(600, 300);
|
||
}
|
||
|
||
#region MainLife
|
||
|
||
protected override void OnEnable()
|
||
{
|
||
var buildTargetString = PlayerPrefs.GetString("BuildTarget");
|
||
if (Enum.TryParse<BuildTarget>(buildTargetString, out BuildTarget parsedBuildTarget))
|
||
{
|
||
buildTarget = parsedBuildTarget;
|
||
}
|
||
|
||
version = PlayerPrefs.GetString("Version");
|
||
workSpace = PlayerPrefs.GetString("WorkSpace");
|
||
localBuild = BuildUtils.ConvertBool(PlayerPrefs.GetString("LocalBuild"));
|
||
remoteBuild = BuildUtils.ConvertBool(PlayerPrefs.GetString("RemoteBuild"));
|
||
enableHotUpdateDll = BuildUtils.ConvertBool(PlayerPrefs.GetString("IgnoreHotUpdateDll"));
|
||
}
|
||
|
||
protected override void OnDisable()
|
||
{
|
||
PlayerPrefs.SetString("LocalBuild", localBuild.ToString());
|
||
PlayerPrefs.SetString("RemoteBuild", remoteBuild.ToString());
|
||
PlayerPrefs.SetString("BuildTarget", buildTarget.ToString());
|
||
PlayerPrefs.SetString("Version", version);
|
||
PlayerPrefs.SetString("WorkSpace", workSpace);
|
||
PlayerPrefs.SetString("IgnoreHotUpdateDll", enableHotUpdateDll.ToString());
|
||
PlayerPrefs.Save();
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region Build Param
|
||
|
||
[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)]
|
||
public BuildTarget buildTarget = BuildTarget.Android;
|
||
|
||
[VerticalGroup("Version")] [LabelText("版本号"), LabelWidth(150)]
|
||
public string version;
|
||
|
||
[VerticalGroup("developmentBuild")] [LabelText("Development Build"), LabelWidth(150)]
|
||
public bool developmentBuild;
|
||
|
||
[HorizontalGroup("PackageMode")] [LabelText("本地包")] [OnValueChanged("OnLocalBuildChanged")]
|
||
public bool localBuild;
|
||
|
||
[HorizontalGroup("PackageMode")] [LabelText("远程包")] [OnValueChanged("OnRemoteBuildChanged")]
|
||
public bool remoteBuild;
|
||
|
||
[VerticalGroup("WorkSpace")]
|
||
[InfoBox("远程包需要创建一个对应渠道的AppConfig")]
|
||
[LabelText("渠道"), LabelWidth(150), ShowIf("remoteBuild")]
|
||
public string workSpace = "Dev";
|
||
|
||
[VerticalGroup("HotUpdate")] [LabelText("开启热更新"), LabelWidth(150), ShowIf("remoteBuild")]
|
||
public bool enableHotUpdateDll;
|
||
|
||
[HideInInspector] public string profileName = "AllLocal";
|
||
|
||
#endregion
|
||
|
||
#region OnValuChanged
|
||
|
||
private void OnLocalBuildChanged()
|
||
{
|
||
if (localBuild && remoteBuild)
|
||
remoteBuild = false;
|
||
if (localBuild)
|
||
{
|
||
workSpace = "Dev";
|
||
profileName = "AllLocal";
|
||
}
|
||
|
||
enableHotUpdateDll = !localBuild;
|
||
}
|
||
|
||
private void OnRemoteBuildChanged()
|
||
{
|
||
if (localBuild && remoteBuild)
|
||
localBuild = false;
|
||
if (remoteBuild)
|
||
{
|
||
enableHotUpdateDll = true;
|
||
profileName = "Debug";
|
||
workSpace = "";
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region Build
|
||
|
||
[PropertySpace(10)]
|
||
[HorizontalGroup("package")]
|
||
[Button("构建资源和包体")]
|
||
private void BuildResourceAndPlayer()
|
||
{
|
||
if (!CheckParam()) return;
|
||
BuildLauncher.Init(buildTarget, workSpace, version, profileName, developmentBuild, enableHotUpdateDll);
|
||
BuildLauncher.BuildResourceAndPlayer();
|
||
AssetDatabase.SaveAssets();
|
||
}
|
||
|
||
[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")]
|
||
[Button("上传资源")]
|
||
private void UploadResource()
|
||
{
|
||
if (!CheckParam()) return;
|
||
BuildLauncher.UploadToServer(workSpace, version, buildTarget);
|
||
}
|
||
|
||
[HorizontalGroup("package3")]
|
||
[PropertySpace(10)]
|
||
[Button("单独构建热更")]
|
||
private void BuildHotUpdateDlls()
|
||
{
|
||
BuildLauncher.BuildHotUpdateDlls();
|
||
}
|
||
|
||
[PropertySpace(10)]
|
||
[HorizontalGroup("package3/1")]
|
||
[Button("单独构建包体")]
|
||
private void OnBuildPlayer()
|
||
{
|
||
if (!CheckParam()) return;
|
||
BuildLauncher.Init(buildTarget, workSpace, version, profileName, developmentBuild, enableHotUpdateDll);
|
||
BuildLauncher.BuildPlayer();
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region API
|
||
|
||
[PropertySpace(10)]
|
||
[HorizontalGroup("Clean")]
|
||
[Button("还原设置")]
|
||
private void RevertSettings()
|
||
{
|
||
buildTarget = BuildTarget.Android;
|
||
version = PlayerSettings.bundleVersion;
|
||
workSpace = "Dev";
|
||
enableHotUpdateDll = true;
|
||
developmentBuild = true;
|
||
localBuild = false;
|
||
remoteBuild = false;
|
||
}
|
||
|
||
private bool CheckParam()
|
||
{
|
||
if (!localBuild && !remoteBuild)
|
||
{
|
||
DebugUtil.LogError("请选择打包方式");
|
||
return false;
|
||
}
|
||
|
||
if (!profileName.Equals("Debug") && !profileName.Equals("AllLocal"))
|
||
{
|
||
return false;
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(workSpace))
|
||
{
|
||
DebugUtil.LogError("渠道不能为空");
|
||
return false;
|
||
}
|
||
|
||
if (localBuild && !workSpace.Equals("Dev"))
|
||
{
|
||
DebugUtil.LogError("打本地包,渠道需要设置为Dev");
|
||
return false;
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(version))
|
||
{
|
||
DebugUtil.LogError("版本号不能为空");
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
#endregion
|
||
} |