【m】更新后台

This commit is contained in:
2025-05-30 14:50:46 +08:00
parent cbd48e8411
commit 078f080fcc
68 changed files with 764 additions and 342 deletions

View File

@@ -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)

View File

@@ -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,
}
}

View File

@@ -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>();

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 10cd38fccc1db684d9a576da1f9dc85e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,40 +0,0 @@
// using System;
// using System.IO;
//
// namespace Stary.Evo.Editor
// {
// public class ChangeScriptTemplates : UnityEditor.AssetModificationProcessor
// {
// // 要添加的注释的内容
// private static string annotationStr =
// "/**************************************************** \r\n"
// + " 文件:#Filename\r\n"
// + " 作者:#CreateAuthor#\r\n"
// + " 邮箱:\r\n"
// + " 日期:#CreateTime#\r\n"
// + " 功能:\r\n"
// + "*****************************************************/\r\n\n";
//
// public static void OnWillCreateAsset(string path)
// {
// //将.meta后缀屏蔽
// path = path.Replace(".meta", "");
// //只对.cs脚本作操作
// if (path.EndsWith(".cs"))
// {
// //读取该路径下的.cs文件中的所有文本.
// //注意此时Unity已经对脚本完成了模版内容的替换包括#SCRIPTNAME#也已经被替换为文件名了,读取到的是替换后的文本内容.
// annotationStr += File.ReadAllText(path);
// //获取用户名和当前系统时间并替换对应位置内容
// annotationStr = annotationStr.Replace("#CreateAuthor#", Environment.UserName)
// .Replace("#CreateTime#", string.Concat(DateTime.Now.Year, "/", DateTime.Now.Month, "/",
// DateTime.Now.Day, " ", DateTime.Now.Hour, ":", DateTime.Now.Minute, ":", DateTime.Now.Second))
// .Replace("#Filename", Path.GetFileName(path));
// if (!File.ReadAllText(path).Contains("文件") && !File.ReadAllText(path).Contains("作者") && !File.ReadAllText(path).Contains("邮箱") && !File.ReadAllText(path).Contains("日期") && !File.ReadAllText(path).Contains("功能"))
// //重新将文本写入.cs文件
// File.WriteAllText(path, annotationStr);
// }
//
// }
// }
// }

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 46fd7b74d162e9042a93085169ef025f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,25 @@
/****************************************************
文件StringToLayer.cs
作者:张铮
邮箱834207172@qq.com
日期2022/3/3 17:53:52
功能:
*****************************************************/
using System.IO;
using System.Text;
using UnityEditor;
using UnityEngine;
namespace Stary.Evo.Editor
{
public class PlayerPrefsData
{
[MenuItem("Evo/Utility/PlayerPrefsClear")]
private static void PlayerPrefsClear()
{
PlayerPrefs.DeleteAll();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 56c6f609a1f54a48939218df73a1e4fd
timeCreated: 1748584452

View File

@@ -133,10 +133,10 @@ namespace Stary.Evo.Editor
if (oneKeyBUildEntity.isRaw)
{
string configPath =
$"Assets/Domain/{oneKeyBUildEntity.DomainName}/Conf/HotfixMainResDomain.asset";
HotfixMainResDomain hotfixMainResDomain =
AssetDatabase.LoadAssetAtPath<HotfixMainResDomain>(configPath);
packageName = hotfixMainResDomain.hotfixMainResDomainEntity.domain;
$"Assets/Domain/{oneKeyBUildEntity.DomainName}/AddressableRes/Config/DomainConfig.asset";
DomainConfig domainConfig =
AssetDatabase.LoadAssetAtPath<DomainConfig>(configPath);
packageName = domainConfig.domain;
Mark();
if (!oneKeyBUildEntity.DomainName.Equals("Main"))
CreateRes(packageName,
@@ -175,9 +175,10 @@ namespace Stary.Evo.Editor
}
string configPath =
$"Assets/Domain/{BuildAssetWindow.GetBuildPackageName()}/Conf/HotfixMainResDomain.asset";
HotfixMainResDomain hotfixMainResDomain = AssetDatabase.LoadAssetAtPath<HotfixMainResDomain>(configPath);
packageName = hotfixMainResDomain.hotfixMainResDomainEntity.domain;
$"Assets/Domain/{BuildAssetWindow.GetBuildPackageName()}/AddressableRes/Config/DomainConfig.asset";
DomainConfig domainConfig =
AssetDatabase.LoadAssetAtPath<DomainConfig>(configPath);
packageName = domainConfig.domain;
Mark();
if (!BuildAssetWindow.GetBuildPackageName().Equals("Main"))
CreateRes(packageName,

View File

@@ -0,0 +1,58 @@
using Unity.Collections;
using UnityEditor;
namespace Stary.Evo.Editor
{
/// <summary>
/// 内存泄露检测模式
/// </summary>
public class LeakDetectionMode
{
[MenuItem("Jobs/内存泄漏检测/显示当前模式")]
static void ShowLeakDetection()
{
string message = string.Format("当前模式: {0}", NativeLeakDetection.Mode.ToString());
EditorUtility.DisplayDialog("内存泄漏检测模式", message, "OK");
}
[MenuItem("Jobs/内存泄漏检测/禁用")]
static void LeakDetectionDisable()
{
NativeLeakDetection.Mode = NativeLeakDetectionMode.Disabled;
}
// 验证方法会在正式方法前执行,通不过就会置灰
[MenuItem("Jobs/内存泄漏检测/禁用", true)]
static bool ValidateLeakDetectionDisable()
{
return NativeLeakDetection.Mode != NativeLeakDetectionMode.Disabled;
}
[MenuItem("Jobs/内存泄漏检测/启用")]
static void LeakDetectionEnabled()
{
NativeLeakDetection.Mode = NativeLeakDetectionMode.Enabled;
}
[MenuItem("Jobs/内存泄漏检测/启用", true)]
static bool ValidateLeakDetectionEnabled()
{
return NativeLeakDetection.Mode != NativeLeakDetectionMode.Enabled;
}
[MenuItem("Jobs/内存泄漏检测/启用堆栈跟踪")]
static void LeakDetectionEnabledWithStackTrace()
{
NativeLeakDetection.Mode = NativeLeakDetectionMode.EnabledWithStackTrace;
}
[MenuItem("Jobs/内存泄漏检测/启用堆栈跟踪", true)]
static bool ValidateLeakDetectionEnabledWithStackTrace()
{
return NativeLeakDetection.Mode != NativeLeakDetectionMode.EnabledWithStackTrace;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a27e919c74384f689d6a50a45236b7f4
timeCreated: 1748333122