【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)
|
public void SetButtonName(string ButtonName)
|
||||||
|
|||||||
@@ -11,9 +11,13 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using EditorFramework;
|
using EditorFramework;
|
||||||
using HybridCLR.Editor;
|
using HybridCLR.Editor;
|
||||||
using HybridCLR.Editor.Commands;
|
using HybridCLR.Editor.Commands;
|
||||||
|
using InterfaceEntity.Entity.Requests;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using Sirenix.OdinInspector;
|
using Sirenix.OdinInspector;
|
||||||
using Sirenix.OdinInspector.Editor;
|
using Sirenix.OdinInspector.Editor;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
@@ -27,7 +31,7 @@ namespace Stary.Evo.Editor
|
|||||||
{
|
{
|
||||||
public class BuildAssetWindow : OdinEditorWindow
|
public class BuildAssetWindow : OdinEditorWindow
|
||||||
{
|
{
|
||||||
private static BuildAssetWindow window;
|
public static OdinEditorWindow window;
|
||||||
|
|
||||||
|
|
||||||
[MenuItem("Evo/资源打包工具")]
|
[MenuItem("Evo/资源打包工具")]
|
||||||
@@ -44,10 +48,26 @@ namespace Stary.Evo.Editor
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected override void Initialize()
|
protected override async void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
GetBuildPackageNames();
|
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()
|
public static void RemoveBuildAssetWindow()
|
||||||
@@ -56,6 +76,43 @@ namespace Stary.Evo.Editor
|
|||||||
window.Close();
|
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()
|
protected void OnSelectionChange()
|
||||||
{
|
{
|
||||||
EditorUtility.SetDirty(BuildAssetDataSetting);
|
EditorUtility.SetDirty(BuildAssetDataSetting);
|
||||||
@@ -63,24 +120,29 @@ namespace Stary.Evo.Editor
|
|||||||
//AssetDatabase.Refresh();
|
//AssetDatabase.Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[BoxGroup("Build", showLabel: false)]
|
||||||
|
[ShowIf("@ buildAssetType== BuildAssetType.Build")]
|
||||||
[Title("包裹列表", titleAlignment: TitleAlignments.Centered)]
|
[Title("包裹列表", titleAlignment: TitleAlignments.Centered)]
|
||||||
[HorizontalGroup("BuildPipeline"), HideLabel]
|
[HorizontalGroup("Build/BuildPipeline"), HideLabel]
|
||||||
[ValueDropdown("GetBuildPackageNames")]
|
[ValueDropdown("GetBuildPackageNames")]
|
||||||
[OnValueChanged("SetBuildPackageNames")]
|
[OnValueChanged("SetBuildPackageNames")]
|
||||||
public string selectedPackageNames;
|
public string selectedPackageNames;
|
||||||
|
|
||||||
|
[BoxGroup("Build", showLabel: false)]
|
||||||
|
[ShowIf("@ buildAssetType== BuildAssetType.Build")]
|
||||||
[Title("当前打包平台", titleAlignment: TitleAlignments.Centered)]
|
[Title("当前打包平台", titleAlignment: TitleAlignments.Centered)]
|
||||||
[ReadOnly]
|
[ReadOnly]
|
||||||
[HorizontalGroup("BuildPipeline"), HideLabel]
|
[HorizontalGroup("Build/BuildPipeline"), HideLabel]
|
||||||
public string buildTarget;
|
public string buildTarget;
|
||||||
|
|
||||||
public static string packageName;
|
public static string packageName;
|
||||||
|
|
||||||
#region HyBridCLRBuild
|
#region HyBridCLRBuild
|
||||||
|
|
||||||
[HideIf("@ packageName== \"Main\"")]
|
[BoxGroup("Build", showLabel: false)]
|
||||||
[Title("HyBridCLRBuild", titleAlignment: TitleAlignments.Centered)]
|
[HideIf("@ packageName== \"Main\" || buildAssetType!= BuildAssetType.Build")]
|
||||||
[HideLabel]
|
[Title("打包dll(子包仅打一次)", titleAlignment: TitleAlignments.Centered)]
|
||||||
|
[HorizontalGroup("Build/HyBridClrBuildEntity"), HideLabel]
|
||||||
public BuildAssetEntity hyBridClrBuildEntity =
|
public BuildAssetEntity hyBridClrBuildEntity =
|
||||||
new BuildAssetEntity("HyBridCLRBuild", "DllBuildTarget", () =>
|
new BuildAssetEntity("HyBridCLRBuild", "DllBuildTarget", () =>
|
||||||
{
|
{
|
||||||
@@ -93,7 +155,10 @@ namespace Stary.Evo.Editor
|
|||||||
|
|
||||||
#region MarkAsset
|
#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 =
|
public BuildAssetEntity markAssetEntity =
|
||||||
new BuildAssetEntity("MarkAsset", "MarkAsset", MarkAdressable.AddMark);
|
new BuildAssetEntity("MarkAsset", "MarkAsset", MarkAdressable.AddMark);
|
||||||
|
|
||||||
@@ -101,7 +166,10 @@ namespace Stary.Evo.Editor
|
|||||||
|
|
||||||
#region BuildAsset
|
#region BuildAsset
|
||||||
|
|
||||||
[InlineEditor(InlineEditorObjectFieldModes.CompletelyHidden)] [HideLabel]
|
[BoxGroup("Build", showLabel: false)]
|
||||||
|
[ShowIf("@ buildAssetType== BuildAssetType.Build")]
|
||||||
|
[InlineEditor(InlineEditorObjectFieldModes.CompletelyHidden)]
|
||||||
|
[HideLabel]
|
||||||
public BuildAssetDataSetting BuildAssetDataSetting;
|
public BuildAssetDataSetting BuildAssetDataSetting;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -170,26 +238,29 @@ namespace Stary.Evo.Editor
|
|||||||
|
|
||||||
#region Update
|
#region Update
|
||||||
|
|
||||||
[Title("BuildAssetButton", titleAlignment: TitleAlignments.Centered)] [HideLabel]
|
[BoxGroup("Build", showLabel: false)]
|
||||||
|
[ShowIf("@ buildAssetType== BuildAssetType.Build")]
|
||||||
|
[Title("打包本地资源", titleAlignment: TitleAlignments.Centered)]
|
||||||
|
[HideLabel]
|
||||||
public BuildAssetEntity onBuildPipelineEntity;
|
public BuildAssetEntity onBuildPipelineEntity;
|
||||||
|
|
||||||
[FormerlySerializedAs("UpdateServerPath")]
|
// [BoxGroup("Build", showLabel: false)]
|
||||||
[TitleGroup("UpdateAssetButton", alignment: TitleAlignments.Centered)]
|
// [TitleGroup("Build/UpdateAssetButton", alignment: TitleAlignments.Centered)]
|
||||||
[ShowIf("@ BuildAssetDataSetting.environmentType== EnvironmentType.Release", true)]
|
// // [ShowIf("@ BuildAssetDataSetting.environmentType== EnvironmentType.Release ", true)]
|
||||||
[ReadOnly]
|
// [ReadOnly]
|
||||||
[InfoBox("服务器资源盘位未存在", InfoMessageType.Error, "@ _isCheckDriveExist==false")]
|
// [InfoBox("服务器资源盘位未存在", InfoMessageType.Error, "@ _isCheckDriveExist==false")]
|
||||||
[InfoBox("1、映射网络驱动器\n2、添加http://192.168.31.100:5005/alist/HotRefresh地址\n3、设置盘符为Z盘", InfoMessageType.Info,
|
// [InfoBox("1、映射网络驱动器\n2、添加http://192.168.31.100:5005/alist/HotRefresh地址\n3、设置盘符为Z盘", InfoMessageType.Info,
|
||||||
"@ _isCheckDriveExist==false")]
|
// "@ _isCheckDriveExist==false")]
|
||||||
[HideIf("@ selectedPackageNames==\"Main\"")]
|
// [HideIf(
|
||||||
public string updateServerPath;
|
// "@ selectedPackageNames==\"Main\" ||BuildAssetDataSetting.environmentType!= EnvironmentType.Release || buildAssetType!= BuildAssetType.Build")]
|
||||||
|
// public string updateServerPath;
|
||||||
private bool _isCheckDriveExist;
|
|
||||||
|
|
||||||
|
|
||||||
[TitleGroup("UpdateAssetButton", alignment: TitleAlignments.Centered)]
|
[BoxGroup("Build", showLabel: false)]
|
||||||
|
[Title("上传资源", titleAlignment: TitleAlignments.Centered)]
|
||||||
[HideLabel]
|
[HideLabel]
|
||||||
[ShowIf(
|
[ShowIf(
|
||||||
"@ _isCheckDriveExist&&BuildAssetDataSetting.environmentType== EnvironmentType.Release&&selectedPackageNames!=\"Main\"")]
|
"@ BuildAssetDataSetting.environmentType== EnvironmentType.Release&&selectedPackageNames!=\"Main\" && buildAssetType== BuildAssetType.Build")]
|
||||||
public BuildAssetEntity onUpdateBuildPipelineEntity;
|
public BuildAssetEntity onUpdateBuildPipelineEntity;
|
||||||
|
|
||||||
|
|
||||||
@@ -206,10 +277,11 @@ namespace Stary.Evo.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnUpdateBuildPipeline()
|
private async void OnUpdateBuildPipeline()
|
||||||
{
|
{
|
||||||
if (EditorUtility.DisplayDialog("提示", $"开始上传至服务器[{selectedPackageNames}]!", "Yes", "No"))
|
if (EditorUtility.DisplayDialog("提示", $"开始上传至服务器[{selectedPackageNames}]!", "Yes", "No"))
|
||||||
{
|
{
|
||||||
|
EditorUtility.DisplayProgressBar("提示", "开始上传(打包zip)", 0.0f);
|
||||||
// 新增:打包为zip的逻辑
|
// 新增:打包为zip的逻辑
|
||||||
string zipFileName =
|
string zipFileName =
|
||||||
$"{BuildAssetDataSetting.packageName}_{BuildAssetDataSetting.packageVersion}.zip";
|
$"{BuildAssetDataSetting.packageName}_{BuildAssetDataSetting.packageVersion}.zip";
|
||||||
@@ -221,33 +293,98 @@ namespace Stary.Evo.Editor
|
|||||||
string zipFilePath = Path.Combine(outputPackageDirectory, zipFileName);
|
string zipFilePath = Path.Combine(outputPackageDirectory, zipFileName);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 压缩输出目录到zip文件(会覆盖已存在的同名文件)
|
using (FileStream zipStream = new FileStream(zipFilePath, FileMode.Create))
|
||||||
ZipFile.CreateFromDirectory(
|
using (ZipArchive archive = new ZipArchive(zipStream, ZipArchiveMode.Create))
|
||||||
outFilePath,
|
{
|
||||||
zipFilePath,
|
// 指定需要压缩的后缀(例如:只压缩.json和.dll文件)
|
||||||
System.IO.Compression.CompressionLevel.Optimal,
|
//string[] targetExtensions = { ".bundle" };
|
||||||
false
|
|
||||||
);
|
// 遍历目录下所有文件
|
||||||
|
// 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}");
|
Debug.Log($"成功打包为zip:{zipFilePath}");
|
||||||
|
EditorUtility.DisplayProgressBar("提示", "开始上传(打包zip)", 0.25f);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.LogError($"打包zip失败:{ex.Message}");
|
Debug.LogError($"打包zip失败:{ex.Message}");
|
||||||
|
EditorUtility.ClearProgressBar();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Stary.Evo.Editor.FileUtility.Copy(
|
var messageEntity = await WebRequestSystem.PostFile(ip + "/FileLoad/UpLoadFile", new[] { zipFilePath });
|
||||||
zipFilePath, $"{updateServerPath}/{zipFileName}", true);
|
EditorUtility.DisplayProgressBar("提示", "开始上传(上传zip文件)", 0.5f);
|
||||||
CreatePackageVersionJson();
|
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);
|
await Task.Delay(1000);
|
||||||
|
EditorUtility.ClearProgressBar();
|
||||||
EditorUtility.DisplayDialog("提示", $"上传服务器完成!", "确定");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
EditorUtility.ClearProgressBar();
|
||||||
|
EditorUtility.DisplayDialog("提示", "Update] 上传已经取消", "确定");
|
||||||
Debug.LogWarning("[Update] 上传已经取消");
|
Debug.LogWarning("[Update] 上传已经取消");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -257,8 +394,6 @@ namespace Stary.Evo.Editor
|
|||||||
protected void Init()
|
protected void Init()
|
||||||
{
|
{
|
||||||
//Update
|
//Update
|
||||||
//检测Z盘
|
|
||||||
_isCheckDriveExist = Stary.Evo.Editor.FileUtility.CheckDriveExists("Z");
|
|
||||||
buildTarget = EditorUserBuildSettings.activeBuildTarget.ToString();
|
buildTarget = EditorUserBuildSettings.activeBuildTarget.ToString();
|
||||||
onBuildPipelineEntity =
|
onBuildPipelineEntity =
|
||||||
new BuildAssetEntity("打包", $"打包资源包【版本:{BuildAssetDataSetting.packageVersion}】", OnBuildPipeline);
|
new BuildAssetEntity("打包", $"打包资源包【版本:{BuildAssetDataSetting.packageVersion}】", OnBuildPipeline);
|
||||||
@@ -291,42 +426,25 @@ namespace Stary.Evo.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void BuildServerPath()
|
private void BuildServerPath()
|
||||||
{
|
{
|
||||||
if (!_isCheckDriveExist)
|
// if (!_isCheckDriveExist)
|
||||||
{
|
// {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
updateServerPath =
|
// updateServerPath =
|
||||||
$"Z:/{Application.productName}/{BuildAssetDataSetting.packageName}/{EditorUserBuildSettings.activeBuildTarget}/{BuildAssetDataSetting.packageVersion}";
|
// $"Z:/{Application.productName}/{BuildAssetDataSetting.packageName}/{EditorUserBuildSettings.activeBuildTarget}/{BuildAssetDataSetting.packageVersion}";
|
||||||
if (!Directory.Exists(updateServerPath))
|
// if (!Directory.Exists(updateServerPath))
|
||||||
Directory.CreateDirectory(updateServerPath);
|
// Directory.CreateDirectory(updateServerPath);
|
||||||
|
|
||||||
//更新Button文字
|
//更新Button文字
|
||||||
onBuildPipelineEntity.SetButtonName($"打包资源包【版本:{BuildAssetDataSetting.packageVersion}】");
|
onBuildPipelineEntity.SetButtonName($"打包资源包【版本:{BuildAssetDataSetting.packageVersion}】");
|
||||||
onUpdateBuildPipelineEntity.SetButtonName($"更新至服务器【版本:{BuildAssetDataSetting.packageVersion}】");
|
onUpdateBuildPipelineEntity.SetButtonName($"更新至服务器【版本:{BuildAssetDataSetting.packageVersion}】");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void CreatePackageVersionJson()
|
public enum BuildAssetType
|
||||||
{
|
{
|
||||||
string mainResDomainPath = $"Assets/Domain/{selectedPackageNames}/Conf/HotfixMainResDomain.asset";
|
Login,
|
||||||
HotfixMainResDomain mainResDomain =
|
Build,
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,12 +158,7 @@ namespace Stary.Evo.Editor
|
|||||||
moduleConfig.@namespace = domain;
|
moduleConfig.@namespace = domain;
|
||||||
AssetDatabase.CreateAsset(moduleConfig, $"Assets/Domain/{domain}/AddressableRes/Config/DomainConfig.asset");
|
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>();
|
BuildAssetDataSetting buildAssetDataSetting = CreateInstance<BuildAssetDataSetting>();
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 10cd38fccc1db684d9a576da1f9dc85e
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -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);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 46fd7b74d162e9042a93085169ef025f
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 56c6f609a1f54a48939218df73a1e4fd
|
||||||
|
timeCreated: 1748584452
|
||||||
@@ -133,10 +133,10 @@ namespace Stary.Evo.Editor
|
|||||||
if (oneKeyBUildEntity.isRaw)
|
if (oneKeyBUildEntity.isRaw)
|
||||||
{
|
{
|
||||||
string configPath =
|
string configPath =
|
||||||
$"Assets/Domain/{oneKeyBUildEntity.DomainName}/Conf/HotfixMainResDomain.asset";
|
$"Assets/Domain/{oneKeyBUildEntity.DomainName}/AddressableRes/Config/DomainConfig.asset";
|
||||||
HotfixMainResDomain hotfixMainResDomain =
|
DomainConfig domainConfig =
|
||||||
AssetDatabase.LoadAssetAtPath<HotfixMainResDomain>(configPath);
|
AssetDatabase.LoadAssetAtPath<DomainConfig>(configPath);
|
||||||
packageName = hotfixMainResDomain.hotfixMainResDomainEntity.domain;
|
packageName = domainConfig.domain;
|
||||||
Mark();
|
Mark();
|
||||||
if (!oneKeyBUildEntity.DomainName.Equals("Main"))
|
if (!oneKeyBUildEntity.DomainName.Equals("Main"))
|
||||||
CreateRes(packageName,
|
CreateRes(packageName,
|
||||||
@@ -175,9 +175,10 @@ namespace Stary.Evo.Editor
|
|||||||
}
|
}
|
||||||
|
|
||||||
string configPath =
|
string configPath =
|
||||||
$"Assets/Domain/{BuildAssetWindow.GetBuildPackageName()}/Conf/HotfixMainResDomain.asset";
|
$"Assets/Domain/{BuildAssetWindow.GetBuildPackageName()}/AddressableRes/Config/DomainConfig.asset";
|
||||||
HotfixMainResDomain hotfixMainResDomain = AssetDatabase.LoadAssetAtPath<HotfixMainResDomain>(configPath);
|
DomainConfig domainConfig =
|
||||||
packageName = hotfixMainResDomain.hotfixMainResDomainEntity.domain;
|
AssetDatabase.LoadAssetAtPath<DomainConfig>(configPath);
|
||||||
|
packageName = domainConfig.domain;
|
||||||
Mark();
|
Mark();
|
||||||
if (!BuildAssetWindow.GetBuildPackageName().Equals("Main"))
|
if (!BuildAssetWindow.GetBuildPackageName().Equals("Main"))
|
||||||
CreateRes(packageName,
|
CreateRes(packageName,
|
||||||
|
|||||||
58
Assets/00.StaryEvo/Editor/Tools/LeakDetectionMode.cs
Normal file
58
Assets/00.StaryEvo/Editor/Tools/LeakDetectionMode.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a27e919c74384f689d6a50a45236b7f4
|
||||||
|
timeCreated: 1748333122
|
||||||
@@ -14,11 +14,10 @@ namespace Stary.Evo
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class HotfixMainResDomainEntity
|
public class HotfixMainResDomainEntity
|
||||||
{
|
{
|
||||||
public string domain;
|
|
||||||
public string ipconfig="http://192.168.31.100:5005/HotRefresh";
|
public string ipconfig="http://192.168.31.100:5005/HotRefresh";
|
||||||
public string pathconfig;
|
public string mainDomainVersion ="";
|
||||||
public string packageVersion;
|
|
||||||
public string username="UnityHot";
|
public string username="UnityHot";
|
||||||
public string password="Unity1234";
|
public string password="Unity1234";
|
||||||
|
public string productName="UnityEvo";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,47 +1,280 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Cysharp.Threading.Tasks;
|
using Cysharp.Threading.Tasks;
|
||||||
|
using InterfaceEntity.Entity.Requests;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Networking;
|
using UnityEngine.Networking;
|
||||||
|
|
||||||
namespace Stary.Evo
|
namespace Stary.Evo
|
||||||
{
|
{
|
||||||
public interface IWebRequestSystem
|
public static class WebRequestSystem
|
||||||
{
|
{
|
||||||
Task<string> Post(string url, string postData);
|
private static string authorization;
|
||||||
Task<string> Get(string url, string token=null);
|
|
||||||
|
public static async Task<bool> Login(string url, string username, string password)
|
||||||
}
|
{
|
||||||
|
var data = new
|
||||||
|
{
|
||||||
|
username = username,
|
||||||
|
password = password,
|
||||||
|
roleType = "client",
|
||||||
|
};
|
||||||
|
string postData = JsonConvert.SerializeObject(data);
|
||||||
|
using (UnityWebRequest webRequest = UnityWebRequest.Post(url, postData)) //第二种写法此行注释
|
||||||
|
{
|
||||||
|
byte[] postBytes = System.Text.Encoding.UTF8.GetBytes(postData);
|
||||||
|
webRequest.uploadHandler = new UploadHandlerRaw(postBytes);
|
||||||
|
webRequest.SetRequestHeader("Content-Type", "application/json");
|
||||||
|
await webRequest.SendWebRequest();
|
||||||
|
|
||||||
|
webRequest.uploadHandler?.Dispose();
|
||||||
|
// 更新错误检查方式
|
||||||
|
if (webRequest.result == UnityWebRequest.Result.ConnectionError ||
|
||||||
|
webRequest.result == UnityWebRequest.Result.ProtocolError)
|
||||||
|
{
|
||||||
|
Debug.LogError(webRequest.error);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ResultMessageEntity authResponse =
|
||||||
|
JsonConvert.DeserializeObject<ResultMessageEntity>(webRequest.downloadHandler.text);
|
||||||
|
if (authResponse.code == 200)
|
||||||
|
{
|
||||||
|
AuthenticationResponse authResponseData =
|
||||||
|
JsonConvert.DeserializeObject<AuthenticationResponse>(authResponse.data.ToString());
|
||||||
|
authorization = authResponseData.Token;
|
||||||
|
PlayerPrefs.SetString("Authorization", authorization);
|
||||||
|
Debug.Log("登录成功");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// GET请求数据
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="url">请求数据的URL地址</param>
|
||||||
|
/// <param name="token">token验证的参数,此处为authorization</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<bool> GetValidateToken(string url)
|
||||||
|
{
|
||||||
|
authorization = PlayerPrefs.GetString("Authorization");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (UnityWebRequest webRequest = UnityWebRequest.Get($"{url}?token={authorization}"))
|
||||||
|
{
|
||||||
|
webRequest.downloadHandler = new DownloadHandlerBuffer();
|
||||||
|
await webRequest.SendWebRequest();
|
||||||
|
|
||||||
|
// 增强错误处理
|
||||||
|
if (webRequest.result != UnityWebRequest.Result.Success)
|
||||||
|
{
|
||||||
|
var errorMsg = $"HTTP {webRequest.responseCode}\n" +
|
||||||
|
$"URL: {url}\n" +
|
||||||
|
$"Error: {webRequest.error}\n" +
|
||||||
|
$"Response: {webRequest.downloadHandler.text}";
|
||||||
|
|
||||||
|
Debug.LogError(errorMsg);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultMessageEntity resultMessageEntity =
|
||||||
|
JsonConvert.DeserializeObject<ResultMessageEntity>(webRequest.downloadHandler.text);
|
||||||
|
if (resultMessageEntity.code == 200)
|
||||||
|
return true; // 添加返回值
|
||||||
|
else
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.LogError(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public class WebRequestSystem : IWebRequestSystem
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// POST请求数据
|
/// POST请求数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url">获取Token值的服务URL地址(很重要)</param>
|
/// <param name="url">获取Token值的服务URL地址(很重要)</param>
|
||||||
/// <param name="postData">传入请求的参数,此处参数为JOSN格式</param>
|
/// <param name="postData">传入请求的参数,此处参数为JOSN格式</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<string> Post(string url, string postData)
|
public static async Task<ResultMessageEntity> PostFile(string url, string[] path)
|
||||||
{
|
{
|
||||||
using (UnityWebRequest webRequest = UnityWebRequest.Post(url, postData)) //第二种写法此行注释
|
if (!GetTokenState())
|
||||||
{
|
{
|
||||||
byte[] postBytes = System.Text.Encoding.UTF8.GetBytes(postData);
|
Debug.LogError("用户未登录,请先登录");
|
||||||
webRequest.uploadHandler = (UploadHandler)new UploadHandlerRaw(postBytes);
|
return new ResultMessageEntity()
|
||||||
webRequest.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
|
{
|
||||||
webRequest.SetRequestHeader("Content-Type", "application/json");
|
code = 2001,
|
||||||
|
message = "用户未登录,请先登录"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
//UnityWebRequest[] files = new UnityWebRequest[3];
|
||||||
|
WWWForm form = new WWWForm();
|
||||||
|
|
||||||
|
for (int i = 0; i < path.Length; i++)
|
||||||
|
{
|
||||||
|
byte[] bytes = await File.ReadAllBytesAsync(path[i]);
|
||||||
|
form.AddBinaryData("files[]", bytes, Path.GetFileName(path[i]));
|
||||||
|
}
|
||||||
|
using (UnityWebRequest webRequest = UnityWebRequest.Post(url, form))
|
||||||
|
{
|
||||||
|
webRequest.SetRequestHeader("Authorization", authorization);
|
||||||
|
webRequest.disposeUploadHandlerOnDispose = true;
|
||||||
|
webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
|
webRequest.disposeCertificateHandlerOnDispose = true;
|
||||||
await webRequest.SendWebRequest();
|
await webRequest.SendWebRequest();
|
||||||
|
webRequest.uploadHandler?.Dispose();
|
||||||
// 更新错误检查方式
|
// 更新错误检查方式
|
||||||
if (webRequest.result == UnityWebRequest.Result.ConnectionError ||
|
if (webRequest.result == UnityWebRequest.Result.ConnectionError ||
|
||||||
webRequest.result == UnityWebRequest.Result.ProtocolError)
|
webRequest.result == UnityWebRequest.Result.ProtocolError)
|
||||||
{
|
{
|
||||||
Debug.LogError(webRequest.error);
|
Debug.LogError(webRequest.error);
|
||||||
return webRequest.error;
|
return new ResultMessageEntity()
|
||||||
|
{
|
||||||
|
code = 5001,
|
||||||
|
message = webRequest.error
|
||||||
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return webRequest.downloadHandler.text;
|
ResultMessageEntity resultMessageEntity =
|
||||||
|
JsonConvert.DeserializeObject<ResultMessageEntity>(webRequest.downloadHandler.text);
|
||||||
|
if (resultMessageEntity.code != 200)
|
||||||
|
{
|
||||||
|
Debug.LogError("上传异常,无文件数据返回!!");
|
||||||
|
}
|
||||||
|
return resultMessageEntity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// GET请求数据
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="url">请求数据的URL地址</param>
|
||||||
|
/// <param name="token">token验证的参数,此处为authorization</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<ResultMessageEntity> GetFile(string url,string tempPath, Action<float> downloadProgress = null)
|
||||||
|
{
|
||||||
|
if (!GetTokenState())
|
||||||
|
{
|
||||||
|
Debug.LogError("用户未登录,请先登录");
|
||||||
|
return new ResultMessageEntity()
|
||||||
|
{
|
||||||
|
code = 2001,
|
||||||
|
message = "用户未登录,请先登录"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
|
||||||
|
{
|
||||||
|
webRequest.downloadHandler = new DownloadHandlerFile(tempPath);
|
||||||
|
if (authorization != null)
|
||||||
|
webRequest.SetRequestHeader("Authorization", authorization); // 修正请求头名称规范
|
||||||
|
|
||||||
|
|
||||||
|
var operation= webRequest.SendWebRequest();
|
||||||
|
while (!operation.isDone)
|
||||||
|
{
|
||||||
|
downloadProgress?.Invoke(webRequest.downloadProgress);
|
||||||
|
await UniTask.Yield();
|
||||||
|
}
|
||||||
|
// 增强错误处理
|
||||||
|
if (webRequest.result != UnityWebRequest.Result.Success)
|
||||||
|
{
|
||||||
|
var errorMsg = $"HTTP {webRequest.responseCode}\n" +
|
||||||
|
$"URL: {url}\n" +
|
||||||
|
$"Error: {webRequest.error}\n";
|
||||||
|
|
||||||
|
Debug.LogError(errorMsg);
|
||||||
|
return new ResultMessageEntity()
|
||||||
|
{
|
||||||
|
code = 5001,
|
||||||
|
message = errorMsg
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new ResultMessageEntity()
|
||||||
|
{
|
||||||
|
code = 200,
|
||||||
|
message = "下载成功"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.LogError(e);
|
||||||
|
return new ResultMessageEntity()
|
||||||
|
{
|
||||||
|
code = 5001,
|
||||||
|
message = e.Message
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// POST请求数据
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="url">获取Token值的服务URL地址(很重要)</param>
|
||||||
|
/// <param name="postData">传入请求的参数,此处参数为JOSN格式</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<ResultMessageEntity> Post(string url, string postData)
|
||||||
|
{
|
||||||
|
if (!GetTokenState())
|
||||||
|
{
|
||||||
|
Debug.LogError("用户未登录,请先登录");
|
||||||
|
return new ResultMessageEntity()
|
||||||
|
{
|
||||||
|
code = 2001,
|
||||||
|
message = "用户未登录,请先登录"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
using (UnityWebRequest webRequest = UnityWebRequest.Post(url, postData)) //第二种写法此行注释
|
||||||
|
{
|
||||||
|
byte[] postBytes = System.Text.Encoding.UTF8.GetBytes(postData);
|
||||||
|
webRequest.uploadHandler = new UploadHandlerRaw(postBytes);
|
||||||
|
webRequest.SetRequestHeader("Content-Type", "application/json");
|
||||||
|
webRequest.SetRequestHeader("Authorization", authorization);
|
||||||
|
webRequest.disposeUploadHandlerOnDispose = true;
|
||||||
|
webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
|
webRequest.disposeCertificateHandlerOnDispose = true;
|
||||||
|
await webRequest.SendWebRequest();
|
||||||
|
webRequest.uploadHandler?.Dispose();
|
||||||
|
// 更新错误检查方式
|
||||||
|
if (webRequest.result == UnityWebRequest.Result.ConnectionError ||
|
||||||
|
webRequest.result == UnityWebRequest.Result.ProtocolError)
|
||||||
|
{
|
||||||
|
Debug.LogError(webRequest.error);
|
||||||
|
return new ResultMessageEntity()
|
||||||
|
{
|
||||||
|
code = 5001,
|
||||||
|
message = webRequest.error
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ResultMessageEntity resultMessageEntity =
|
||||||
|
JsonConvert.DeserializeObject<ResultMessageEntity>(webRequest.downloadHandler.text);
|
||||||
|
if (resultMessageEntity.code != 200)
|
||||||
|
{
|
||||||
|
Debug.LogError(resultMessageEntity.message);
|
||||||
|
}
|
||||||
|
return resultMessageEntity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,43 +285,73 @@ namespace Stary.Evo
|
|||||||
/// <param name="url">请求数据的URL地址</param>
|
/// <param name="url">请求数据的URL地址</param>
|
||||||
/// <param name="token">token验证的参数,此处为authorization</param>
|
/// <param name="token">token验证的参数,此处为authorization</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<string> Get(string url, string token=null)
|
public static async Task<ResultMessageEntity> Get(string url)
|
||||||
{
|
{
|
||||||
|
if (!GetTokenState())
|
||||||
|
{
|
||||||
|
Debug.LogError("用户未登录,请先登录");
|
||||||
|
return new ResultMessageEntity()
|
||||||
|
{
|
||||||
|
code = 2001,
|
||||||
|
message = "用户未登录,请先登录"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
|
using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
|
||||||
{
|
|
||||||
webRequest.downloadHandler = new DownloadHandlerBuffer();
|
|
||||||
if (token != null)
|
|
||||||
webRequest.SetRequestHeader("Authorization", token); // 修正请求头名称规范
|
|
||||||
|
|
||||||
await webRequest.SendWebRequest();
|
|
||||||
|
|
||||||
// 增强错误处理
|
|
||||||
if (webRequest.result != UnityWebRequest.Result.Success)
|
|
||||||
{
|
{
|
||||||
var errorMsg = $"HTTP {webRequest.responseCode}\n" +
|
webRequest.downloadHandler = new DownloadHandlerBuffer();
|
||||||
$"URL: {url}\n" +
|
if (authorization != null)
|
||||||
$"Error: {webRequest.error}\n" +
|
webRequest.SetRequestHeader("Authorization", authorization); // 修正请求头名称规范
|
||||||
$"Response: {webRequest.downloadHandler.text}";
|
|
||||||
|
await webRequest.SendWebRequest();
|
||||||
Debug.LogError(errorMsg);
|
|
||||||
return null;
|
// 增强错误处理
|
||||||
|
if (webRequest.result != UnityWebRequest.Result.Success)
|
||||||
|
{
|
||||||
|
var errorMsg = $"HTTP {webRequest.responseCode}\n" +
|
||||||
|
$"URL: {url}\n" +
|
||||||
|
$"Error: {webRequest.error}\n" +
|
||||||
|
$"Response: {webRequest.downloadHandler.text}";
|
||||||
|
|
||||||
|
Debug.LogError(errorMsg);
|
||||||
|
return new ResultMessageEntity()
|
||||||
|
{
|
||||||
|
code = 5001,
|
||||||
|
message = errorMsg
|
||||||
|
};
|
||||||
|
}
|
||||||
|
ResultMessageEntity resultMessageEntity =
|
||||||
|
JsonConvert.DeserializeObject<ResultMessageEntity>(webRequest.downloadHandler.text);
|
||||||
|
if (resultMessageEntity.code != 200)
|
||||||
|
{
|
||||||
|
Debug.LogError(resultMessageEntity.message);
|
||||||
|
}
|
||||||
|
return resultMessageEntity;
|
||||||
}
|
}
|
||||||
return webRequest.downloadHandler.text; // 添加返回值
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Debug.LogError(e);
|
Debug.LogError(e);
|
||||||
|
return new ResultMessageEntity()
|
||||||
|
{
|
||||||
|
code = 5001,
|
||||||
|
message = e.Message
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static bool GetTokenState()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(authorization))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "com.staryevo.main",
|
"name": "com.staryevo.main",
|
||||||
"version": "1.1.1",
|
"version": "1.2.0",
|
||||||
"displayName": "00.StaryEvo",
|
"displayName": "00.StaryEvo",
|
||||||
"description": "This is an Framework package",
|
"description": "This is an Framework package(后台服务器版本,端口9527)",
|
||||||
"unity": "2021.3",
|
"unity": "2021.3",
|
||||||
"unityRelease": "30f1",
|
"unityRelease": "30f1",
|
||||||
"author": {
|
"author": {
|
||||||
|
|||||||
@@ -8,24 +8,24 @@ namespace Stary.Evo
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// package name
|
/// package name
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string ASSETPACKGENAME;
|
public static string PackageDomainName { get; set; }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
public static string IpConfig { get; set; }
|
||||||
/// 热更资源路径
|
public static string UserName { get; set; }
|
||||||
/// </summary>
|
public static string PassWord { get; set; }
|
||||||
public static string PATHCONFIG;
|
public static string ProductName { get; set; }
|
||||||
|
public static string Platform { get; set; }
|
||||||
public static string IPCONFIG;
|
|
||||||
public static string USERNAME;
|
public static string MainDomainVersion { get; set; }
|
||||||
public static string PASSWORD;
|
|
||||||
|
|
||||||
public static string IPCONFIGVideo;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 主场景main实例物体
|
/// 主场景main实例物体
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static GameObject _MainBaseModel;
|
private static GameObject _MainBaseModel;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 赋值默认的实例
|
/// 赋值默认的实例
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -32,7 +32,7 @@ namespace Stary.Evo
|
|||||||
{
|
{
|
||||||
DomainConfig domainConfig = param as DomainConfig;
|
DomainConfig domainConfig = param as DomainConfig;
|
||||||
Debug.Log("UnityEvo:热更脚本...");
|
Debug.Log("UnityEvo:热更脚本...");
|
||||||
var package = YooAssets.GetPackage(AppConfig.ASSETPACKGENAME);
|
var package = YooAssets.GetPackage(AppConfig.PackageDomainName);
|
||||||
// Editor环境下,HotUpdate.dll.bytes已经被自动加载,不需要加载,重复加载反而会出问题。
|
// Editor环境下,HotUpdate.dll.bytes已经被自动加载,不需要加载,重复加载反而会出问题。
|
||||||
|
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ namespace Stary.Evo
|
|||||||
Assembly hotUpdateAss = System.AppDomain.CurrentDomain.GetAssemblies()
|
Assembly hotUpdateAss = System.AppDomain.CurrentDomain.GetAssemblies()
|
||||||
.First(a => a.GetName().Name == $"HotUpdate_{AppConfig.ASSETPACKGENAME}");
|
.First(a => a.GetName().Name == $"HotUpdate_{AppConfig.ASSETPACKGENAME}");
|
||||||
#else
|
#else
|
||||||
string hotUpdateAssemblyName = $"HotUpdate_{AppConfig.ASSETPACKGENAME}";
|
string hotUpdateAssemblyName = $"HotUpdate_{AppConfig.PackageDomainName}";
|
||||||
|
|
||||||
|
|
||||||
Type assemblyType = IsAssetLoaded(fullClassName);
|
Type assemblyType = IsAssetLoaded(fullClassName);
|
||||||
@@ -78,9 +78,9 @@ namespace Stary.Evo
|
|||||||
LoadMetadataForAOTAssemblies();
|
LoadMetadataForAOTAssemblies();
|
||||||
|
|
||||||
// 加载热更dll
|
// 加载热更dll
|
||||||
var hotfixDll = package.LoadAssetAsync<TextAsset>($"Android_HotUpdate_{AppConfig.ASSETPACKGENAME}.dll");
|
var hotfixDll = package.LoadAssetAsync<TextAsset>($"Android_HotUpdate_{AppConfig.PackageDomainName}.dll");
|
||||||
await hotfixDll;
|
await hotfixDll;
|
||||||
var hotfixPdb = package.LoadAssetAsync<TextAsset>($"Android_HotUpdate_{AppConfig.ASSETPACKGENAME}.pdb");
|
var hotfixPdb = package.LoadAssetAsync<TextAsset>($"Android_HotUpdate_{AppConfig.PackageDomainName}.pdb");
|
||||||
await hotfixPdb;
|
await hotfixPdb;
|
||||||
Assembly hotUpdateAss = null;
|
Assembly hotUpdateAss = null;
|
||||||
if (hotfixDll.Status == EOperationStatus.Succeed)
|
if (hotfixDll.Status == EOperationStatus.Succeed)
|
||||||
@@ -100,7 +100,7 @@ namespace Stary.Evo
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.LogError($"UnityEvo:Android_HotUpdate_{AppConfig.ASSETPACKGENAME}.dll加载失败!!!!!");
|
Debug.LogError($"UnityEvo:Android_HotUpdate_{AppConfig.PackageDomainName}.dll加载失败!!!!!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using Cysharp.Threading.Tasks;
|
using Cysharp.Threading.Tasks;
|
||||||
|
using Main;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Stary.Evo.UIFarme;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Assertions;
|
using UnityEngine.Assertions;
|
||||||
@@ -16,38 +19,39 @@ namespace Stary.Evo
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public override async UniTask OnEnterAsync()
|
public override async UniTask OnEnterAsync()
|
||||||
{
|
{
|
||||||
Debug.Log("UnityEvo:启动开始资源初始化...");
|
Debug.Log("UnityEvo:启动开始资源初始化...");
|
||||||
|
|
||||||
|
|
||||||
//初始化读取资源配置表
|
//初始化读取资源配置表
|
||||||
HotfixMainResDomain hotfixMainResDomain = Resources.Load<HotfixMainResDomain>("HotfixMainResDomain");
|
HotfixMainResDomain hotfixMainResDomain = Resources.Load<HotfixMainResDomain>("HotfixMainResDomain");
|
||||||
if (hotfixMainResDomain != null)
|
if (hotfixMainResDomain != null)
|
||||||
{
|
{
|
||||||
AppConfig.IPCONFIG = hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig;
|
AppConfig.IpConfig = hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig;
|
||||||
AppConfig.USERNAME = hotfixMainResDomain.hotfixMainResDomainEntity.username;
|
AppConfig.UserName = hotfixMainResDomain.hotfixMainResDomainEntity.username;
|
||||||
AppConfig.PASSWORD = hotfixMainResDomain.hotfixMainResDomainEntity.password;
|
AppConfig.PassWord = hotfixMainResDomain.hotfixMainResDomainEntity.password;
|
||||||
|
AppConfig.ProductName = hotfixMainResDomain.hotfixMainResDomainEntity.productName;
|
||||||
|
AppConfig.MainDomainVersion = hotfixMainResDomain.hotfixMainResDomainEntity.mainDomainVersion;
|
||||||
}
|
}
|
||||||
Debug.Log($"UnityEvo:读取资源配置表成功...{ AppConfig.IPCONFIG}{AppConfig.USERNAME}{AppConfig.PASSWORD}");
|
|
||||||
|
Debug.Log($"UnityEvo:读取资源配置表成功...{AppConfig.IpConfig}{AppConfig.UserName}{AppConfig.PassWord}");
|
||||||
// 初始化资源系统
|
// 初始化资源系统
|
||||||
YooAssets.Initialize();
|
YooAssets.Initialize();
|
||||||
|
|
||||||
|
|
||||||
//自定义网络请求器
|
//自定义网络请求器
|
||||||
// 设置自定义请求委托
|
// 设置自定义请求委托
|
||||||
YooAssets.SetDownloadSystemUnityWebRequest(NasWebRequester);
|
//YooAssets.SetDownloadSystemUnityWebRequest(NasWebRequester);
|
||||||
|
|
||||||
|
|
||||||
//初始化资源加载模块
|
//初始化资源加载模块
|
||||||
// 增加包存在性检查
|
// 增加包存在性检查
|
||||||
var package = YooAssets.TryGetPackage(AppConfig.ASSETPACKGENAME);
|
var package = YooAssets.TryGetPackage(AppConfig.PackageDomainName);
|
||||||
if (package == null)
|
if (package == null)
|
||||||
{
|
{
|
||||||
Debug.LogWarning($"UnityEvo:资源包 {AppConfig.ASSETPACKGENAME} 不存在,正在尝试创建...");
|
Debug.LogWarning($"UnityEvo:资源包 {AppConfig.PackageDomainName} 不存在,正在尝试创建...");
|
||||||
package = YooAssets.CreatePackage(AppConfig.ASSETPACKGENAME);
|
package = YooAssets.CreatePackage(AppConfig.PackageDomainName);
|
||||||
}
|
}
|
||||||
|
|
||||||
YooAssets.SetDefaultPackage(package);
|
YooAssets.SetDefaultPackage(package);
|
||||||
@@ -55,11 +59,10 @@ namespace Stary.Evo
|
|||||||
// 初始化资源包
|
// 初始化资源包
|
||||||
#if EDITOR_SIMULATEMODE
|
#if EDITOR_SIMULATEMODE
|
||||||
await EDITOR_SIMULATEMODE(package);
|
await EDITOR_SIMULATEMODE(package);
|
||||||
AppConfig.IPCONFIGVideo = "http://192.168.31.100:9527/";
|
FsmSystem.SetCurState(nameof(ResUpdateServerState));
|
||||||
#elif OFFLINE_PLAYMODE
|
#elif OFFLINE_PLAYMODE
|
||||||
await OFFLINE_PLAYMODE(package);
|
await OFFLINE_PLAYMODE(package);
|
||||||
AppConfig.IPCONFIGVideo = Application.streamingAssetsPath + "/";
|
FsmSystem.SetCurState(nameof(ResUpdateLocalState));
|
||||||
|
|
||||||
#elif HOST_PLAYMODE
|
#elif HOST_PLAYMODE
|
||||||
if (package.PackageName.Equals("Main"))
|
if (package.PackageName.Equals("Main"))
|
||||||
{
|
{
|
||||||
@@ -67,10 +70,17 @@ namespace Stary.Evo
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await HOST_PLAYMODE(package);
|
//登录
|
||||||
|
string url = AppConfig.IpConfig + "/Authentication/login";
|
||||||
|
bool isLogin = await WebRequestSystem.Login(url, AppConfig.UserName, AppConfig.PassWord);
|
||||||
|
if (isLogin)
|
||||||
|
await HOST_PLAYMODE(package);
|
||||||
|
else
|
||||||
|
await OFFLINE_PLAYMODE(package);
|
||||||
}
|
}
|
||||||
|
|
||||||
AppConfig.IPCONFIGVideo = "http://192.168.31.100:9527/";
|
FsmSystem.SetCurState(nameof(ResUpdateLocalState));
|
||||||
|
|
||||||
#elif WEB_PLAYMODE
|
#elif WEB_PLAYMODE
|
||||||
// IRemoteServices remoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
|
// IRemoteServices remoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
|
||||||
// var webServerFileSystemParams = FileSystemParameters.CreateDefaultWebServerFileSystemParameters();
|
// var webServerFileSystemParams = FileSystemParameters.CreateDefaultWebServerFileSystemParameters();
|
||||||
@@ -91,24 +101,23 @@ namespace Stary.Evo
|
|||||||
|
|
||||||
Debug.LogError($"UnityEvo:暂不支持");
|
Debug.LogError($"UnityEvo:暂不支持");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FsmSystem.SetCurState(nameof(ResUpdateServerState));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override UniTask OnEnterAsync<T>(T param)
|
public override UniTask OnEnterAsync<T>(T param)
|
||||||
{
|
{
|
||||||
return UniTask.CompletedTask;
|
return UniTask.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override UniTask OnEnterAsync<T1, T2>(T1 param1, T2 param2)
|
public override UniTask OnEnterAsync<T1, T2>(T1 param1, T2 param2)
|
||||||
{
|
{
|
||||||
return UniTask.CompletedTask;
|
return UniTask.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnUpdate()
|
public override void OnUpdate()
|
||||||
{
|
{
|
||||||
base.OnUpdate();
|
base.OnUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public override UniTask OnExitAsync()
|
public override UniTask OnExitAsync()
|
||||||
{
|
{
|
||||||
@@ -117,7 +126,7 @@ namespace Stary.Evo
|
|||||||
|
|
||||||
private async UniTask EDITOR_SIMULATEMODE(ResourcePackage package)
|
private async UniTask EDITOR_SIMULATEMODE(ResourcePackage package)
|
||||||
{
|
{
|
||||||
var buildResult = EditorSimulateModeHelper.SimulateBuild(AppConfig.ASSETPACKGENAME);
|
var buildResult = EditorSimulateModeHelper.SimulateBuild(AppConfig.PackageDomainName);
|
||||||
var packageRoot = buildResult.PackageRootDirectory;
|
var packageRoot = buildResult.PackageRootDirectory;
|
||||||
var editorFileSystemParameters = FileSystemParameters.CreateDefaultEditorFileSystemParameters(packageRoot);
|
var editorFileSystemParameters = FileSystemParameters.CreateDefaultEditorFileSystemParameters(packageRoot);
|
||||||
var initParams = new EditorSimulateModeParameters();
|
var initParams = new EditorSimulateModeParameters();
|
||||||
@@ -154,65 +163,52 @@ namespace Stary.Evo
|
|||||||
// 新增平台判断代码
|
// 新增平台判断代码
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
BuildTarget buildTarget = UnityEditor.EditorUserBuildSettings.activeBuildTarget;
|
BuildTarget buildTarget = UnityEditor.EditorUserBuildSettings.activeBuildTarget;
|
||||||
string platformName = buildTarget.ToString();
|
AppConfig.Platform = buildTarget.ToString();
|
||||||
#else
|
#else
|
||||||
string platformName = Application.platform.ToString();
|
AppConfig.Platform = Application.platform.ToString();
|
||||||
#endif
|
#endif
|
||||||
Debug.Log($"目标平台标识: {platformName}");
|
Debug.Log($"目标平台标识: {AppConfig.Platform}");
|
||||||
//从服务器加载配置列表
|
|
||||||
WebRequestSystem webRequestSystem = new WebRequestSystem();
|
// 请求资源版本
|
||||||
string URL =
|
string url = $"{AppConfig.IpConfig}/ResDomain/GetResDomainByDomain";
|
||||||
$"{AppConfig.IPCONFIG}/HybridclrConfigData/{AppConfig.ASSETPACKGENAME}/{platformName}/{Application.productName}.json";
|
var resDmainRequst = new ResDmainRequst()
|
||||||
Debug.Log("UnityEvo: 服务器配置文件地址:" + URL);
|
|
||||||
string text = await webRequestSystem.Get(URL, GetAuthorization(AppConfig.USERNAME, AppConfig.PASSWORD));
|
|
||||||
if (!string.IsNullOrEmpty(text))
|
|
||||||
{
|
{
|
||||||
try
|
ProductName = AppConfig.ProductName,
|
||||||
|
DomainName = AppConfig.PackageDomainName,
|
||||||
|
Platform = AppConfig.Platform,
|
||||||
|
};
|
||||||
|
//获取服务器版本
|
||||||
|
var resDmainMessageEntity = await WebRequestSystem.Post(url, JsonConvert.SerializeObject(resDmainRequst));
|
||||||
|
if (resDmainMessageEntity.code == 200)
|
||||||
|
{
|
||||||
|
ResDmainResponse resDmainResponse =
|
||||||
|
JsonConvert.DeserializeObject<ResDmainResponse>(resDmainMessageEntity.data.ToString());
|
||||||
|
//获取当前版本
|
||||||
|
var oldVersion = PlayerPrefs.GetString($"{AppConfig.PackageDomainName}_GAME_VERSION");
|
||||||
|
//版本不一致,开始下载
|
||||||
|
if (resDmainResponse.PackageVersion != oldVersion)
|
||||||
{
|
{
|
||||||
Debug.Log("UnityEvo: 服务器配置文件读取成功:" + text);
|
await Download(resDmainResponse.DocumentFileId);
|
||||||
text = text.Trim('\uFEFF'); // 移除 BOM 字符
|
PlayerPrefs.SetString($"{AppConfig.PackageDomainName}_GAME_VERSION",
|
||||||
HotfixMainResDomainEntity hotfixMainResDomainEntity =
|
resDmainResponse.PackageVersion);
|
||||||
JsonConvert.DeserializeObject<HotfixMainResDomainEntity>(text);
|
|
||||||
if (hotfixMainResDomainEntity != null &&
|
|
||||||
hotfixMainResDomainEntity.domain == AppConfig.ASSETPACKGENAME)
|
|
||||||
{
|
|
||||||
AppConfig.IPCONFIG = hotfixMainResDomainEntity.ipconfig;
|
|
||||||
AppConfig.PATHCONFIG = hotfixMainResDomainEntity.pathconfig;
|
|
||||||
AppConfig.ASSETPACKGENAME = hotfixMainResDomainEntity.domain;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new Exception("服务器配置文件中Domain与指定domain不匹配,进程中断,请排查:" + AppConfig.ASSETPACKGENAME);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (JsonException e)
|
else //版本一致,加载缓存资源
|
||||||
{
|
{
|
||||||
Debug.LogError($"UnityEvo:JSON解析失败: {e.Message}\n原始内容: {text}");
|
Debug.Log($"UnityEvo:资源版本一致,自动跳过更新...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.LogError("UnityEvo:从服务器获取的配置数据为空");
|
Debug.LogError($"UnityEvo:获取资源版本失败: 【{resDmainMessageEntity.message}】");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var initParameters = new OfflinePlayModeParameters();
|
||||||
string defaultHostServer = $"{AppConfig.IPCONFIG}/{AppConfig.PATHCONFIG}";
|
var buildinFileSystemParams = FileSystemParameters.CreateDefaultBuildinFileSystemParameters(null,
|
||||||
string fallbackHostServer = $"{AppConfig.IPCONFIG}/{AppConfig.PATHCONFIG}";
|
$"{Application.persistentDataPath}/DownloadedContent/{AppConfig.PackageDomainName}");
|
||||||
|
|
||||||
Debug.Log($"UnityEvo:正在初始化远程资源包,主服务器:{defaultHostServer}");
|
|
||||||
// 在初始化下载器前添加证书验证配置
|
|
||||||
|
|
||||||
|
|
||||||
var initParameters = new HostPlayModeParameters();
|
|
||||||
IRemoteServices remoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
|
|
||||||
var cacheFileSystemParams = FileSystemParameters.CreateDefaultCacheFileSystemParameters(remoteServices);
|
|
||||||
cacheFileSystemParams.AddParameter(FileSystemParametersDefine.APPEND_FILE_EXTENSION, true);
|
|
||||||
|
|
||||||
var buildinFileSystemParams = FileSystemParameters.CreateDefaultBuildinFileSystemParameters();
|
|
||||||
buildinFileSystemParams.AddParameter(FileSystemParametersDefine.APPEND_FILE_EXTENSION, true);
|
buildinFileSystemParams.AddParameter(FileSystemParametersDefine.APPEND_FILE_EXTENSION, true);
|
||||||
buildinFileSystemParams.AddParameter(FileSystemParametersDefine.COPY_BUILDIN_PACKAGE_MANIFEST, true);
|
buildinFileSystemParams.AddParameter(FileSystemParametersDefine.COPY_BUILDIN_PACKAGE_MANIFEST, true);
|
||||||
initParameters.BuildinFileSystemParameters = null;
|
initParameters.BuildinFileSystemParameters = buildinFileSystemParams;
|
||||||
initParameters.CacheFileSystemParameters = cacheFileSystemParams;
|
// initParameters.CacheFileSystemParameters = cacheFileSystemParams;
|
||||||
|
|
||||||
var initOperation = package.InitializeAsync(initParameters);
|
var initOperation = package.InitializeAsync(initParameters);
|
||||||
|
|
||||||
@@ -224,24 +220,32 @@ namespace Stary.Evo
|
|||||||
Debug.LogError($"UnityEvo:从远程加载资源包,初始化失败:{initOperation.Error}");
|
Debug.LogError($"UnityEvo:从远程加载资源包,初始化失败:{initOperation.Error}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public async UniTask Download(string fileId)
|
||||||
/// 自定义网络请求器需要登录
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="url"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
private UnityWebRequest NasWebRequester(string url)
|
|
||||||
{
|
{
|
||||||
var request = new UnityWebRequest(url, UnityWebRequest.kHttpVerbGET);
|
// 在任意MonoBehaviour或DomainBase派生类中
|
||||||
var authorization = GetAuthorization(AppConfig.USERNAME, AppConfig.PASSWORD);
|
string loadPath = $"{Application.persistentDataPath}/DownloadedContent/{AppConfig.PackageDomainName}";
|
||||||
request.SetRequestHeader("AUTHORIZATION", authorization);
|
if (Directory.Exists(loadPath))
|
||||||
return request;
|
{
|
||||||
|
Directory.Delete(loadPath, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
await MainArchitecture.Interface.GetSystem<IPanelSystem>()
|
||||||
|
.PushQueue<ProgressBarPanel>(Camera.main.transform, "Main");
|
||||||
|
await ZipTool.DownloadAndUnzipAsync(fileId, loadPath, DownLoadProgress, UnzipProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetAuthorization(string userName, string password)
|
private void DownLoadProgress(float progress)
|
||||||
{
|
{
|
||||||
string auth = userName + ":" + password;
|
Debug.Log($"下载进度:{progress:P0}");
|
||||||
var bytes = System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(auth);
|
MainArchitecture.Interface.GetSystem<IPanelSystem>()
|
||||||
return "Basic " + System.Convert.ToBase64String(bytes);
|
.SendPanelEvent(ProgressBarPanel.ProgressBarType.Add, "下载中", progress);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UnzipProgress(float progress)
|
||||||
|
{
|
||||||
|
Debug.Log($"解压进度:{progress:P0}");
|
||||||
|
MainArchitecture.Interface.GetSystem<IPanelSystem>()
|
||||||
|
.SendPanelEvent(ProgressBarPanel.ProgressBarType.Add, "解压中", progress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,20 +20,40 @@ namespace Stary.Evo
|
|||||||
public override async UniTask OnEnterAsync()
|
public override async UniTask OnEnterAsync()
|
||||||
{
|
{
|
||||||
//初始化读取资源配置表
|
//初始化读取资源配置表
|
||||||
var package = YooAssets.GetPackage(AppConfig.ASSETPACKGENAME);
|
var package = YooAssets.GetPackage(AppConfig.PackageDomainName);
|
||||||
|
|
||||||
|
|
||||||
//更新失败
|
//更新失败
|
||||||
|
|
||||||
Debug.Log($"UnityEvo:切换为加载本地缓存资源...");
|
Debug.Log($"UnityEvo:切换为加载本地缓存资源...");
|
||||||
|
string packageVersion = "";
|
||||||
// 获取上次成功记录的版本
|
if (package.PackageName.Equals("Main"))
|
||||||
string packageVersion = PlayerPrefs.GetString("GAME_VERSION", string.Empty);
|
|
||||||
if (string.IsNullOrEmpty(packageVersion))
|
|
||||||
{
|
{
|
||||||
Debug.Log($"UnityEvo:没有找到本地版本记录,需要更新资源!");
|
var operation = package.RequestPackageVersionAsync();
|
||||||
return;
|
await operation;
|
||||||
|
if (operation.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
//更新成功
|
||||||
|
packageVersion = operation.PackageVersion;
|
||||||
|
Debug.Log($"Unity:【Main】Request package Version : {packageVersion}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//更新失败
|
||||||
|
Debug.LogError("Unity:【Main】"+operation.Error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 获取上次成功记录的版本
|
||||||
|
packageVersion = PlayerPrefs.GetString($"{AppConfig.PackageDomainName}_GAME_VERSION", string.Empty);
|
||||||
|
if (string.IsNullOrEmpty(packageVersion))
|
||||||
|
{
|
||||||
|
Debug.Log($"UnityEvo:没有找到本地版本记录,需要更新资源!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Debug.Log($"UnityEvo:获取资源版本 Version : 【{packageVersion}】");
|
Debug.Log($"UnityEvo:获取资源版本 Version : 【{packageVersion}】");
|
||||||
Debug.Log($"UnityEvo:开始加载本地资源...");
|
Debug.Log($"UnityEvo:开始加载本地资源...");
|
||||||
@@ -116,7 +136,7 @@ namespace Stary.Evo
|
|||||||
{
|
{
|
||||||
int downloadingMaxNum = 1;
|
int downloadingMaxNum = 1;
|
||||||
int failedTryAgain = 1;
|
int failedTryAgain = 1;
|
||||||
var package = YooAssets.GetPackage(AppConfig.ASSETPACKGENAME);
|
var package = YooAssets.GetPackage(AppConfig.PackageDomainName);
|
||||||
var downloader = package.CreateResourceDownloader(downloadingMaxNum, failedTryAgain);
|
var downloader = package.CreateResourceDownloader(downloadingMaxNum, failedTryAgain);
|
||||||
|
|
||||||
// 在正常开始游戏之前,还需要验证本地清单内容的完整性。
|
// 在正常开始游戏之前,还需要验证本地清单内容的完整性。
|
||||||
@@ -20,7 +20,7 @@ namespace Stary.Evo
|
|||||||
|
|
||||||
|
|
||||||
// //初始化读取资源配置表
|
// //初始化读取资源配置表
|
||||||
var package = YooAssets.GetPackage(AppConfig.ASSETPACKGENAME);
|
var package = YooAssets.GetPackage(AppConfig.PackageDomainName);
|
||||||
// 请求资源版本
|
// 请求资源版本
|
||||||
var requetVersionOp = package.RequestPackageVersionAsync();
|
var requetVersionOp = package.RequestPackageVersionAsync();
|
||||||
await requetVersionOp;
|
await requetVersionOp;
|
||||||
@@ -29,7 +29,7 @@ namespace Stary.Evo
|
|||||||
{
|
{
|
||||||
//更新成功
|
//更新成功
|
||||||
packageVersion = requetVersionOp.PackageVersion;
|
packageVersion = requetVersionOp.PackageVersion;
|
||||||
PlayerPrefs.SetString("GAME_VERSION", packageVersion);
|
PlayerPrefs.SetString($"{AppConfig.PackageDomainName}_GAME_VERSION", packageVersion);
|
||||||
Debug.Log($"UnityEvo:获取资源版本 Version : 【{packageVersion}】");
|
Debug.Log($"UnityEvo:获取资源版本 Version : 【{packageVersion}】");
|
||||||
Debug.Log($"UnityEvo:开始加载服务器资源...");
|
Debug.Log($"UnityEvo:开始加载服务器资源...");
|
||||||
}
|
}
|
||||||
@@ -120,46 +120,34 @@ namespace Stary.Evo
|
|||||||
|
|
||||||
public async UniTask Download()
|
public async UniTask Download()
|
||||||
{
|
{
|
||||||
// 在任意MonoBehaviour或DomainBase派生类中
|
|
||||||
string[] andUnzipAsyncPath= await ZipTool.DownloadAndUnzipAsync(
|
|
||||||
$"{AppConfig.IPCONFIG}/XOSMOPlug_inLibrary/{AppConfig.ASSETPACKGENAME}/Android/1.0.5/X_02_01_1.0.5.zip",
|
|
||||||
Application.persistentDataPath + "/DownloadedContent",
|
|
||||||
progress => Debug.Log($"下载进度:{progress:P0}"),
|
|
||||||
progress => Debug.Log($"解压进度:{progress:P0}")
|
|
||||||
);
|
|
||||||
var package = YooAssets.GetPackage(AppConfig.ASSETPACKGENAME);
|
|
||||||
var downloader = package.CreateResourceImporter(andUnzipAsyncPath, 3, 3);
|
|
||||||
|
|
||||||
|
int downloadingMaxNum = 10;
|
||||||
|
int failedTryAgain = 3;
|
||||||
|
var package = YooAssets.GetPackage(AppConfig.PackageDomainName);
|
||||||
|
var downloader = package.CreateResourceDownloader(downloadingMaxNum, failedTryAgain);
|
||||||
|
|
||||||
|
//没有需要下载的资源
|
||||||
|
if (downloader.TotalDownloadCount == 0)
|
||||||
|
{
|
||||||
|
Debug.Log("UnityEvo:没有需要下载的资源,跳过更新");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//需要下载的文件总数和总大小
|
||||||
|
int totalDownloadCount = downloader.TotalDownloadCount;
|
||||||
|
long totalDownloadBytes = downloader.TotalDownloadBytes;
|
||||||
|
Debug.Log($"UnityEvo:需要下载的资源的个数【{totalDownloadCount}】,需要下载的资源的总大小{totalDownloadBytes/1024} MB");
|
||||||
|
//===================================适应新版本YooAsset插件的修改===================================
|
||||||
|
//注册回调方法
|
||||||
|
downloader.DownloadErrorCallback = OnDownloadErrorFunction;
|
||||||
|
downloader.DownloadUpdateCallback = OnDownloadProgressUpdateFunction;
|
||||||
|
downloader.DownloadFinishCallback = OnDownloadOverFunction;
|
||||||
|
downloader.DownloadFileBeginCallback = OnStartDownloadFileFunction;
|
||||||
|
//===================================适应新版本YooAsset插件的修改===================================
|
||||||
|
|
||||||
// int downloadingMaxNum = 10;
|
//开启下载
|
||||||
// int failedTryAgain = 3;
|
downloader.BeginDownload();
|
||||||
// var package = YooAssets.GetPackage(AppConfig.ASSETPACKGENAME);
|
await downloader;
|
||||||
// var downloader = package.CreateResourceDownloader(downloadingMaxNum, failedTryAgain);
|
|
||||||
|
|
||||||
// //没有需要下载的资源
|
|
||||||
// if (downloader.TotalDownloadCount == 0)
|
|
||||||
// {
|
|
||||||
// Debug.Log("UnityEvo:没有需要下载的资源,跳过更新");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //需要下载的文件总数和总大小
|
|
||||||
// int totalDownloadCount = downloader.TotalDownloadCount;
|
|
||||||
// long totalDownloadBytes = downloader.TotalDownloadBytes;
|
|
||||||
// Debug.Log($"UnityEvo:需要下载的资源的个数【{totalDownloadCount}】,需要下载的资源的总大小{totalDownloadBytes/1024} MB");
|
|
||||||
// //===================================适应新版本YooAsset插件的修改===================================
|
|
||||||
// //注册回调方法
|
|
||||||
// downloader.DownloadErrorCallback = OnDownloadErrorFunction;
|
|
||||||
// downloader.DownloadUpdateCallback = OnDownloadProgressUpdateFunction;
|
|
||||||
// downloader.DownloadFinishCallback = OnDownloadOverFunction;
|
|
||||||
// downloader.DownloadFileBeginCallback = OnStartDownloadFileFunction;
|
|
||||||
// //===================================适应新版本YooAsset插件的修改===================================
|
|
||||||
//
|
|
||||||
// //开启下载
|
|
||||||
// downloader.BeginDownload();
|
|
||||||
await downloader;
|
|
||||||
|
|
||||||
//检测下载结果
|
//检测下载结果
|
||||||
if (downloader.Status == EOperationStatus.Succeed)
|
if (downloader.Status == EOperationStatus.Succeed)
|
||||||
@@ -30,20 +30,20 @@ namespace Stary.Evo
|
|||||||
domain = "Main";
|
domain = "Main";
|
||||||
#endif
|
#endif
|
||||||
_fsmSystem.SetOpenDomainType(OpenDomainType.DEFAULT);
|
_fsmSystem.SetOpenDomainType(OpenDomainType.DEFAULT);
|
||||||
AppConfig.ASSETPACKGENAME = domain;
|
AppConfig.PackageDomainName = domain;
|
||||||
_fsmSystem.SetCurState(nameof(ResStartState));
|
_fsmSystem.SetCurState(nameof(ResStartState));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenDomain()
|
public void OpenDomain()
|
||||||
{
|
{
|
||||||
AppConfig.ASSETPACKGENAME = domain;
|
AppConfig.PackageDomainName = domain;
|
||||||
_fsmSystem.SetCurState(nameof(ResStartState));
|
_fsmSystem.SetCurState(nameof(ResStartState));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenDomain(string domain, OpenDomainType openDomainType)
|
public void OpenDomain(string domain, OpenDomainType openDomainType)
|
||||||
{
|
{
|
||||||
_fsmSystem.SetOpenDomainType(openDomainType);
|
_fsmSystem.SetOpenDomainType(openDomainType);
|
||||||
AppConfig.ASSETPACKGENAME = domain;
|
AppConfig.PackageDomainName = domain;
|
||||||
_fsmSystem.SetCurState(nameof(ResStartState));
|
_fsmSystem.SetCurState(nameof(ResStartState));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
7
Assets/Main/Script/Runtime/Tools/WebRequestTools.cs
Normal file
7
Assets/Main/Script/Runtime/Tools/WebRequestTools.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Stary.Evo
|
||||||
|
{
|
||||||
|
public class WebRequestTools
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Assets/Main/Script/Runtime/Tools/WebRequestTools.cs.meta
Normal file
3
Assets/Main/Script/Runtime/Tools/WebRequestTools.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 48091c7012fc4cd88a54c096febdcdd0
|
||||||
|
timeCreated: 1748318581
|
||||||
Reference in New Issue
Block a user