2025-03-31 11:16:52 +08:00
|
|
|
|
/****************************************************
|
|
|
|
|
|
文件:BuildAssetWindow.cs
|
|
|
|
|
|
作者:xosmo_
|
|
|
|
|
|
邮箱:
|
|
|
|
|
|
日期:2025/3/10 10:43:20
|
|
|
|
|
|
功能:
|
|
|
|
|
|
*****************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
2025-05-23 18:26:47 +08:00
|
|
|
|
using System.IO.Compression;
|
2025-03-31 11:16:52 +08:00
|
|
|
|
using System.Linq;
|
2025-05-30 14:50:46 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2025-03-31 11:16:52 +08:00
|
|
|
|
using EditorFramework;
|
|
|
|
|
|
using HybridCLR.Editor;
|
|
|
|
|
|
using HybridCLR.Editor.Commands;
|
2025-05-30 14:50:46 +08:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
2025-03-31 11:16:52 +08:00
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
|
|
using Sirenix.OdinInspector.Editor;
|
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
|
using UnityEditorInternal;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.Serialization;
|
|
|
|
|
|
using YooAsset;
|
|
|
|
|
|
using YooAsset.Editor;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Stary.Evo.Editor
|
|
|
|
|
|
{
|
|
|
|
|
|
public class BuildAssetWindow : OdinEditorWindow
|
|
|
|
|
|
{
|
2025-05-30 14:50:46 +08:00
|
|
|
|
public static OdinEditorWindow window;
|
2025-04-27 10:22:16 +08:00
|
|
|
|
|
2025-05-06 11:36:31 +08:00
|
|
|
|
|
2025-03-31 11:16:52 +08:00
|
|
|
|
[MenuItem("Evo/资源打包工具")]
|
|
|
|
|
|
static void ShowWindows()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (CreatAssetWindow.GetCreatDomainAll().Count <= 0)
|
|
|
|
|
|
{
|
2025-04-27 10:22:16 +08:00
|
|
|
|
EditorUtility.DisplayDialog("提示", "不存在Domain元素,无法打开此面板,请先创建Domain元素", "确定");
|
2025-03-31 11:16:52 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-04-27 10:22:16 +08:00
|
|
|
|
|
2025-03-31 11:16:52 +08:00
|
|
|
|
window = (BuildAssetWindow)EditorWindow.GetWindow(typeof(BuildAssetWindow));
|
|
|
|
|
|
window.Show();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-05 17:12:56 +08:00
|
|
|
|
protected override void OnDisable()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnDisable();
|
|
|
|
|
|
EditorUtility.ClearProgressBar();
|
|
|
|
|
|
}
|
2025-03-31 11:16:52 +08:00
|
|
|
|
|
2025-05-30 14:50:46 +08:00
|
|
|
|
protected override async void Initialize()
|
2025-03-31 11:16:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
GetBuildPackageNames();
|
2025-05-30 14:50:46 +08:00
|
|
|
|
UpdateMessage(false);
|
|
|
|
|
|
if (string.IsNullOrEmpty(ip))
|
|
|
|
|
|
{
|
|
|
|
|
|
buildAssetType = BuildAssetType.Login;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool isValidateToken = await WebRequestSystem.GetValidateToken(ip + "/Authentication/validateToken");
|
|
|
|
|
|
if (isValidateToken)
|
|
|
|
|
|
{
|
|
|
|
|
|
buildAssetType = BuildAssetType.Build;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buildAssetType = BuildAssetType.Login;
|
2025-03-31 11:16:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void RemoveBuildAssetWindow()
|
|
|
|
|
|
{
|
2025-04-27 10:22:16 +08:00
|
|
|
|
if (window != null)
|
|
|
|
|
|
window.Close();
|
2025-03-31 11:16:52 +08:00
|
|
|
|
}
|
2025-04-27 10:22:16 +08:00
|
|
|
|
|
2025-05-30 14:50:46 +08:00
|
|
|
|
[EnumToggleButtons, HideLabel] public BuildAssetType buildAssetType;
|
|
|
|
|
|
|
|
|
|
|
|
#region BuildAssetLogin
|
|
|
|
|
|
|
|
|
|
|
|
[ShowIf("@ buildAssetType== BuildAssetType.Login")] [BoxGroup("Login", showLabel: false)]
|
|
|
|
|
|
public string ip, userName, password;
|
2025-06-23 16:07:27 +08:00
|
|
|
|
|
2025-05-30 14:50:46 +08:00
|
|
|
|
[ShowIf("@ buildAssetType== BuildAssetType.Login")]
|
|
|
|
|
|
[BoxGroup("Login", showLabel: false)]
|
|
|
|
|
|
[Button("登录", ButtonSizes.Large)]
|
|
|
|
|
|
[InfoBox("@ message", InfoMessageType.Info)]
|
|
|
|
|
|
public async void LoginButton()
|
|
|
|
|
|
{
|
|
|
|
|
|
string url = ip + "/Authentication/login";
|
2025-06-05 17:12:56 +08:00
|
|
|
|
EditorUtility.DisplayProgressBar("提示", $"登陆中~", 0f);
|
2025-05-30 14:50:46 +08:00
|
|
|
|
bool islogin = await WebRequestSystem.Login(url, userName, password);
|
2025-06-05 17:12:56 +08:00
|
|
|
|
float progress = 0f;
|
2025-06-12 12:21:02 +08:00
|
|
|
|
while (progress >= 1f)
|
2025-06-05 17:12:56 +08:00
|
|
|
|
{
|
|
|
|
|
|
progress += 0.1f;
|
|
|
|
|
|
EditorUtility.DisplayProgressBar("提示", $"登陆中~", progress);
|
|
|
|
|
|
await Task.Delay(TimeSpan.FromSeconds(0.2f));
|
|
|
|
|
|
}
|
2025-06-12 12:21:02 +08:00
|
|
|
|
|
2025-06-05 17:12:56 +08:00
|
|
|
|
EditorUtility.ClearProgressBar();
|
2025-05-30 14:50:46 +08:00
|
|
|
|
UpdateMessage(islogin);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string message;
|
|
|
|
|
|
|
|
|
|
|
|
public async void UpdateMessage(bool islogin)
|
|
|
|
|
|
{
|
|
|
|
|
|
message = "当前登录状态为:" + islogin;
|
2025-06-13 11:09:42 +08:00
|
|
|
|
//初始化读取资源配置表
|
|
|
|
|
|
HotfixMainResDomain hotfixMainResDomain = Resources.Load<HotfixMainResDomain>("HotfixMainResDomain");
|
|
|
|
|
|
if (hotfixMainResDomain == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError($"UnityEvo:读取资源配置表失败【HotfixMainResDomain】...表不存在");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
ip = hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig;
|
|
|
|
|
|
userName = hotfixMainResDomain.hotfixMainResDomainEntity.username;
|
|
|
|
|
|
password = hotfixMainResDomain.hotfixMainResDomainEntity.password;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-30 14:50:46 +08:00
|
|
|
|
if (islogin)
|
|
|
|
|
|
{
|
|
|
|
|
|
buildAssetType = BuildAssetType.Build;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2025-03-31 11:16:52 +08:00
|
|
|
|
protected void OnSelectionChange()
|
|
|
|
|
|
{
|
|
|
|
|
|
EditorUtility.SetDirty(BuildAssetDataSetting);
|
|
|
|
|
|
AssetDatabase.SaveAssets();
|
|
|
|
|
|
//AssetDatabase.Refresh();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-30 14:50:46 +08:00
|
|
|
|
[BoxGroup("Build", showLabel: false)]
|
|
|
|
|
|
[ShowIf("@ buildAssetType== BuildAssetType.Build")]
|
2025-03-31 11:16:52 +08:00
|
|
|
|
[Title("包裹列表", titleAlignment: TitleAlignments.Centered)]
|
2025-05-30 14:50:46 +08:00
|
|
|
|
[HorizontalGroup("Build/BuildPipeline"), HideLabel]
|
2025-03-31 11:16:52 +08:00
|
|
|
|
[ValueDropdown("GetBuildPackageNames")]
|
|
|
|
|
|
[OnValueChanged("SetBuildPackageNames")]
|
|
|
|
|
|
public string selectedPackageNames;
|
2025-04-27 10:22:16 +08:00
|
|
|
|
|
2025-05-30 14:50:46 +08:00
|
|
|
|
[BoxGroup("Build", showLabel: false)]
|
|
|
|
|
|
[ShowIf("@ buildAssetType== BuildAssetType.Build")]
|
2025-04-27 10:22:16 +08:00
|
|
|
|
[Title("当前打包平台", titleAlignment: TitleAlignments.Centered)]
|
|
|
|
|
|
[ReadOnly]
|
2025-05-30 14:50:46 +08:00
|
|
|
|
[HorizontalGroup("Build/BuildPipeline"), HideLabel]
|
2025-04-27 10:22:16 +08:00
|
|
|
|
public string buildTarget;
|
|
|
|
|
|
|
2025-03-31 11:16:52 +08:00
|
|
|
|
public static string packageName;
|
2025-04-27 10:22:16 +08:00
|
|
|
|
|
2025-03-31 11:16:52 +08:00
|
|
|
|
#region HyBridCLRBuild
|
|
|
|
|
|
|
2025-05-30 14:50:46 +08:00
|
|
|
|
[BoxGroup("Build", showLabel: false)]
|
2025-06-19 14:57:58 +08:00
|
|
|
|
[HideIf("@ buildAssetType!= BuildAssetType.Build")]
|
2025-05-30 14:50:46 +08:00
|
|
|
|
[Title("打包dll(子包仅打一次)", titleAlignment: TitleAlignments.Centered)]
|
|
|
|
|
|
[HorizontalGroup("Build/HyBridClrBuildEntity"), HideLabel]
|
2025-03-31 11:16:52 +08:00
|
|
|
|
public BuildAssetEntity hyBridClrBuildEntity =
|
2025-04-27 10:22:16 +08:00
|
|
|
|
new BuildAssetEntity("HyBridCLRBuild", "DllBuildTarget", () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
//PrebuildCommand.GenerateAll();
|
|
|
|
|
|
CompileDllCommand.CompileDllActiveBuildTarget();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-03-31 11:16:52 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region MarkAsset
|
|
|
|
|
|
|
2025-05-30 14:50:46 +08:00
|
|
|
|
[BoxGroup("Build", showLabel: false)]
|
|
|
|
|
|
[ShowIf("@ buildAssetType== BuildAssetType.Build")]
|
|
|
|
|
|
[Title("标记资源", titleAlignment: TitleAlignments.Centered)]
|
|
|
|
|
|
[HorizontalGroup("Build/HyBridClrBuildEntity"), HideLabel]
|
2025-03-31 11:16:52 +08:00
|
|
|
|
public BuildAssetEntity markAssetEntity =
|
|
|
|
|
|
new BuildAssetEntity("MarkAsset", "MarkAsset", MarkAdressable.AddMark);
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region BuildAsset
|
|
|
|
|
|
|
2025-05-30 14:50:46 +08:00
|
|
|
|
[BoxGroup("Build", showLabel: false)]
|
|
|
|
|
|
[ShowIf("@ buildAssetType== BuildAssetType.Build")]
|
|
|
|
|
|
[InlineEditor(InlineEditorObjectFieldModes.CompletelyHidden)]
|
|
|
|
|
|
[HideLabel]
|
2025-04-27 10:22:16 +08:00
|
|
|
|
public BuildAssetDataSetting BuildAssetDataSetting;
|
2025-03-31 11:16:52 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 检测当前所有包裹
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private List<string> GetBuildPackageNames()
|
|
|
|
|
|
{
|
|
|
|
|
|
List<string> result = new List<string>();
|
2025-04-27 10:22:16 +08:00
|
|
|
|
foreach (var name in CreatAssetWindow.GetCreatDomainAllName())
|
2025-03-31 11:16:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
result.Add(name);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (selectedPackageNames.IsNullOrEmpty())
|
|
|
|
|
|
{
|
|
|
|
|
|
// string buildPackageName = DataSetting.packageName;
|
|
|
|
|
|
// if (result.Exists(p => p == buildPackageName))
|
|
|
|
|
|
// {
|
|
|
|
|
|
// selectedPackageNames = buildPackageName;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else
|
|
|
|
|
|
// {
|
|
|
|
|
|
selectedPackageNames = result[0];
|
|
|
|
|
|
//}
|
|
|
|
|
|
}
|
2025-04-27 10:22:16 +08:00
|
|
|
|
|
2025-03-31 11:16:52 +08:00
|
|
|
|
SetBuildPackageNames();
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设置当前包裹
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private void SetBuildPackageNames()
|
|
|
|
|
|
{
|
|
|
|
|
|
//PlayerPrefs.SetString("BuildPackageNames", selectedPackageNames);
|
|
|
|
|
|
// DataSetting.packageName = selectedPackageNames;
|
2025-06-12 12:21:02 +08:00
|
|
|
|
|
2025-06-12 12:28:19 +08:00
|
|
|
|
|
2025-03-31 11:16:52 +08:00
|
|
|
|
// DataSetting = Resources.Load<BuildAssetDataSetting>("BuildAssetDataSetting");
|
2025-06-12 12:21:02 +08:00
|
|
|
|
string buildAssetDataSettingPath =
|
|
|
|
|
|
$"Assets/Domain/{selectedPackageNames}/Conf/BuildAssetDataSetting.asset";
|
2025-03-31 11:16:52 +08:00
|
|
|
|
BuildAssetDataSetting buildAssetDataSetting =
|
|
|
|
|
|
AssetDatabase.LoadAssetAtPath<BuildAssetDataSetting>(buildAssetDataSettingPath);
|
|
|
|
|
|
if (buildAssetDataSetting != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
BuildAssetDataSetting = buildAssetDataSetting;
|
|
|
|
|
|
Init();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError($"UnityEvo:BuildAssetDataSetting 不存在,请检查路径{buildAssetDataSettingPath}");
|
|
|
|
|
|
}
|
2025-06-12 12:03:00 +08:00
|
|
|
|
|
2025-06-12 12:21:02 +08:00
|
|
|
|
if (selectedPackageNames != packageName)
|
|
|
|
|
|
{
|
|
|
|
|
|
GetHostBuildPackageVersion(buildAssetDataSetting);
|
|
|
|
|
|
}
|
2025-06-12 12:28:19 +08:00
|
|
|
|
|
2025-06-12 12:21:02 +08:00
|
|
|
|
packageName = selectedPackageNames;
|
2025-03-31 11:16:52 +08:00
|
|
|
|
}
|
2025-04-27 10:22:16 +08:00
|
|
|
|
|
2025-03-31 11:16:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取当前包裹
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static string GetBuildPackageName()
|
|
|
|
|
|
{
|
|
|
|
|
|
return packageName;
|
|
|
|
|
|
}
|
2025-04-27 10:22:16 +08:00
|
|
|
|
|
2025-03-31 11:16:52 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Update
|
2025-05-23 18:26:47 +08:00
|
|
|
|
|
2025-05-30 14:50:46 +08:00
|
|
|
|
[BoxGroup("Build", showLabel: false)]
|
|
|
|
|
|
[ShowIf("@ buildAssetType== BuildAssetType.Build")]
|
|
|
|
|
|
[Title("打包本地资源", titleAlignment: TitleAlignments.Centered)]
|
|
|
|
|
|
[HideLabel]
|
2025-03-31 11:16:52 +08:00
|
|
|
|
public BuildAssetEntity onBuildPipelineEntity;
|
|
|
|
|
|
|
2025-05-30 14:50:46 +08:00
|
|
|
|
[BoxGroup("Build", showLabel: false)]
|
|
|
|
|
|
[Title("上传资源", titleAlignment: TitleAlignments.Centered)]
|
2025-04-27 10:22:16 +08:00
|
|
|
|
[HideLabel]
|
|
|
|
|
|
[ShowIf(
|
2025-06-19 14:57:58 +08:00
|
|
|
|
"@ BuildAssetDataSetting.environmentType== EnvironmentType.Release && buildAssetType== BuildAssetType.Build")]
|
2025-03-31 11:16:52 +08:00
|
|
|
|
public BuildAssetEntity onUpdateBuildPipelineEntity;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void OnBuildPipeline()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (EditorUtility.DisplayDialog("提示", $"开始构建资源包[{selectedPackageNames}]!", "Yes", "No"))
|
|
|
|
|
|
{
|
|
|
|
|
|
EditorTools.ClearUnityConsole();
|
|
|
|
|
|
EditorApplication.delayCall += BuildAssetDataSetting.viewer.ExecuteBuild;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogWarning("[Build] 打包已经取消");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-30 14:50:46 +08:00
|
|
|
|
private async void OnUpdateBuildPipeline()
|
2025-03-31 11:16:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (EditorUtility.DisplayDialog("提示", $"开始上传至服务器[{selectedPackageNames}]!", "Yes", "No"))
|
|
|
|
|
|
{
|
2025-05-23 18:26:47 +08:00
|
|
|
|
// 新增:打包为zip的逻辑
|
2025-05-30 17:00:07 +08:00
|
|
|
|
string zipFilePath = BuildZip(BuildAssetDataSetting);
|
|
|
|
|
|
await UpdateFileDataResDomain(BuildAssetDataSetting, zipFilePath);
|
|
|
|
|
|
await Task.Delay(1000);
|
|
|
|
|
|
EditorUtility.ClearProgressBar();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
EditorUtility.ClearProgressBar();
|
|
|
|
|
|
EditorUtility.DisplayDialog("提示", "Update] 上传已经取消", "确定");
|
|
|
|
|
|
Debug.LogWarning("[Update] 上传已经取消");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-12 12:21:02 +08:00
|
|
|
|
|
2025-05-30 17:00:07 +08:00
|
|
|
|
public static string BuildZip(BuildAssetDataSetting setting)
|
|
|
|
|
|
{
|
|
|
|
|
|
EditorUtility.DisplayProgressBar("提示", $"开始上传{setting.packageName}(打包zip)", 0.0f);
|
|
|
|
|
|
// 新增:打包为zip的逻辑
|
|
|
|
|
|
string zipFileName =
|
|
|
|
|
|
$"{setting.packageName}_{setting.packageVersion}.zip";
|
|
|
|
|
|
var outputPackageDirectory =
|
|
|
|
|
|
$"{AssetBundleBuilderHelper.GetDefaultBuildOutputRoot()}/{EditorUserBuildSettings.activeBuildTarget}/{setting.packageName}";
|
|
|
|
|
|
//拷贝目录
|
|
|
|
|
|
string outFilePath = $"{outputPackageDirectory}/{setting.packageVersion}";
|
2025-06-12 12:21:02 +08:00
|
|
|
|
|
2025-06-11 18:28:57 +08:00
|
|
|
|
DefaultBuildinFileSystemBuild.CreateBuildinCatalogFile(setting.packageName, outFilePath);
|
2025-06-12 12:21:02 +08:00
|
|
|
|
|
2025-05-30 17:00:07 +08:00
|
|
|
|
//输出目录
|
|
|
|
|
|
string zipFilePath = Path.Combine(outputPackageDirectory, zipFileName);
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
using (FileStream zipStream = new FileStream(zipFilePath, FileMode.Create))
|
|
|
|
|
|
using (ZipArchive archive = new ZipArchive(zipStream, ZipArchiveMode.Create))
|
2025-05-23 18:26:47 +08:00
|
|
|
|
{
|
2025-05-30 17:00:07 +08:00
|
|
|
|
// 指定需要压缩的后缀(例如:只压缩.json和.dll文件)
|
|
|
|
|
|
//string[] targetExtensions = { ".bundle" };
|
|
|
|
|
|
|
|
|
|
|
|
// 遍历目录下所有文件
|
|
|
|
|
|
// foreach (string filePath in Directory.GetFiles(outFilePath, "*.*", SearchOption.AllDirectories)
|
|
|
|
|
|
// .Where(f => targetExtensions.Contains(Path.GetExtension(f),
|
|
|
|
|
|
// StringComparer.OrdinalIgnoreCase)))
|
|
|
|
|
|
foreach (string filePath in Directory.GetFiles(outFilePath, "*.*", SearchOption.AllDirectories))
|
2025-05-30 14:50:46 +08:00
|
|
|
|
{
|
2025-05-30 17:00:07 +08:00
|
|
|
|
// 获取文件在压缩包中的相对路径
|
|
|
|
|
|
string entryName = Path.GetRelativePath(outFilePath, filePath);
|
|
|
|
|
|
|
|
|
|
|
|
// 创建zip条目
|
|
|
|
|
|
ZipArchiveEntry entry = archive.CreateEntry(entryName,
|
|
|
|
|
|
System.IO.Compression.CompressionLevel.Optimal);
|
|
|
|
|
|
|
|
|
|
|
|
// 写入文件内容
|
|
|
|
|
|
using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
|
|
|
|
|
|
using (Stream entryStream = entry.Open())
|
2025-05-30 14:50:46 +08:00
|
|
|
|
{
|
2025-05-30 17:00:07 +08:00
|
|
|
|
fileStream.CopyTo(entryStream);
|
2025-05-30 14:50:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-05-23 18:26:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-30 17:00:07 +08:00
|
|
|
|
Debug.Log($"成功打包为zip:{zipFilePath}");
|
|
|
|
|
|
EditorUtility.DisplayProgressBar("提示", $"开始上传{setting.packageName}(打包zip)", 0.25f);
|
|
|
|
|
|
return zipFilePath;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError($"打包zip失败:{ex.Message}");
|
|
|
|
|
|
EditorUtility.ClearProgressBar();
|
|
|
|
|
|
return default;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static async Task UpdateFileDataResDomain(BuildAssetDataSetting setting, string zipFilePath)
|
|
|
|
|
|
{
|
2025-06-23 16:07:27 +08:00
|
|
|
|
//初始化读取资源配置表
|
|
|
|
|
|
HotfixMainResDomain hotfixMainResDomain = Resources.Load<HotfixMainResDomain>("HotfixMainResDomain");
|
|
|
|
|
|
if (hotfixMainResDomain == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError($"UnityEvo:读取资源配置表失败【HotfixMainResDomain】...表不存在");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
var ip = hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig;
|
2025-05-30 17:00:07 +08:00
|
|
|
|
var messageEntity = await WebRequestSystem.PostFile(ip + "/FileLoad/UpLoadFile", new[] { zipFilePath });
|
|
|
|
|
|
EditorUtility.DisplayProgressBar("提示", $"开始上传{setting.packageName}(上传zip文件)", 0.5f);
|
|
|
|
|
|
if (messageEntity.code == 200)
|
|
|
|
|
|
{
|
|
|
|
|
|
List<ResultMessageEntity> resultMessageEntities =
|
|
|
|
|
|
JsonConvert.DeserializeObject<List<ResultMessageEntity>>(messageEntity.data.ToString());
|
|
|
|
|
|
if (resultMessageEntities.Count > 0)
|
2025-05-30 14:50:46 +08:00
|
|
|
|
{
|
2025-05-30 17:00:07 +08:00
|
|
|
|
EditorUtility.DisplayProgressBar("提示", "开始上传(更新数据库)", 0.75f);
|
|
|
|
|
|
foreach (var resultMessageEntity in resultMessageEntities)
|
2025-05-30 14:50:46 +08:00
|
|
|
|
{
|
2025-05-30 17:00:07 +08:00
|
|
|
|
var data = JsonConvert.DeserializeObject(resultMessageEntity.data.ToString()) as JObject;
|
|
|
|
|
|
string fileId = data["id"].ToString();
|
|
|
|
|
|
ResDmainAddRequst resDmainAddRequst = new ResDmainAddRequst()
|
|
|
|
|
|
{
|
2025-06-12 12:03:00 +08:00
|
|
|
|
ProductName = Application.identifier,
|
2025-05-30 17:00:07 +08:00
|
|
|
|
DomainName = setting.packageName,
|
|
|
|
|
|
Platform = EditorUserBuildSettings.activeBuildTarget.ToString(),
|
|
|
|
|
|
PackageVersion = setting.packageVersion,
|
|
|
|
|
|
DocumentFileId = fileId
|
|
|
|
|
|
};
|
|
|
|
|
|
var resResultMessage = await WebRequestSystem.Post(ip + "/ResDomain/AddResDomain",
|
|
|
|
|
|
JsonConvert.SerializeObject(resDmainAddRequst));
|
|
|
|
|
|
//如果低于服务器版本,更新版本号
|
|
|
|
|
|
if (resResultMessage.code == 1009)
|
2025-05-30 14:50:46 +08:00
|
|
|
|
{
|
2025-05-30 17:00:07 +08:00
|
|
|
|
ResDmainVersionResponse dmainVersionResponse =
|
|
|
|
|
|
JsonConvert.DeserializeObject<ResDmainVersionResponse>(resResultMessage.data
|
|
|
|
|
|
.ToString());
|
|
|
|
|
|
string[] versions = dmainVersionResponse.PackageVersion.Split('.');
|
|
|
|
|
|
setting.packageVersionX = int.Parse(versions[0]);
|
|
|
|
|
|
setting.packageVersionY = int.Parse(versions[1]);
|
|
|
|
|
|
setting.packageVersionZ = int.Parse(versions[2]);
|
2025-05-30 14:50:46 +08:00
|
|
|
|
EditorUtility.DisplayDialog("提示",
|
|
|
|
|
|
$"{resResultMessage.message + $"\n{resResultMessage.data.ToString()}"}", "确定");
|
|
|
|
|
|
}
|
2025-04-27 10:22:16 +08:00
|
|
|
|
|
2025-05-30 17:00:07 +08:00
|
|
|
|
setting.GetBuildPackageVersion(true);
|
|
|
|
|
|
}
|
2025-04-27 10:22:16 +08:00
|
|
|
|
|
2025-05-30 17:00:07 +08:00
|
|
|
|
EditorUtility.DisplayProgressBar("提示", $"开始上传{setting.packageName}(更新数据库)", 1f);
|
|
|
|
|
|
}
|
2025-03-31 11:16:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-05-30 17:00:07 +08:00
|
|
|
|
EditorUtility.DisplayProgressBar("提示", $"{messageEntity.message}", 1f);
|
2025-03-31 11:16:52 +08:00
|
|
|
|
}
|
2025-05-30 17:00:07 +08:00
|
|
|
|
|
|
|
|
|
|
await Task.Delay(1000);
|
|
|
|
|
|
EditorUtility.ClearProgressBar();
|
|
|
|
|
|
return;
|
2025-03-31 11:16:52 +08:00
|
|
|
|
}
|
2025-06-12 12:21:02 +08:00
|
|
|
|
|
2025-06-12 12:03:00 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取服务器上版本号
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private async void GetHostBuildPackageVersion(BuildAssetDataSetting setting)
|
|
|
|
|
|
{
|
|
|
|
|
|
var resDmainAddRequst = new ResDmainRequst()
|
|
|
|
|
|
{
|
|
|
|
|
|
ProductName = Application.identifier,
|
|
|
|
|
|
DomainName = selectedPackageNames,
|
|
|
|
|
|
Platform = EditorUserBuildSettings.activeBuildTarget.ToString(),
|
|
|
|
|
|
};
|
|
|
|
|
|
var resResultMessage = await WebRequestSystem.Post(ip + "/ResDomain/GetResDomainByDomain",
|
|
|
|
|
|
JsonConvert.SerializeObject(resDmainAddRequst));
|
|
|
|
|
|
//如果低于服务器版本,更新版本号
|
|
|
|
|
|
if (resResultMessage.code != 1011)
|
|
|
|
|
|
{
|
|
|
|
|
|
ResDmainResponse domainResponse =
|
|
|
|
|
|
JsonConvert.DeserializeObject<ResDmainResponse>(resResultMessage.data
|
|
|
|
|
|
.ToString());
|
|
|
|
|
|
string[] versions = domainResponse.PackageVersion.Split('.');
|
|
|
|
|
|
setting.packageVersionX = int.Parse(versions[0]);
|
|
|
|
|
|
setting.packageVersionY = int.Parse(versions[1]);
|
|
|
|
|
|
setting.packageVersionZ = int.Parse(versions[2]);
|
|
|
|
|
|
setting.GetBuildPackageVersion(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
EditorUtility.DisplayDialog("提示",
|
|
|
|
|
|
$"{resResultMessage.message},默认1.0.0版本 ", "确定");
|
|
|
|
|
|
setting.packageVersionX = 1;
|
|
|
|
|
|
setting.packageVersionY = 0;
|
|
|
|
|
|
setting.packageVersionZ = 0;
|
|
|
|
|
|
setting.GetBuildPackageVersion(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-06-12 12:21:02 +08:00
|
|
|
|
|
2025-03-31 11:16:52 +08:00
|
|
|
|
#endregion
|
2025-04-27 10:22:16 +08:00
|
|
|
|
|
|
|
|
|
|
protected void Init()
|
2025-03-31 11:16:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
//Update
|
2025-04-27 10:22:16 +08:00
|
|
|
|
buildTarget = EditorUserBuildSettings.activeBuildTarget.ToString();
|
2025-03-31 11:16:52 +08:00
|
|
|
|
onBuildPipelineEntity =
|
|
|
|
|
|
new BuildAssetEntity("打包", $"打包资源包【版本:{BuildAssetDataSetting.packageVersion}】", OnBuildPipeline);
|
|
|
|
|
|
onUpdateBuildPipelineEntity =
|
2025-05-30 17:00:07 +08:00
|
|
|
|
new BuildAssetEntity("更新", $"更新至服务器【版本:{BuildAssetDataSetting.packageVersion}】",
|
|
|
|
|
|
OnUpdateBuildPipeline);
|
2025-03-31 11:16:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Vector2 scroll;
|
|
|
|
|
|
|
|
|
|
|
|
protected override void DrawEditor(int index)
|
|
|
|
|
|
{
|
|
|
|
|
|
scroll = GUILayout.BeginScrollView(scroll);
|
|
|
|
|
|
{
|
|
|
|
|
|
base.DrawEditor(index);
|
|
|
|
|
|
}
|
|
|
|
|
|
GUILayout.EndScrollView();
|
2025-05-23 18:26:47 +08:00
|
|
|
|
|
2025-05-16 11:07:02 +08:00
|
|
|
|
BuildServerPath();
|
|
|
|
|
|
UpdateBuildPipelineButtonName();
|
2025-03-31 11:16:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-16 11:07:02 +08:00
|
|
|
|
public void UpdateBuildPipelineButtonName()
|
|
|
|
|
|
{
|
|
|
|
|
|
onBuildPipelineEntity.SetButtonName($"打包资源包【版本:{BuildAssetDataSetting.packageVersion}】");
|
|
|
|
|
|
onUpdateBuildPipelineEntity.SetButtonName($"更新至服务器【版本:{BuildAssetDataSetting.packageVersion}】");
|
|
|
|
|
|
}
|
2025-05-23 18:26:47 +08:00
|
|
|
|
|
2025-03-31 11:16:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 生成服务器路径
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void BuildServerPath()
|
|
|
|
|
|
{
|
2025-05-30 14:50:46 +08:00
|
|
|
|
// if (!_isCheckDriveExist)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// return;
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// updateServerPath =
|
|
|
|
|
|
// $"Z:/{Application.productName}/{BuildAssetDataSetting.packageName}/{EditorUserBuildSettings.activeBuildTarget}/{BuildAssetDataSetting.packageVersion}";
|
|
|
|
|
|
// if (!Directory.Exists(updateServerPath))
|
|
|
|
|
|
// Directory.CreateDirectory(updateServerPath);
|
2025-03-31 11:16:52 +08:00
|
|
|
|
|
|
|
|
|
|
//更新Button文字
|
|
|
|
|
|
onBuildPipelineEntity.SetButtonName($"打包资源包【版本:{BuildAssetDataSetting.packageVersion}】");
|
|
|
|
|
|
onUpdateBuildPipelineEntity.SetButtonName($"更新至服务器【版本:{BuildAssetDataSetting.packageVersion}】");
|
|
|
|
|
|
}
|
2025-05-30 14:50:46 +08:00
|
|
|
|
}
|
2025-03-31 11:16:52 +08:00
|
|
|
|
|
2025-05-30 14:50:46 +08:00
|
|
|
|
public enum BuildAssetType
|
|
|
|
|
|
{
|
|
|
|
|
|
Login,
|
|
|
|
|
|
Build,
|
2025-03-31 11:16:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|