Skip to content

Commit

Permalink
updated to v2.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
michael811125 committed Mar 6, 2024
1 parent b65a2cc commit 8e71075
Show file tree
Hide file tree
Showing 19 changed files with 359 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public enum BuildMode
RawFileBuildPipeline = 2
}

public enum BuiltinQueryMode
{
WebRequest,
BuiltinFileManifest,
BuiltinFileManifestWithCRC
}

public class CryptogramType
{
public const string NONE = "NONE";
Expand Down Expand Up @@ -93,6 +100,7 @@ public class CryptogramType
/// 預設下載失敗重新嘗試次數
/// </summary>
internal const int DEFAULT_FAILED_RETRY_COUNT = 3;

/// <summary>
/// 下載失敗重新嘗試次數
/// </summary>
Expand All @@ -103,6 +111,11 @@ public class CryptogramType
/// </summary>
public static uint breakpointFileSizeThreshold = 20 * 1 << 20;

/// <summary>
/// 查找內置資源方式
/// </summary>
public static BuiltinQueryMode builtinQueryMode = BuiltinQueryMode.WebRequest;

/// <summary>
/// 解密 Key, [NONE], [OFFSET, dummySize], [XOR, key], [HT2XOR, hKey, tKey, jKey], [AES, key, iv]
/// </summary>
Expand Down Expand Up @@ -141,7 +154,9 @@ internal static void InitDecryptInfo(string args, bool secured, int saltSize, in
/// </summary>
internal static void ReleaseSecureString()
{
if (_decryptArgs != null) foreach (var decryptArg in _decryptArgs) decryptArg.Dispose();
if (_decryptArgs != null)
foreach (var decryptArg in _decryptArgs)
decryptArg.Dispose();
}
#endregion

Expand Down
31 changes: 21 additions & 10 deletions Assets/OxGFrame/AssetLoader/Scripts/Runtime/Bundle/PatchLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
using UnityEngine;
using OxGKit.LoggingSystem;

#if UNITY_EDITOR
using UnityEditor;
#endif

namespace OxGFrame.AssetLoader.Bundle
{
[DisallowMultipleComponent]
Expand All @@ -16,7 +12,7 @@ internal class PatchLauncher : MonoBehaviour
public BundleConfig.PlayMode playMode = BundleConfig.PlayMode.EditorSimulateMode;
[Tooltip("If checked, the patch field will compare whole version."), ConditionalField(nameof(playMode), false, BundleConfig.PlayMode.HostMode, BundleConfig.PlayMode.WebGLMode)]
public BundleConfig.SemanticRule semanticRule = new BundleConfig.SemanticRule();
[Tooltip("If checked, will skip preset app packages download step of the patch (force download while playing)."), ConditionalField(nameof(playMode), false, BundleConfig.PlayMode.HostMode)]
[Tooltip("If checked, will skip preset packages download step of the patch (force download while playing)."), ConditionalField(nameof(playMode), false, BundleConfig.PlayMode.HostMode)]
public bool skipMainDownload = false;
[Tooltip("If checked, will check disk space is it enough while patch checking."), ConditionalField(new string[] { nameof(playMode), nameof(skipMainDownload) }, new bool[] { false, true }, BundleConfig.PlayMode.HostMode)]
public bool checkDiskSpace = true;
Expand All @@ -25,10 +21,12 @@ internal class PatchLauncher : MonoBehaviour
[Tooltip("The first element will be default app package.\n\nNote: The presets will combine in main download of the patch.")]
public List<AppPackageInfoWithBuild> listAppPackages = new List<AppPackageInfoWithBuild>() { new AppPackageInfoWithBuild() { packageName = "DefaultPackage" } };

[Separator("Preset DLC Packages"), Tooltip("Preset DLC packages must be fixed versions.\n\nNote: The presets will combine in main download of the patch.")]
[Separator("Preset DLC Packages"), Tooltip("The preset DLC packages must be fixed versions.\n\nNote: The presets will combine in main download of the patch.")]
public List<DlcPackageInfoWithBuild> listDlcPackages = new List<DlcPackageInfoWithBuild>();

[Separator("Download Options")]
[Tooltip("* [WebRequest] supports dynamic query built-in files (Some memory will be used, but will be released at next GC).\n\n* [BuiltinFileManifest] query built-in files from manifest (setup at build-time or manual export).\n\n* [BuiltinFileManifest with CRC] query built-in files and check CRC from manifest (setup at build-time or manual export).")]
public BundleConfig.BuiltinQueryMode builtinQueryMode = BundleConfig.BuiltinQueryMode.WebRequest;
public int maxConcurrencyDownloadCount = BundleConfig.maxConcurrencyDownloadCount;
public int failedRetryCount = BundleConfig.failedRetryCount;
[Tooltip("If file size >= [BreakpointFileSizeThreshold] that file will enable breakpoint mechanism (for all downloaders).")]
Expand Down Expand Up @@ -79,6 +77,8 @@ private async void Awake()
#endregion

#region Download Options
// Set built-in files query mode
BundleConfig.builtinQueryMode = this.builtinQueryMode;
BundleConfig.maxConcurrencyDownloadCount = this.maxConcurrencyDownloadCount <= 0 ? BundleConfig.DEFAULT_MAX_CONCURRENCY_MAX_DOWNLOAD_COUNT : this.maxConcurrencyDownloadCount;
BundleConfig.failedRetryCount = this.failedRetryCount <= 0 ? BundleConfig.DEFAULT_FAILED_RETRY_COUNT : this.failedRetryCount;
// Set download breakpoint size threshold
Expand All @@ -102,7 +102,7 @@ private async void Awake()

private void OnApplicationQuit()
{
#if !UNITY_WEBGL
#if !UNITY_WEBGL
PackageManager.Release();
Logging.Print<Logger>("<color=#ff84d1>(Powered by YooAsset) Release Packages Completes.</color>");
#endif
Expand All @@ -116,17 +116,28 @@ private void OnValidate()
switch (this.playMode)
{
case BundleConfig.PlayMode.OfflineMode:
Logging.Print<Logger>($"<color=#ff1f4c>[Offline Mode] is not supported on {EditorUserBuildSettings.activeBuildTarget}.</color>");
this.playMode = BundleConfig.PlayMode.EditorSimulateMode;
Debug.Log($"<color=#ff1f4c>[Offline Mode] is not supported on {UnityEditor.EditorUserBuildSettings.activeBuildTarget}.</color>");
break;
case BundleConfig.PlayMode.HostMode:
Logging.Print<Logger>($"<color=#ff1f4c>[Host Mode] is not supported on {EditorUserBuildSettings.activeBuildTarget}.</color>");
this.playMode = BundleConfig.PlayMode.EditorSimulateMode;
Debug.Log($"<color=#ff1f4c>[Host Mode] is not supported on {UnityEditor.EditorUserBuildSettings.activeBuildTarget}.</color>");
break;
}

switch (this.builtinQueryMode)
{
case BundleConfig.BuiltinQueryMode.WebRequest:
this.builtinQueryMode = BundleConfig.BuiltinQueryMode.BuiltinFileManifest;
Debug.Log($"<color=#ff1f4c>[WebRequest QueryMode] is not supported on {UnityEditor.EditorUserBuildSettings.activeBuildTarget}.</color>");
break;
}
#else
switch (this.playMode)
{
case BundleConfig.PlayMode.WebGLMode:
Logging.Print<Logger>($"<color=#ff1f4c>[WebGL Mode] is not supported on {EditorUserBuildSettings.activeBuildTarget}.</color>");
this.playMode = BundleConfig.PlayMode.EditorSimulateMode;
Debug.Log($"<color=#ff1f4c>[WebGL Mode] is not supported on {UnityEditor.EditorUserBuildSettings.activeBuildTarget}.</color>");
break;
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ protected string ConvertToWWWPath(string path)
{
#if UNITY_EDITOR
return string.Format("file:///{0}", path);
#elif UNITY_IPHONE
#elif UNITY_IPHONE
return string.Format("file://{0}", path);
#elif UNITY_ANDROID
#elif UNITY_ANDROID
return path;
#elif UNITY_STANDALONE
#elif UNITY_STANDALONE
return string.Format("file:///{0}", path);
#else
return path;
Expand All @@ -93,22 +93,33 @@ public class RequestBuiltinQuery : RequestQueryBase
{
public override bool Query(string packageName, string fileName, string fileCRC)
{
// Safety check
#if UNITY_WEBGL
return StreamingAssetsHelper.FileExists(packageName, fileName);
#else
#region Builtin (StreamingAssets)
string builtinPackagePath = BundleConfig.GetBuiltinPackagePath(packageName);
string url = Path.Combine(builtinPackagePath, fileName);
#endregion
if (BundleConfig.builtinQueryMode == BundleConfig.BuiltinQueryMode.WebRequest)
BundleConfig.builtinQueryMode = BundleConfig.BuiltinQueryMode.BuiltinFileManifest;
#endif

switch (BundleConfig.builtinQueryMode)
{
case BundleConfig.BuiltinQueryMode.WebRequest:
// Builtin (StreamingAssets)
string builtinPackagePath = BundleConfig.GetBuiltinPackagePath(packageName);
string url = Path.Combine(builtinPackagePath, fileName);
// Convert url to www path
var e = this.WebRequest(this.ConvertToWWWPath(url));
while (e.MoveNext())
if (e.Current != null)
return (bool)e.Current;
return false;

// Convert url to www path
var e = this.WebRequest(this.ConvertToWWWPath(url));
while (e.MoveNext())
if (e.Current != null)
return (bool)e.Current;
case BundleConfig.BuiltinQueryMode.BuiltinFileManifest:
return StreamingAssetsHelper.FileExists(packageName, fileName, null);

case BundleConfig.BuiltinQueryMode.BuiltinFileManifestWithCRC:
return StreamingAssetsHelper.FileExists(packageName, fileName, fileCRC);
}

return false;
#endif
}
}
#endregion
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using MyBox;
using System;
using System.Collections.Generic;
using UnityEngine;

namespace OxGFrame.AssetLoader.Bundle
{
// Reference: YooAsset

/// <summary>
/// 内置资源清单
/// </summary>
public class BuiltinFileManifest : ScriptableObject
{
[Serializable]
public class Element
{
[ReadOnly]
public string PackageName;
[ReadOnly]
public string FileName;
[ReadOnly]
public string FileCRC32;
}

public List<Element> BuiltinFiles = new List<Element>();
}
}
Loading

0 comments on commit 8e71075

Please sign in to comment.