【m】框架优化

This commit is contained in:
zhangzheng
2026-01-07 18:20:13 +08:00
parent 8ef57d9079
commit cd1207a99a
48 changed files with 2624 additions and 1453 deletions

View File

@@ -15,7 +15,7 @@ namespace Stary.Evo.Editor
public void OnPreprocessBuild(UnityEditor.Build.Reporting.BuildReport report)
{
string platform = EditorPrefs.GetString("ChangePlayerSchema");
string platform = CustomEditorPrefs.GetString("ChangePlayerSchema");
// build前
if (Enum.Parse<PLayerMode>(platform) == PLayerMode.EDITOR_SIMULATEMODE)
{

View File

@@ -13,7 +13,7 @@ namespace Stary.Evo.Editor
{
public void OnEnable()
{
viewer = new ScriptableBuildPipelineViewer(packageName, selectedBuildPipelines.ToString(),
viewer = new MixedBuildPipelineViewer(packageName, selectedBuildPipelines.ToString(),
packageVersion);
oldVersionX = packageVersionX;
oldVersionY = packageVersionY;

View File

@@ -162,7 +162,7 @@ namespace Stary.Evo.Editor
/// <returns></returns>
private void SetBuildPackageNames()
{
//PlayerPrefs.SetString("BuildPackageNames", selectedPackageNames);
//CustomPlayerPrefs.SetString("BuildPackageNames", selectedPackageNames);
// DataSetting.packageName = selectedPackageNames;
@@ -248,69 +248,94 @@ namespace Stary.Evo.Editor
}
public static string BuildZip(BuildAssetDataSetting setting)
public static string BuildZip(BuildAssetDataSetting setting)
{
EditorUtility.DisplayProgressBar("提示", $"开始上传{setting.packageName}(打包zip)", 0.0f);
// 新增打包为zip的逻辑
string zipFileName =
$"{setting.packageName}_{setting.packageVersion}.zip";
//原yooAsset目录
var outputPackageDirectory =
$"{AssetBundleBuilderHelper.GetDefaultBuildOutputRoot()}/{EditorUserBuildSettings.activeBuildTarget}/{setting.packageName}";
//RawFile目录路径
var outputRawFileDirectory =
$"{AssetBundleBuilderHelper.GetDefaultBuildOutputRoot()}/{EditorUserBuildSettings.activeBuildTarget}/{setting.packageName}_RawFile";
//拷贝目录
string outFilePath = $"{outputPackageDirectory}/{setting.packageVersion}";
string outRawFilePath = $"{outputRawFileDirectory}/{setting.packageVersion}";
var copyPackageDirectory =
$"{Application.streamingAssetsPath}/{YooAssetSettingsData.GetDefaultYooFolderName()}/{setting.packageName}";
//拷贝BuildinCatalog文件
CreateBuildinCatalogFile("BuildinCatalog.json", copyPackageDirectory, outFilePath);
CreateBuildinCatalogFile("BuildinCatalog.bytes", copyPackageDirectory, outFilePath);
var copyRawFilePackageDirectory =
$"{Application.streamingAssetsPath}/{YooAssetSettingsData.GetDefaultYooFolderName()}/{setting.packageName}_RawFile";
CreateBuildinCatalogFile("BuildinCatalog.json", copyRawFilePackageDirectory, outRawFilePath);
CreateBuildinCatalogFile("BuildinCatalog.bytes", copyRawFilePackageDirectory, outRawFilePath);
//输出目录
string zipFilePath = Path.Combine(outputPackageDirectory, zipFileName);
try
{
using (FileStream zipStream = new FileStream(zipFilePath, FileMode.Create))
using (ZipArchive archive = new ZipArchive(zipStream, ZipArchiveMode.Create))
{
EditorUtility.DisplayProgressBar("提示", $"开始上传{setting.packageName}(打包zip)", 0.0f);
// 新增打包为zip的逻辑
string zipFileName =
$"{setting.packageName}_{setting.packageVersion}.zip";
//原yooAsset目录
var outputPackageDirectory =
$"{AssetBundleBuilderHelper.GetDefaultBuildOutputRoot()}/{EditorUserBuildSettings.activeBuildTarget}/{setting.packageName}";
//拷贝目录
string outFilePath = $"{outputPackageDirectory}/{setting.packageVersion}";
var copyPackageDirectory =
$"{Application.streamingAssetsPath}/{YooAssetSettingsData.GetDefaultYooFolderName()}/{setting.packageName}";
//拷贝BuildinCatalog文件
CreateBuildinCatalogFile("BuildinCatalog.json", copyPackageDirectory, outFilePath);
CreateBuildinCatalogFile("BuildinCatalog.bytes", copyPackageDirectory, outFilePath);
//输出目录
string zipFilePath = Path.Combine(outputPackageDirectory, zipFileName);
try
// 打包主包文件
foreach (string filePath in Directory.GetFiles(outFilePath, "*.*", SearchOption.AllDirectories))
{
using (FileStream zipStream = new FileStream(zipFilePath, FileMode.Create))
using (ZipArchive archive = new ZipArchive(zipStream, ZipArchiveMode.Create))
// 获取文件在压缩包中的相对路径
string entryName =$"{setting.packageName}/{ 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())
{
// 指定需要压缩的后缀(例如:只压缩.json和.dll文件
//string[] targetExtensions = { ".bundle" };
fileStream.CopyTo(entryStream);
}
}
// 打包RawFile文件
if (Directory.Exists(outRawFilePath))
{
foreach (string filePath in Directory.GetFiles(outRawFilePath, "*.*", SearchOption.AllDirectories))
{
// 获取文件在压缩包中的相对路径
string entryName =$"{setting.packageName}_RawFile/{ Path.GetRelativePath(outRawFilePath, filePath)}";
// 遍历目录下所有文件
// 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))
// 创建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())
{
// 获取文件在压缩包中的相对路径
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);
}
fileStream.CopyTo(entryStream);
}
}
Debug.Log($"成功打包为zip{zipFilePath}");
EditorUtility.DisplayProgressBar("提示", $"开始上传{setting.packageName}(打包zip)", 0.25f);
return zipFilePath;
}
catch (Exception ex)
{
Debug.LogError($"打包zip失败{ex.Message}");
EditorUtility.ClearProgressBar();
return default;
}
}
Debug.Log($"成功打包为zip{zipFilePath}");
EditorUtility.DisplayProgressBar("提示", $"开始上传{setting.packageName}(打包zip)", 0.25f);
return zipFilePath;
}
catch (Exception ex)
{
Debug.LogError($"打包zip失败{ex.Message}");
EditorUtility.ClearProgressBar();
return default;
}
}
private static void CreateBuildinCatalogFile(string fileName, string copyPackageDirectory, string outFilePath)
{
// 假设 BuildinCatalog 文件名为 BuildinCatalog.json
@@ -332,7 +357,7 @@ namespace Stary.Evo.Editor
{
string ip = EditorPrefs.GetString("ip");
string ip = CustomEditorPrefs.GetString("ip");
var messageEntity = await WebRequestSystem.PostFile(ip + "/FileLoad/UpLoadFile", new[] { zipFilePath });
EditorUtility.DisplayProgressBar("提示", $"开始上传{setting.packageName}(上传zip文件)", 0.5f);
if (messageEntity.code == 200)
@@ -403,7 +428,7 @@ namespace Stary.Evo.Editor
DomainName = selectedPackageNames,
Platform = EditorUserBuildSettings.activeBuildTarget.ToString(),
};
var resResultMessage = await WebRequestSystem.Post(EditorPrefs.GetString("ip") + "/ResDomain/GetResDomainByDomain",
var resResultMessage = await WebRequestSystem.Post(CustomEditorPrefs.GetString("ip") + "/ResDomain/GetResDomainByDomain",
JsonConvert.SerializeObject(resDmainAddRequst));
//如果低于服务器版本,更新版本号
if (resResultMessage.code != 1011)

View File

@@ -30,7 +30,7 @@ namespace Stary.Evo.Editor
[MenuItem(EditorNotUpdateMode, true)]
private static bool ValidateModeMenu()
{
string platform = EditorPrefs.GetString("ChangeHotUpdateSchema");
string platform = CustomEditorPrefs.GetString("ChangeHotUpdateSchema");
Menu.SetChecked(EditorNotUpdateMode, platform == HotUpdateMode.NotUpdate.ToString());
Menu.SetChecked(EditorHotUpdateMode, platform == HotUpdateMode.HotUpdate.ToString());
//Menu.SetChecked(WebPlayMode, platform == HotUpdateMode.WEB_PLAYMODE.ToString());
@@ -54,7 +54,7 @@ namespace Stary.Evo.Editor
PlayerSettings.SetScriptingDefineSymbolsForGroup(currentTarget, string.Join(";", defines));
Debug.Log($"当前编译符号: {string.Join(";", defines)}"); // 添加调试日志
_hotUpdate = mode;
EditorPrefs.SetString("ChangeHotUpdateSchema", _hotUpdate.ToString());
CustomEditorPrefs.SetString("ChangeHotUpdateSchema", _hotUpdate.ToString());
ValidateModeMenu();
AssetDatabase.Refresh();

View File

@@ -30,7 +30,7 @@ namespace Stary.Evo.Editor
[MenuItem(EditorSimulateMode, true,3)]
private static bool ValidateModeMenu()
{
string platform = EditorPrefs.GetString("ChangePlayerSchema");
string platform = CustomEditorPrefs.GetString("ChangePlayerSchema");
Menu.SetChecked(EditorSimulateMode, platform == PLayerMode.EDITOR_SIMULATEMODE.ToString());
Menu.SetChecked(HostPlayMode, platform == PLayerMode.HOST_PLAYMODE.ToString());
//Menu.SetChecked(WebPlayMode, platform == PLayerMode.WEB_PLAYMODE.ToString());
@@ -54,7 +54,7 @@ namespace Stary.Evo.Editor
PlayerSettings.SetScriptingDefineSymbolsForGroup(currentTarget, string.Join(";", defines));
Debug.Log($"当前编译符号: {string.Join(";", defines)}"); // 添加调试日志
_pLayerMode = mode;
EditorPrefs.SetString("ChangePlayerSchema", _pLayerMode.ToString());
CustomEditorPrefs.SetString("ChangePlayerSchema", _pLayerMode.ToString());
ValidateModeMenu();
AssetDatabase.Refresh();
// 添加解决方案文件重新生成逻辑

View File

@@ -30,7 +30,7 @@ namespace Stary.Evo.Editor
[MenuItem(EditorNotMode, true)]
private static bool ValidateModeMenu()
{
string platform = EditorPrefs.GetString("ChangePoindClondSchema");
string platform = CustomEditorPrefs.GetString("ChangePoindClondSchema");
Menu.SetChecked(EditorNotMode, platform == PointClondMode.NotPointClond.ToString());
Menu.SetChecked(EditorImmersalMode, platform == PointClondMode.Immersal.ToString());
//Menu.SetChecked(WebPlayMode, platform == HotUpdateMode.WEB_PLAYMODE.ToString());
@@ -54,7 +54,7 @@ namespace Stary.Evo.Editor
PlayerSettings.SetScriptingDefineSymbolsForGroup(currentTarget, string.Join(";", defines));
Debug.Log($"当前编译符号: {string.Join(";", defines)}"); // 添加调试日志
_pointClondMode = mode;
EditorPrefs.SetString("ChangePoindClondSchema", _pointClondMode.ToString());
CustomEditorPrefs.SetString("ChangePoindClondSchema", _pointClondMode.ToString());
ValidateModeMenu();
AssetDatabase.Refresh();

View File

@@ -17,15 +17,15 @@ namespace Stary.Evo
Debug.Log(" 自动运行 ");
if (!EditorPrefs.HasKey("StartUp"))
if (!CustomEditorPrefs.HasKey("StartUp"))
{
// 通过标记记录是否已经执行过该方法
OnEditorStartUp();
EditorPrefs.SetInt("StartUp", 1);
CustomEditorPrefs.SetInt("StartUp", 1);
if (EditorPrefs.GetInt("CreatDomainDirectory") == 0)
if (CustomEditorPrefs.GetInt("CreatDomainDirectory") == 0)
{
EditorPrefs.SetInt("CreatDomainDirectory", 1);
CustomEditorPrefs.SetInt("CreatDomainDirectory", 1);
bool isOk = EditorUtility.DisplayDialog("提示", "发现目录存在缺失,是否检索并创建缺失目录", "是", "否");
if (isOk)
{
@@ -37,17 +37,17 @@ namespace Stary.Evo
}
}
if (EditorPrefs.GetString("ChangeHotUpdateSchema") == "")
if (CustomEditorPrefs.GetString("ChangeHotUpdateSchema") == "")
{
ChangeHotUpdateSchema.SetHotUpdateMode(HotUpdateMode.NotUpdate);
}
else
{
ChangeHotUpdateSchema.SetHotUpdateMode(
Enum.Parse<HotUpdateMode>(EditorPrefs.GetString("ChangeHotUpdateSchema")));
Enum.Parse<HotUpdateMode>(CustomEditorPrefs.GetString("ChangeHotUpdateSchema")));
}
if (EditorPrefs.GetString("ChangePlayerSchema") == "")
if (CustomEditorPrefs.GetString("ChangePlayerSchema") == "")
{
ChangePlayerSchema.SetPlayerMode(PLayerMode.EDITOR_SIMULATEMODE);
}

View File

@@ -118,7 +118,7 @@ namespace Stary.Evo.Editor
AssetBundleBuilderSetting.SetPackageBuildinFileCopyOption(packageName,
selectedBuildPipelines, copyBuildinFileOption);
//PlayerPrefs.SetInt("CopyBuildinFileOption", (int)copyBuildinFileOption);
//CustomPlayerPrefs.SetInt("CopyBuildinFileOption", (int)copyBuildinFileOption);
}
private void SetCopyBuildinFileParams()
@@ -126,7 +126,7 @@ namespace Stary.Evo.Editor
AssetBundleBuilderSetting.SetPackageBuildinFileCopyParams(packageName,
selectedBuildPipelines, copyBuildinFileParams);
//PlayerPrefs.SetInt("CopyBuildinFileOption", (int)copyBuildinFileOption);
//CustomPlayerPrefs.SetInt("CopyBuildinFileOption", (int)copyBuildinFileOption);
}
public void SetBuildCacheToggle()

View File

@@ -0,0 +1,149 @@
using System;
using System.IO;
using UnityEditor;
using UnityEngine;
using YooAsset;
using YooAsset.Editor;
namespace Stary.Evo.Editor
{
[Serializable]
public class MixedBuildPipelineViewer : AbstractBuildPipelineViewer
{
public MixedBuildPipelineViewer(string packageName, string selectedBuildPipelines, string packageVersion) :
base(packageName, selectedBuildPipelines, packageVersion)
{
}
public override void ExecuteBuild()
{
// 1. 首先使用RawFileBuildPipeline打包视频文件
Debug.Log("开始使用ScriptableBuildPipeline打包其余文件...");
var scriptableBuildResult = BuildOtherFiles();
if (!scriptableBuildResult.Success)
{
Debug.LogError("其余文件打包失败!");
return;
}
// 2. 然后使用ScriptableBuildPipeline打包其余文件
Debug.Log("开始使用RawFileBuildPipeline打包视频文件...");
var rawBuildResult = BuildRawFiles();
if (!rawBuildResult.Success)
{
Debug.LogError("视频文件打包失败!");
return;
}
Debug.Log("混合打包完成!");
base.ExecuteBuild();
}
private BuildResult BuildRawFiles()
{
var rawPackageName = $"{packageName}_RawFile";
var fileNameStyle = AssetBundleBuilderSetting.GetPackageFileNameStyle(packageName, selectedBuildPipelines);
var buildinFileCopyOption =
AssetBundleBuilderSetting.GetPackageBuildinFileCopyOption(packageName, selectedBuildPipelines);
var buildinFileCopyParams =
AssetBundleBuilderSetting.GetPackageBuildinFileCopyParams(packageName, selectedBuildPipelines);
var clearBuildCache =
AssetBundleBuilderSetting.GetPackageClearBuildCache(packageName, selectedBuildPipelines);
var useAssetDependencyDB =
AssetBundleBuilderSetting.GetPackageUseAssetDependencyDB(packageName, selectedBuildPipelines);
RawFileBuildParameters buildParameters = new RawFileBuildParameters();
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
buildParameters.BuildPipeline = selectedBuildPipelines;
buildParameters.BuildBundleType = (int)EBuildBundleType.RawBundle;
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
buildParameters.PackageName = rawPackageName;
buildParameters.PackageVersion = packageVersion;
buildParameters.VerifyBuildingResult = true;
buildParameters.FileNameStyle = fileNameStyle;
buildParameters.BuildinFileCopyOption = buildinFileCopyOption;
buildParameters.BuildinFileCopyParams = buildinFileCopyParams;
buildParameters.ClearBuildCacheFiles = clearBuildCache;
buildParameters.UseAssetDependencyDB = useAssetDependencyDB;
buildParameters.EncryptionServices = CreateEncryptionInstance();
// SetVideoGroupActive(true);
RawFileBuildPipeline pipeline = new RawFileBuildPipeline();
return pipeline.Run(buildParameters, true);
}
private BuildResult BuildOtherFiles()
{
var fileNameStyle = AssetBundleBuilderSetting.GetPackageFileNameStyle(packageName, selectedBuildPipelines);
var buildinFileCopyOption =
AssetBundleBuilderSetting.GetPackageBuildinFileCopyOption(packageName, selectedBuildPipelines);
var buildinFileCopyParams =
AssetBundleBuilderSetting.GetPackageBuildinFileCopyParams(packageName, selectedBuildPipelines);
var compressOption =
AssetBundleBuilderSetting.GetPackageCompressOption(packageName, selectedBuildPipelines);
var useAssetDependencyDB =
AssetBundleBuilderSetting.GetPackageUseAssetDependencyDB(packageName, selectedBuildPipelines);
var clearBuildCache = AssetBundleBuilderSetting.GetPackageClearBuildCache(packageName, selectedBuildPipelines);
var builtinShaderBundleName = GetBuiltinShaderBundleName();
ScriptableBuildParameters buildParameters = new ScriptableBuildParameters();
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
buildParameters.BuildPipeline = selectedBuildPipelines;
buildParameters.BuildBundleType = (int)EBuildBundleType.AssetBundle;
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
buildParameters.PackageName = packageName;
buildParameters.PackageVersion = packageVersion;
buildParameters.EnableSharePackRule = true;
buildParameters.VerifyBuildingResult = true;
buildParameters.FileNameStyle = fileNameStyle;
buildParameters.BuildinFileCopyOption = buildinFileCopyOption;
buildParameters.BuildinFileCopyParams = buildinFileCopyParams;
buildParameters.CompressOption = compressOption;
buildParameters.ClearBuildCacheFiles = clearBuildCache;
buildParameters.UseAssetDependencyDB = useAssetDependencyDB;
buildParameters.BuiltinShadersBundleName = builtinShaderBundleName;
buildParameters.EncryptionServices = CreateEncryptionInstance();
ScriptableBuildPipeline pipeline = new ScriptableBuildPipeline();
var result = pipeline.Run(buildParameters, true);
return result;
}
// private void SetVideoGroupActive(bool isActive)
// {
// var setting = YooAsset.Editor.AssetBundleCollectorSettingData.Setting;
// if (setting == null)
// {
// Debug.LogError("UnityEvo: 打包设置获取失败请检查AssetBundleCollectorSettingData设置");
// return;
// }
//
// // 使用LINQ简化Package查找
// var collectorPackage = setting.Packages.Find(p => p.PackageName == packageName);
// if (collectorPackage == null)
// {
// Debug.LogError($"UnityEvo: 打包视频文件失败【{packageName}】...未找到对应的Package文件请检查");
// return;
// }
//
// // 定义激活和禁用规则名称
// string enableRule = nameof(EnableGroup);
// string disableRule = nameof(DisableGroup);
//
// // 遍历所有组并设置激活规则
// foreach (var group in collectorPackage.Groups)
// {
// // 使用三元运算符简化逻辑,减少重复代码
// bool shouldEnableGroup = group.GroupName == "Video" ? isActive : !isActive;
// group.ActiveRuleName = shouldEnableGroup ? enableRule : disableRule;
// }
//
// YooAsset.Editor.AssetBundleCollectorSettingData.SaveFile();
// }
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c0023f14896b4a189fd6e7c7d4d6072b
timeCreated: 1767687803

View File

@@ -40,7 +40,6 @@ namespace Stary.Evo.Editor
buildParameters.ClearBuildCacheFiles = clearBuildCache;
buildParameters.UseAssetDependencyDB = useAssetDependencyDB;
buildParameters.EncryptionServices = CreateEncryptionInstance();
RawFileBuildPipeline pipeline = new RawFileBuildPipeline();
var buildResult = pipeline.Run(buildParameters, true);
if (buildResult.Success)

View File

@@ -40,7 +40,7 @@ namespace Stary.Evo
else
{
ip = hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig;
EditorPrefs.SetString("ip", ip);
CustomEditorPrefs.SetString("ip", ip);
userName = hotfixMainResDomain.hotfixMainResDomainEntity.username;
password = hotfixMainResDomain.hotfixMainResDomainEntity.password;
}
@@ -96,7 +96,7 @@ namespace Stary.Evo
{
buildAssetType = BuildAssetType.Login;
message = "未登录";
EditorPrefs.DeleteKey("Authorization");
CustomEditorPrefs.DeleteKey("Authorization");
}
private void SetWebRequestInfo()
@@ -106,7 +106,7 @@ namespace Stary.Evo
hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig = ip;
hotfixMainResDomain.hotfixMainResDomainEntity.username = userName;
hotfixMainResDomain.hotfixMainResDomainEntity.password = password;
EditorPrefs.SetString("ip", ip);
CustomEditorPrefs.SetString("ip", ip);
EditorUtility.SetDirty(hotfixMainResDomain);
AssetDatabase.SaveAssets();
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
#if HotUpdate
using HybridCLR.Editor;
@@ -17,14 +18,22 @@ namespace Stary.Evo.Editor
public class MarkAdressable
{
private static AssetBundleCollectorPackage package;
private static string _packageName;
private static AssetBundleCollectorPackage packageRawFile;
private static Dictionary<string, string> addressDic = new Dictionary<string, string>();
private static Dictionary<string, AssetBundleCollectorGroup> _collectorGroupDic =
new Dictionary<string, AssetBundleCollectorGroup>();
private static string _packageName;
private static string[] rawFiles = new[] { "Video" };
public static string DomainRoot
{
get { return Application.dataPath + "/Domain"; }
}
public static void AddHotfixAddressableDll()
{
CopyDllHotUpdateAssembly(BuildAssetWindow.GetBuildPackageName(),
@@ -136,26 +145,9 @@ namespace Stary.Evo.Editor
public static void AddDomainMark()
{
// //清空主包旧数据
AssetBundleCollectorPackage assetBundleCollectorPackage = null;
//copydll
AddHotfixAddressableDll();
//清空用户旧数据
foreach (var package in AssetBundleCollectorSettingData.Setting.Packages)
{
if (package.PackageName == BuildAssetWindow.GetBuildPackageName())
{
assetBundleCollectorPackage = package;
}
}
if (assetBundleCollectorPackage != null)
{
YooAsset.Editor.AssetBundleCollectorSettingData.RemovePackage(assetBundleCollectorPackage);
}
string configPath =
$"Assets/Domain/{BuildAssetWindow.GetBuildPackageName()}/AddressableRes/Config/DomainConfig.asset";
DomainConfig domainConfig =
@@ -173,6 +165,23 @@ namespace Stary.Evo.Editor
});
}
public static void AddRawFileMark()
{
AssetBundleCollectorPackage assetBundleCollectorPackage = null;
var packageRawFile = $"{BuildAssetWindow.GetBuildPackageName()}_RawFile";
foreach (var package in AssetBundleCollectorSettingData.Setting.Packages)
{
if (packageRawFile == BuildAssetWindow.GetBuildPackageName())
{
assetBundleCollectorPackage = package;
}
}
if (assetBundleCollectorPackage != null)
{
YooAsset.Editor.AssetBundleCollectorSettingData.RemovePackage(assetBundleCollectorPackage);
}
}
private static void CreateRes(string domain, string resPath, string outputPath)
{
@@ -182,11 +191,6 @@ namespace Stary.Evo.Editor
#region
private static Dictionary<string, string> addressDic = new Dictionary<string, string>();
private static Dictionary<string, AssetBundleCollectorGroup> _collectorGroupDic =
new Dictionary<string, AssetBundleCollectorGroup>();
public static void Mark()
{
addressDic.Clear();
@@ -196,39 +200,26 @@ namespace Stary.Evo.Editor
string remotedRoot = $"{DomainRoot}/{_packageName}/AddressableRes";
DirectoryInfo[] dirs = new DirectoryInfo(remotedRoot).GetDirectories();
var setting = YooAsset.Editor.AssetBundleCollectorSettingData.Setting;
setting.ShowPackageView = true;
setting.UniqueBundleName = true;
//创建Package文件
package = YooAsset.Editor.AssetBundleCollectorSettingData.CreatePackage(_packageName);
//检测Packages是否存在TestPackage
package.PackageName = _packageName;
package.EnableAddressable = true;
package.IncludeAssetGUID = true;
package.AutoCollectShaders = true;
package.IgnoreRuleName = "NormalIgnoreRule";
package = CreatePackage(_packageName);
packageRawFile = CreatePackage($"{_packageName}_RawFile");
//检测Packages是否存在Group
foreach (var info in dirs)
{
string groupName = info.Name;
if (info.Name != "Atlas")
if (groupName.Equals("Atlas"))
{
AssetBundleCollectorGroup collectorGroup =
YooAsset.Editor.AssetBundleCollectorSettingData.CreateGroup(package, groupName);
collectorGroup.AssetTags = groupName;
continue;
}
if (!_collectorGroupDic.ContainsKey(groupName))
{
_collectorGroupDic.Add(groupName, collectorGroup);
}
else
{
Debug.LogError("分组 " + groupName + "已存在,请检查资源目录,避免重复");
}
if (rawFiles.Contains(groupName))
{
AddGroup(packageRawFile, groupName);
}
else
{
AddGroup(package, groupName);
}
AutoMarkRootAddress(info);
@@ -240,7 +231,7 @@ namespace Stary.Evo.Editor
///自动创建图集
Debug.Log("开始创建图集");
AutoCreateSpriteAtlas(remotedRoot);
MarkStatus();
DeleteMarkGroup();
YooAsset.Editor.AssetBundleCollectorSettingData.SaveFile();
// CreateRes();
@@ -276,33 +267,35 @@ namespace Stary.Evo.Editor
string groupName = dir.Name;
string assetPath = FilesUtils.AbsoluteToRelativePath("Assets", file); //Asset到文件的路径
var guid = AssetDatabase.AssetPathToGUID(assetPath);
var group = _collectorGroupDic[groupName];
if (group != null)
{
AssetBundleCollector collector = new AssetBundleCollector()
{
CollectPath = assetPath,
CollectorGUID = guid,
CollectorType = ECollectorType.MainAssetCollector,
AddressRuleName = nameof(AddressByFolderAndFileName),
AssetTags = groupName,
};
//TODO 暂时不设置
// 如果是video目录设置
// if (groupName == "Video")
// {
// collector.PackRuleName = nameof(PackVideoFile);
// }
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(group, collector);
Debug.Log("GetAssetAddress:" + GetAssetAddress(file));
AddAddressInfo(file, GetAssetAddress(file));
}
else
{
Debug.LogError("分组 = " + groupName + "不存在");
}
AddCollector(groupName, guid, assetPath, file);
// var group = _collectorGroupDic[groupName];
// if (group != null)
// {
// AssetBundleCollector collector = new AssetBundleCollector()
// {
// CollectPath = assetPath,
// CollectorGUID = guid,
// CollectorType = ECollectorType.MainAssetCollector,
// AddressRuleName = nameof(AddressByFolderAndFileName),
// AssetTags = groupName,
// };
//
// //TODO 暂时不设置
// // 如果是video目录设置
// // if (groupName == "Video")
// // {
// // collector.PackRuleName = nameof(PackVideoFile);
// // }
//
// YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(group, collector);
// Debug.Log("GetAssetAddress:" + GetAssetAddress(file));
// AddAddressInfo(file, GetAssetAddress(file));
// }
// else
// {
// Debug.LogError("分组 = " + groupName + "不存在");
// }
}
}
}
@@ -380,27 +373,27 @@ namespace Stary.Evo.Editor
}
var guid = AssetDatabase.AssetPathToGUID(guidPath);
var group = _collectorGroupDic[groupname];
if (group != null)
{
AssetBundleCollector collector = new AssetBundleCollector()
{
CollectPath = guidPath,
CollectorGUID = guid,
CollectorType = ECollectorType.MainAssetCollector,
AddressRuleName = nameof(AddressByFolderAndFileName),
AssetTags = groupname,
};
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(group, collector);
AddAddressInfo(path, GetAssetAddress(path));
}
else
{
Debug.LogError("分组 = " + GetAssetAddress(path) + "不存在");
}
AddCollector(groupname, guid, guidPath, path);
// var group = _collectorGroupDic[groupname];
// if (group != null)
// {
// AssetBundleCollector collector = new AssetBundleCollector()
// {
// CollectPath = guidPath,
// CollectorGUID = guid,
// CollectorType = ECollectorType.MainAssetCollector,
// AddressRuleName = nameof(AddressByFolderAndFileName),
// AssetTags = groupname,
// };
// YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(group, collector);
//
//
// AddAddressInfo(path, GetAssetAddress(path));
// }
// else
// {
// Debug.LogError("分组 = " + GetAssetAddress(path) + "不存在");
// }
AssetDatabase.Refresh();
}
@@ -418,6 +411,86 @@ namespace Stary.Evo.Editor
#endregion
private static AssetBundleCollectorPackage CreatePackage(string packageName)
{
var setting = YooAsset.Editor.AssetBundleCollectorSettingData.Setting;
setting.ShowPackageView = true;
setting.UniqueBundleName = true;
AssetBundleCollectorPackage assetBundleCollectorPackage = null;
foreach (var package in AssetBundleCollectorSettingData.Setting.Packages)
{
if (package.PackageName == packageName)
{
assetBundleCollectorPackage = package;
break;
}
}
if (assetBundleCollectorPackage != null)
{
YooAsset.Editor.AssetBundleCollectorSettingData.RemovePackage(assetBundleCollectorPackage);
}
//创建Package文件
assetBundleCollectorPackage = YooAsset.Editor.AssetBundleCollectorSettingData.CreatePackage(packageName);
//检测Packages是否存在TestPackage
assetBundleCollectorPackage.PackageName = packageName;
assetBundleCollectorPackage.EnableAddressable = true;
assetBundleCollectorPackage.IncludeAssetGUID = true;
assetBundleCollectorPackage.AutoCollectShaders = true;
assetBundleCollectorPackage.IgnoreRuleName = "NormalIgnoreRule";
return assetBundleCollectorPackage;
}
private static void AddGroup(AssetBundleCollectorPackage package, string groupName)
{
AssetBundleCollectorGroup collectorGroup =
YooAsset.Editor.AssetBundleCollectorSettingData.CreateGroup(package, groupName);
collectorGroup.AssetTags = groupName;
if (!_collectorGroupDic.ContainsKey(groupName))
{
_collectorGroupDic.Add(groupName, collectorGroup);
}
else
{
Debug.LogError("分组 " + groupName + "已存在,请检查资源目录,避免重复");
}
}
private static void AddCollector(string groupName, string guid, string assetPath, string file)
{
var group = _collectorGroupDic[groupName];
if (group != null)
{
AssetBundleCollector collector = new AssetBundleCollector()
{
CollectPath = assetPath,
CollectorGUID = guid,
CollectorType = ECollectorType.MainAssetCollector,
AddressRuleName = nameof(AddressByFolderAndFileName),
AssetTags = groupName,
};
////TODO 暂时不设置
//如果是video目录设置
if (rawFiles.Contains(groupName))
{
collector.PackRuleName = nameof(PackVideoFile);
}
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(group, collector);
Debug.Log("GetAssetAddress:" + GetAssetAddress(file));
AddAddressInfo(file, GetAssetAddress(file));
}
else
{
Debug.LogError("分组 = " + groupName + "不存在");
}
}
private static void AddAddressInfo(string assetPath, string address)
{
if (addressDic.ContainsKey(assetPath))
@@ -447,22 +520,22 @@ namespace Stary.Evo.Editor
#endregion
/// <summary>
/// 标记为资源分组
/// 删除资源为空的分组
/// </summary>
private static void MarkStatus()
private static void DeleteMarkGroup()
{
List<AssetBundleCollectorGroup> deleteList = new List<AssetBundleCollectorGroup>();
for (int i = 0; i < package.Groups.Count; i++)
{
var group = package.Groups[i];
if (group.GroupName != "Default Local Group" && group.GroupName != "Built In Data")
// if (group.GroupName != "Default Local Group" && group.GroupName != "Built In Data")
// {
if (group.Collectors.Count <= 0)
{
if (group.Collectors.Count <= 0)
{
///删除没有资源的分组
deleteList.Add(group);
}
///删除没有资源的分组
deleteList.Add(group);
}
//}
}
for (int i = 0; i < deleteList.Count; i++)
@@ -471,6 +544,8 @@ namespace Stary.Evo.Editor
}
}
#region shader变体
public static void CollectSvc(string root, string packageName, Action complete)
{
string remotedRoot = $"{root}/{packageName}/ShaderVariants";
@@ -505,7 +580,6 @@ namespace Stary.Evo.Editor
ShaderVariantCollector.Run(localSavePath, packageName, 1000, CompletedCallback);
}
// 新增方法创建独立的ShaderVariants分组防止多个package冲突
private static void CreateShaderVariantsGroup(string packageName, string localSavePath)
{
string groupname = $"ShaderVariants_{packageName}";
@@ -537,5 +611,7 @@ namespace Stary.Evo.Editor
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(collectorGroup, collector);
YooAsset.Editor.AssetBundleCollectorSettingData.SaveFile();
}
#endregion
}
}

View File

@@ -24,5 +24,7 @@ namespace Stary.Evo
// /// 原生文件构建管线 (RFBP)
// /// </summary>
// RawFileBuildPipeline,
MixedBuildPipeline
}
}

View File

@@ -1,186 +1,186 @@
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.Assertions;
using YooAsset;
namespace Stary.Evo
{
public class ArtResEditorSimulateState : AbstractFSMIStateAsync
{
public ArtResEditorSimulateState(IFsmSystemAsync system) : base(system)
{
}
public override async UniTask OnEnterAsync()
{
Debug.Log("UnityEvo:开始资源更新...");
// //初始化读取资源配置表
var package = YooAssets.GetPackage(AppConfig.PackageDomainName);
// 请求资源版本
var requetVersionOp = package.RequestPackageVersionAsync();
await requetVersionOp;
string packageVersion = "";
if (requetVersionOp.Status == EOperationStatus.Succeed)
{
//更新成功
packageVersion = requetVersionOp.PackageVersion;
PlayerPrefs.SetString($"{AppConfig.PackageDomainName}_GAME_VERSION", packageVersion);
Debug.Log($"UnityEvo:获取资源版本 Version : 【{packageVersion}】");
Debug.Log($"UnityEvo:开始加载服务器资源...");
}
else
{
Debug.LogError($"UnityEvo:获取资源版本失败: 【{requetVersionOp.Error}】");
FsmSystem.SetCurState(nameof(ResUpdateLocalState));
return;
}
// 更新资源清单
var updateManifestOp = package.UpdatePackageManifestAsync(packageVersion);
await updateManifestOp;
if (updateManifestOp.Status == EOperationStatus.Succeed)
{
//更新成功
Debug.Log($"UnityEvo:更新资源清单 updateManifest : 【成功】");
}
else
{
//更新失败
Debug.LogError($"UnityEvo:更新资源清单失败: 【{updateManifestOp.Error}】");
}
//4.下载补丁包
await Download();
//加载热更配置文件
var loadArtSceneDataOp = package.LoadAssetAsync<ArtSceneData>("Config_ArtSceneData");
await loadArtSceneDataOp;
ArtSceneData artSceneData = null;
if (loadArtSceneDataOp.Status == EOperationStatus.Succeed)
{
//更新成功
Debug.Log($"UnityEvo:加载热更配置文件 ArtSceneData : 【成功】");
artSceneData = loadArtSceneDataOp.AssetObject as ArtSceneData;
}
else
{
Debug.LogError($"UnityEvo:加载热更配置文件 ArtSceneData : 【失败】");
}
if (artSceneData == null)
{
Debug.LogError($"UnityEvo:【{package.PackageName}】加载ArtSceneData为空无法继续执行后续流程请检查");
}
}
public override UniTask OnEnterAsync<T>(T param)
{
return UniTask.CompletedTask;
}
public override UniTask OnEnterAsync<T1, T2>(T1 param1, T2 param2)
{
return UniTask.CompletedTask;
}
public override void OnUpdate()
{
base.OnUpdate();
}
public override async UniTask OnExitAsync()
{
await ((FsmLoadSystem)FsmSystem).ForceUnloadAllAssets(AppConfig.PackageDomainName);
AppConfig.PackageDomainName = "";
}
#region
public async UniTask Download()
{
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插件的修改===================================
//开启下载
downloader.BeginDownload();
await downloader;
//检测下载结果
if (downloader.Status == EOperationStatus.Succeed)
{
//下载成功
Debug.Log("UnityEvo:资源更新完成");
}
else
{
//下载失败
Debug.Log("UnityEvo:资源更新失败");
}
}
//===================================适应新版本YooAsset插件的修改===================================
/// <summary>
/// 开始下载
/// </summary>
private void OnStartDownloadFileFunction(DownloadFileData downloadFileData)
{
Debug.Log(
$"UnityEvo:开始下载:文件名:{downloadFileData.FileName},文件大小:{downloadFileData.FileSize / 1024f / 1024f} MB");
}
/// <summary>
/// 下载完成
/// </summary>
private void OnDownloadOverFunction(DownloaderFinishData downloaderFinishData)
{
Debug.Log("UnityEvo:下载" + (downloaderFinishData.Succeed ? "成功" : "失败"));
}
/// <summary>
/// 更新中
/// </summary>
private void OnDownloadProgressUpdateFunction(DownloadUpdateData downloadUpdateData)
{
Debug.Log(
$"UnityEvo:文件总数:{downloadUpdateData.TotalDownloadCount},已下载文件数:{downloadUpdateData.CurrentDownloadCount},下载总大小:{downloadUpdateData.TotalDownloadBytes / 1024f / 1024f} MB已下载大小{downloadUpdateData.CurrentDownloadBytes / 1024f / 1024f} MB");
}
/// <summary>
/// 下载出错
/// </summary>
/// <param name="errorData"></param>
private void OnDownloadErrorFunction(DownloadErrorData errorData)
{
Debug.Log($"UnityEvo:下载出错:包名:{errorData.PackageName} 文件名:{errorData.FileName},错误信息:{errorData.ErrorInfo}");
}
//===================================适应新版本YooAsset插件的修改===================================
#endregion
}
}
// using Cysharp.Threading.Tasks;
// using UnityEngine;
// using UnityEngine.Assertions;
// using YooAsset;
//
// namespace Stary.Evo
// {
// public class ArtResEditorSimulateState : AbstractFSMIStateAsync
// {
// public ArtResEditorSimulateState(IFsmSystemAsync system) : base(system)
// {
// }
//
// public override async UniTask OnEnterAsync()
// {
// Debug.Log("UnityEvo:开始资源更新...");
//
//
// // //初始化读取资源配置表
// var package = YooAssets.GetPackage(AppConfig.PackageDomainName);
// // 请求资源版本
// var requetVersionOp = package.RequestPackageVersionAsync();
// await requetVersionOp;
// string packageVersion = "";
// if (requetVersionOp.Status == EOperationStatus.Succeed)
// {
// //更新成功
// packageVersion = requetVersionOp.PackageVersion;
// PlayerPrefs.SetString($"{AppConfig.PackageDomainName}_GAME_VERSION", packageVersion);
// Debug.Log($"UnityEvo:获取资源版本 Version : 【{packageVersion}】");
// Debug.Log($"UnityEvo:开始加载服务器资源...");
// }
// else
// {
// Debug.LogError($"UnityEvo:获取资源版本失败: 【{requetVersionOp.Error}】");
// FsmSystem.SetCurState(nameof(ResUpdateLocalState));
// return;
// }
//
// // 更新资源清单
// var updateManifestOp = package.UpdatePackageManifestAsync(packageVersion);
// await updateManifestOp;
// if (updateManifestOp.Status == EOperationStatus.Succeed)
// {
// //更新成功
// Debug.Log($"UnityEvo:更新资源清单 updateManifest : 【成功】");
// }
// else
// {
// //更新失败
// Debug.LogError($"UnityEvo:更新资源清单失败: 【{updateManifestOp.Error}】");
// }
//
// //4.下载补丁包
// await Download();
//
//
// //加载热更配置文件
// var loadArtSceneDataOp = package.LoadAssetAsync<ArtSceneData>("Config_ArtSceneData");
// await loadArtSceneDataOp;
// ArtSceneData artSceneData = null;
// if (loadArtSceneDataOp.Status == EOperationStatus.Succeed)
// {
// //更新成功
// Debug.Log($"UnityEvo:加载热更配置文件 ArtSceneData : 【成功】");
// artSceneData = loadArtSceneDataOp.AssetObject as ArtSceneData;
// }
// else
// {
// Debug.LogError($"UnityEvo:加载热更配置文件 ArtSceneData : 【失败】");
// }
//
//
// if (artSceneData == null)
// {
// Debug.LogError($"UnityEvo:【{package.PackageName}】加载ArtSceneData为空无法继续执行后续流程请检查");
// }
// }
//
// public override UniTask OnEnterAsync<T>(T param)
// {
// return UniTask.CompletedTask;
// }
//
// public override UniTask OnEnterAsync<T1, T2>(T1 param1, T2 param2)
// {
// return UniTask.CompletedTask;
// }
//
// public override void OnUpdate()
// {
// base.OnUpdate();
// }
//
//
// public override async UniTask OnExitAsync()
// {
// await ((FsmLoadSystem)FsmSystem).ForceUnloadAllAssets(AppConfig.PackageDomainName);
// AppConfig.PackageDomainName = "";
// }
//
// #region 下载热更资
//
// public async UniTask Download()
// {
// 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插件的修改===================================
//
// //开启下载
// downloader.BeginDownload();
// await downloader;
//
// //检测下载结果
// if (downloader.Status == EOperationStatus.Succeed)
// {
// //下载成功
// Debug.Log("UnityEvo:资源更新完成");
// }
// else
// {
// //下载失败
// Debug.Log("UnityEvo:资源更新失败");
// }
// }
//
// //===================================适应新版本YooAsset插件的修改===================================
// /// <summary>
// /// 开始下载
// /// </summary>
// private void OnStartDownloadFileFunction(DownloadFileData downloadFileData)
// {
// Debug.Log(
// $"UnityEvo:开始下载:文件名:{downloadFileData.FileName},文件大小:{downloadFileData.FileSize / 1024f / 1024f} MB");
// }
//
// /// <summary>
// /// 下载完成
// /// </summary>
// private void OnDownloadOverFunction(DownloaderFinishData downloaderFinishData)
// {
// Debug.Log("UnityEvo:下载" + (downloaderFinishData.Succeed ? "成功" : "失败"));
// }
//
// /// <summary>
// /// 更新中
// /// </summary>
// private void OnDownloadProgressUpdateFunction(DownloadUpdateData downloadUpdateData)
// {
// Debug.Log(
// $"UnityEvo:文件总数:{downloadUpdateData.TotalDownloadCount},已下载文件数:{downloadUpdateData.CurrentDownloadCount},下载总大小:{downloadUpdateData.TotalDownloadBytes / 1024f / 1024f} MB已下载大小{downloadUpdateData.CurrentDownloadBytes / 1024f / 1024f} MB");
// }
//
// /// <summary>
// /// 下载出错
// /// </summary>
// /// <param name="errorData"></param>
// private void OnDownloadErrorFunction(DownloadErrorData errorData)
// {
// Debug.Log($"UnityEvo:下载出错:包名:{errorData.PackageName} 文件名:{errorData.FileName},错误信息:{errorData.ErrorInfo}");
// }
// //===================================适应新版本YooAsset插件的修改===================================
//
// #endregion
// }
// }

View File

@@ -1,147 +1,147 @@
using System;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.Assertions;
using YooAsset;
namespace Stary.Evo
{
public class ArtResUpdateLocalState : AbstractFSMIStateAsync
{
public ArtResUpdateLocalState(IFsmSystemAsync system) : base(system)
{
}
public override async UniTask OnEnterAsync()
{
//初始化读取资源配置表
var package = YooAssets.GetPackage(AppConfig.PackageDomainName);
//更新失败
Debug.Log($"UnityEvo:切换为加载本地缓存资源...");
string packageVersion = "";
// if (package.PackageName.Equals("Main"))
// {
// 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:开始加载本地资源...");
// Assert.AreEqual(EOperationStatus.Succeed, requetVersionOp.Status);
// 加载本地缓存的资源清单文件
var updateManifestOp = package.UpdatePackageManifestAsync(packageVersion);
await updateManifestOp;
if (updateManifestOp.Status == EOperationStatus.Succeed)
{
//更新成功
Debug.Log($"UnityEvo:更新本地资源清单 updateManifest : 【成功】");
}
else
{
//更新失败
Debug.LogError($"UnityEvo:加载本地资源清单文件失败,需要更新资源!: 【{updateManifestOp.Error}】");
return;
}
Assert.AreEqual(EOperationStatus.Succeed, updateManifestOp.Status);
//4.检测补丁包
await Download();
//加载热更配置文件
var loadArtSceneDataOp = package.LoadAssetAsync<ArtSceneData>("Config_ArtSceneData");
await loadArtSceneDataOp;
ArtSceneData artSceneData = null;
if (loadArtSceneDataOp.Status == EOperationStatus.Succeed)
{
//更新成功
Debug.Log($"UnityEvo:加载热更配置文件 ArtSceneData : 【成功】");
artSceneData = loadArtSceneDataOp.AssetObject as ArtSceneData;
}
else
{
Debug.LogError($"UnityEvo:加载热更配置文件 ArtSceneData : 【失败】");
}
if (artSceneData == null)
{
Debug.LogError($"UnityEvo:【{package.PackageName}】加载ArtSceneData为空无法继续执行后续流程请检查");
}
}
public override UniTask OnEnterAsync<T>(T param)
{
return UniTask.CompletedTask;
}
public override UniTask OnEnterAsync<T1, T2>(T1 param1, T2 param2)
{
return UniTask.CompletedTask;
}
public override void OnUpdate()
{
base.OnUpdate();
}
public override async UniTask OnExitAsync()
{
await ((FsmLoadSystem)FsmSystem).ForceUnloadAllAssets(AppConfig.PackageDomainName);
AppConfig.PackageDomainName = "";
}
#region
public async UniTask Download()
{
int downloadingMaxNum = 1;
int failedTryAgain = 1;
var package = YooAssets.GetPackage(AppConfig.PackageDomainName);
var downloader = package.CreateResourceDownloader(downloadingMaxNum, failedTryAgain);
// 在正常开始游戏之前,还需要验证本地清单内容的完整性。
if (downloader.TotalDownloadCount > 0)
{
Debug.Log("UnityEvo:资源内容本地并不完整,需要更新资源!");
return;
}
}
#endregion
}
}
// using System;
// using Cysharp.Threading.Tasks;
// using UnityEngine;
// using UnityEngine.Assertions;
// using YooAsset;
//
// namespace Stary.Evo
// {
// public class ArtResUpdateLocalState : AbstractFSMIStateAsync
// {
// public ArtResUpdateLocalState(IFsmSystemAsync system) : base(system)
// {
// }
//
//
// public override async UniTask OnEnterAsync()
// {
// //初始化读取资源配置表
// var package = YooAssets.GetPackage(AppConfig.PackageDomainName);
//
//
// //更新失败
//
// Debug.Log($"UnityEvo:切换为加载本地缓存资源...");
// string packageVersion = "";
// // if (package.PackageName.Equals("Main"))
// // {
// // 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:开始加载本地资源...");
// // Assert.AreEqual(EOperationStatus.Succeed, requetVersionOp.Status);
//
//
// // 加载本地缓存的资源清单文件
// var updateManifestOp = package.UpdatePackageManifestAsync(packageVersion);
// await updateManifestOp;
// if (updateManifestOp.Status == EOperationStatus.Succeed)
// {
// //更新成功
// Debug.Log($"UnityEvo:更新本地资源清单 updateManifest : 【成功】");
// }
// else
// {
// //更新失败
// Debug.LogError($"UnityEvo:加载本地资源清单文件失败,需要更新资源!: 【{updateManifestOp.Error}】");
// return;
// }
//
// Assert.AreEqual(EOperationStatus.Succeed, updateManifestOp.Status);
//
//
// //4.检测补丁包
// await Download();
//
//
// //加载热更配置文件
// var loadArtSceneDataOp = package.LoadAssetAsync<ArtSceneData>("Config_ArtSceneData");
// await loadArtSceneDataOp;
// ArtSceneData artSceneData = null;
// if (loadArtSceneDataOp.Status == EOperationStatus.Succeed)
// {
// //更新成功
// Debug.Log($"UnityEvo:加载热更配置文件 ArtSceneData : 【成功】");
// artSceneData = loadArtSceneDataOp.AssetObject as ArtSceneData;
// }
// else
// {
// Debug.LogError($"UnityEvo:加载热更配置文件 ArtSceneData : 【失败】");
// }
//
//
// if (artSceneData == null)
// {
// Debug.LogError($"UnityEvo:【{package.PackageName}】加载ArtSceneData为空无法继续执行后续流程请检查");
// }
//
// }
//
// public override UniTask OnEnterAsync<T>(T param)
// {
// return UniTask.CompletedTask;
// }
//
// public override UniTask OnEnterAsync<T1, T2>(T1 param1, T2 param2)
// {
// return UniTask.CompletedTask;
// }
//
// public override void OnUpdate()
// {
// base.OnUpdate();
// }
//
//
// public override async UniTask OnExitAsync()
// {
// await ((FsmLoadSystem)FsmSystem).ForceUnloadAllAssets(AppConfig.PackageDomainName);
// AppConfig.PackageDomainName = "";
// }
//
// #region 下载热更资
//
// public async UniTask Download()
// {
// int downloadingMaxNum = 1;
// int failedTryAgain = 1;
// var package = YooAssets.GetPackage(AppConfig.PackageDomainName);
// var downloader = package.CreateResourceDownloader(downloadingMaxNum, failedTryAgain);
//
// // 在正常开始游戏之前,还需要验证本地清单内容的完整性。
// if (downloader.TotalDownloadCount > 0)
// {
// Debug.Log("UnityEvo:资源内容本地并不完整,需要更新资源!");
// return;
// }
// }
//
// #endregion
//
//
// }
// }

View File

@@ -1,234 +1,234 @@
using System;
using System.IO;
using Cysharp.Threading.Tasks;
using Main;
using Newtonsoft.Json;
using UnityEditor;
using UnityEngine;
using UnityEngine.Assertions;
using YooAsset;
using Object = UnityEngine.Object;
namespace Stary.Evo
{
public class ArtResStartState : AbstractFSMIStateAsync
{
public ArtResStartState(IFsmSystemAsync system) : base(system)
{
}
public override async UniTask OnEnterAsync()
{
Debug.Log("UnityEvo:启动开始资源初始化...");
//初始化读取资源配置表
HotfixMainResDomain hotfixMainResDomain = Resources.Load<HotfixMainResDomain>("HotfixMainResDomain");
if (hotfixMainResDomain != null)
{
AppConfig.IpConfig = hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig;
AppConfig.UserName = hotfixMainResDomain.hotfixMainResDomainEntity.username;
AppConfig.PassWord = hotfixMainResDomain.hotfixMainResDomainEntity.password;
AppConfig.ProductName =Application.identifier;
AppConfig.MainDomainVersion = hotfixMainResDomain.hotfixMainResDomainEntity.mainDomainVersion;
}
Debug.Log($"UnityEvo:读取资源配置表成功...{AppConfig.IpConfig}{AppConfig.UserName}{AppConfig.PassWord}");
// 初始化资源系统
YooAssets.Initialize();
//自定义网络请求器
// 设置自定义请求委托
//YooAssets.SetDownloadSystemUnityWebRequest(NasWebRequester);
//初始化资源加载模块
// 增加包存在性检查
var package = YooAssets.TryGetPackage(AppConfig.PackageDomainName);
if (package == null)
{
Debug.LogWarning($"UnityEvo:资源包 {AppConfig.PackageDomainName} 不存在,正在尝试创建...");
package = YooAssets.CreatePackage(AppConfig.PackageDomainName);
}
YooAssets.SetDefaultPackage(package);
// 初始化资源包
#if EDITOR_SIMULATEMODE
await EDITOR_SIMULATEMODE(package);
//await FsmSystem.SetCurState(nameof(ResUpdateServerState));
await FsmSystem.SetCurState(nameof(ArtResEditorSimulateState));
#elif HOST_PLAYMODE
//登录
string url = AppConfig.IpConfig + "/Authentication/login";
bool isLogin = await WebRequestSystem.Login(url, AppConfig.UserName, AppConfig.PassWord);
if (isLogin)
await HOST_PLAYMODE(package);
else
await Chche_PLAYMODE(package);
await FsmSystem.SetCurState(nameof(ArtResUpdateLocalState));
#endif
}
public override UniTask OnEnterAsync<T>(T param)
{
return UniTask.CompletedTask;
}
public override UniTask OnEnterAsync<T1, T2>(T1 param1, T2 param2)
{
return UniTask.CompletedTask;
}
public override void OnUpdate()
{
base.OnUpdate();
}
public override UniTask OnExitAsync()
{
return UniTask.CompletedTask;
}
private async UniTask EDITOR_SIMULATEMODE(ResourcePackage package)
{
var initParams=YooAssetFileSystem.EditorSimulateInitializeParameter(package.PackageName);
var initialization = package.InitializeAsync(initParams);
await initialization;
if (initialization.Status == EOperationStatus.Succeed)
{
Assert.AreEqual(EOperationStatus.Succeed, initialization.Status);
Debug.Log("UnityEvo:资源包初始化成功!");
}
else
{
Debug.LogError($"UnityEvo:资源包初始化失败:{initialization.Error}");
}
//运行模拟文件系统
}
private async UniTask Chche_PLAYMODE(ResourcePackage package)
{
Debug.Log("UnityEvo:网络连接不通畅,切换缓存加载!");
var initParams=YooAssetFileSystem.HostInitializeParameter();
var initOperation = package.InitializeAsync(initParams);
await initOperation;
var operation = package.RequestPackageVersionAsync();
await operation;
if (operation.Status == EOperationStatus.Succeed)
{
PlayerPrefs.SetString($"{AppConfig.PackageDomainName}_GAME_VERSION", operation.PackageVersion);
Debug.Log("UnityEvo:从本地缓存中加载资源包,初始化获取版本号成功!");
}else
{
Debug.LogError($"UnityEvo:从本地缓存中加载资源包,初始化获取版本号失败!");
}
if (initOperation.Status == EOperationStatus.Succeed)
Debug.Log("UnityEvo:从本地缓存中资源包,初始化成功!");
else
Debug.LogError($"UnityEvo:从本地缓存中资源包,初始化失败:{initOperation.Error}");
}
public async UniTask HOST_PLAYMODE(ResourcePackage package)
{
// 新增平台判断代码
#if UNITY_EDITOR
BuildTarget buildTarget = UnityEditor.EditorUserBuildSettings.activeBuildTarget;
AppConfig.Platform = buildTarget.ToString();
#else
AppConfig.Platform = Application.platform.ToString();
#endif
Debug.Log($"目标平台标识: {AppConfig.Platform}");
// 请求资源版本
string url = $"{AppConfig.IpConfig}/ResDomain/GetResDomainByDomain";
var resDmainRequst = new ResDmainRequst()
{
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)
{
await Download(resDmainResponse.DocumentFileId);
PlayerPrefs.SetString($"{AppConfig.PackageDomainName}_GAME_VERSION",
resDmainResponse.PackageVersion);
}
else //版本一致,加载缓存资源
{
Debug.Log($"UnityEvo:资源版本一致,自动跳过更新...");
}
}
else
{
Debug.LogError($"UnityEvo:获取资源版本失败: 【{resDmainMessageEntity.message}】");
}
var initParams=YooAssetFileSystem.HostInitializeParameter();
// initParameters.CacheFileSystemParameters = cacheFileSystemParams;
var initOperation = package.InitializeAsync(initParams);
await initOperation;
if (initOperation.Status == EOperationStatus.Succeed)
Debug.Log("UnityEvo:从远程加载资源包,初始化成功!");
else
Debug.LogError($"UnityEvo:从远程加载资源包,初始化失败:{initOperation.Error}");
}
public async UniTask Download(string fileId)
{
// 在任意MonoBehaviour或DomainBase派生类中
string loadPath = Path.Combine(Application.temporaryCachePath, "DownloadedContent",
AppConfig.PackageDomainName);
//string loadPath = $"{Application.persistentDataPath}/DownloadedContent/{AppConfig.PackageDomainName}";
if (Directory.Exists(loadPath))
{
Directory.Delete(loadPath, true);
// 等一帧,让系统真正释放句柄
await UniTask.DelayFrame(1);
}
FsmLoadSystem loadSystem =FsmSystem as FsmLoadSystem;
if (loadSystem.ProgressBarPanel == null)
{
loadSystem.ProgressBarPanel =Object.Instantiate(Resources.Load<GameObject>("ProgressBarPanel"),
Camera.main.transform).GetOrAddComponent<ProgressBarPanel>();
}
await ZipTool.DownloadAndUnzipAsync(fileId, loadPath, DownLoadProgress, UnzipProgress);
}
private void DownLoadProgress(float progress)
{
Debug.Log($"下载进度:{progress:P0}");
FsmLoadSystem loadSystem =FsmSystem as FsmLoadSystem;
loadSystem.ProgressBarPanel.SetProgressBarValue("下载中", progress);
}
private void UnzipProgress(float progress)
{
Debug.Log($"解压进度:{progress:P0}");
FsmLoadSystem loadSystem =FsmSystem as FsmLoadSystem;
loadSystem.ProgressBarPanel.SetProgressBarValue("解压中", progress);
}
}
}
// using System;
// using System.IO;
// using Cysharp.Threading.Tasks;
// using Main;
// using Newtonsoft.Json;
// using UnityEditor;
// using UnityEngine;
// using UnityEngine.Assertions;
// using YooAsset;
// using Object = UnityEngine.Object;
//
// namespace Stary.Evo
// {
// public class ArtResStartState : AbstractFSMIStateAsync
// {
// public ArtResStartState(IFsmSystemAsync system) : base(system)
// {
// }
//
//
// public override async UniTask OnEnterAsync()
// {
// Debug.Log("UnityEvo:启动开始资源初始化...");
//
//
// //初始化读取资源配置表
// HotfixMainResDomain hotfixMainResDomain = Resources.Load<HotfixMainResDomain>("HotfixMainResDomain");
// if (hotfixMainResDomain != null)
// {
// AppConfig.IpConfig = hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig;
// AppConfig.UserName = hotfixMainResDomain.hotfixMainResDomainEntity.username;
// AppConfig.PassWord = hotfixMainResDomain.hotfixMainResDomainEntity.password;
// AppConfig.ProductName =Application.identifier;
// AppConfig.MainDomainVersion = hotfixMainResDomain.hotfixMainResDomainEntity.mainDomainVersion;
// }
//
// Debug.Log($"UnityEvo:读取资源配置表成功...{AppConfig.IpConfig}{AppConfig.UserName}{AppConfig.PassWord}");
// // 初始化资源系统
// YooAssets.Initialize();
//
//
// //自定义网络请求器
// // 设置自定义请求委托
// //YooAssets.SetDownloadSystemUnityWebRequest(NasWebRequester);
//
//
// //初始化资源加载模块
// // 增加包存在性检查
// var package = YooAssets.TryGetPackage(AppConfig.PackageDomainName);
// if (package == null)
// {
// Debug.LogWarning($"UnityEvo:资源包 {AppConfig.PackageDomainName} 不存在,正在尝试创建...");
// package = YooAssets.CreatePackage(AppConfig.PackageDomainName);
// }
//
// YooAssets.SetDefaultPackage(package);
//
// // 初始化资源包
// #if EDITOR_SIMULATEMODE
// await EDITOR_SIMULATEMODE(package);
// //await FsmSystem.SetCurState(nameof(ResUpdateServerState));
// await FsmSystem.SetCurState(nameof(ArtResEditorSimulateState));
// #elif HOST_PLAYMODE
//
// //登录
// string url = AppConfig.IpConfig + "/Authentication/login";
// bool isLogin = await WebRequestSystem.Login(url, AppConfig.UserName, AppConfig.PassWord);
// if (isLogin)
// await HOST_PLAYMODE(package);
// else
// await Chche_PLAYMODE(package);
//
//
// await FsmSystem.SetCurState(nameof(ArtResUpdateLocalState));
// #endif
// }
//
// public override UniTask OnEnterAsync<T>(T param)
// {
// return UniTask.CompletedTask;
// }
//
// public override UniTask OnEnterAsync<T1, T2>(T1 param1, T2 param2)
// {
// return UniTask.CompletedTask;
// }
//
// public override void OnUpdate()
// {
// base.OnUpdate();
// }
//
//
// public override UniTask OnExitAsync()
// {
// return UniTask.CompletedTask;
// }
//
// private async UniTask EDITOR_SIMULATEMODE(ResourcePackage package)
// {
//
// var initParams=YooAssetFileSystem.EditorSimulateInitializeParameter(package.PackageName);
// var initialization = package.InitializeAsync(initParams);
// await initialization;
// if (initialization.Status == EOperationStatus.Succeed)
// {
// Assert.AreEqual(EOperationStatus.Succeed, initialization.Status);
// Debug.Log("UnityEvo:资源包初始化成功!");
// }
// else
// {
// Debug.LogError($"UnityEvo:资源包初始化失败:{initialization.Error}");
// }
//
// //运行模拟文件系统
//
// }
// private async UniTask Chche_PLAYMODE(ResourcePackage package)
// {
// Debug.Log("UnityEvo:网络连接不通畅,切换缓存加载!");
// var initParams=YooAssetFileSystem.HostInitializeParameter();
// var initOperation = package.InitializeAsync(initParams);
// await initOperation;
//
// var operation = package.RequestPackageVersionAsync();
// await operation;
// if (operation.Status == EOperationStatus.Succeed)
// {
// PlayerPrefs.SetString($"{AppConfig.PackageDomainName}_GAME_VERSION", operation.PackageVersion);
// Debug.Log("UnityEvo:从本地缓存中加载资源包,初始化获取版本号成功!");
// }else
// {
// Debug.LogError($"UnityEvo:从本地缓存中加载资源包,初始化获取版本号失败!");
// }
//
// if (initOperation.Status == EOperationStatus.Succeed)
// Debug.Log("UnityEvo:从本地缓存中资源包,初始化成功!");
// else
// Debug.LogError($"UnityEvo:从本地缓存中资源包,初始化失败:{initOperation.Error}");
// }
//
// public async UniTask HOST_PLAYMODE(ResourcePackage package)
// {
// // 新增平台判断代码
// #if UNITY_EDITOR
// BuildTarget buildTarget = UnityEditor.EditorUserBuildSettings.activeBuildTarget;
// AppConfig.Platform = buildTarget.ToString();
// #else
// AppConfig.Platform = Application.platform.ToString();
// #endif
// Debug.Log($"目标平台标识: {AppConfig.Platform}");
//
// // 请求资源版本
// string url = $"{AppConfig.IpConfig}/ResDomain/GetResDomainByDomain";
// var resDmainRequst = new ResDmainRequst()
// {
// 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)
// {
// await Download(resDmainResponse.DocumentFileId);
// PlayerPrefs.SetString($"{AppConfig.PackageDomainName}_GAME_VERSION",
// resDmainResponse.PackageVersion);
// }
// else //版本一致,加载缓存资源
// {
// Debug.Log($"UnityEvo:资源版本一致,自动跳过更新...");
// }
// }
// else
// {
// Debug.LogError($"UnityEvo:获取资源版本失败: 【{resDmainMessageEntity.message}】");
// }
//
// var initParams=YooAssetFileSystem.HostInitializeParameter();
// // initParameters.CacheFileSystemParameters = cacheFileSystemParams;
//
// var initOperation = package.InitializeAsync(initParams);
//
// await initOperation;
//
// if (initOperation.Status == EOperationStatus.Succeed)
// Debug.Log("UnityEvo:从远程加载资源包,初始化成功!");
// else
// Debug.LogError($"UnityEvo:从远程加载资源包,初始化失败:{initOperation.Error}");
// }
//
// public async UniTask Download(string fileId)
// {
// // 在任意MonoBehaviour或DomainBase派生类中
// string loadPath = Path.Combine(Application.temporaryCachePath, "DownloadedContent",
// AppConfig.PackageDomainName);
// //string loadPath = $"{Application.persistentDataPath}/DownloadedContent/{AppConfig.PackageDomainName}";
// if (Directory.Exists(loadPath))
// {
// Directory.Delete(loadPath, true);
// // 等一帧,让系统真正释放句柄
// await UniTask.DelayFrame(1);
// }
// FsmLoadSystem loadSystem =FsmSystem as FsmLoadSystem;
// if (loadSystem.ProgressBarPanel == null)
// {
// loadSystem.ProgressBarPanel =Object.Instantiate(Resources.Load<GameObject>("ProgressBarPanel"),
// Camera.main.transform).GetOrAddComponent<ProgressBarPanel>();
// }
// await ZipTool.DownloadAndUnzipAsync(fileId, loadPath, DownLoadProgress, UnzipProgress);
// }
//
// private void DownLoadProgress(float progress)
// {
// Debug.Log($"下载进度:{progress:P0}");
// FsmLoadSystem loadSystem =FsmSystem as FsmLoadSystem;
// loadSystem.ProgressBarPanel.SetProgressBarValue("下载中", progress);
// }
//
// private void UnzipProgress(float progress)
// {
// Debug.Log($"解压进度:{progress:P0}");
// FsmLoadSystem loadSystem =FsmSystem as FsmLoadSystem;
// loadSystem.ProgressBarPanel.SetProgressBarValue("解压中", progress);
// }
// }
// }

View File

@@ -13,7 +13,7 @@ namespace Stary.Evo
public class DomainBase : MonoBehaviour
{
public string DomainName { get; set; }
public string DomainNameRaw { get; set; }
/// <summary>
/// 触发Domain时调用该方法

View File

@@ -42,7 +42,7 @@ namespace Stary.Evo
public async UniTask ForceUnloadAllAssets(string packageName)
{
var package = YooAssets.TryGetPackage(packageName);
if (package != null)
if (package != null&&package.InitializeStatus == EOperationStatus.Succeed)
{
var operation = package.UnloadAllAssetsAsync();
await operation;

View File

@@ -9,12 +9,11 @@ using YooAsset;
namespace Stary.Evo
{
public class HotFixState : AbstractFSMIStateAsync
public class HotFixDllState : AbstractFSMIStateAsync
{
public string[] PatchedAOTAssemblyList =
{
"System.Core.dll",
"System.Core.dll",
"UnityEngine.CoreModule.dll",
"mscorlib.dll",
"DOTween.dll",
@@ -25,7 +24,7 @@ namespace Stary.Evo
"mscorlib.dll"
};
public HotFixState(IFsmSystemAsync system) : base(system)
public HotFixDllState(IFsmSystemAsync system) : base(system)
{
}
@@ -52,7 +51,7 @@ namespace Stary.Evo
if (assemblyType != null)
{
Debug.Log($"UnityEvo:热更程序集:{hotUpdateAssemblyName} 已经加载过了");
FsmSystem.SetCurState(nameof(LoadResState), domainConfig, assemblyType);
FsmSystem.SetCurState(nameof(ResStartState), domainConfig, assemblyType);
return;
}
@@ -208,7 +207,7 @@ namespace Stary.Evo
Debug.Log("UnityEvo:dll:OnExit检查成功");
// AppConfig.SetDefaultHotfixType(type);
FsmSystem.SetCurState(nameof(LoadResState), domainConfig, type);
FsmSystem.SetCurState(nameof(ResStartState), domainConfig, type);
// // 创建热更类实例
// DomainBase hotfixInstance = AppConfig.HOTFIXBASE.AddComponent(type) as DomainBase;
//

View File

@@ -0,0 +1,418 @@
using System;
using System.IO;
using Cysharp.Threading.Tasks;
using Main;
using Newtonsoft.Json;
using UnityEditor;
using UnityEngine;
using UnityEngine.Assertions;
using YooAsset;
using Object = UnityEngine.Object;
namespace Stary.Evo
{
public class HotFixStartState : AbstractFSMIStateAsync
{
public HotFixStartState(IFsmSystemAsync system) : base(system)
{
}
public override async UniTask OnEnterAsync()
{
Debug.Log("UnityEvo:启动开始资源初始化...");
// 初始化资源系统
YooAssets.Initialize();
//初始化资源加载模块
// 增加包存在性检查
var package = YooAssets.TryGetPackage(AppConfig.PackageDomainName);
if (package == null)
{
Debug.LogWarning($"UnityEvo:资源包 {AppConfig.PackageDomainName} 不存在,正在尝试创建...");
package = YooAssets.CreatePackage(AppConfig.PackageDomainName);
}
YooAssets.SetDefaultPackage(package);
var packageRawFile = YooAssets.TryGetPackage($"{AppConfig.PackageDomainName}_RawFile");
if (packageRawFile == null)
{
Debug.LogWarning($"UnityEvo:资源包 {AppConfig.PackageDomainName}_RawFile 不存在,正在尝试创建...");
packageRawFile = YooAssets.CreatePackage($"{AppConfig.PackageDomainName}_RawFile");
}
// 初始化资源包
#if EDITOR_SIMULATEMODE
await EDITOR_SIMULATEMODE(package);
await FsmSystem.SetCurState(nameof(ResEditorSimulateState));
#elif HOST_PLAYMODE
bool isInitSuccess = false;
//登录
if (((FsmLoadSystem)FsmSystem).IsLogin)
{
await GetServerVersion();
await HOST_PLAYMODE(package);
isInitSuccess = await HOST_PLAYMODE(packageRawFile);
}
else
{
await OFFLINE_PLAYMODE(package);
await ChChe_PLAYMODE(package);
await OFFLINE_PLAYMODE(packageRawFile);
isInitSuccess = await ChChe_PLAYMODE(packageRawFile);
}
await UpdateLocalPackage(package);
if (isInitSuccess)
await UpdateLocalPackage(packageRawFile);
await LoadHotfixSettings();
//await FsmSystem.SetCurState(nameof(ResUpdateLocalState));
#elif WEB_PLAYMODE
// IRemoteServices remoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
// var webServerFileSystemParams = FileSystemParameters.CreateDefaultWebServerFileSystemParameters();
// var webRemoteFileSystemParams =
// FileSystemParameters.CreateDefaultWebRemoteFileSystemParameters(remoteServices); //支持跨域下载
//
// var initParameters = new WebPlayModeParameters();
// initParameters.WebServerFileSystemParameters = webServerFileSystemParams;
// initParameters.WebRemoteFileSystemParameters = webRemoteFileSystemParams;
//
// var initOperation = package.InitializeAsync(initParameters);
// await initOperation;
//
// if (initOperation.Status == EOperationStatus.Succeed)
// Debug.Log("UnityEvo:资源包初始化成功!");
// else
// Debug.LogError($"UnityEvo:资源包初始化失败:{initOperation.Error}");
Debug.LogError($"UnityEvo:暂不支持");
#endif
}
public override UniTask OnEnterAsync<T>(T param)
{
return UniTask.CompletedTask;
}
public override UniTask OnEnterAsync<T1, T2>(T1 param1, T2 param2)
{
return UniTask.CompletedTask;
}
public override UniTask OnExitAsync()
{
return UniTask.CompletedTask;
}
#region PLAYMODE
private async UniTask EDITOR_SIMULATEMODE(ResourcePackage package)
{
var initParams = YooAssetFileSystem.EditorSimulateInitializeParameter(package.PackageName);
var initialization = package.InitializeAsync(initParams);
await initialization;
if (initialization.Status == EOperationStatus.Succeed)
{
Assert.AreEqual(EOperationStatus.Succeed, initialization.Status);
Debug.Log("UnityEvo:资源包初始化成功!");
}
else
{
Debug.LogError($"UnityEvo:资源包初始化失败:{initialization.Error}");
}
}
private async UniTask<bool> HOST_PLAYMODE(ResourcePackage package)
{
var initParams = YooAssetFileSystem.HostInitializeParameter(package.PackageName);
// initParameters.CacheFileSystemParameters = cacheFileSystemParams;
var initOperation = package.InitializeAsync(initParams);
await initOperation;
if (initOperation.Status == EOperationStatus.Succeed)
{
Debug.Log("UnityEvo:从远程加载资源包,初始化成功!");
return true;
}
else
{
Debug.LogError($"UnityEvo:从远程加载资源包,初始化失败:{initOperation.Error}");
return false;
}
}
private async UniTask OFFLINE_PLAYMODE(ResourcePackage package)
{
Debug.Log("UnityEvo:网络连接不通畅,切换缓存加载!");
CopyLocalFile(package.PackageName);
}
private async UniTask<bool> ChChe_PLAYMODE(ResourcePackage package)
{
//Debug.Log("UnityEvo:网络连接不通畅,切换缓存加载!");
var initParams = YooAssetFileSystem.HostInitializeParameter(package.PackageName);
var initOperation = package.InitializeAsync(initParams);
await initOperation;
if (initOperation.Status == EOperationStatus.Succeed)
{
Debug.Log("UnityEvo:从本地缓存中资源包,初始化成功!");
return true;
}
else
{
Debug.LogError($"UnityEvo:从本地缓存中资源包,初始化失败:{initOperation.Error}");
return false;
}
var operation = package.RequestPackageVersionAsync();
await operation;
if (operation.Status == EOperationStatus.Succeed)
{
CustomPlayerPrefs.SetString($"{AppConfig.PackageDomainName}_GAME_VERSION", operation.PackageVersion);
Debug.Log("UnityEvo:从本地缓存中加载资源包,初始化获取版本号成功!");
}
else
{
Debug.LogError($"UnityEvo:从本地缓存中加载资源包,初始化获取版本号失败!");
}
}
#endregion
private void CopyLocalFile(string packageDomainName)
{
#if UNITY_ANDROID
// 将StreamingAssets下指定的package拷贝到目标路径
string sourcePath = Path.Combine(Application.streamingAssetsPath,
YooAssetSettingsData.GetDefaultYooFolderName(), packageDomainName);
string loadPath = Path.Combine(Application.temporaryCachePath, "DownloadedContent",
packageDomainName);
// 创建目标目录(如果不存在)
if (!Directory.Exists(loadPath))
{
Directory.CreateDirectory(loadPath);
}
else
{
return;
}
// 检查源路径是否存在
if (Directory.Exists(sourcePath))
{
// 拷贝所有文件
string[] files = Directory.GetFiles(sourcePath, "*", SearchOption.AllDirectories);
foreach (string file in files)
{
// 计算目标文件路径
string relativePath = Path.GetRelativePath(sourcePath, file);
string destFile = Path.Combine(loadPath, relativePath);
// 创建目标子目录(如果不存在)
string destDir = Path.GetDirectoryName(destFile);
if (!Directory.Exists(destDir))
{
Directory.CreateDirectory(destDir);
}
// 拷贝文件
File.Copy(file, destFile, true);
}
Debug.Log($"UnityEvo:成功将StreamingAssets下的{packageDomainName}包拷贝到{loadPath}");
}
else
{
Debug.LogError($"UnityEvo:StreamingAssets下的{packageDomainName}包不存在");
}
#endif
}
private async UniTask GetServerVersion()
{
// 新增平台判断代码
#if UNITY_EDITOR
BuildTarget buildTarget = UnityEditor.EditorUserBuildSettings.activeBuildTarget;
AppConfig.Platform = buildTarget.ToString();
#else
AppConfig.Platform = Application.platform.ToString();
#endif
Debug.Log($"目标平台标识: {AppConfig.Platform}");
// 请求资源版本
string url = $"{AppConfig.IpConfig}/ResDomain/GetResDomainByDomain";
var resDmainRequst = new ResDmainRequst()
{
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 = CustomPlayerPrefs.GetString($"{AppConfig.PackageDomainName}_GAME_VERSION");
//版本不一致,开始下载
if (resDmainResponse.PackageVersion != oldVersion)
{
await Download(resDmainResponse.DocumentFileId);
CustomPlayerPrefs.SetString($"{AppConfig.PackageDomainName}_GAME_VERSION",
resDmainResponse.PackageVersion);
}
else //版本一致,加载缓存资源
{
Debug.Log($"UnityEvo:当前版本{oldVersion}资源版本一致,自动跳过更新...");
}
}
else
{
Debug.LogError($"UnityEvo:获取资源版本失败: 【{resDmainMessageEntity.message}】");
}
}
private async UniTask UpdateLocalPackage(ResourcePackage package)
{
//更新失败
Debug.Log($"UnityEvo:开始加载本地缓存资源...");
// 获取上次成功记录的版本
string packageVersion =
CustomPlayerPrefs.GetString($"{AppConfig.PackageDomainName}_GAME_VERSION", string.Empty);
if (string.IsNullOrEmpty(packageVersion))
{
Debug.Log($"UnityEvo:{package.PackageName}没有找到本地版本记录,需要更新资源!");
return;
}
Debug.Log($"UnityEvo:获取资源版本 Version : 【{packageVersion}】");
// Assert.AreEqual(EOperationStatus.Succeed, requetVersionOp.Status);
// 加载本地缓存的资源清单文件
var updateManifestOp = package.UpdatePackageManifestAsync(packageVersion, 10);
await updateManifestOp;
if (updateManifestOp.Status == EOperationStatus.Succeed)
{
//更新成功
Debug.Log($"UnityEvo:更新本地资源清单 updateManifest : 【成功】");
}
else
{
//更新失败
Debug.LogError($"UnityEvo:加载本地资源清单文件失败,需要更新资源!: 【{updateManifestOp.Error}】");
return;
}
Assert.AreEqual(EOperationStatus.Succeed, updateManifestOp.Status);
}
private async UniTask LoadHotfixSettings()
{
//初始化读取资源配置表
var package = YooAssets.GetPackage(AppConfig.PackageDomainName);
if (HybridClREntrance.Global.stage == StageType.Developer)
{
//加载热更配置文件
var loadHotfixSettingsOp = package.LoadAssetAsync<DomainConfig>("Config_DomainConfig");
await loadHotfixSettingsOp;
DomainConfig domainConfig = null;
if (loadHotfixSettingsOp.Status == EOperationStatus.Succeed)
{
//更新成功
Debug.Log($"UnityEvo:加载热更配置文件 DomainConfig : 【成功】");
domainConfig = loadHotfixSettingsOp.AssetObject as DomainConfig;
}
else
{
Debug.LogError($"UnityEvo:加载热更配置文件 DomainConfig : 【失败】");
}
if (domainConfig == null)
{
Debug.LogError($"UnityEvo:【{package.PackageName}】加载DomainConfig为空无法继续执行后续流程请检查");
}
FsmSystem.SetCurState(nameof(HotFixDllState), domainConfig);
}
else if (HybridClREntrance.Global.stage == StageType.Originality)
{
//加载热更配置文件
var loadArtSceneDataOp = package.LoadAssetAsync<ArtSceneData>("Config_ArtSceneData");
await loadArtSceneDataOp;
ArtSceneData artSceneData = null;
if (loadArtSceneDataOp.Status == EOperationStatus.Succeed)
{
//更新成功
Debug.Log($"UnityEvo:加载热更配置文件 ArtSceneData : 【成功】");
artSceneData = loadArtSceneDataOp.AssetObject as ArtSceneData;
await FsmSystem.SetCurState(nameof(ResStartState), null);
}
else
{
Debug.LogError($"UnityEvo:加载热更配置文件 ArtSceneData : 【失败】");
}
if (artSceneData == null)
{
Debug.LogError($"UnityEvo:【{package.PackageName}】加载ArtSceneData为空无法继续执行后续流程请检查");
}
}
}
#region
public async UniTask Download(string fileId)
{
// 在任意MonoBehaviour或DomainBase派生类中
//string loadPath = Path.Combine(Application.temporaryCachePath, "DownloadedContent", AppConfig.PackageDomainName);
string loadPath = Path.Combine(Application.temporaryCachePath, "DownloadedContent");
//string loadPath = $"{Application.persistentDataPath}/DownloadedContent/{AppConfig.PackageDomainName}";
if (Directory.Exists(loadPath))
{
Directory.Delete(loadPath, true);
// 等一帧,让系统真正释放句柄
await UniTask.DelayFrame(1);
}
FsmLoadSystem loadSystem = FsmSystem as FsmLoadSystem;
if (loadSystem != null && loadSystem.ProgressBarPanel == null)
{
loadSystem.ProgressBarPanel = Object.Instantiate(Resources.Load<GameObject>("ProgressBarPanel"),
Camera.main.transform).GetOrAddComponent<ProgressBarPanel>();
}
await ZipTool.DownloadAndUnzipAsync(fileId, loadPath, DownLoadProgress, UnzipProgress);
}
private void DownLoadProgress(float progress)
{
Debug.Log($"下载进度:{progress:P0}");
FsmLoadSystem loadSystem = FsmSystem as FsmLoadSystem;
if (loadSystem != null)
loadSystem.ProgressBarPanel.SetProgressBarValue("下载中", progress);
}
private void UnzipProgress(float progress)
{
Debug.Log($"解压进度:{progress:P0}");
FsmLoadSystem loadSystem = FsmSystem as FsmLoadSystem;
if (loadSystem != null)
loadSystem.ProgressBarPanel.SetProgressBarValue("解压中", progress);
}
#endregion
}
}

View File

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

View File

@@ -1,188 +0,0 @@
using System;
using Cysharp.Threading.Tasks;
#if Immersal
using Immersal.AR;
#endif
using Stary.Evo;
using Stary.Evo.InformationSave;
using UnityEngine;
using UnityEngine.SceneManagement;
using YooAsset;
namespace Stary.Evo
{
public class LoadResState : AbstractFSMIStateAsync
{
private DomainConfig.LoadResType loadResType;
public GameObject mainPrefab;
private DomainConfig domainConfig;
private string _sceneName;
public LoadResState(IFsmSystemAsync system) : base(system)
{
}
public override UniTask OnEnterAsync()
{
return UniTask.CompletedTask;
}
public override UniTask OnEnterAsync<T>(T param)
{
return UniTask.CompletedTask;
}
public override async UniTask OnEnterAsync<T1, T2>(T1 param1, T2 param2)
{
Debug.Log("加载资源...");
domainConfig = param1 as DomainConfig;
loadResType = domainConfig.loadResType;
Type type = param2 as Type;
var package = YooAssets.GetPackage(domainConfig.domain);
switch (loadResType)
{
case DomainConfig.LoadResType.Prefab:
await LoadDomainPrefab(package);
break;
case DomainConfig.LoadResType.Scene:
var sceneMode = domainConfig.loadSceneMode;
var physicsMode = LocalPhysicsMode.None;
SceneHandle handle = package.LoadSceneAsync(domainConfig.sceneIdentifier, sceneMode, physicsMode);
await handle;
Scene targetScene = SceneManager.GetSceneByName(handle.SceneName);
// targetScene.name = domainConfig.mainScene;
// 设置为 active scene 或者后续 Move 到该 scene
SceneManager.SetActiveScene(targetScene);
_sceneName = targetScene.name;
mainPrefab = GameObject.Find(domainConfig.mainPrefab);
if (mainPrefab == null)
{
await LoadDomainPrefab(package);
}
break;
}
if (domainConfig.domain != "Main")
{
LocalTransformInfo info = mainPrefab.GetOrAddComponent<LocalTransformInfo>();
FsmLoadSystem fsmLoadSystem = FsmSystem as FsmLoadSystem;
if (info._list.Count >= 2)
{
if (fsmLoadSystem.GetOpenDomainType() == OpenDomainType.PointCloud)
{
info.Switch(1);
}
else if (fsmLoadSystem.GetOpenDomainType() == OpenDomainType.VIOICE)
{
info.Switch(0);
}
else if (fsmLoadSystem.GetOpenDomainType() == OpenDomainType.ImageTracked)
{
info.transform.position = fsmLoadSystem.GetTransformCtor().position;
info.transform.rotation = Quaternion.Euler(fsmLoadSystem.GetTransformCtor().rotation);
info.transform.localScale = fsmLoadSystem.GetTransformCtor().scale;
}
else
{
info.Switch(0);
}
}
else
{
Debug.LogError($"UnityEvo:{mainPrefab.name}的TransformInfo长度小于2无法继续运行请排查");
}
}
if (mainPrefab != null)
{
DomainBase hotfixInstance = mainPrefab.GetComponent(type) as DomainBase;
if (hotfixInstance == null)
{
hotfixInstance = mainPrefab.AddComponent(type) as DomainBase;
}
hotfixInstance.DomainName = domainConfig.domain;
if (hotfixInstance == null)
{
Debug.LogError($"热更类{type.Name}实例创建失败必须继承MonoBehaviour");
return;
}
// 原有调用逻辑修改为使用实例
hotfixInstance.OnEnter("");
hotfixInstance.OnEnterAsync("");
}
}
public override void OnUpdate()
{
base.OnUpdate();
}
private async UniTask LoadDomainPrefab(ResourcePackage package)
{
// 加载热更资源
var loadOperation = package.LoadAssetAsync<GameObject>(domainConfig.mainPrefab);
await loadOperation;
if (loadOperation.Status == EOperationStatus.Succeed)
{
#if Immersal
ARSpace arSpace = GameObject.FindObjectOfType<ARSpace>();
if (arSpace != null)
{
Debug.Log("UnityEvo:找到ARSpace开始加载点云运行环境...");
mainPrefab = loadOperation.InstantiateSync(arSpace.transform);
} else
{
Debug.Log("UnityEvo:未找到ARSpace开始加载普通运行环境通过语音唤醒...");
mainPrefab = loadOperation.InstantiateSync();
}
#elif NotPointClond
mainPrefab = loadOperation.InstantiateSync();
#endif
if (domainConfig.domain == "Main")
AppConfig.SetDefaultMainInstance(mainPrefab);
}
}
public override async UniTask OnExitAsync()
{
Debug.Log("UnityEvo:Domain退出...");
if (domainConfig.domain != "Main")
{
DomainBase domainBase = mainPrefab.GetOrAddComponent<DomainBase>();
if (domainBase == null)
{
Debug.LogError($"UnityEvo:{mainPrefab.name}的DomainBase为空无法退出请排查");
}
else
{
domainBase.OnExit();
await domainBase.OnExitAsync();
}
if (domainBase != null)
{
GameObject.Destroy(domainBase.gameObject);
await ((FsmLoadSystem)FsmSystem).ForceUnloadAllAssets(domainBase.DomainName);
}
if (loadResType == DomainConfig.LoadResType.Scene)
{
await SceneManager.UnloadSceneAsync(_sceneName);
}
}
}
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: f689e40cd4654793a8f1d3ce69ba3532
timeCreated: 1741165763

View File

@@ -26,14 +26,14 @@ namespace Stary.Evo
{
//更新成功
packageVersion = requetVersionOp.PackageVersion;
PlayerPrefs.SetString($"{AppConfig.PackageDomainName}_GAME_VERSION", packageVersion);
CustomPlayerPrefs.SetString($"{AppConfig.PackageDomainName}_GAME_VERSION", packageVersion);
Debug.Log($"UnityEvo:获取资源版本 Version : 【{packageVersion}】");
Debug.Log($"UnityEvo:开始加载服务器资源...");
}
else
{
Debug.LogError($"UnityEvo:获取资源版本失败: 【{requetVersionOp.Error}】");
FsmSystem.SetCurState(nameof(ResUpdateLocalState));
//FsmSystem.SetCurState(nameof(ResUpdateLocalState));
return;
}
@@ -60,29 +60,55 @@ namespace Stary.Evo
//4.下载补丁包
await Download();
//加载热更配置文件
var loadHotfixSettingsOp = package.LoadAssetAsync<DomainConfig>("Config_DomainConfig");
await loadHotfixSettingsOp;
DomainConfig domainConfig = null;
if (loadHotfixSettingsOp.Status == EOperationStatus.Succeed)
if (HybridClREntrance.Global.stage == StageType.Developer)
{
//更新成功
Debug.Log($"UnityEvo:加载热更配置文件 loadHotfixSettings : 【成功】");
domainConfig = loadHotfixSettingsOp.AssetObject as DomainConfig;
//加载热更配置文件
var loadHotfixSettingsOp = package.LoadAssetAsync<DomainConfig>("Config_DomainConfig");
await loadHotfixSettingsOp;
DomainConfig domainConfig = null;
if (loadHotfixSettingsOp.Status == EOperationStatus.Succeed)
{
//更新成功
Debug.Log($"UnityEvo:加载热更配置文件 loadHotfixSettings : 【成功】");
domainConfig = loadHotfixSettingsOp.AssetObject as DomainConfig;
}
else
{
Debug.LogError($"UnityEvo:加载热更配置文件 loadHotfixSettings : 【失败】");
}
if (domainConfig == null)
{
Debug.LogError($"UnityEvo:【{package.PackageName}】加载DomainConfig为空无法继续执行后续流程请检查");
}
FsmSystem.SetCurState(nameof(HotFixDllState), domainConfig);
}
else
else if (HybridClREntrance.Global.stage == StageType.Originality)
{
Debug.LogError($"UnityEvo:加载热更配置文件 loadHotfixSettings : 【失败】");
//加载热更配置文件
var loadArtSceneDataOp = package.LoadAssetAsync<ArtSceneData>("Config_ArtSceneData");
await loadArtSceneDataOp;
ArtSceneData artSceneData = null;
if (loadArtSceneDataOp.Status == EOperationStatus.Succeed)
{
//更新成功
Debug.Log($"UnityEvo:加载热更配置文件 ArtSceneData : 【成功】");
artSceneData = loadArtSceneDataOp.AssetObject as ArtSceneData;
await FsmSystem.SetCurState(nameof(ResStartState), null);
}
else
{
Debug.LogError($"UnityEvo:加载热更配置文件 ArtSceneData : 【失败】");
}
if (artSceneData == null)
{
Debug.LogError($"UnityEvo:【{package.PackageName}】加载ArtSceneData为空无法继续执行后续流程请检查");
}
}
if (domainConfig == null)
{
Debug.LogError($"UnityEvo:【{package.PackageName}】加载DomainConfig为空无法继续执行后续流程请检查");
}
FsmSystem.SetCurState(nameof(HotFixState), domainConfig);
}
public override UniTask OnEnterAsync<T>(T param)

View File

@@ -1,81 +1,33 @@
using System;
using System.IO;
using Cysharp.Threading.Tasks;
using Main;
using Newtonsoft.Json;
using UnityEditor;
#if Immersal
using Immersal.AR;
#endif
using Stary.Evo;
using Stary.Evo.InformationSave;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.SceneManagement;
using YooAsset;
using Object = UnityEngine.Object;
namespace Stary.Evo
{
public class ResStartState : AbstractFSMIStateAsync
{
private DomainConfig.LoadResType loadResType;
public GameObject mainPrefab;
private DomainConfig domainConfig;
private string _sceneName;
public ResStartState(IFsmSystemAsync system) : base(system)
{
}
public override async UniTask OnEnterAsync()
public override UniTask OnEnterAsync()
{
Debug.Log("UnityEvo:启动开始资源初始化...");
// 初始化资源系统
YooAssets.Initialize();
//初始化资源加载模块
// 增加包存在性检查
var package = YooAssets.TryGetPackage(AppConfig.PackageDomainName);
if (package == null)
{
Debug.LogWarning($"UnityEvo:资源包 {AppConfig.PackageDomainName} 不存在,正在尝试创建...");
package = YooAssets.CreatePackage(AppConfig.PackageDomainName);
}
YooAssets.SetDefaultPackage(package);
// 初始化资源包
#if EDITOR_SIMULATEMODE
await EDITOR_SIMULATEMODE(package);
await FsmSystem.SetCurState(nameof(ResEditorSimulateState));
#elif OFFLINE_PLAYMODE
await OFFLINE_PLAYMODE(package);
await FsmSystem.SetCurState(nameof(ResUpdateLocalState));
#elif HOST_PLAYMODE
//登录
if (((FsmLoadSystem)FsmSystem).IsLogin)
await HOST_PLAYMODE(package);
else
{
await OFFLINE_PLAYMODE(package);
await ChChe_PLAYMODE(package);
}
await FsmSystem.SetCurState(nameof(ResUpdateLocalState));
#elif WEB_PLAYMODE
// IRemoteServices remoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
// var webServerFileSystemParams = FileSystemParameters.CreateDefaultWebServerFileSystemParameters();
// var webRemoteFileSystemParams =
// FileSystemParameters.CreateDefaultWebRemoteFileSystemParameters(remoteServices); //支持跨域下载
//
// var initParameters = new WebPlayModeParameters();
// initParameters.WebServerFileSystemParameters = webServerFileSystemParams;
// initParameters.WebRemoteFileSystemParameters = webRemoteFileSystemParams;
//
// var initOperation = package.InitializeAsync(initParameters);
// await initOperation;
//
// if (initOperation.Status == EOperationStatus.Succeed)
// Debug.Log("UnityEvo:资源包初始化成功!");
// else
// Debug.LogError($"UnityEvo:资源包初始化失败:{initOperation.Error}");
Debug.LogError($"UnityEvo:暂不支持");
#endif
return UniTask.CompletedTask;
}
public override UniTask OnEnterAsync<T>(T param)
@@ -83,233 +35,162 @@ namespace Stary.Evo
return UniTask.CompletedTask;
}
public override UniTask OnEnterAsync<T1, T2>(T1 param1, T2 param2)
public override async UniTask OnEnterAsync<T1, T2>(T1 param1, T2 param2)
{
return UniTask.CompletedTask;
}
public override void OnUpdate()
{
base.OnUpdate();
}
public override UniTask OnExitAsync()
{
return UniTask.CompletedTask;
}
private async UniTask EDITOR_SIMULATEMODE(ResourcePackage package)
{
var initParams = YooAssetFileSystem.EditorSimulateInitializeParameter(package.PackageName);
var initialization = package.InitializeAsync(initParams);
await initialization;
if (initialization.Status == EOperationStatus.Succeed)
{
Assert.AreEqual(EOperationStatus.Succeed, initialization.Status);
Debug.Log("UnityEvo:资源包初始化成功!");
}
else
{
Debug.LogError($"UnityEvo:资源包初始化失败:{initialization.Error}");
}
}
private async UniTask ChChe_PLAYMODE(ResourcePackage package)
{
//Debug.Log("UnityEvo:网络连接不通畅,切换缓存加载!");
var initParams = YooAssetFileSystem.HostInitializeParameter();
var initOperation = package.InitializeAsync(initParams);
await initOperation;
if (initOperation.Status == EOperationStatus.Succeed)
Debug.Log("UnityEvo:从本地缓存中资源包,初始化成功!");
else
{
Debug.LogError($"UnityEvo:从本地缓存中资源包,初始化失败:{initOperation.Error}");
}
var operation = package.RequestPackageVersionAsync();
await operation;
if (operation.Status == EOperationStatus.Succeed)
{
PlayerPrefs.SetString($"{AppConfig.PackageDomainName}_GAME_VERSION", operation.PackageVersion);
Debug.Log("UnityEvo:从本地缓存中加载资源包,初始化获取版本号成功!");
}
else
{
Debug.LogError($"UnityEvo:从本地缓存中加载资源包,初始化获取版本号失败!");
}
}
private async UniTask OFFLINE_PLAYMODE(ResourcePackage package)
{
Debug.Log("UnityEvo:网络连接不通畅,切换缓存加载!");
CopyLocalFile();
// var initParams = YooAssetFileSystem.OfflineInitializeParameter();
// var initOperation = package.InitializeAsync(initParams);
// await initOperation;
//
// var operation = package.RequestPackageVersionAsync();
// await operation;
// if (operation.Status == EOperationStatus.Succeed)
// {
// PlayerPrefs.SetString($"{AppConfig.PackageDomainName}_GAME_VERSION", operation.PackageVersion);
// Debug.Log("UnityEvo:从本地StreamingAssets加载资源包初始化获取版本号成功");
// }
// else
// {
// Debug.LogError($"UnityEvo:从本地StreamingAssets加载资源包初始化获取版本号失败");
// }
//
// if (initOperation.Status == EOperationStatus.Succeed)
// Debug.Log("UnityEvo:从本地StreamingAssets加载资源包初始化成功");
// else
// Debug.LogError($"UnityEvo:从本地StreamingAssets加载资源包初始化失败{initOperation.Error}");
}
private void CopyLocalFile()
{
#if UNITY_ANDROID
// 将StreamingAssets下指定的package拷贝到目标路径
string sourcePath = Path.Combine(Application.streamingAssetsPath,
YooAssetSettingsData.GetDefaultYooFolderName(), AppConfig.PackageDomainName);
string loadPath = Path.Combine(Application.temporaryCachePath, "DownloadedContent",
AppConfig.PackageDomainName);
// 创建目标目录(如果不存在)
if (!Directory.Exists(loadPath))
{
Directory.CreateDirectory(loadPath);
}
else
{
if (HybridClREntrance.Global.stage == StageType.Originality)
return;
}
// 检查源路径是否存在
if (Directory.Exists(sourcePath))
domainConfig = param1 as DomainConfig;
loadResType = domainConfig.loadResType;
Type type = param2 as Type;
var package = YooAssets.GetPackage(domainConfig.domain);
switch (loadResType)
{
// 拷贝所有文件
string[] files = Directory.GetFiles(sourcePath, "*", SearchOption.AllDirectories);
foreach (string file in files)
{
// 计算目标文件路径
string relativePath = Path.GetRelativePath(sourcePath, file);
string destFile = Path.Combine(loadPath, relativePath);
case DomainConfig.LoadResType.Prefab:
// 创建目标子目录(如果不存在)
string destDir = Path.GetDirectoryName(destFile);
if (!Directory.Exists(destDir))
await LoadDomainPrefab(package);
break;
case DomainConfig.LoadResType.Scene:
var sceneMode = domainConfig.loadSceneMode;
var physicsMode = LocalPhysicsMode.None;
SceneHandle handle = package.LoadSceneAsync(domainConfig.sceneIdentifier, sceneMode, physicsMode);
await handle;
Scene targetScene = SceneManager.GetSceneByName(handle.SceneName);
// targetScene.name = domainConfig.mainScene;
// 设置为 active scene 或者后续 Move 到该 scene
SceneManager.SetActiveScene(targetScene);
_sceneName = targetScene.name;
mainPrefab = GameObject.Find(domainConfig.mainPrefab);
if (mainPrefab == null)
{
Directory.CreateDirectory(destDir);
await LoadDomainPrefab(package);
}
// 拷贝文件
File.Copy(file, destFile, true);
}
Debug.Log($"UnityEvo:成功将StreamingAssets下的{AppConfig.PackageDomainName}包拷贝到{loadPath}");
break;
}
else
{
Debug.LogError($"UnityEvo:StreamingAssets下的{AppConfig.PackageDomainName}包不存在");
}
#endif
}
public async UniTask HOST_PLAYMODE(ResourcePackage package)
{
// 新增平台判断代码
#if UNITY_EDITOR
BuildTarget buildTarget = UnityEditor.EditorUserBuildSettings.activeBuildTarget;
AppConfig.Platform = buildTarget.ToString();
#else
AppConfig.Platform = Application.platform.ToString();
#endif
Debug.Log($"目标平台标识: {AppConfig.Platform}");
if (domainConfig.domain != "Main")
{
LocalTransformInfo info = mainPrefab.GetOrAddComponent<LocalTransformInfo>();
FsmLoadSystem fsmLoadSystem = FsmSystem as FsmLoadSystem;
// 请求资源版本
string url = $"{AppConfig.IpConfig}/ResDomain/GetResDomainByDomain";
var resDmainRequst = new ResDmainRequst()
{
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)
if (info._list.Count >= 2)
{
await Download(resDmainResponse.DocumentFileId);
PlayerPrefs.SetString($"{AppConfig.PackageDomainName}_GAME_VERSION",
resDmainResponse.PackageVersion);
if (fsmLoadSystem.GetOpenDomainType() == OpenDomainType.PointCloud)
{
info.Switch(1);
}
else if (fsmLoadSystem.GetOpenDomainType() == OpenDomainType.VIOICE)
{
info.Switch(0);
}
else if (fsmLoadSystem.GetOpenDomainType() == OpenDomainType.ImageTracked)
{
info.transform.position = fsmLoadSystem.GetTransformCtor().position;
info.transform.rotation = Quaternion.Euler(fsmLoadSystem.GetTransformCtor().rotation);
info.transform.localScale = fsmLoadSystem.GetTransformCtor().scale;
}
else
{
info.Switch(0);
}
}
else //版本一致,加载缓存资源
else
{
Debug.Log($"UnityEvo:资源版本一致,自动跳过更新...");
Debug.LogError($"UnityEvo:{mainPrefab.name}的TransformInfo长度小于2无法继续运行请排查");
}
}
else
if (mainPrefab != null)
{
Debug.LogError($"UnityEvo:获取资源版本失败: 【{resDmainMessageEntity.message}】");
DomainBase hotfixInstance = mainPrefab.GetComponent(type) as DomainBase;
if (hotfixInstance == null)
{
hotfixInstance = mainPrefab.AddComponent(type) as DomainBase;
}
if (hotfixInstance == null)
{
Debug.LogError($"热更类{type.Name}实例创建失败必须继承MonoBehaviour");
return;
}
hotfixInstance.DomainName = domainConfig.domain;
hotfixInstance.DomainNameRaw = $"{domainConfig.domain}_RawFile";
// 原有调用逻辑修改为使用实例
hotfixInstance.OnEnter("");
hotfixInstance.OnEnterAsync("");
}
var initParams = YooAssetFileSystem.HostInitializeParameter();
// initParameters.CacheFileSystemParameters = cacheFileSystemParams;
var initOperation = package.InitializeAsync(initParams);
await initOperation;
if (initOperation.Status == EOperationStatus.Succeed)
Debug.Log("UnityEvo:从远程加载资源包,初始化成功!");
else
Debug.LogError($"UnityEvo:从远程加载资源包,初始化失败:{initOperation.Error}");
}
public async UniTask Download(string fileId)
private async UniTask LoadDomainPrefab(ResourcePackage package)
{
// 在任意MonoBehaviour或DomainBase派生类中
string loadPath = Path.Combine(Application.temporaryCachePath, "DownloadedContent",
AppConfig.PackageDomainName);
//string loadPath = $"{Application.persistentDataPath}/DownloadedContent/{AppConfig.PackageDomainName}";
if (Directory.Exists(loadPath))
{
Directory.Delete(loadPath, true);
// 等一帧,让系统真正释放句柄
await UniTask.DelayFrame(1);
}
// 加载热更资源
var loadOperation = package.LoadAssetAsync<GameObject>(domainConfig.mainPrefab);
FsmLoadSystem loadSystem = FsmSystem as FsmLoadSystem;
if (loadSystem.ProgressBarPanel == null)
await loadOperation;
if (loadOperation.Status == EOperationStatus.Succeed)
{
loadSystem.ProgressBarPanel = Object.Instantiate(Resources.Load<GameObject>("ProgressBarPanel"),
Camera.main.transform).GetOrAddComponent<ProgressBarPanel>();
#if Immersal
ARSpace arSpace = GameObject.FindObjectOfType<ARSpace>();
if (arSpace != null)
{
Debug.Log("UnityEvo:找到ARSpace开始加载点云运行环境...");
mainPrefab = loadOperation.InstantiateSync(arSpace.transform);
} else
{
Debug.Log("UnityEvo:未找到ARSpace开始加载普通运行环境通过语音唤醒...");
mainPrefab = loadOperation.InstantiateSync();
}
#elif NotPointClond
mainPrefab = loadOperation.InstantiateSync();
#endif
if (domainConfig.domain == "Main")
AppConfig.SetDefaultMainInstance(mainPrefab);
}
await ZipTool.DownloadAndUnzipAsync(fileId, loadPath, DownLoadProgress, UnzipProgress);
}
private void DownLoadProgress(float progress)
public override async UniTask OnExitAsync()
{
Debug.Log($"下载进度:{progress:P0}");
FsmLoadSystem loadSystem = FsmSystem as FsmLoadSystem;
loadSystem.ProgressBarPanel.SetProgressBarValue("下载中", progress);
}
Debug.Log("UnityEvo:Domain退出...");
if (HybridClREntrance.Global.stage == StageType.Developer)
{
if (domainConfig.domain != "Main")
{
DomainBase domainBase = mainPrefab.GetOrAddComponent<DomainBase>();
if (domainBase == null)
{
Debug.LogError($"UnityEvo:{mainPrefab.name}的DomainBase为空无法退出请排查");
}
else
{
domainBase.OnExit();
await domainBase.OnExitAsync();
}
private void UnzipProgress(float progress)
{
Debug.Log($"解压进度:{progress:P0}");
FsmLoadSystem loadSystem = FsmSystem as FsmLoadSystem;
loadSystem.ProgressBarPanel.SetProgressBarValue("解压中", progress);
if (domainBase != null)
{
GameObject.Destroy(domainBase.gameObject);
await ((FsmLoadSystem)FsmSystem).ForceUnloadAllAssets(domainBase.DomainName);
await ((FsmLoadSystem)FsmSystem).ForceUnloadAllAssets(domainBase.DomainNameRaw);
}
if (loadResType == DomainConfig.LoadResType.Scene)
{
await SceneManager.UnloadSceneAsync(_sceneName);
}
}
}
else if (HybridClREntrance.Global.stage == StageType.Originality)
{
await ((FsmLoadSystem)FsmSystem).ForceUnloadAllAssets(AppConfig.PackageDomainName);
AppConfig.PackageDomainName = "";
}
}
}
}

View File

@@ -1,3 +1,3 @@
fileFormatVersion: 2
guid: 2462c737fc9c4b53b35557f8a6aac453
timeCreated: 1741165298
guid: f689e40cd4654793a8f1d3ce69ba3532
timeCreated: 1741165763

View File

@@ -1,123 +0,0 @@
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.Assertions;
using YooAsset;
namespace Stary.Evo
{
public class ResUpdateLocalState : AbstractFSMIStateAsync
{
public ResUpdateLocalState(IFsmSystemAsync system) : base(system)
{
}
public override async UniTask OnEnterAsync()
{
//初始化读取资源配置表
var package = YooAssets.GetPackage(AppConfig.PackageDomainName);
//更新失败
Debug.Log($"UnityEvo:开始加载本地缓存资源...");
// 获取上次成功记录的版本
string packageVersion = PlayerPrefs.GetString($"{AppConfig.PackageDomainName}_GAME_VERSION", string.Empty);
if (string.IsNullOrEmpty(packageVersion))
{
Debug.Log($"UnityEvo:没有找到本地版本记录,需要更新资源!");
return;
}
Debug.Log($"UnityEvo:获取资源版本 Version : 【{packageVersion}】");
// Assert.AreEqual(EOperationStatus.Succeed, requetVersionOp.Status);
// 加载本地缓存的资源清单文件
var updateManifestOp = package.UpdatePackageManifestAsync(packageVersion);
await updateManifestOp;
if (updateManifestOp.Status == EOperationStatus.Succeed)
{
//更新成功
Debug.Log($"UnityEvo:更新本地资源清单 updateManifest : 【成功】");
}
else
{
//更新失败
Debug.LogError($"UnityEvo:加载本地资源清单文件失败,需要更新资源!: 【{updateManifestOp.Error}】");
return;
}
Assert.AreEqual(EOperationStatus.Succeed, updateManifestOp.Status);
//4.下载补丁包
//await Download();
//加载热更配置文件
var loadHotfixSettingsOp = package.LoadAssetAsync<DomainConfig>("Config_DomainConfig");
await loadHotfixSettingsOp;
DomainConfig domainConfig = null;
if (loadHotfixSettingsOp.Status == EOperationStatus.Succeed)
{
//更新成功
Debug.Log($"UnityEvo:加载热更配置文件 DomainConfig : 【成功】");
domainConfig = loadHotfixSettingsOp.AssetObject as DomainConfig;
}
else
{
Debug.LogError($"UnityEvo:加载热更配置文件 DomainConfig : 【失败】");
}
if (domainConfig == null)
{
Debug.LogError($"UnityEvo:【{package.PackageName}】加载DomainConfig为空无法继续执行后续流程请检查");
}
FsmSystem.SetCurState(nameof(HotFixState), domainConfig);
}
public override UniTask OnEnterAsync<T>(T param)
{
return UniTask.CompletedTask;
}
public override UniTask OnEnterAsync<T1, T2>(T1 param1, T2 param2)
{
return UniTask.CompletedTask;
}
public override void OnUpdate()
{
base.OnUpdate();
}
public override UniTask OnExitAsync()
{
return UniTask.CompletedTask;
}
#region
public async UniTask Download()
{
int downloadingMaxNum = 1;
int failedTryAgain = 1;
var package = YooAssets.GetPackage(AppConfig.PackageDomainName);
var downloader = package.CreateResourceDownloader(downloadingMaxNum, failedTryAgain);
// 在正常开始游戏之前,还需要验证本地清单内容的完整性。
if (downloader.TotalDownloadCount > 0)
{
Debug.Log("UnityEvo:资源内容本地并不完整,需要更新资源!");
return;
}
}
#endregion
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: eca158039896455dba3ded1eb703a5da
timeCreated: 1742291100

View File

@@ -9,8 +9,7 @@ namespace Stary.Evo
public StageType stage;
public string domain;
private FsmLoadSystem _devLoadSystem;
private FsmLoadSystem _originalityLoadSystem;
private FsmLoadSystem _loadSystem;
/// <summary>
@@ -31,14 +30,12 @@ namespace Stary.Evo
return;
}
_devLoadSystem = new FsmLoadSystem();
_loadSystem = new FsmLoadSystem();
// 初始化日志
_devLoadSystem.AddState(new ResStartState(_devLoadSystem));
_devLoadSystem.AddState(new ResEditorSimulateState(_devLoadSystem));
_devLoadSystem.AddState(new ResUpdateLocalState(_devLoadSystem));
_devLoadSystem.AddState(new HotFixState(_devLoadSystem));
_devLoadSystem.AddState(new LoadResState(_devLoadSystem));
//_fsmSystem.AddState(new LoadResMainState(_fsmSystem));
_loadSystem.AddState(new HotFixStartState(_loadSystem));
_loadSystem.AddState(new ResEditorSimulateState(_loadSystem));
_loadSystem.AddState(new HotFixDllState(_loadSystem));
_loadSystem.AddState(new ResStartState(_loadSystem));
//初始化读取资源配置表
HotfixMainResDomain hotfixMainResDomain = Resources.Load<HotfixMainResDomain>("HotfixMainResDomain");
@@ -54,7 +51,7 @@ namespace Stary.Evo
Debug.Log($"UnityEvo:读取资源配置表成功...{AppConfig.IpConfig}{AppConfig.UserName}{AppConfig.PassWord}");
//登录
string url = AppConfig.IpConfig + "/Authentication/login";
_devLoadSystem.IsLogin = await WebRequestSystem.Login(url, AppConfig.UserName, AppConfig.PassWord);
_loadSystem.IsLogin = await WebRequestSystem.Login(url, AppConfig.UserName, AppConfig.PassWord);
}
private void Start()
@@ -75,45 +72,30 @@ namespace Stary.Evo
AppConfig.PackageDomainName = "Main";
}
_devLoadSystem.SetCurState(nameof(ResStartState));
_loadSystem.SetCurState(nameof(HotFixStartState));
}
private void Update()
{
if (_devLoadSystem.CurState != null)
_devLoadSystem.CurState.OnUpdate();
if (_loadSystem.CurState != null)
_loadSystem.CurState.OnUpdate();
}
public async Task OpenDomain()
{
AppConfig.PackageDomainName = domain;
if (stage == StageType.Developer)
{
await _devLoadSystem.SetCurState(nameof(ResStartState));
}
else if (stage == StageType.Originality)
{
if (_originalityLoadSystem == null)
{
_originalityLoadSystem = new FsmLoadSystem();
_originalityLoadSystem.AddState(new ArtResStartState(_originalityLoadSystem));
_originalityLoadSystem.AddState(new ArtResUpdateLocalState(_originalityLoadSystem));
_originalityLoadSystem.AddState(new ArtResEditorSimulateState(_originalityLoadSystem));
}
await _originalityLoadSystem.SetCurState(nameof(ArtResStartState));
}
await _loadSystem.SetCurState(nameof(HotFixStartState));
}
public async void OpenDomain(string domain, OpenDomainType openDomainType)
{
this.domain = domain;
_devLoadSystem.SetOpenDomainType(openDomainType);
_loadSystem.SetOpenDomainType(openDomainType);
if (this.domain != AppConfig.PackageDomainName)
{
AppConfig.PackageDomainName = domain;
await _devLoadSystem.SetCurState(nameof(ResStartState));
await _loadSystem.SetCurState(nameof(HotFixStartState));
}
else
{
@@ -124,12 +106,12 @@ namespace Stary.Evo
public void OpenDomain(string domain, TransformCtor transformCtor)
{
this.domain = domain;
_devLoadSystem.SetOpenDomainType(OpenDomainType.ImageTracked);
_devLoadSystem.SetTransformCtor(transformCtor);
_loadSystem.SetOpenDomainType(OpenDomainType.ImageTracked);
_loadSystem.SetTransformCtor(transformCtor);
if (this.domain != AppConfig.PackageDomainName)
{
AppConfig.PackageDomainName = domain;
_devLoadSystem.SetCurState(nameof(ResStartState));
_loadSystem.SetCurState(nameof(HotFixStartState));
}
else
{
@@ -140,12 +122,12 @@ namespace Stary.Evo
public void OpenDomain(string domain, Transform transform)
{
this.domain = domain;
_devLoadSystem.SetOpenDomainType(OpenDomainType.ImageTracked);
_devLoadSystem.SetTransformCtor(transform);
_loadSystem.SetOpenDomainType(OpenDomainType.ImageTracked);
_loadSystem.SetTransformCtor(transform);
if (this.domain != AppConfig.PackageDomainName)
{
AppConfig.PackageDomainName = domain;
_devLoadSystem.SetCurState(nameof(ResStartState));
_loadSystem.SetCurState(nameof(HotFixStartState));
}
else
{
@@ -155,10 +137,8 @@ namespace Stary.Evo
public void CloseDomain()
{
if (_devLoadSystem != null)
_devLoadSystem.SetCurState(nameof(DefaultStateAsync));
if (_originalityLoadSystem != null)
_originalityLoadSystem.SetCurState(nameof(DefaultStateAsync));
if (_loadSystem != null)
_loadSystem.SetCurState(nameof(DefaultStateAsync));
}
}

View File

@@ -15,12 +15,12 @@ namespace Stary.Evo
return initParameters;
}
public static InitializeParameters HostInitializeParameter()
public static InitializeParameters HostInitializeParameter(string packageName)
{
var initParameters = new OfflinePlayModeParameters();
var buildinFileSystemParams = FileSystemParameters.CreateDefaultBuildinFileSystemParameters(null,
$"{Application.temporaryCachePath}/DownloadedContent/{AppConfig.PackageDomainName}");
Debug.Log($"UnityEvo:Host InitializeParameterPath: 【{Application.temporaryCachePath}/DownloadedContent/{AppConfig.PackageDomainName}】");
$"{Application.temporaryCachePath}/DownloadedContent/{packageName}");
Debug.Log($"UnityEvo:Host InitializeParameterPath: 【{Application.temporaryCachePath}/DownloadedContent/{packageName}】");
buildinFileSystemParams.AddParameter(FileSystemParametersDefine.APPEND_FILE_EXTENSION, true);
buildinFileSystemParams.AddParameter(FileSystemParametersDefine.COPY_BUILDIN_PACKAGE_MANIFEST, true);
initParameters.BuildinFileSystemParameters = buildinFileSystemParams;

View File

@@ -0,0 +1,19 @@
using YooAsset;
namespace Stary.Evo
{
public static class YooAssetRaw
{
/// <summary>
/// 获取原始文件路径
/// </summary>
/// <param name="handle"></param>
/// <returns></returns>
public static RawFileHandle LoadRawFileAsync(string rawFilePath)
{
var package = YooAssets.TryGetPackage($"{AppConfig.PackageDomainName}_RawFile");
var handle = package.LoadRawFileAsync(rawFilePath);
return handle;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 36487317401342f9a337736581d9c751
timeCreated: 1767773460

View File

@@ -1,6 +1,6 @@
{
"name": "com.staryevo.tools",
"version": "1.3.1",
"version": "1.3.3",
"displayName": "00.StaryEvo.Tools",
"description": "This is an Framework package(后台服务器版本端口9527)",
"unity": "2021.3",