diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/Encryption.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/Encryption.cs index 97094ee..3b8a075 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/Encryption.cs +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/Encryption.cs @@ -14,7 +14,7 @@ public class FileOffsetEncryption : IEncryptionServices if (fileInfo.BundleName.Contains("_gameres_audio")) { int offset = 32; - byte[] fileData = File.ReadAllBytes(fileInfo.FilePath); + byte[] fileData = File.ReadAllBytes(fileInfo.FileLoadPath); var encryptedData = new byte[fileData.Length + offset]; Buffer.BlockCopy(fileData, 0, encryptedData, offset, fileData.Length); @@ -41,7 +41,7 @@ public class FileStreamEncryption : IEncryptionServices { if (fileInfo.BundleName.Contains("_gameres_audio")) { - var fileData = File.ReadAllBytes(fileInfo.FilePath); + var fileData = File.ReadAllBytes(fileInfo.FileLoadPath); for (int i = 0; i < fileData.Length; i++) { fileData[i] ^= BundleStream.KEY; diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/Behaviour/ApplicationQuit.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/Behaviour/ApplicationQuit.cs deleted file mode 100644 index ca161dc..0000000 --- a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/Behaviour/ApplicationQuit.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using UnityEngine; -using YooAsset; - -public class ApplicationQuit : MonoBehaviour -{ - private void Awake() - { - DontDestroyOnLoad(this.gameObject); - } - private void OnApplicationQuit() - { - YooAssets.Destroy(); - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/Behaviour/ApplicationQuit.cs.meta b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/Behaviour/ApplicationQuit.cs.meta deleted file mode 100644 index f6a262d..0000000 --- a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/Behaviour/ApplicationQuit.cs.meta +++ /dev/null @@ -1,10 +0,0 @@ -fileFormatVersion: 2 -guid: 3cbcea01819f3d94ba5162624ad9c75f -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/GameLogic/SceneBattle.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/GameLogic/SceneBattle.cs index 0cafc86..f088f46 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/GameLogic/SceneBattle.cs +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/GameLogic/SceneBattle.cs @@ -59,7 +59,7 @@ internal class SceneBattle : MonoBehaviour if (YooAssets.Initialized) { var package = YooAssets.GetPackage("DefaultPackage"); - package.UnloadUnusedAssets(); + package.UnloadUnusedAssetsAsync(); } } private void Update() diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/GameLogic/SceneHome.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/GameLogic/SceneHome.cs index fa4f520..6f6f9f8 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/GameLogic/SceneHome.cs +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/GameLogic/SceneHome.cs @@ -12,7 +12,7 @@ public class SceneHome : MonoBehaviour private IEnumerator Start() { // 加载登录页面 - _windowHandle = YooAssets.LoadAssetAsync("UIHome"); + _windowHandle = YooAssets.LoadAssetSync("UIHome"); yield return _windowHandle; _windowHandle.InstantiateSync(CanvasDesktop.transform); } @@ -28,7 +28,7 @@ public class SceneHome : MonoBehaviour if (YooAssets.Initialized) { var package = YooAssets.GetPackage("DefaultPackage"); - package.UnloadUnusedAssets(); + package.UnloadUnusedAssetsAsync(); } } } \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmClearPackageCache.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmClearPackageCache.cs index 31a0c6f..b64b29b 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmClearPackageCache.cs +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmClearPackageCache.cs @@ -20,7 +20,7 @@ internal class FsmClearPackageCache : IStateNode PatchEventDefine.PatchStatesChange.SendEventMessage("清理未使用的缓存文件!"); var packageName = (string)_machine.GetBlackboardValue("PackageName"); var package = YooAssets.GetPackage(packageName); - var operation = package.ClearUnusedCacheFilesAsync(); + var operation = package.ClearUnusedBundleFilesAsync(); operation.Completed += Operation_Completed; } void IStateNode.OnUpdate() diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmInitializePackage.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmInitializePackage.cs index cd6f404..5f9326a 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmInitializePackage.cs +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmInitializePackage.cs @@ -44,8 +44,9 @@ internal class FsmInitializePackage : IStateNode InitializationOperation initializationOperation = null; if (playMode == EPlayMode.EditorSimulateMode) { + string simulateManifestFilePath = EditorSimulateModeHelper.SimulateBuild(buildPipeline, packageName); var createParameters = new EditorSimulateModeParameters(); - createParameters.SimulateManifestFilePath = EditorSimulateModeHelper.SimulateBuild(buildPipeline, packageName); + createParameters.EditorFileSystemParameters = FileSystemParameters.CreateDefaultEditorFileSystemParameters(simulateManifestFilePath); initializationOperation = package.InitializeAsync(createParameters); } @@ -53,7 +54,7 @@ internal class FsmInitializePackage : IStateNode if (playMode == EPlayMode.OfflinePlayMode) { var createParameters = new OfflinePlayModeParameters(); - createParameters.DecryptionServices = new FileStreamDecryption(); + createParameters.BuildinFileSystemParameters = FileSystemParameters.CreateDefaultBuildinFileSystemParameters(); initializationOperation = package.InitializeAsync(createParameters); } @@ -62,10 +63,10 @@ internal class FsmInitializePackage : IStateNode { string defaultHostServer = GetHostServerURL(); string fallbackHostServer = GetHostServerURL(); + IRemoteServices remoteServices = new RemoteServices(defaultHostServer, fallbackHostServer); var createParameters = new HostPlayModeParameters(); - createParameters.DecryptionServices = new FileStreamDecryption(); - createParameters.BuildinQueryServices = new GameQueryServices(); - createParameters.RemoteServices = new RemoteServices(defaultHostServer, fallbackHostServer); + createParameters.BuildinFileSystemParameters = FileSystemParameters.CreateDefaultBuildinFileSystemParameters(); + createParameters.CacheFileSystemParameters = FileSystemParameters.CreateDefaultCacheFileSystemParameters(remoteServices); initializationOperation = package.InitializeAsync(createParameters); } @@ -74,10 +75,9 @@ internal class FsmInitializePackage : IStateNode { string defaultHostServer = GetHostServerURL(); string fallbackHostServer = GetHostServerURL(); + IRemoteServices remoteServices = new RemoteServices(defaultHostServer, fallbackHostServer); var createParameters = new WebPlayModeParameters(); - createParameters.DecryptionServices = new FileStreamDecryption(); - createParameters.BuildinQueryServices = new GameQueryServices(); - createParameters.RemoteServices = new RemoteServices(defaultHostServer, fallbackHostServer); + createParameters.WebFileSystemParameters = FileSystemParameters.CreateDefaultWebFileSystemParameters(remoteServices); initializationOperation = package.InitializeAsync(createParameters); } @@ -91,8 +91,6 @@ internal class FsmInitializePackage : IStateNode } else { - var version = initializationOperation.PackageVersion; - Debug.Log($"Init resource package version : {version}"); _machine.ChangeState(); } } @@ -163,7 +161,7 @@ internal class FsmInitializePackage : IStateNode { BundleStream bundleStream = new BundleStream(fileInfo.FileLoadPath, FileMode.Open, FileAccess.Read, FileShare.Read); managedStream = bundleStream; - return AssetBundle.LoadFromStream(bundleStream, fileInfo.ConentCRC, GetManagedReadBufferSize()); + return AssetBundle.LoadFromStream(bundleStream, fileInfo.FileLoadCRC, GetManagedReadBufferSize()); } /// @@ -174,7 +172,7 @@ internal class FsmInitializePackage : IStateNode { BundleStream bundleStream = new BundleStream(fileInfo.FileLoadPath, FileMode.Open, FileAccess.Read, FileShare.Read); managedStream = bundleStream; - return AssetBundle.LoadFromStreamAsync(bundleStream, fileInfo.ConentCRC, GetManagedReadBufferSize()); + return AssetBundle.LoadFromStreamAsync(bundleStream, fileInfo.FileLoadCRC, GetManagedReadBufferSize()); } private static uint GetManagedReadBufferSize() @@ -195,7 +193,7 @@ internal class FsmInitializePackage : IStateNode AssetBundle IDecryptionServices.LoadAssetBundle(DecryptFileInfo fileInfo, out Stream managedStream) { managedStream = null; - return AssetBundle.LoadFromFile(fileInfo.FileLoadPath, fileInfo.ConentCRC, GetFileOffset()); + return AssetBundle.LoadFromFile(fileInfo.FileLoadPath, fileInfo.FileLoadCRC, GetFileOffset()); } /// @@ -205,7 +203,7 @@ internal class FsmInitializePackage : IStateNode AssetBundleCreateRequest IDecryptionServices.LoadAssetBundleAsync(DecryptFileInfo fileInfo, out Stream managedStream) { managedStream = null; - return AssetBundle.LoadFromFileAsync(fileInfo.FileLoadPath, fileInfo.ConentCRC, GetFileOffset()); + return AssetBundle.LoadFromFileAsync(fileInfo.FileLoadPath, fileInfo.FileLoadCRC, GetFileOffset()); } private static ulong GetFileOffset() diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmUpdatePackageManifest.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmUpdatePackageManifest.cs index 0f2011f..c5dae9d 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmUpdatePackageManifest.cs +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmUpdatePackageManifest.cs @@ -34,8 +34,7 @@ public class FsmUpdatePackageManifest : IStateNode var packageName = (string)_machine.GetBlackboardValue("PackageName"); var packageVersion = (string)_machine.GetBlackboardValue("PackageVersion"); var package = YooAssets.GetPackage(packageName); - bool savePackageVersion = true; - var operation = package.UpdatePackageManifestAsync(packageVersion, savePackageVersion); + var operation = package.UpdatePackageManifestAsync(packageVersion); yield return operation; if (operation.Status != EOperationStatus.Succeed) diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmUpdatePackageVersion.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmUpdatePackageVersion.cs index 78b1c67..0e74107 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmUpdatePackageVersion.cs +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmUpdatePackageVersion.cs @@ -33,7 +33,7 @@ internal class FsmUpdatePackageVersion : IStateNode var packageName = (string)_machine.GetBlackboardValue("PackageName"); var package = YooAssets.GetPackage(packageName); - var operation = package.UpdatePackageVersionAsync(); + var operation = package.RequestPackageVersionAsync(); yield return operation; if (operation.Status != EOperationStatus.Succeed) diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameSetting/AssetBundleCollectorSetting.asset b/Assets/YooAsset/Samples~/Space Shooter/GameSetting/AssetBundleCollectorSetting.asset index 5183a03..da09447 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameSetting/AssetBundleCollectorSetting.asset +++ b/Assets/YooAsset/Samples~/Space Shooter/GameSetting/AssetBundleCollectorSetting.asset @@ -100,3 +100,11 @@ MonoBehaviour: FilterRuleName: CollectAll AssetTags: UserData: + - CollectPath: Assets/Samples/Space Shooter/GameRes/UIAtlas + CollectorGUID: 80caf8bc3d0ac5b48a5cab7765a68205 + CollectorType: 0 + AddressRuleName: AddressByFileName + PackRuleName: PackDirectory + FilterRuleName: CollectAll + AssetTags: + UserData: diff --git a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper.meta b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper.meta deleted file mode 100644 index 51097df..0000000 --- a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 0dc8cc2d1f4fd7149a0a1f13f8f8e54b -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/BuildinFileManifest.cs b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/BuildinFileManifest.cs deleted file mode 100644 index fd9d057..0000000 --- a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/BuildinFileManifest.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; - -/// -/// 内置资源清单 -/// -public class BuildinFileManifest : ScriptableObject -{ - [Serializable] - public class Element - { - public string PackageName; - public string FileName; - public string FileCRC32; - } - - public List BuildinFiles = new List(); -} \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/BuildinFileManifest.cs.meta b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/BuildinFileManifest.cs.meta deleted file mode 100644 index 428aff2..0000000 --- a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/BuildinFileManifest.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 71b02dfa7aa9d4545b3417a18477fbee -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsDefine.cs b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsDefine.cs deleted file mode 100644 index 0ab85fc..0000000 --- a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsDefine.cs +++ /dev/null @@ -1,8 +0,0 @@ - -public class StreamingAssetsDefine -{ - /// - /// 根目录名称(保持和YooAssets资源系统一致) - /// - public const string RootFolderName = "yoo"; -} \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsDefine.cs.meta b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsDefine.cs.meta deleted file mode 100644 index ce70537..0000000 --- a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsDefine.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 7e44d691f47abe34e9deb9cb309074f4 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelper.cs b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelper.cs deleted file mode 100644 index b28793d..0000000 --- a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelper.cs +++ /dev/null @@ -1,162 +0,0 @@ -using System.IO; -using System.Collections.Generic; -using UnityEngine; -using YooAsset; - -/// -/// 资源文件查询服务类 -/// -public class GameQueryServices : IBuildinQueryServices -{ - /// - /// 查询内置文件的时候,是否比对文件哈希值 - /// - public static bool CompareFileCRC = false; - - public bool Query(string packageName, string fileName, string fileCRC) - { - // 注意:fileName包含文件格式 - return StreamingAssetsHelper.FileExists(packageName, fileName, fileCRC); - } -} - -#if UNITY_EDITOR -public sealed class StreamingAssetsHelper -{ - public static void Init() { } - public static bool FileExists(string packageName, string fileName, string fileCRC) - { - string filePath = Path.Combine(Application.streamingAssetsPath, StreamingAssetsDefine.RootFolderName, packageName, fileName); - if (File.Exists(filePath)) - { - if (GameQueryServices.CompareFileCRC) - { - string crc32 = YooAsset.HashUtility.FileCRC32(filePath); - return crc32 == fileCRC; - } - else - { - return true; - } - } - else - { - return false; - } - } -} -#else -public sealed class StreamingAssetsHelper -{ - private class PackageQuery - { - public readonly Dictionary Elements = new Dictionary(1000); - } - - private static bool _isInit = false; - private static readonly Dictionary _packages = new Dictionary(10); - - /// - /// 初始化 - /// - public static void Init() - { - if (_isInit == false) - { - _isInit = true; - - var manifest = Resources.Load("BuildinFileManifest"); - if (manifest != null) - { - foreach (var element in manifest.BuildinFiles) - { - if (_packages.TryGetValue(element.PackageName, out PackageQuery package) == false) - { - package = new PackageQuery(); - _packages.Add(element.PackageName, package); - } - package.Elements.Add(element.FileName, element); - } - } - } - } - - /// - /// 内置文件查询方法 - /// - public static bool FileExists(string packageName, string fileName, string fileCRC32) - { - if (_isInit == false) - Init(); - - if (_packages.TryGetValue(packageName, out PackageQuery package) == false) - return false; - - if (package.Elements.TryGetValue(fileName, out var element) == false) - return false; - - if (GameQueryServices.CompareFileCRC) - { - return element.FileCRC32 == fileCRC32; - } - else - { - return true; - } - } -} -#endif - - -#if UNITY_EDITOR -internal class PreprocessBuild : UnityEditor.Build.IPreprocessBuildWithReport -{ - public int callbackOrder { get { return 0; } } - - /// - /// 在构建应用程序前处理 - /// 原理:在构建APP之前,搜索StreamingAssets目录下的所有资源文件,然后将这些文件信息写入内置清单,内置清单存储在Resources文件夹下。 - /// - public void OnPreprocessBuild(UnityEditor.Build.Reporting.BuildReport report) - { - string saveFilePath = "Assets/Resources/BuildinFileManifest.asset"; - if (File.Exists(saveFilePath)) - { - File.Delete(saveFilePath); - UnityEditor.AssetDatabase.SaveAssets(); - UnityEditor.AssetDatabase.Refresh(); - } - - string folderPath = $"{Application.dataPath}/StreamingAssets/{StreamingAssetsDefine.RootFolderName}"; - DirectoryInfo root = new DirectoryInfo(folderPath); - if (root.Exists == false) - { - Debug.LogWarning($"没有发现YooAsset内置目录 : {folderPath}"); - return; - } - - var manifest = ScriptableObject.CreateInstance(); - FileInfo[] files = root.GetFiles("*", SearchOption.AllDirectories); - foreach (var fileInfo in files) - { - if (fileInfo.Extension == ".meta") - continue; - if (fileInfo.Name.StartsWith("PackageManifest_")) - continue; - - BuildinFileManifest.Element element = new BuildinFileManifest.Element(); - element.PackageName = fileInfo.Directory.Name; - element.FileCRC32 = YooAsset.HashUtility.FileCRC32(fileInfo.FullName); - element.FileName = fileInfo.Name; - manifest.BuildinFiles.Add(element); - } - - if (Directory.Exists("Assets/Resources") == false) - Directory.CreateDirectory("Assets/Resources"); - UnityEditor.AssetDatabase.CreateAsset(manifest, saveFilePath); - UnityEditor.AssetDatabase.SaveAssets(); - UnityEditor.AssetDatabase.Refresh(); - Debug.Log($"一共{manifest.BuildinFiles.Count}个内置文件,内置资源清单保存成功 : {saveFilePath}"); - } -} -#endif \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelper.cs.meta b/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelper.cs.meta deleted file mode 100644 index e7f3da4..0000000 --- a/Assets/YooAsset/Samples~/Space Shooter/ThirdParty/StreamingAssetsHelper/StreamingAssetsHelper.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ca0617f5ec2b4504b923e3205dc77f54 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: