1111
This commit is contained in:
@@ -18,6 +18,8 @@ namespace Stary.Evo
|
||||
public GameObject mainPrefab;
|
||||
private DomainConfig domainConfig;
|
||||
|
||||
private string _sceneName;
|
||||
|
||||
public LoadResState(IFsmSystemAsync system) : base(system)
|
||||
{
|
||||
}
|
||||
@@ -44,7 +46,7 @@ namespace Stary.Evo
|
||||
{
|
||||
case DomainConfig.LoadResType.Prefab:
|
||||
|
||||
LoadDomainPrefab(package);
|
||||
await LoadDomainPrefab(package);
|
||||
|
||||
break;
|
||||
case DomainConfig.LoadResType.Scene:
|
||||
@@ -53,48 +55,52 @@ namespace Stary.Evo
|
||||
var physicsMode = LocalPhysicsMode.None;
|
||||
SceneHandle handle = package.LoadSceneAsync(domainConfig.mainScene, sceneMode, physicsMode);
|
||||
await handle;
|
||||
Scene targetScene = SceneManager.GetSceneByName(domainConfig.mainScene);
|
||||
targetScene.name = domainConfig.mainScene;
|
||||
|
||||
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)
|
||||
{
|
||||
LoadDomainPrefab(package);
|
||||
await LoadDomainPrefab(package);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
LocalTransformInfo info = mainPrefab.GetOrAddComponent<LocalTransformInfo>();
|
||||
FsmLoadSystem fsmLoadSystem = FsmSystem as FsmLoadSystem;
|
||||
|
||||
if (info._list.Count >= 2)
|
||||
if (domainConfig.domain != "Main")
|
||||
{
|
||||
if (fsmLoadSystem.GetOpenDomainType() == OpenDomainType.PointCloud)
|
||||
LocalTransformInfo info = mainPrefab.GetOrAddComponent<LocalTransformInfo>();
|
||||
FsmLoadSystem fsmLoadSystem = FsmSystem as FsmLoadSystem;
|
||||
|
||||
if (info._list.Count >= 2)
|
||||
{
|
||||
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;
|
||||
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
|
||||
{
|
||||
info.Switch(0);
|
||||
Debug.LogError($"UnityEvo:{mainPrefab.name}的TransformInfo长度小于2,无法继续运行,请排查");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"UnityEvo:{mainPrefab.name}的TransformInfo长度小于2,无法继续运行,请排查");
|
||||
}
|
||||
|
||||
if (mainPrefab != null)
|
||||
{
|
||||
@@ -123,7 +129,7 @@ namespace Stary.Evo
|
||||
base.OnUpdate();
|
||||
}
|
||||
|
||||
private async void LoadDomainPrefab(ResourcePackage package)
|
||||
private async UniTask LoadDomainPrefab(ResourcePackage package)
|
||||
{
|
||||
// 加载热更资源
|
||||
var loadOperation = package.LoadAssetAsync<GameObject>(domainConfig.mainPrefab);
|
||||
@@ -155,7 +161,7 @@ namespace Stary.Evo
|
||||
Debug.Log("UnityEvo:Domain退出...");
|
||||
if (domainConfig.domain != "Main")
|
||||
{
|
||||
DomainBase domainBase = mainPrefab.GetComponent<DomainBase>();
|
||||
DomainBase domainBase = mainPrefab.GetOrAddComponent<DomainBase>();
|
||||
if (domainBase == null)
|
||||
{
|
||||
Debug.LogError($"UnityEvo:{mainPrefab.name}的DomainBase为空,无法退出,请排查");
|
||||
@@ -165,18 +171,17 @@ namespace Stary.Evo
|
||||
domainBase.OnExit();
|
||||
await domainBase.OnExitAsync();
|
||||
}
|
||||
|
||||
if (loadResType == DomainConfig.LoadResType.Scene)
|
||||
{
|
||||
await SceneManager.UnloadSceneAsync(domainConfig.mainScene);
|
||||
}
|
||||
|
||||
if (domainBase != null)
|
||||
{
|
||||
GameObject.Destroy(domainBase.gameObject);
|
||||
|
||||
await ForceUnloadAllAssets(domainBase.DomainName);
|
||||
}
|
||||
if (loadResType == DomainConfig.LoadResType.Scene)
|
||||
{
|
||||
await SceneManager.UnloadSceneAsync(_sceneName);
|
||||
}
|
||||
AppConfig.PackageDomainName = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -240,10 +240,14 @@ namespace Stary.Evo
|
||||
public async UniTask Download(string fileId)
|
||||
{
|
||||
// 在任意MonoBehaviour或DomainBase派生类中
|
||||
string loadPath = $"{Application.persistentDataPath}/DownloadedContent/{AppConfig.PackageDomainName}";
|
||||
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)
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Stary.Evo
|
||||
{
|
||||
var initParameters = new OfflinePlayModeParameters();
|
||||
var buildinFileSystemParams = FileSystemParameters.CreateDefaultBuildinFileSystemParameters(null,
|
||||
$"{Application.persistentDataPath}/DownloadedContent/{AppConfig.PackageDomainName}");
|
||||
$"{Application.temporaryCachePath}/DownloadedContent/{AppConfig.PackageDomainName}");
|
||||
buildinFileSystemParams.AddParameter(FileSystemParametersDefine.APPEND_FILE_EXTENSION, true);
|
||||
buildinFileSystemParams.AddParameter(FileSystemParametersDefine.COPY_BUILDIN_PACKAGE_MANIFEST, true);
|
||||
initParameters.BuildinFileSystemParameters = buildinFileSystemParams;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
@@ -10,6 +11,7 @@ namespace Stary.Evo
|
||||
{
|
||||
public class ZipTool
|
||||
{
|
||||
private static SemaphoreSlim unzipLock = new(1, 1);
|
||||
// 新增:带进度回调的下载解压方法
|
||||
public static async UniTask DownloadAndUnzipAsync(string fildId, string extractPath,
|
||||
Action<float> downloadProgress = null, Action<float> unzipProgress = null)
|
||||
@@ -41,7 +43,9 @@ namespace Stary.Evo
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
// 验证路径安全性
|
||||
string fullExtractPath = Path.GetFullPath(extractPath);
|
||||
|
||||
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
|
||||
{
|
||||
float totalEntries = archive.Entries.Count;
|
||||
@@ -49,7 +53,13 @@ namespace Stary.Evo
|
||||
|
||||
foreach (ZipArchiveEntry entry in archive.Entries)
|
||||
{
|
||||
string filePath = Path.Combine(extractPath, entry.FullName);
|
||||
// 安全检查:防止目录遍历
|
||||
string filePath = Path.GetFullPath(Path.Combine(extractPath, entry.FullName));
|
||||
if (!filePath.StartsWith(fullExtractPath))
|
||||
{
|
||||
Debug.LogWarning($"跳过不安全的文件路径: {entry.FullName}");
|
||||
continue;
|
||||
}
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
|
||||
|
||||
if (!string.IsNullOrEmpty(entry.Name))
|
||||
@@ -57,7 +67,7 @@ namespace Stary.Evo
|
||||
using (Stream inputStream = entry.Open())
|
||||
using (FileStream outputStream = File.Create(filePath))
|
||||
{
|
||||
await inputStream.CopyToAsync(outputStream);
|
||||
await inputStream.CopyToAsync(outputStream,81920);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +81,7 @@ namespace Stary.Evo
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"解压失败: {ex.Message}");
|
||||
throw;
|
||||
throw; // 重新抛出异常让调用方处理
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user