From 392bf104db1d0e3dc20d48baab77f0cd4539111f Mon Sep 17 00:00:00 2001 From: MichaelO Date: Mon, 7 Aug 2023 19:42:27 +0800 Subject: [PATCH] added methods --- Assets/AssetBundleBuilderSetting.asset | 4 +- .../Scripts/Runtime/AssetPatcher.cs | 20 ++++++ .../Scripts/Runtime/Bundle/PackageManager.cs | 62 +++++++++++++++++++ Assets/OxGFrame/CHANGELOG.md | 4 ++ Assets/OxGFrame/package.json | 2 +- 5 files changed, 89 insertions(+), 3 deletions(-) diff --git a/Assets/AssetBundleBuilderSetting.asset b/Assets/AssetBundleBuilderSetting.asset index 9ec8205a..f5108c20 100644 --- a/Assets/AssetBundleBuilderSetting.asset +++ b/Assets/AssetBundleBuilderSetting.asset @@ -14,9 +14,9 @@ MonoBehaviour: m_EditorClassIdentifier: BuildPipeline: 1 BuildMode: 1 - BuildPackage: DefaultPackage + BuildPackage: OtherPackage CompressOption: 2 OutputNameStyle: 1 - CopyBuildinFileOption: 1 + CopyBuildinFileOption: 0 CopyBuildinFileTags: EncyptionClassName: EncryptionNone diff --git a/Assets/OxGFrame/AssetLoader/Scripts/Runtime/AssetPatcher.cs b/Assets/OxGFrame/AssetLoader/Scripts/Runtime/AssetPatcher.cs index b031fb46..d5a354f9 100644 --- a/Assets/OxGFrame/AssetLoader/Scripts/Runtime/AssetPatcher.cs +++ b/Assets/OxGFrame/AssetLoader/Scripts/Runtime/AssetPatcher.cs @@ -191,6 +191,26 @@ public static string GetPatchVersion(bool encode = false, int encodeLength = 6, #endregion #region Package Operation + /// + /// Check package has any files in local + /// + /// + /// + public static bool CheckPackageHasAnyFilesInLocal(string packageName) + { + return PackageManager.CheckPackageHasAnyFilesInLocal(packageName); + } + + /// + /// Get package files size in local + /// + /// + /// + public static ulong GetPackageSizeInLocal(string packageName) + { + return PackageManager.GetPackageSizeInLocal(packageName); + } + /// /// Unload package and clear package files from sandbox /// diff --git a/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Bundle/PackageManager.cs b/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Bundle/PackageManager.cs index 1136d491..f8a36416 100644 --- a/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Bundle/PackageManager.cs +++ b/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Bundle/PackageManager.cs @@ -1,6 +1,8 @@ using Cysharp.Threading.Tasks; using System; using System.Collections.Generic; +using System.IO; +using System.Linq; using UnityEngine; using YooAsset; @@ -197,6 +199,66 @@ public static async UniTask UpdatePackage(string packageName) } } + /// + /// Check package has any files in local + /// + /// + /// + public static bool CheckPackageHasAnyFilesInLocal(string packageName) + { + if (BundleConfig.playMode == BundleConfig.PlayMode.EditorSimulateMode) + { + Debug.Log($"[{BundleConfig.PlayMode.EditorSimulateMode}] Check Package In Local return true"); + return true; + } + + try + { + var package = GetPackage(packageName); + if (package == null) return false; + + string path = BundleConfig.GetLocalSandboxPackagePath(packageName); + if (!Directory.Exists(path)) return false; + + DirectoryInfo directoryInfo = new DirectoryInfo(path); + return directoryInfo.GetFiles("*.*", SearchOption.AllDirectories).Any(); + } + catch + { + return false; + } + } + + /// + /// Get package files size in local + /// + /// + /// + public static ulong GetPackageSizeInLocal(string packageName) + { + if (BundleConfig.playMode == BundleConfig.PlayMode.EditorSimulateMode) + { + Debug.Log($"[{BundleConfig.PlayMode.EditorSimulateMode}] Get Package Size In Local return 1"); + return 1; + } + + try + { + var package = GetPackage(packageName); + if (package == null) return 0; + + string path = BundleConfig.GetLocalSandboxPackagePath(packageName); + if (!Directory.Exists(path)) return 0; + + DirectoryInfo directoryInfo = new DirectoryInfo(path); + return (ulong)directoryInfo.GetFiles("*.*", SearchOption.AllDirectories).Sum(fi => fi.Length); + } + catch + { + return 0; + } + } + /// /// Unload package and clear package files from sandbox /// diff --git a/Assets/OxGFrame/CHANGELOG.md b/Assets/OxGFrame/CHANGELOG.md index 53d3c9d7..1c455b17 100644 --- a/Assets/OxGFrame/CHANGELOG.md +++ b/Assets/OxGFrame/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## [2.7.2] - 2023-08-07 +- Added CheckPackageHasAnyFilesInLocal(string packageName). +- Added GetPackageSizeInLocal(string packageName). + ## [2.7.1] - 2023-08-05 - Added Default API in GSIManagerBase (protected GetInstance() method). ``` diff --git a/Assets/OxGFrame/package.json b/Assets/OxGFrame/package.json index 024490a5..fecd71c5 100644 --- a/Assets/OxGFrame/package.json +++ b/Assets/OxGFrame/package.json @@ -2,7 +2,7 @@ "name": "com.michaelo.oxgframe", "displayName": "OxGFrame", "description": "The OxGFrame is a framework based on Unity for accelerating game development. Supports multi-platform Win, Android, iOS, WebGL.", - "version": "2.7.1", + "version": "2.7.2", "unity": "2021.3", "license": "MIT", "samples": [