【m】更新后台
This commit is contained in:
@@ -43,13 +43,7 @@ namespace Stary.Evo.Editor
|
||||
}
|
||||
}
|
||||
|
||||
[HorizontalGroup("@ HorizontalGroupName", Width = 68)]
|
||||
[Button(ButtonSizes.Large, Icon = SdfIconType.CheckCircleFill, IconAlignment = IconAlignment.RightEdge,
|
||||
ButtonHeight = 68),
|
||||
GUIColor("@messageColor")]
|
||||
private void CopyDll1()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void SetButtonName(string ButtonName)
|
||||
|
||||
@@ -11,9 +11,13 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using EditorFramework;
|
||||
using HybridCLR.Editor;
|
||||
using HybridCLR.Editor.Commands;
|
||||
using InterfaceEntity.Entity.Requests;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Sirenix.OdinInspector;
|
||||
using Sirenix.OdinInspector.Editor;
|
||||
using UnityEditor;
|
||||
@@ -27,7 +31,7 @@ namespace Stary.Evo.Editor
|
||||
{
|
||||
public class BuildAssetWindow : OdinEditorWindow
|
||||
{
|
||||
private static BuildAssetWindow window;
|
||||
public static OdinEditorWindow window;
|
||||
|
||||
|
||||
[MenuItem("Evo/资源打包工具")]
|
||||
@@ -44,10 +48,26 @@ namespace Stary.Evo.Editor
|
||||
}
|
||||
|
||||
|
||||
protected override void Initialize()
|
||||
protected override async void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
GetBuildPackageNames();
|
||||
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;
|
||||
}
|
||||
|
||||
public static void RemoveBuildAssetWindow()
|
||||
@@ -56,6 +76,43 @@ namespace Stary.Evo.Editor
|
||||
window.Close();
|
||||
}
|
||||
|
||||
[EnumToggleButtons, HideLabel] public BuildAssetType buildAssetType;
|
||||
|
||||
#region BuildAssetLogin
|
||||
|
||||
[ShowIf("@ buildAssetType== BuildAssetType.Login")] [BoxGroup("Login", showLabel: false)]
|
||||
public string ip, userName, password;
|
||||
|
||||
[ShowIf("@ buildAssetType== BuildAssetType.Login")]
|
||||
[BoxGroup("Login", showLabel: false)]
|
||||
[Button("登录", ButtonSizes.Large)]
|
||||
[InfoBox("@ message", InfoMessageType.Info)]
|
||||
public async void LoginButton()
|
||||
{
|
||||
PlayerPrefs.SetString("LoginIp", ip);
|
||||
PlayerPrefs.SetString("LoginUserName", userName);
|
||||
PlayerPrefs.SetString("LoginPassword", password);
|
||||
string url = ip + "/Authentication/login";
|
||||
bool islogin = await WebRequestSystem.Login(url, userName, password);
|
||||
UpdateMessage(islogin);
|
||||
}
|
||||
|
||||
private string message;
|
||||
|
||||
public async void UpdateMessage(bool islogin)
|
||||
{
|
||||
message = "当前登录状态为:" + islogin;
|
||||
ip = PlayerPrefs.GetString("LoginIp");
|
||||
userName = PlayerPrefs.GetString("LoginUserName");
|
||||
password = PlayerPrefs.GetString("LoginPassword");
|
||||
if (islogin)
|
||||
{
|
||||
buildAssetType = BuildAssetType.Build;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected void OnSelectionChange()
|
||||
{
|
||||
EditorUtility.SetDirty(BuildAssetDataSetting);
|
||||
@@ -63,24 +120,29 @@ namespace Stary.Evo.Editor
|
||||
//AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
[BoxGroup("Build", showLabel: false)]
|
||||
[ShowIf("@ buildAssetType== BuildAssetType.Build")]
|
||||
[Title("包裹列表", titleAlignment: TitleAlignments.Centered)]
|
||||
[HorizontalGroup("BuildPipeline"), HideLabel]
|
||||
[HorizontalGroup("Build/BuildPipeline"), HideLabel]
|
||||
[ValueDropdown("GetBuildPackageNames")]
|
||||
[OnValueChanged("SetBuildPackageNames")]
|
||||
public string selectedPackageNames;
|
||||
|
||||
[BoxGroup("Build", showLabel: false)]
|
||||
[ShowIf("@ buildAssetType== BuildAssetType.Build")]
|
||||
[Title("当前打包平台", titleAlignment: TitleAlignments.Centered)]
|
||||
[ReadOnly]
|
||||
[HorizontalGroup("BuildPipeline"), HideLabel]
|
||||
[HorizontalGroup("Build/BuildPipeline"), HideLabel]
|
||||
public string buildTarget;
|
||||
|
||||
public static string packageName;
|
||||
|
||||
#region HyBridCLRBuild
|
||||
|
||||
[HideIf("@ packageName== \"Main\"")]
|
||||
[Title("HyBridCLRBuild", titleAlignment: TitleAlignments.Centered)]
|
||||
[HideLabel]
|
||||
[BoxGroup("Build", showLabel: false)]
|
||||
[HideIf("@ packageName== \"Main\" || buildAssetType!= BuildAssetType.Build")]
|
||||
[Title("打包dll(子包仅打一次)", titleAlignment: TitleAlignments.Centered)]
|
||||
[HorizontalGroup("Build/HyBridClrBuildEntity"), HideLabel]
|
||||
public BuildAssetEntity hyBridClrBuildEntity =
|
||||
new BuildAssetEntity("HyBridCLRBuild", "DllBuildTarget", () =>
|
||||
{
|
||||
@@ -93,7 +155,10 @@ namespace Stary.Evo.Editor
|
||||
|
||||
#region MarkAsset
|
||||
|
||||
[Title("MarkAsset", titleAlignment: TitleAlignments.Centered)] [HideLabel]
|
||||
[BoxGroup("Build", showLabel: false)]
|
||||
[ShowIf("@ buildAssetType== BuildAssetType.Build")]
|
||||
[Title("标记资源", titleAlignment: TitleAlignments.Centered)]
|
||||
[HorizontalGroup("Build/HyBridClrBuildEntity"), HideLabel]
|
||||
public BuildAssetEntity markAssetEntity =
|
||||
new BuildAssetEntity("MarkAsset", "MarkAsset", MarkAdressable.AddMark);
|
||||
|
||||
@@ -101,7 +166,10 @@ namespace Stary.Evo.Editor
|
||||
|
||||
#region BuildAsset
|
||||
|
||||
[InlineEditor(InlineEditorObjectFieldModes.CompletelyHidden)] [HideLabel]
|
||||
[BoxGroup("Build", showLabel: false)]
|
||||
[ShowIf("@ buildAssetType== BuildAssetType.Build")]
|
||||
[InlineEditor(InlineEditorObjectFieldModes.CompletelyHidden)]
|
||||
[HideLabel]
|
||||
public BuildAssetDataSetting BuildAssetDataSetting;
|
||||
|
||||
/// <summary>
|
||||
@@ -170,26 +238,29 @@ namespace Stary.Evo.Editor
|
||||
|
||||
#region Update
|
||||
|
||||
[Title("BuildAssetButton", titleAlignment: TitleAlignments.Centered)] [HideLabel]
|
||||
[BoxGroup("Build", showLabel: false)]
|
||||
[ShowIf("@ buildAssetType== BuildAssetType.Build")]
|
||||
[Title("打包本地资源", titleAlignment: TitleAlignments.Centered)]
|
||||
[HideLabel]
|
||||
public BuildAssetEntity onBuildPipelineEntity;
|
||||
|
||||
[FormerlySerializedAs("UpdateServerPath")]
|
||||
[TitleGroup("UpdateAssetButton", alignment: TitleAlignments.Centered)]
|
||||
[ShowIf("@ BuildAssetDataSetting.environmentType== EnvironmentType.Release", true)]
|
||||
[ReadOnly]
|
||||
[InfoBox("服务器资源盘位未存在", InfoMessageType.Error, "@ _isCheckDriveExist==false")]
|
||||
[InfoBox("1、映射网络驱动器\n2、添加http://192.168.31.100:5005/alist/HotRefresh地址\n3、设置盘符为Z盘", InfoMessageType.Info,
|
||||
"@ _isCheckDriveExist==false")]
|
||||
[HideIf("@ selectedPackageNames==\"Main\"")]
|
||||
public string updateServerPath;
|
||||
|
||||
private bool _isCheckDriveExist;
|
||||
// [BoxGroup("Build", showLabel: false)]
|
||||
// [TitleGroup("Build/UpdateAssetButton", alignment: TitleAlignments.Centered)]
|
||||
// // [ShowIf("@ BuildAssetDataSetting.environmentType== EnvironmentType.Release ", true)]
|
||||
// [ReadOnly]
|
||||
// [InfoBox("服务器资源盘位未存在", InfoMessageType.Error, "@ _isCheckDriveExist==false")]
|
||||
// [InfoBox("1、映射网络驱动器\n2、添加http://192.168.31.100:5005/alist/HotRefresh地址\n3、设置盘符为Z盘", InfoMessageType.Info,
|
||||
// "@ _isCheckDriveExist==false")]
|
||||
// [HideIf(
|
||||
// "@ selectedPackageNames==\"Main\" ||BuildAssetDataSetting.environmentType!= EnvironmentType.Release || buildAssetType!= BuildAssetType.Build")]
|
||||
// public string updateServerPath;
|
||||
|
||||
|
||||
[TitleGroup("UpdateAssetButton", alignment: TitleAlignments.Centered)]
|
||||
[BoxGroup("Build", showLabel: false)]
|
||||
[Title("上传资源", titleAlignment: TitleAlignments.Centered)]
|
||||
[HideLabel]
|
||||
[ShowIf(
|
||||
"@ _isCheckDriveExist&&BuildAssetDataSetting.environmentType== EnvironmentType.Release&&selectedPackageNames!=\"Main\"")]
|
||||
"@ BuildAssetDataSetting.environmentType== EnvironmentType.Release&&selectedPackageNames!=\"Main\" && buildAssetType== BuildAssetType.Build")]
|
||||
public BuildAssetEntity onUpdateBuildPipelineEntity;
|
||||
|
||||
|
||||
@@ -206,10 +277,11 @@ namespace Stary.Evo.Editor
|
||||
}
|
||||
}
|
||||
|
||||
private void OnUpdateBuildPipeline()
|
||||
private async void OnUpdateBuildPipeline()
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("提示", $"开始上传至服务器[{selectedPackageNames}]!", "Yes", "No"))
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("提示", "开始上传(打包zip)", 0.0f);
|
||||
// 新增:打包为zip的逻辑
|
||||
string zipFileName =
|
||||
$"{BuildAssetDataSetting.packageName}_{BuildAssetDataSetting.packageVersion}.zip";
|
||||
@@ -221,33 +293,98 @@ namespace Stary.Evo.Editor
|
||||
string zipFilePath = Path.Combine(outputPackageDirectory, zipFileName);
|
||||
try
|
||||
{
|
||||
// 压缩输出目录到zip文件(会覆盖已存在的同名文件)
|
||||
ZipFile.CreateFromDirectory(
|
||||
outFilePath,
|
||||
zipFilePath,
|
||||
System.IO.Compression.CompressionLevel.Optimal,
|
||||
false
|
||||
);
|
||||
using (FileStream zipStream = new FileStream(zipFilePath, FileMode.Create))
|
||||
using (ZipArchive archive = new ZipArchive(zipStream, ZipArchiveMode.Create))
|
||||
{
|
||||
// 指定需要压缩的后缀(例如:只压缩.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))
|
||||
{
|
||||
// 获取文件在压缩包中的相对路径
|
||||
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())
|
||||
{
|
||||
fileStream.CopyTo(entryStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log($"成功打包为zip:{zipFilePath}");
|
||||
EditorUtility.DisplayProgressBar("提示", "开始上传(打包zip)", 0.25f);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"打包zip失败:{ex.Message}");
|
||||
EditorUtility.ClearProgressBar();
|
||||
return;
|
||||
}
|
||||
|
||||
Stary.Evo.Editor.FileUtility.Copy(
|
||||
zipFilePath, $"{updateServerPath}/{zipFileName}", true);
|
||||
CreatePackageVersionJson();
|
||||
var messageEntity = await WebRequestSystem.PostFile(ip + "/FileLoad/UpLoadFile", new[] { zipFilePath });
|
||||
EditorUtility.DisplayProgressBar("提示", "开始上传(上传zip文件)", 0.5f);
|
||||
if (messageEntity.code == 200)
|
||||
{
|
||||
List<ResultMessageEntity> resultMessageEntities =
|
||||
JsonConvert.DeserializeObject<List<ResultMessageEntity>>(messageEntity.data.ToString());
|
||||
if (resultMessageEntities.Count > 0)
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("提示", "开始上传(更新数据库)", 0.75f);
|
||||
foreach (var resultMessageEntity in resultMessageEntities)
|
||||
{
|
||||
var data = JsonConvert.DeserializeObject(resultMessageEntity.data.ToString()) as JObject;
|
||||
string fileId = data["id"].ToString();
|
||||
ResDmainAddRequst resDmainAddRequst = new ResDmainAddRequst()
|
||||
{
|
||||
ProductName = Application.productName,
|
||||
DomainName = BuildAssetDataSetting.packageName,
|
||||
Platform = EditorUserBuildSettings.activeBuildTarget.ToString(),
|
||||
PackageVersion = BuildAssetDataSetting.packageVersion,
|
||||
DocumentFileId = fileId
|
||||
};
|
||||
var resResultMessage = await WebRequestSystem.Post(ip + "/ResDomain/AddResDomain",
|
||||
JsonConvert.SerializeObject(resDmainAddRequst));
|
||||
//如果低于服务器版本,更新版本号
|
||||
if (resResultMessage.code == 1009)
|
||||
{
|
||||
ResDmainVersionResponse dmainVersionResponse =
|
||||
JsonConvert.DeserializeObject<ResDmainVersionResponse>(resResultMessage.data
|
||||
.ToString());
|
||||
string[] versions = dmainVersionResponse.PackageVersion.Split('.');
|
||||
BuildAssetDataSetting.packageVersionX = int.Parse(versions[0]);
|
||||
BuildAssetDataSetting.packageVersionY = int.Parse(versions[1]);
|
||||
BuildAssetDataSetting.packageVersionZ = int.Parse(versions[2]);
|
||||
}
|
||||
EditorUtility.DisplayDialog("提示",
|
||||
$"{resResultMessage.message + $"\n{resResultMessage.data.ToString()}"}", "确定");
|
||||
BuildAssetDataSetting.GetBuildPackageVersion(true);
|
||||
}
|
||||
EditorUtility.DisplayProgressBar("提示", "开始上传(更新数据库)", 1f);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("提示", $"{messageEntity.message}", 1f);
|
||||
}
|
||||
|
||||
|
||||
BuildAssetDataSetting.GetBuildPackageVersion(true);
|
||||
|
||||
EditorUtility.DisplayDialog("提示", $"上传服务器完成!", "确定");
|
||||
await Task.Delay(1000);
|
||||
EditorUtility.ClearProgressBar();
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorUtility.ClearProgressBar();
|
||||
EditorUtility.DisplayDialog("提示", "Update] 上传已经取消", "确定");
|
||||
Debug.LogWarning("[Update] 上传已经取消");
|
||||
}
|
||||
}
|
||||
@@ -257,8 +394,6 @@ namespace Stary.Evo.Editor
|
||||
protected void Init()
|
||||
{
|
||||
//Update
|
||||
//检测Z盘
|
||||
_isCheckDriveExist = Stary.Evo.Editor.FileUtility.CheckDriveExists("Z");
|
||||
buildTarget = EditorUserBuildSettings.activeBuildTarget.ToString();
|
||||
onBuildPipelineEntity =
|
||||
new BuildAssetEntity("打包", $"打包资源包【版本:{BuildAssetDataSetting.packageVersion}】", OnBuildPipeline);
|
||||
@@ -291,42 +426,25 @@ namespace Stary.Evo.Editor
|
||||
/// </summary>
|
||||
private void BuildServerPath()
|
||||
{
|
||||
if (!_isCheckDriveExist)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
updateServerPath =
|
||||
$"Z:/{Application.productName}/{BuildAssetDataSetting.packageName}/{EditorUserBuildSettings.activeBuildTarget}/{BuildAssetDataSetting.packageVersion}";
|
||||
if (!Directory.Exists(updateServerPath))
|
||||
Directory.CreateDirectory(updateServerPath);
|
||||
// if (!_isCheckDriveExist)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// updateServerPath =
|
||||
// $"Z:/{Application.productName}/{BuildAssetDataSetting.packageName}/{EditorUserBuildSettings.activeBuildTarget}/{BuildAssetDataSetting.packageVersion}";
|
||||
// if (!Directory.Exists(updateServerPath))
|
||||
// Directory.CreateDirectory(updateServerPath);
|
||||
|
||||
//更新Button文字
|
||||
onBuildPipelineEntity.SetButtonName($"打包资源包【版本:{BuildAssetDataSetting.packageVersion}】");
|
||||
onUpdateBuildPipelineEntity.SetButtonName($"更新至服务器【版本:{BuildAssetDataSetting.packageVersion}】");
|
||||
}
|
||||
}
|
||||
|
||||
private void CreatePackageVersionJson()
|
||||
{
|
||||
string mainResDomainPath = $"Assets/Domain/{selectedPackageNames}/Conf/HotfixMainResDomain.asset";
|
||||
HotfixMainResDomain mainResDomain =
|
||||
AssetDatabase.LoadAssetAtPath<HotfixMainResDomain>(mainResDomainPath);
|
||||
|
||||
if (mainResDomain != null)
|
||||
{
|
||||
mainResDomain.hotfixMainResDomainEntity.packageVersion = BuildAssetDataSetting.packageVersion;
|
||||
mainResDomain.hotfixMainResDomainEntity.pathconfig =
|
||||
$"{Application.productName}/{BuildAssetDataSetting.packageName}/{EditorUserBuildSettings.activeBuildTarget}/{BuildAssetDataSetting.packageVersion}";
|
||||
}
|
||||
|
||||
AssetDatabase.Refresh();
|
||||
EditorUtility.SetDirty(mainResDomain);
|
||||
// 保存更改
|
||||
AssetDatabase.SaveAssets();
|
||||
string serverPath =
|
||||
$"Z:/HybridclrConfigData/{BuildAssetDataSetting.packageName}/{EditorUserBuildSettings.activeBuildTarget}/";
|
||||
//直接保存服务器路径下,本地不保存
|
||||
EditorFrameworkUtils.SaveJson(mainResDomain.hotfixMainResDomainEntity, serverPath, Application.productName);
|
||||
}
|
||||
public enum BuildAssetType
|
||||
{
|
||||
Login,
|
||||
Build,
|
||||
}
|
||||
}
|
||||
@@ -158,12 +158,7 @@ namespace Stary.Evo.Editor
|
||||
moduleConfig.@namespace = domain;
|
||||
AssetDatabase.CreateAsset(moduleConfig, $"Assets/Domain/{domain}/AddressableRes/Config/DomainConfig.asset");
|
||||
//
|
||||
//模块服务器配置资源
|
||||
|
||||
HotfixMainResDomain hotfixMainResDomain = CreateInstance<HotfixMainResDomain>();
|
||||
hotfixMainResDomain.hotfixMainResDomainEntity = new HotfixMainResDomainEntity();
|
||||
hotfixMainResDomain.hotfixMainResDomainEntity.domain = domain;
|
||||
AssetDatabase.CreateAsset(hotfixMainResDomain, $"Assets/Domain/{domain}/Conf/HotfixMainResDomain.asset");
|
||||
|
||||
|
||||
//编辑器配置资源
|
||||
BuildAssetDataSetting buildAssetDataSetting = CreateInstance<BuildAssetDataSetting>();
|
||||
|
||||
Reference in New Issue
Block a user