diff --git a/Assets/00.StaryEvo/Editor/BuildAsset/BuildAssetEntity.cs b/Assets/00.StaryEvo/Editor/BuildAsset/BuildAssetEntity.cs
index 233fd0f..484b3d7 100644
--- a/Assets/00.StaryEvo/Editor/BuildAsset/BuildAssetEntity.cs
+++ b/Assets/00.StaryEvo/Editor/BuildAsset/BuildAssetEntity.cs
@@ -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)
diff --git a/Assets/00.StaryEvo/Editor/BuildAsset/BuildAssetWindow.cs b/Assets/00.StaryEvo/Editor/BuildAsset/BuildAssetWindow.cs
index 0385113..07f47a4 100644
--- a/Assets/00.StaryEvo/Editor/BuildAsset/BuildAssetWindow.cs
+++ b/Assets/00.StaryEvo/Editor/BuildAsset/BuildAssetWindow.cs
@@ -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;
///
@@ -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 resultMessageEntities =
+ JsonConvert.DeserializeObject>(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(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
///
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(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,
}
}
\ No newline at end of file
diff --git a/Assets/00.StaryEvo/Editor/BuildAsset/CreatAssetWindow.cs b/Assets/00.StaryEvo/Editor/BuildAsset/CreatAssetWindow.cs
index a63542f..d7ad156 100644
--- a/Assets/00.StaryEvo/Editor/BuildAsset/CreatAssetWindow.cs
+++ b/Assets/00.StaryEvo/Editor/BuildAsset/CreatAssetWindow.cs
@@ -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.hotfixMainResDomainEntity = new HotfixMainResDomainEntity();
- hotfixMainResDomain.hotfixMainResDomainEntity.domain = domain;
- AssetDatabase.CreateAsset(hotfixMainResDomain, $"Assets/Domain/{domain}/Conf/HotfixMainResDomain.asset");
+
//编辑器配置资源
BuildAssetDataSetting buildAssetDataSetting = CreateInstance();
diff --git a/Assets/00.StaryEvo/Editor/Create/ChangeScriptTemplates.meta b/Assets/00.StaryEvo/Editor/Create/ChangeScriptTemplates.meta
deleted file mode 100644
index 81be761..0000000
--- a/Assets/00.StaryEvo/Editor/Create/ChangeScriptTemplates.meta
+++ /dev/null
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: 10cd38fccc1db684d9a576da1f9dc85e
-folderAsset: yes
-DefaultImporter:
- externalObjects: {}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/00.StaryEvo/Editor/Create/ChangeScriptTemplates/ChangeScriptTemplates.cs b/Assets/00.StaryEvo/Editor/Create/ChangeScriptTemplates/ChangeScriptTemplates.cs
deleted file mode 100644
index 029e68e..0000000
--- a/Assets/00.StaryEvo/Editor/Create/ChangeScriptTemplates/ChangeScriptTemplates.cs
+++ /dev/null
@@ -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);
-// }
-//
-// }
-// }
-// }
\ No newline at end of file
diff --git a/Assets/00.StaryEvo/Editor/Create/ChangeScriptTemplates/ChangeScriptTemplates.cs.meta b/Assets/00.StaryEvo/Editor/Create/ChangeScriptTemplates/ChangeScriptTemplates.cs.meta
deleted file mode 100644
index 31f4239..0000000
--- a/Assets/00.StaryEvo/Editor/Create/ChangeScriptTemplates/ChangeScriptTemplates.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 46fd7b74d162e9042a93085169ef025f
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/00.StaryEvo/Editor/Create/CreatStringToLayer/PlayerPrefsData.cs b/Assets/00.StaryEvo/Editor/Create/CreatStringToLayer/PlayerPrefsData.cs
new file mode 100644
index 0000000..2341882
--- /dev/null
+++ b/Assets/00.StaryEvo/Editor/Create/CreatStringToLayer/PlayerPrefsData.cs
@@ -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();
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/Assets/00.StaryEvo/Editor/Create/CreatStringToLayer/PlayerPrefsData.cs.meta b/Assets/00.StaryEvo/Editor/Create/CreatStringToLayer/PlayerPrefsData.cs.meta
new file mode 100644
index 0000000..92e6333
--- /dev/null
+++ b/Assets/00.StaryEvo/Editor/Create/CreatStringToLayer/PlayerPrefsData.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 56c6f609a1f54a48939218df73a1e4fd
+timeCreated: 1748584452
\ No newline at end of file
diff --git a/Assets/00.StaryEvo/Editor/MarkAdressable/MarkAdressable.cs b/Assets/00.StaryEvo/Editor/MarkAdressable/MarkAdressable.cs
index 03716b8..e4771b4 100644
--- a/Assets/00.StaryEvo/Editor/MarkAdressable/MarkAdressable.cs
+++ b/Assets/00.StaryEvo/Editor/MarkAdressable/MarkAdressable.cs
@@ -133,10 +133,10 @@ namespace Stary.Evo.Editor
if (oneKeyBUildEntity.isRaw)
{
string configPath =
- $"Assets/Domain/{oneKeyBUildEntity.DomainName}/Conf/HotfixMainResDomain.asset";
- HotfixMainResDomain hotfixMainResDomain =
- AssetDatabase.LoadAssetAtPath(configPath);
- packageName = hotfixMainResDomain.hotfixMainResDomainEntity.domain;
+ $"Assets/Domain/{oneKeyBUildEntity.DomainName}/AddressableRes/Config/DomainConfig.asset";
+ DomainConfig domainConfig =
+ AssetDatabase.LoadAssetAtPath(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(configPath);
- packageName = hotfixMainResDomain.hotfixMainResDomainEntity.domain;
+ $"Assets/Domain/{BuildAssetWindow.GetBuildPackageName()}/AddressableRes/Config/DomainConfig.asset";
+ DomainConfig domainConfig =
+ AssetDatabase.LoadAssetAtPath(configPath);
+ packageName = domainConfig.domain;
Mark();
if (!BuildAssetWindow.GetBuildPackageName().Equals("Main"))
CreateRes(packageName,
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor.meta b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor.meta
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor.meta
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor.meta
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools.meta b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools.meta
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools.meta
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools.meta
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/DragAndDropTool.meta b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/DragAndDropTool.meta
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/DragAndDropTool.meta
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/DragAndDropTool.meta
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/DragAndDropTool/DragAndDropTool.cs b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/DragAndDropTool/DragAndDropTool.cs
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/DragAndDropTool/DragAndDropTool.cs
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/DragAndDropTool/DragAndDropTool.cs
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/DragAndDropTool/DragAndDropTool.cs.meta b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/DragAndDropTool/DragAndDropTool.cs.meta
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/DragAndDropTool/DragAndDropTool.cs.meta
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/DragAndDropTool/DragAndDropTool.cs.meta
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/EditorWindowLayout.cs b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/EditorWindowLayout.cs
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/EditorWindowLayout.cs
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/EditorWindowLayout.cs
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/EditorWindowLayout.cs.meta b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/EditorWindowLayout.cs.meta
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/EditorWindowLayout.cs.meta
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/EditorWindowLayout.cs.meta
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/FolderField.meta b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/FolderField.meta
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/FolderField.meta
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/FolderField.meta
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/FolderField/FolderField.cs b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/FolderField/FolderField.cs
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/FolderField/FolderField.cs
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/FolderField/FolderField.cs
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/FolderField/FolderField.cs.meta b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/FolderField/FolderField.cs.meta
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/FolderField/FolderField.cs.meta
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/FolderField/FolderField.cs.meta
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/FolderField/GUIBase.cs b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/FolderField/GUIBase.cs
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/FolderField/GUIBase.cs
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/FolderField/GUIBase.cs
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/FolderField/GUIBase.cs.meta b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/FolderField/GUIBase.cs.meta
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/FolderField/GUIBase.cs.meta
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/FolderField/GUIBase.cs.meta
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/FolderField/GUIContents.cs b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/FolderField/GUIContents.cs
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/FolderField/GUIContents.cs
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/FolderField/GUIContents.cs
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/FolderField/GUIContents.cs.meta b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/FolderField/GUIContents.cs.meta
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/FolderField/GUIContents.cs.meta
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/FolderField/GUIContents.cs.meta
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/RectExtension.meta b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/RectExtension.meta
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/RectExtension.meta
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/RectExtension.meta
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/RectExtension/RectExtension.cs b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/RectExtension/RectExtension.cs
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/RectExtension/RectExtension.cs
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/RectExtension/RectExtension.cs
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/RectExtension/RectExtension.cs.meta b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/RectExtension/RectExtension.cs.meta
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/RectExtension/RectExtension.cs.meta
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/RectExtension/RectExtension.cs.meta
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/ScriptBuilder.cs b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/ScriptBuilder.cs
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/ScriptBuilder.cs
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/ScriptBuilder.cs
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/ScriptBuilder.cs.meta b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/ScriptBuilder.cs.meta
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/ScriptBuilder.cs.meta
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/ScriptBuilder.cs.meta
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/StringExtension.meta b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/StringExtension.meta
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/StringExtension.meta
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/StringExtension.meta
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/StringExtension/StringExtension.cs b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/StringExtension/StringExtension.cs
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/StringExtension/StringExtension.cs
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/StringExtension/StringExtension.cs
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/StringExtension/StringExtension.cs.meta b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/StringExtension/StringExtension.cs.meta
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/StringExtension/StringExtension.cs.meta
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/StringExtension/StringExtension.cs.meta
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/UnoEditorLayout.cs b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/UnoEditorLayout.cs
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/UnoEditorLayout.cs
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/UnoEditorLayout.cs
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/UnoEditorLayout.cs.meta b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/UnoEditorLayout.cs.meta
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/UnoEditorLayout.cs.meta
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/UnoEditorLayout.cs.meta
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/UtilityEditor.cs b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/UtilityEditor.cs
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/UtilityEditor.cs
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/UtilityEditor.cs
diff --git a/Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/UtilityEditor.cs.meta b/Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/UtilityEditor.cs.meta
similarity index 100%
rename from Assets/00.StaryEvo/Editor/FrameWorkEditor/Tools/UtilityEditor.cs.meta
rename to Assets/00.StaryEvo/Editor/Tools/FrameWorkEditor/Tools/UtilityEditor.cs.meta
diff --git a/Assets/00.StaryEvo/Editor/Tools/LeakDetectionMode.cs b/Assets/00.StaryEvo/Editor/Tools/LeakDetectionMode.cs
new file mode 100644
index 0000000..e8402ae
--- /dev/null
+++ b/Assets/00.StaryEvo/Editor/Tools/LeakDetectionMode.cs
@@ -0,0 +1,58 @@
+using Unity.Collections;
+using UnityEditor;
+
+namespace Stary.Evo.Editor
+{
+ ///
+ /// 内存泄露检测模式
+ ///
+ 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;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/00.StaryEvo/Editor/Tools/LeakDetectionMode.cs.meta b/Assets/00.StaryEvo/Editor/Tools/LeakDetectionMode.cs.meta
new file mode 100644
index 0000000..85b259f
--- /dev/null
+++ b/Assets/00.StaryEvo/Editor/Tools/LeakDetectionMode.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: a27e919c74384f689d6a50a45236b7f4
+timeCreated: 1748333122
\ No newline at end of file
diff --git a/Assets/00.StaryEvo/Runtime/PlayerSettings/HotfixMainResDomain.cs b/Assets/00.StaryEvo/Runtime/PlayerSettings/HotfixMainResDomain.cs
index 9bda2f4..53b23dc 100644
--- a/Assets/00.StaryEvo/Runtime/PlayerSettings/HotfixMainResDomain.cs
+++ b/Assets/00.StaryEvo/Runtime/PlayerSettings/HotfixMainResDomain.cs
@@ -14,11 +14,10 @@ namespace Stary.Evo
[Serializable]
public class HotfixMainResDomainEntity
{
- public string domain;
public string ipconfig="http://192.168.31.100:5005/HotRefresh";
- public string pathconfig;
- public string packageVersion;
+ public string mainDomainVersion ="";
public string username="UnityHot";
public string password="Unity1234";
+ public string productName="UnityEvo";
}
}
\ No newline at end of file
diff --git a/Assets/00.StaryEvo/Runtime/Utility/WebRequestSystem.cs b/Assets/00.StaryEvo/Runtime/Utility/WebRequestSystem.cs
index f99468a..5ebeede 100644
--- a/Assets/00.StaryEvo/Runtime/Utility/WebRequestSystem.cs
+++ b/Assets/00.StaryEvo/Runtime/Utility/WebRequestSystem.cs
@@ -1,47 +1,280 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Threading.Tasks;
using Cysharp.Threading.Tasks;
+using InterfaceEntity.Entity.Requests;
+using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.Networking;
namespace Stary.Evo
{
- public interface IWebRequestSystem
+ public static class WebRequestSystem
{
- Task Post(string url, string postData);
- Task Get(string url, string token=null);
-
- }
+ private static string authorization;
+
+ public static async Task 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(webRequest.downloadHandler.text);
+ if (authResponse.code == 200)
+ {
+ AuthenticationResponse authResponseData =
+ JsonConvert.DeserializeObject(authResponse.data.ToString());
+ authorization = authResponseData.Token;
+ PlayerPrefs.SetString("Authorization", authorization);
+ Debug.Log("登录成功");
+ return true;
+ }
+ }
+
+ return false;
+ }
+ }
+
+ ///
+ /// GET请求数据
+ ///
+ /// 请求数据的URL地址
+ /// token验证的参数,此处为authorization
+ ///
+ public static async Task 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(webRequest.downloadHandler.text);
+ if (resultMessageEntity.code == 200)
+ return true; // 添加返回值
+ else
+
+ return false;
+ }
+ }
+ catch (Exception e)
+ {
+ Debug.LogError(e);
+ }
+
+ return false;
+ }
- public class WebRequestSystem : IWebRequestSystem
- {
///
/// POST请求数据
///
/// 获取Token值的服务URL地址(很重要)
/// 传入请求的参数,此处参数为JOSN格式
///
- public async Task Post(string url, string postData)
+ public static async Task PostFile(string url, string[] path)
{
- using (UnityWebRequest webRequest = UnityWebRequest.Post(url, postData)) //第二种写法此行注释
+ if (!GetTokenState())
{
- byte[] postBytes = System.Text.Encoding.UTF8.GetBytes(postData);
- webRequest.uploadHandler = (UploadHandler)new UploadHandlerRaw(postBytes);
- webRequest.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
- webRequest.SetRequestHeader("Content-Type", "application/json");
+ Debug.LogError("用户未登录,请先登录");
+ return new ResultMessageEntity()
+ {
+ 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();
+ webRequest.uploadHandler?.Dispose();
// 更新错误检查方式
if (webRequest.result == UnityWebRequest.Result.ConnectionError ||
webRequest.result == UnityWebRequest.Result.ProtocolError)
{
Debug.LogError(webRequest.error);
- return webRequest.error;
+ return new ResultMessageEntity()
+ {
+ code = 5001,
+ message = webRequest.error
+ };
}
else
{
- return webRequest.downloadHandler.text;
+ ResultMessageEntity resultMessageEntity =
+ JsonConvert.DeserializeObject(webRequest.downloadHandler.text);
+ if (resultMessageEntity.code != 200)
+ {
+ Debug.LogError("上传异常,无文件数据返回!!");
+ }
+ return resultMessageEntity;
+ }
+ }
+ }
+
+ ///
+ /// GET请求数据
+ ///
+ /// 请求数据的URL地址
+ /// token验证的参数,此处为authorization
+ ///
+ public static async Task GetFile(string url,string tempPath, Action 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
+ };
+ }
+
+ }
+ ///
+ /// POST请求数据
+ ///
+ /// 获取Token值的服务URL地址(很重要)
+ /// 传入请求的参数,此处参数为JOSN格式
+ ///
+ public static async Task 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(webRequest.downloadHandler.text);
+ if (resultMessageEntity.code != 200)
+ {
+ Debug.LogError(resultMessageEntity.message);
+ }
+ return resultMessageEntity;
}
}
}
@@ -52,43 +285,73 @@ namespace Stary.Evo
/// 请求数据的URL地址
/// token验证的参数,此处为authorization
///
- public async Task Get(string url, string token=null)
+ public static async Task Get(string url)
{
+ if (!GetTokenState())
+ {
+ Debug.LogError("用户未登录,请先登录");
+ return new ResultMessageEntity()
+ {
+ code = 2001,
+ message = "用户未登录,请先登录"
+ };
+ }
+
try
{
- 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)
+ using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
{
- var errorMsg = $"HTTP {webRequest.responseCode}\n" +
- $"URL: {url}\n" +
- $"Error: {webRequest.error}\n" +
- $"Response: {webRequest.downloadHandler.text}";
-
- Debug.LogError(errorMsg);
- return null;
+ webRequest.downloadHandler = new DownloadHandlerBuffer();
+ if (authorization != null)
+ webRequest.SetRequestHeader("Authorization", authorization); // 修正请求头名称规范
+
+ 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 new ResultMessageEntity()
+ {
+ code = 5001,
+ message = errorMsg
+ };
+ }
+ ResultMessageEntity resultMessageEntity =
+ JsonConvert.DeserializeObject(webRequest.downloadHandler.text);
+ if (resultMessageEntity.code != 200)
+ {
+ Debug.LogError(resultMessageEntity.message);
+ }
+ return resultMessageEntity;
}
- return webRequest.downloadHandler.text; // 添加返回值
- }
-
}
catch (Exception 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;
}
-
-
-
-
-
}
}
\ No newline at end of file
diff --git a/Assets/00.StaryEvo/package.json b/Assets/00.StaryEvo/package.json
index dec6a00..4f5c280 100644
--- a/Assets/00.StaryEvo/package.json
+++ b/Assets/00.StaryEvo/package.json
@@ -1,8 +1,8 @@
{
"name": "com.staryevo.main",
- "version": "1.1.1",
+ "version": "1.2.0",
"displayName": "00.StaryEvo",
- "description": "This is an Framework package",
+ "description": "This is an Framework package(后台服务器版本,端口9527)",
"unity": "2021.3",
"unityRelease": "30f1",
"author": {
diff --git a/Assets/Main/Script/Runtime/Enum/Mode.cs b/Assets/Main/Script/Runtime/Enum/ZoneType.cs
similarity index 100%
rename from Assets/Main/Script/Runtime/Enum/Mode.cs
rename to Assets/Main/Script/Runtime/Enum/ZoneType.cs
diff --git a/Assets/Main/Script/Runtime/Enum/Mode.cs.meta b/Assets/Main/Script/Runtime/Enum/ZoneType.cs.meta
similarity index 100%
rename from Assets/Main/Script/Runtime/Enum/Mode.cs.meta
rename to Assets/Main/Script/Runtime/Enum/ZoneType.cs.meta
diff --git a/Assets/Main/Script/Runtime/Base.meta b/Assets/Main/Script/Runtime/Init/Base.meta
similarity index 100%
rename from Assets/Main/Script/Runtime/Base.meta
rename to Assets/Main/Script/Runtime/Init/Base.meta
diff --git a/Assets/Main/Script/Runtime/Base/AppConfig.cs b/Assets/Main/Script/Runtime/Init/Base/AppConfig.cs
similarity index 74%
rename from Assets/Main/Script/Runtime/Base/AppConfig.cs
rename to Assets/Main/Script/Runtime/Init/Base/AppConfig.cs
index fa2031e..bae23cd 100644
--- a/Assets/Main/Script/Runtime/Base/AppConfig.cs
+++ b/Assets/Main/Script/Runtime/Init/Base/AppConfig.cs
@@ -8,24 +8,24 @@ namespace Stary.Evo
///
/// package name
///
- public static string ASSETPACKGENAME;
+ public static string PackageDomainName { get; set; }
+
- ///
- /// 热更资源路径
- ///
- public static string PATHCONFIG;
-
- public static string IPCONFIG;
- public static string USERNAME;
- public static string PASSWORD;
-
- public static string IPCONFIGVideo;
+ public static string IpConfig { get; set; }
+ public static string UserName { get; set; }
+ public static string PassWord { get; set; }
+ public static string ProductName { get; set; }
+ public static string Platform { get; set; }
+
+ public static string MainDomainVersion { get; set; }
///
/// 主场景main实例物体
///
private static GameObject _MainBaseModel;
+
+
///
/// 赋值默认的实例
///
diff --git a/Assets/Main/Script/Runtime/Base/AppConfig.cs.meta b/Assets/Main/Script/Runtime/Init/Base/AppConfig.cs.meta
similarity index 100%
rename from Assets/Main/Script/Runtime/Base/AppConfig.cs.meta
rename to Assets/Main/Script/Runtime/Init/Base/AppConfig.cs.meta
diff --git a/Assets/Main/Script/Runtime/Base/DomainBase.cs b/Assets/Main/Script/Runtime/Init/Base/DomainBase.cs
similarity index 100%
rename from Assets/Main/Script/Runtime/Base/DomainBase.cs
rename to Assets/Main/Script/Runtime/Init/Base/DomainBase.cs
diff --git a/Assets/Main/Script/Runtime/Base/DomainBase.cs.meta b/Assets/Main/Script/Runtime/Init/Base/DomainBase.cs.meta
similarity index 100%
rename from Assets/Main/Script/Runtime/Base/DomainBase.cs.meta
rename to Assets/Main/Script/Runtime/Init/Base/DomainBase.cs.meta
diff --git a/Assets/Main/Script/Runtime/ClassObjectPool.meta b/Assets/Main/Script/Runtime/Init/ClassObjectPool.meta
similarity index 100%
rename from Assets/Main/Script/Runtime/ClassObjectPool.meta
rename to Assets/Main/Script/Runtime/Init/ClassObjectPool.meta
diff --git a/Assets/Main/Script/Runtime/ClassObjectPool/IClassPool.cs b/Assets/Main/Script/Runtime/Init/ClassObjectPool/IClassPool.cs
similarity index 100%
rename from Assets/Main/Script/Runtime/ClassObjectPool/IClassPool.cs
rename to Assets/Main/Script/Runtime/Init/ClassObjectPool/IClassPool.cs
diff --git a/Assets/Main/Script/Runtime/ClassObjectPool/IClassPool.cs.meta b/Assets/Main/Script/Runtime/Init/ClassObjectPool/IClassPool.cs.meta
similarity index 100%
rename from Assets/Main/Script/Runtime/ClassObjectPool/IClassPool.cs.meta
rename to Assets/Main/Script/Runtime/Init/ClassObjectPool/IClassPool.cs.meta
diff --git a/Assets/Main/Script/Runtime/Fsm.meta b/Assets/Main/Script/Runtime/Init/Fsm.meta
similarity index 100%
rename from Assets/Main/Script/Runtime/Fsm.meta
rename to Assets/Main/Script/Runtime/Init/Fsm.meta
diff --git a/Assets/Main/Script/Runtime/Fsm/FsmLoadSystem.cs b/Assets/Main/Script/Runtime/Init/Fsm/FsmLoadSystem.cs
similarity index 100%
rename from Assets/Main/Script/Runtime/Fsm/FsmLoadSystem.cs
rename to Assets/Main/Script/Runtime/Init/Fsm/FsmLoadSystem.cs
diff --git a/Assets/Main/Script/Runtime/Fsm/FsmLoadSystem.cs.meta b/Assets/Main/Script/Runtime/Init/Fsm/FsmLoadSystem.cs.meta
similarity index 100%
rename from Assets/Main/Script/Runtime/Fsm/FsmLoadSystem.cs.meta
rename to Assets/Main/Script/Runtime/Init/Fsm/FsmLoadSystem.cs.meta
diff --git a/Assets/Main/Script/Runtime/Fsm/HotFixState.cs b/Assets/Main/Script/Runtime/Init/Fsm/HotFixState.cs
similarity index 97%
rename from Assets/Main/Script/Runtime/Fsm/HotFixState.cs
rename to Assets/Main/Script/Runtime/Init/Fsm/HotFixState.cs
index 3855467..b46e654 100644
--- a/Assets/Main/Script/Runtime/Fsm/HotFixState.cs
+++ b/Assets/Main/Script/Runtime/Init/Fsm/HotFixState.cs
@@ -32,7 +32,7 @@ namespace Stary.Evo
{
DomainConfig domainConfig = param as DomainConfig;
Debug.Log("UnityEvo:热更脚本...");
- var package = YooAssets.GetPackage(AppConfig.ASSETPACKGENAME);
+ var package = YooAssets.GetPackage(AppConfig.PackageDomainName);
// Editor环境下,HotUpdate.dll.bytes已经被自动加载,不需要加载,重复加载反而会出问题。
@@ -44,7 +44,7 @@ namespace Stary.Evo
Assembly hotUpdateAss = System.AppDomain.CurrentDomain.GetAssemblies()
.First(a => a.GetName().Name == $"HotUpdate_{AppConfig.ASSETPACKGENAME}");
#else
- string hotUpdateAssemblyName = $"HotUpdate_{AppConfig.ASSETPACKGENAME}";
+ string hotUpdateAssemblyName = $"HotUpdate_{AppConfig.PackageDomainName}";
Type assemblyType = IsAssetLoaded(fullClassName);
@@ -78,9 +78,9 @@ namespace Stary.Evo
LoadMetadataForAOTAssemblies();
// 加载热更dll
- var hotfixDll = package.LoadAssetAsync($"Android_HotUpdate_{AppConfig.ASSETPACKGENAME}.dll");
+ var hotfixDll = package.LoadAssetAsync($"Android_HotUpdate_{AppConfig.PackageDomainName}.dll");
await hotfixDll;
- var hotfixPdb = package.LoadAssetAsync($"Android_HotUpdate_{AppConfig.ASSETPACKGENAME}.pdb");
+ var hotfixPdb = package.LoadAssetAsync($"Android_HotUpdate_{AppConfig.PackageDomainName}.pdb");
await hotfixPdb;
Assembly hotUpdateAss = null;
if (hotfixDll.Status == EOperationStatus.Succeed)
@@ -100,7 +100,7 @@ namespace Stary.Evo
}
else
{
- Debug.LogError($"UnityEvo:Android_HotUpdate_{AppConfig.ASSETPACKGENAME}.dll加载失败!!!!!");
+ Debug.LogError($"UnityEvo:Android_HotUpdate_{AppConfig.PackageDomainName}.dll加载失败!!!!!");
}
diff --git a/Assets/Main/Script/Runtime/Fsm/HotFixState.cs.meta b/Assets/Main/Script/Runtime/Init/Fsm/HotFixState.cs.meta
similarity index 100%
rename from Assets/Main/Script/Runtime/Fsm/HotFixState.cs.meta
rename to Assets/Main/Script/Runtime/Init/Fsm/HotFixState.cs.meta
diff --git a/Assets/Main/Script/Runtime/Fsm/LoadResMainState.cs b/Assets/Main/Script/Runtime/Init/Fsm/LoadResMainState.cs
similarity index 100%
rename from Assets/Main/Script/Runtime/Fsm/LoadResMainState.cs
rename to Assets/Main/Script/Runtime/Init/Fsm/LoadResMainState.cs
diff --git a/Assets/Main/Script/Runtime/Fsm/LoadResMainState.cs.meta b/Assets/Main/Script/Runtime/Init/Fsm/LoadResMainState.cs.meta
similarity index 100%
rename from Assets/Main/Script/Runtime/Fsm/LoadResMainState.cs.meta
rename to Assets/Main/Script/Runtime/Init/Fsm/LoadResMainState.cs.meta
diff --git a/Assets/Main/Script/Runtime/Fsm/LoadResState.cs b/Assets/Main/Script/Runtime/Init/Fsm/LoadResState.cs
similarity index 100%
rename from Assets/Main/Script/Runtime/Fsm/LoadResState.cs
rename to Assets/Main/Script/Runtime/Init/Fsm/LoadResState.cs
diff --git a/Assets/Main/Script/Runtime/Fsm/LoadResState.cs.meta b/Assets/Main/Script/Runtime/Init/Fsm/LoadResState.cs.meta
similarity index 100%
rename from Assets/Main/Script/Runtime/Fsm/LoadResState.cs.meta
rename to Assets/Main/Script/Runtime/Init/Fsm/LoadResState.cs.meta
diff --git a/Assets/Main/Script/Runtime/Fsm/ResStartState.cs b/Assets/Main/Script/Runtime/Init/Fsm/ResStartState.cs
similarity index 55%
rename from Assets/Main/Script/Runtime/Fsm/ResStartState.cs
rename to Assets/Main/Script/Runtime/Init/Fsm/ResStartState.cs
index 9c23063..75f8372 100644
--- a/Assets/Main/Script/Runtime/Fsm/ResStartState.cs
+++ b/Assets/Main/Script/Runtime/Init/Fsm/ResStartState.cs
@@ -1,6 +1,9 @@
using System;
+using System.IO;
using Cysharp.Threading.Tasks;
+using Main;
using Newtonsoft.Json;
+using Stary.Evo.UIFarme;
using UnityEditor;
using UnityEngine;
using UnityEngine.Assertions;
@@ -16,38 +19,39 @@ namespace Stary.Evo
}
-
-
public override async UniTask OnEnterAsync()
{
- Debug.Log("UnityEvo:启动开始资源初始化...");
+ Debug.Log("UnityEvo:启动开始资源初始化...");
//初始化读取资源配置表
HotfixMainResDomain hotfixMainResDomain = Resources.Load("HotfixMainResDomain");
if (hotfixMainResDomain != null)
{
- AppConfig.IPCONFIG = hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig;
- AppConfig.USERNAME = hotfixMainResDomain.hotfixMainResDomainEntity.username;
- AppConfig.PASSWORD = hotfixMainResDomain.hotfixMainResDomainEntity.password;
+ AppConfig.IpConfig = hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig;
+ AppConfig.UserName = hotfixMainResDomain.hotfixMainResDomainEntity.username;
+ 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.SetDownloadSystemUnityWebRequest(NasWebRequester);
+ //YooAssets.SetDownloadSystemUnityWebRequest(NasWebRequester);
//初始化资源加载模块
// 增加包存在性检查
- var package = YooAssets.TryGetPackage(AppConfig.ASSETPACKGENAME);
+ var package = YooAssets.TryGetPackage(AppConfig.PackageDomainName);
if (package == null)
{
- Debug.LogWarning($"UnityEvo:资源包 {AppConfig.ASSETPACKGENAME} 不存在,正在尝试创建...");
- package = YooAssets.CreatePackage(AppConfig.ASSETPACKGENAME);
+ Debug.LogWarning($"UnityEvo:资源包 {AppConfig.PackageDomainName} 不存在,正在尝试创建...");
+ package = YooAssets.CreatePackage(AppConfig.PackageDomainName);
}
YooAssets.SetDefaultPackage(package);
@@ -55,11 +59,10 @@ namespace Stary.Evo
// 初始化资源包
#if EDITOR_SIMULATEMODE
await EDITOR_SIMULATEMODE(package);
- AppConfig.IPCONFIGVideo = "http://192.168.31.100:9527/";
+ FsmSystem.SetCurState(nameof(ResUpdateServerState));
#elif OFFLINE_PLAYMODE
await OFFLINE_PLAYMODE(package);
- AppConfig.IPCONFIGVideo = Application.streamingAssetsPath + "/";
-
+ FsmSystem.SetCurState(nameof(ResUpdateLocalState));
#elif HOST_PLAYMODE
if (package.PackageName.Equals("Main"))
{
@@ -67,10 +70,17 @@ namespace Stary.Evo
}
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
// IRemoteServices remoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
// var webServerFileSystemParams = FileSystemParameters.CreateDefaultWebServerFileSystemParameters();
@@ -91,24 +101,23 @@ namespace Stary.Evo
Debug.LogError($"UnityEvo:暂不支持");
#endif
-
- FsmSystem.SetCurState(nameof(ResUpdateServerState));
}
- public override UniTask OnEnterAsync(T param)
+ public override UniTask OnEnterAsync(T param)
{
- return UniTask.CompletedTask;
+ return UniTask.CompletedTask;
}
+
public override UniTask OnEnterAsync(T1 param1, T2 param2)
{
return UniTask.CompletedTask;
}
+
public override void OnUpdate()
{
base.OnUpdate();
}
-
public override UniTask OnExitAsync()
{
@@ -117,7 +126,7 @@ namespace Stary.Evo
private async UniTask EDITOR_SIMULATEMODE(ResourcePackage package)
{
- var buildResult = EditorSimulateModeHelper.SimulateBuild(AppConfig.ASSETPACKGENAME);
+ var buildResult = EditorSimulateModeHelper.SimulateBuild(AppConfig.PackageDomainName);
var packageRoot = buildResult.PackageRootDirectory;
var editorFileSystemParameters = FileSystemParameters.CreateDefaultEditorFileSystemParameters(packageRoot);
var initParams = new EditorSimulateModeParameters();
@@ -154,65 +163,52 @@ namespace Stary.Evo
// 新增平台判断代码
#if UNITY_EDITOR
BuildTarget buildTarget = UnityEditor.EditorUserBuildSettings.activeBuildTarget;
- string platformName = buildTarget.ToString();
+ AppConfig.Platform = buildTarget.ToString();
#else
- string platformName = Application.platform.ToString();
+ AppConfig.Platform = Application.platform.ToString();
#endif
- Debug.Log($"目标平台标识: {platformName}");
- //从服务器加载配置列表
- WebRequestSystem webRequestSystem = new WebRequestSystem();
- string URL =
- $"{AppConfig.IPCONFIG}/HybridclrConfigData/{AppConfig.ASSETPACKGENAME}/{platformName}/{Application.productName}.json";
- Debug.Log("UnityEvo: 服务器配置文件地址:" + URL);
- string text = await webRequestSystem.Get(URL, GetAuthorization(AppConfig.USERNAME, AppConfig.PASSWORD));
- if (!string.IsNullOrEmpty(text))
+ Debug.Log($"目标平台标识: {AppConfig.Platform}");
+
+ // 请求资源版本
+ string url = $"{AppConfig.IpConfig}/ResDomain/GetResDomainByDomain";
+ var resDmainRequst = new ResDmainRequst()
{
- 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(resDmainMessageEntity.data.ToString());
+ //获取当前版本
+ var oldVersion = PlayerPrefs.GetString($"{AppConfig.PackageDomainName}_GAME_VERSION");
+ //版本不一致,开始下载
+ if (resDmainResponse.PackageVersion != oldVersion)
{
- Debug.Log("UnityEvo: 服务器配置文件读取成功:" + text);
- text = text.Trim('\uFEFF'); // 移除 BOM 字符
- HotfixMainResDomainEntity hotfixMainResDomainEntity =
- JsonConvert.DeserializeObject(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);
- }
+ await Download(resDmainResponse.DocumentFileId);
+ PlayerPrefs.SetString($"{AppConfig.PackageDomainName}_GAME_VERSION",
+ resDmainResponse.PackageVersion);
}
- catch (JsonException e)
+ else //版本一致,加载缓存资源
{
- Debug.LogError($"UnityEvo:JSON解析失败: {e.Message}\n原始内容: {text}");
+ Debug.Log($"UnityEvo:资源版本一致,自动跳过更新...");
}
}
else
{
- Debug.LogError("UnityEvo:从服务器获取的配置数据为空");
+ Debug.LogError($"UnityEvo:获取资源版本失败: 【{resDmainMessageEntity.message}】");
}
-
- string defaultHostServer = $"{AppConfig.IPCONFIG}/{AppConfig.PATHCONFIG}";
- string fallbackHostServer = $"{AppConfig.IPCONFIG}/{AppConfig.PATHCONFIG}";
-
- 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();
+ var initParameters = new OfflinePlayModeParameters();
+ var buildinFileSystemParams = FileSystemParameters.CreateDefaultBuildinFileSystemParameters(null,
+ $"{Application.persistentDataPath}/DownloadedContent/{AppConfig.PackageDomainName}");
buildinFileSystemParams.AddParameter(FileSystemParametersDefine.APPEND_FILE_EXTENSION, true);
buildinFileSystemParams.AddParameter(FileSystemParametersDefine.COPY_BUILDIN_PACKAGE_MANIFEST, true);
- initParameters.BuildinFileSystemParameters = null;
- initParameters.CacheFileSystemParameters = cacheFileSystemParams;
+ initParameters.BuildinFileSystemParameters = buildinFileSystemParams;
+ // initParameters.CacheFileSystemParameters = cacheFileSystemParams;
var initOperation = package.InitializeAsync(initParameters);
@@ -224,24 +220,32 @@ namespace Stary.Evo
Debug.LogError($"UnityEvo:从远程加载资源包,初始化失败:{initOperation.Error}");
}
- ///
- /// 自定义网络请求器需要登录
- ///
- ///
- ///
- private UnityWebRequest NasWebRequester(string url)
+ public async UniTask Download(string fileId)
{
- var request = new UnityWebRequest(url, UnityWebRequest.kHttpVerbGET);
- var authorization = GetAuthorization(AppConfig.USERNAME, AppConfig.PASSWORD);
- request.SetRequestHeader("AUTHORIZATION", authorization);
- return request;
+ // 在任意MonoBehaviour或DomainBase派生类中
+ string loadPath = $"{Application.persistentDataPath}/DownloadedContent/{AppConfig.PackageDomainName}";
+ if (Directory.Exists(loadPath))
+ {
+ Directory.Delete(loadPath, true);
+ }
+
+ await MainArchitecture.Interface.GetSystem()
+ .PushQueue(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;
- var bytes = System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(auth);
- return "Basic " + System.Convert.ToBase64String(bytes);
+ Debug.Log($"下载进度:{progress:P0}");
+ MainArchitecture.Interface.GetSystem()
+ .SendPanelEvent(ProgressBarPanel.ProgressBarType.Add, "下载中", progress);
+ }
+
+ private void UnzipProgress(float progress)
+ {
+ Debug.Log($"解压进度:{progress:P0}");
+ MainArchitecture.Interface.GetSystem()
+ .SendPanelEvent(ProgressBarPanel.ProgressBarType.Add, "解压中", progress);
}
}
}
\ No newline at end of file
diff --git a/Assets/Main/Script/Runtime/Fsm/ResStartState.cs.meta b/Assets/Main/Script/Runtime/Init/Fsm/ResStartState.cs.meta
similarity index 100%
rename from Assets/Main/Script/Runtime/Fsm/ResStartState.cs.meta
rename to Assets/Main/Script/Runtime/Init/Fsm/ResStartState.cs.meta
diff --git a/Assets/Main/Script/Runtime/Fsm/ResUpdateLocalState.cs b/Assets/Main/Script/Runtime/Init/Fsm/ResUpdateLocalState.cs
similarity index 75%
rename from Assets/Main/Script/Runtime/Fsm/ResUpdateLocalState.cs
rename to Assets/Main/Script/Runtime/Init/Fsm/ResUpdateLocalState.cs
index b17add4..4e3d84d 100644
--- a/Assets/Main/Script/Runtime/Fsm/ResUpdateLocalState.cs
+++ b/Assets/Main/Script/Runtime/Init/Fsm/ResUpdateLocalState.cs
@@ -20,20 +20,40 @@ namespace Stary.Evo
public override async UniTask OnEnterAsync()
{
//初始化读取资源配置表
- var package = YooAssets.GetPackage(AppConfig.ASSETPACKGENAME);
+ var package = YooAssets.GetPackage(AppConfig.PackageDomainName);
//更新失败
Debug.Log($"UnityEvo:切换为加载本地缓存资源...");
-
- // 获取上次成功记录的版本
- string packageVersion = PlayerPrefs.GetString("GAME_VERSION", string.Empty);
- if (string.IsNullOrEmpty(packageVersion))
+ string packageVersion = "";
+ if (package.PackageName.Equals("Main"))
{
- Debug.Log($"UnityEvo:没有找到本地版本记录,需要更新资源!");
- return;
+ var operation = package.RequestPackageVersionAsync();
+ 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:开始加载本地资源...");
@@ -116,7 +136,7 @@ namespace Stary.Evo
{
int downloadingMaxNum = 1;
int failedTryAgain = 1;
- var package = YooAssets.GetPackage(AppConfig.ASSETPACKGENAME);
+ var package = YooAssets.GetPackage(AppConfig.PackageDomainName);
var downloader = package.CreateResourceDownloader(downloadingMaxNum, failedTryAgain);
// 在正常开始游戏之前,还需要验证本地清单内容的完整性。
diff --git a/Assets/Main/Script/Runtime/Fsm/ResUpdateLocalState.cs.meta b/Assets/Main/Script/Runtime/Init/Fsm/ResUpdateLocalState.cs.meta
similarity index 100%
rename from Assets/Main/Script/Runtime/Fsm/ResUpdateLocalState.cs.meta
rename to Assets/Main/Script/Runtime/Init/Fsm/ResUpdateLocalState.cs.meta
diff --git a/Assets/Main/Script/Runtime/Fsm/ResUpdateServerState.cs b/Assets/Main/Script/Runtime/Init/Fsm/ResUpdateServerState.cs
similarity index 72%
rename from Assets/Main/Script/Runtime/Fsm/ResUpdateServerState.cs
rename to Assets/Main/Script/Runtime/Init/Fsm/ResUpdateServerState.cs
index 8d76df5..924caf5 100644
--- a/Assets/Main/Script/Runtime/Fsm/ResUpdateServerState.cs
+++ b/Assets/Main/Script/Runtime/Init/Fsm/ResUpdateServerState.cs
@@ -20,7 +20,7 @@ namespace Stary.Evo
// //初始化读取资源配置表
- var package = YooAssets.GetPackage(AppConfig.ASSETPACKGENAME);
+ var package = YooAssets.GetPackage(AppConfig.PackageDomainName);
// 请求资源版本
var requetVersionOp = package.RequestPackageVersionAsync();
await requetVersionOp;
@@ -29,7 +29,7 @@ namespace Stary.Evo
{
//更新成功
packageVersion = requetVersionOp.PackageVersion;
- PlayerPrefs.SetString("GAME_VERSION", packageVersion);
+ PlayerPrefs.SetString($"{AppConfig.PackageDomainName}_GAME_VERSION", packageVersion);
Debug.Log($"UnityEvo:获取资源版本 Version : 【{packageVersion}】");
Debug.Log($"UnityEvo:开始加载服务器资源...");
}
@@ -120,46 +120,34 @@ namespace Stary.Evo
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;
- // var package = YooAssets.GetPackage(AppConfig.ASSETPACKGENAME);
- // 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;
+ //开启下载
+ downloader.BeginDownload();
+ await downloader;
//检测下载结果
if (downloader.Status == EOperationStatus.Succeed)
diff --git a/Assets/Main/Script/Runtime/Fsm/ResUpdateServerState.cs.meta b/Assets/Main/Script/Runtime/Init/Fsm/ResUpdateServerState.cs.meta
similarity index 100%
rename from Assets/Main/Script/Runtime/Fsm/ResUpdateServerState.cs.meta
rename to Assets/Main/Script/Runtime/Init/Fsm/ResUpdateServerState.cs.meta
diff --git a/Assets/Main/Script/Runtime/Init/HybridClREntrance.cs b/Assets/Main/Script/Runtime/Init/HybridClREntrance.cs
index 1c85705..f7e96ee 100644
--- a/Assets/Main/Script/Runtime/Init/HybridClREntrance.cs
+++ b/Assets/Main/Script/Runtime/Init/HybridClREntrance.cs
@@ -30,20 +30,20 @@ namespace Stary.Evo
domain = "Main";
#endif
_fsmSystem.SetOpenDomainType(OpenDomainType.DEFAULT);
- AppConfig.ASSETPACKGENAME = domain;
+ AppConfig.PackageDomainName = domain;
_fsmSystem.SetCurState(nameof(ResStartState));
}
public void OpenDomain()
{
- AppConfig.ASSETPACKGENAME = domain;
+ AppConfig.PackageDomainName = domain;
_fsmSystem.SetCurState(nameof(ResStartState));
}
public void OpenDomain(string domain, OpenDomainType openDomainType)
{
_fsmSystem.SetOpenDomainType(openDomainType);
- AppConfig.ASSETPACKGENAME = domain;
+ AppConfig.PackageDomainName = domain;
_fsmSystem.SetCurState(nameof(ResStartState));
}
diff --git a/Assets/Main/Script/Runtime/Tools/WebRequestTools.cs b/Assets/Main/Script/Runtime/Tools/WebRequestTools.cs
new file mode 100644
index 0000000..44c6ee4
--- /dev/null
+++ b/Assets/Main/Script/Runtime/Tools/WebRequestTools.cs
@@ -0,0 +1,7 @@
+namespace Stary.Evo
+{
+ public class WebRequestTools
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/Assets/Main/Script/Runtime/Tools/WebRequestTools.cs.meta b/Assets/Main/Script/Runtime/Tools/WebRequestTools.cs.meta
new file mode 100644
index 0000000..607f6e4
--- /dev/null
+++ b/Assets/Main/Script/Runtime/Tools/WebRequestTools.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 48091c7012fc4cd88a54c096febdcdd0
+timeCreated: 1748318581
\ No newline at end of file