mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-23 09:10:11 +00:00
Compare commits
27 Commits
2.3.3-prev
...
e984d69c48
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e984d69c48 | ||
|
|
4d2df5b705 | ||
|
|
79a7732cfd | ||
|
|
0b4f6d6639 | ||
|
|
79467bbf13 | ||
|
|
c7d678282b | ||
|
|
d376afc217 | ||
|
|
a62f808591 | ||
|
|
b334a4986b | ||
|
|
a4111349a0 | ||
|
|
bdcf95384f | ||
|
|
d910af589d | ||
|
|
0531864534 | ||
|
|
72b1278f5c | ||
|
|
875cd24cba | ||
|
|
fcc729a0bf | ||
|
|
d10e54248b | ||
|
|
b84800a905 | ||
|
|
8ccd7e552c | ||
|
|
772ba484eb | ||
|
|
cdbedee705 | ||
|
|
10cce48e71 | ||
|
|
13e8410d80 | ||
|
|
6f07faf4da | ||
|
|
e3228d406e | ||
|
|
daf2133535 | ||
|
|
9bcbc10862 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -20,6 +20,8 @@
|
||||
/Assets/StreamingAssets.meta
|
||||
/Assets/Samples
|
||||
/Assets/Samples.meta
|
||||
/Assets/csc.rsp
|
||||
/Assets/csc.rsp.meta
|
||||
/UserSettings
|
||||
|
||||
|
||||
|
||||
@@ -2,12 +2,41 @@
|
||||
|
||||
All notable changes to this package will be documented in this file.
|
||||
|
||||
## [2.3.4-preview] - 2025-03-08
|
||||
|
||||
### Improvements
|
||||
|
||||
- YooAsset支持了版本宏定义。
|
||||
|
||||
```csharp
|
||||
YOO_ASSET_2
|
||||
YOO_ASSET_2_3
|
||||
YOO_ASSET_2_3_OR_NEWER
|
||||
```
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#389) 修复了禁用域重载(Reload Domain)的情况下,再次启动游戏报错的问题。
|
||||
- (#496) 修复了文件系统参数RESUME_DOWNLOAD_MINMUM_SIZE传入int值会导致异常的错误。
|
||||
- (#498) 修复了v2.3版本尝试加载安卓包内的原生资源包失败的问题。
|
||||
|
||||
### Added
|
||||
|
||||
- 新增了YooAssets.GetAllPackages()方法
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// 获取所有资源包裹
|
||||
/// </summary>
|
||||
public static List<ResourcePackage> GetAllPackages()
|
||||
```
|
||||
|
||||
## [2.3.3-preview] - 2025-03-06
|
||||
|
||||
### Improvements
|
||||
|
||||
- 新增了异步操作任务调试器,AssetBundleDebugger窗口-->OperationView视图模式
|
||||
- 编辑器下模拟构建默认启用依赖关系数据库,可以大幅增加编辑器下开始游戏时间。
|
||||
- 编辑器下模拟构建默认启用依赖关系数据库,可以大幅降低编辑器下启动游戏的时间。
|
||||
- 单元测试用例增加加密解密测试用例。
|
||||
|
||||
### Fixed
|
||||
|
||||
8
Assets/YooAsset/Editor/Assembly.meta
Normal file
8
Assets/YooAsset/Editor/Assembly.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fab3cd742c11be2479b07f5d447a78c9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/YooAsset/Editor/Assembly/MacroDefine.cs
Normal file
17
Assets/YooAsset/Editor/Assembly/MacroDefine.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class MacroDefine
|
||||
{
|
||||
/// <summary>
|
||||
/// YooAsset版本宏定义
|
||||
/// </summary>
|
||||
public static readonly List<string> Macros = new List<string>()
|
||||
{
|
||||
"YOO_ASSET_2",
|
||||
"YOO_ASSET_2_3",
|
||||
"YOO_ASSET_2_3_OR_NEWER",
|
||||
};
|
||||
}
|
||||
}
|
||||
11
Assets/YooAsset/Editor/Assembly/MacroDefine.cs.meta
Normal file
11
Assets/YooAsset/Editor/Assembly/MacroDefine.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a61e5c2ca04aab647b1ed0492086aa8f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
96
Assets/YooAsset/Editor/Assembly/MacroProcessor.cs
Normal file
96
Assets/YooAsset/Editor/Assembly/MacroProcessor.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public class MacroProcessor : AssetPostprocessor
|
||||
{
|
||||
static string OnGeneratedCSProject(string path, string content)
|
||||
{
|
||||
XmlDocument xmlDoc = new XmlDocument();
|
||||
xmlDoc.LoadXml(content);
|
||||
|
||||
if (IsCSProjectReferenced(xmlDoc.DocumentElement) == false)
|
||||
return content;
|
||||
|
||||
if (ProcessDefineConstants(xmlDoc.DocumentElement) == false)
|
||||
return content;
|
||||
|
||||
// 将修改后的XML结构重新输出为文本
|
||||
var stringWriter = new StringWriter();
|
||||
var writerSettings = new XmlWriterSettings();
|
||||
writerSettings.Indent = true;
|
||||
var xmlWriter = XmlWriter.Create(stringWriter, writerSettings);
|
||||
xmlDoc.WriteTo(xmlWriter);
|
||||
xmlWriter.Flush();
|
||||
return stringWriter.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理宏定义
|
||||
/// </summary>
|
||||
private static bool ProcessDefineConstants(XmlElement element)
|
||||
{
|
||||
if (element == null)
|
||||
return false;
|
||||
|
||||
bool processed = false;
|
||||
foreach (XmlNode node in element.ChildNodes)
|
||||
{
|
||||
if (node.Name != "PropertyGroup")
|
||||
continue;
|
||||
|
||||
foreach (XmlNode childNode in node.ChildNodes)
|
||||
{
|
||||
if (childNode.Name != "DefineConstants")
|
||||
continue;
|
||||
|
||||
string[] defines = childNode.InnerText.Split(';');
|
||||
HashSet<string> hashSets = new HashSet<string>(defines);
|
||||
foreach (string yooMacro in MacroDefine.Macros)
|
||||
{
|
||||
string tmpMacro = yooMacro.Trim();
|
||||
if (hashSets.Contains(tmpMacro) == false)
|
||||
hashSets.Add(tmpMacro);
|
||||
}
|
||||
childNode.InnerText = string.Join(";", hashSets.ToArray());
|
||||
processed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return processed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测工程是否引用了YooAsset
|
||||
/// </summary>
|
||||
private static bool IsCSProjectReferenced(XmlElement element)
|
||||
{
|
||||
if (element == null)
|
||||
return false;
|
||||
|
||||
foreach (XmlNode node in element.ChildNodes)
|
||||
{
|
||||
if (node.Name != "ItemGroup")
|
||||
continue;
|
||||
|
||||
foreach (XmlNode childNode in node.ChildNodes)
|
||||
{
|
||||
if (childNode.Name != "Reference" && childNode.Name != "ProjectReference")
|
||||
continue;
|
||||
|
||||
string include = childNode.Attributes["Include"].Value;
|
||||
if (include.Contains("YooAsset"))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/YooAsset/Editor/Assembly/MacroProcessor.cs.meta
Normal file
11
Assets/YooAsset/Editor/Assembly/MacroProcessor.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 88d5a41d078a82e40b82265ed4c3631a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
115
Assets/YooAsset/Editor/Assembly/RspGenerator.cs
Normal file
115
Assets/YooAsset/Editor/Assembly/RspGenerator.cs
Normal file
@@ -0,0 +1,115 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
#if YOO_ASSET_EXPERIMENT
|
||||
namespace YooAsset.Editor.Experiment
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public class RspGenerator
|
||||
{
|
||||
// csc.rsp文件路径
|
||||
private static string RspFilePath => Path.Combine(Application.dataPath, "csc.rsp");
|
||||
|
||||
static RspGenerator()
|
||||
{
|
||||
UpdateRspFile(MacroDefine.Macros, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新csc.rsp文件
|
||||
/// </summary>
|
||||
private static void UpdateRspFile(List<string> addMacros, List<string> removeMacros)
|
||||
{
|
||||
var existingDefines = new HashSet<string>();
|
||||
var otherLines = new List<string>();
|
||||
|
||||
// 1. 读取现有内容
|
||||
ReadRspFile(existingDefines, otherLines);
|
||||
|
||||
// 2. 添加新宏
|
||||
if (addMacros != null && addMacros.Count > 0)
|
||||
{
|
||||
addMacros.ForEach(x =>
|
||||
{
|
||||
if (existingDefines.Contains(x) == false)
|
||||
existingDefines.Add(x);
|
||||
});
|
||||
}
|
||||
|
||||
// 3. 移除指定宏
|
||||
if (removeMacros != null && removeMacros.Count > 0)
|
||||
{
|
||||
removeMacros.ForEach(x =>
|
||||
{
|
||||
existingDefines.Remove(x);
|
||||
});
|
||||
}
|
||||
|
||||
// 4. 重新生成内容
|
||||
WriteRspFile(existingDefines, otherLines);
|
||||
|
||||
// 5. 刷新AssetDatabase
|
||||
AssetDatabase.Refresh();
|
||||
EditorUtility.RequestScriptReload();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取csc.rsp文件,返回宏定义和其他行
|
||||
/// </summary>
|
||||
private static void ReadRspFile(HashSet<string> defines, List<string> others)
|
||||
{
|
||||
if (defines == null)
|
||||
defines = new HashSet<string>();
|
||||
|
||||
if (others == null)
|
||||
others = new List<string>();
|
||||
|
||||
if (File.Exists(RspFilePath) == false)
|
||||
return;
|
||||
|
||||
foreach (string line in File.ReadAllLines(RspFilePath))
|
||||
{
|
||||
if (line.StartsWith("-define:"))
|
||||
{
|
||||
string[] parts = line.Split(new[] { ':' }, 2);
|
||||
if (parts.Length == 2)
|
||||
{
|
||||
defines.Add(parts[1].Trim());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
others.Add(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重新写入csc.rsp文件
|
||||
/// </summary>
|
||||
private static void WriteRspFile(HashSet<string> defines, List<string> others)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (others != null && others.Count > 0)
|
||||
{
|
||||
others.ForEach(o => sb.AppendLine(o));
|
||||
}
|
||||
|
||||
if (defines != null && defines.Count > 0)
|
||||
{
|
||||
foreach (string define in defines)
|
||||
{
|
||||
sb.AppendLine($"-define:{define}");
|
||||
}
|
||||
}
|
||||
|
||||
File.WriteAllText(RspFilePath, sb.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
11
Assets/YooAsset/Editor/Assembly/RspGenerator.cs.meta
Normal file
11
Assets/YooAsset/Editor/Assembly/RspGenerator.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c2662e1d33b1eea469695b68d18b1739
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -15,6 +15,7 @@ namespace YooAsset.Editor
|
||||
if (buildParametersContext.Parameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
|
||||
{
|
||||
CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest);
|
||||
DefaultBuildinFileSystemBuild.ExportBuildinCatalogFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace YooAsset.Editor
|
||||
if (buildParameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
|
||||
{
|
||||
CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest);
|
||||
DefaultBuildinFileSystemBuild.ExportBuildinCatalogFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace YooAsset.Editor
|
||||
if (buildParametersContext.Parameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
|
||||
{
|
||||
CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest);
|
||||
DefaultBuildinFileSystemBuild.ExportBuildinCatalogFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 忽略的文件类型
|
||||
/// </summary>
|
||||
public readonly static HashSet<string> IgnoreFileExtensions = new HashSet<string>() { "", ".so", ".dll", ".cs", ".js", ".boo", ".meta", ".cginc", ".hlsl" };
|
||||
public readonly static HashSet<string> IgnoreFileExtensions = new HashSet<string>() { "", ".so", ".cs", ".js", ".boo", ".meta", ".cginc", ".hlsl" };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
8
Assets/YooAsset/Runtime/Assembly.meta
Normal file
8
Assets/YooAsset/Runtime/Assembly.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 569f60ef80f74a642bac91eca0b20a2b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -7,6 +7,15 @@ namespace YooAsset
|
||||
{
|
||||
internal class RemoteDebuggerInRuntime : MonoBehaviour
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
private static void OnRuntimeInitialize()
|
||||
{
|
||||
_sampleOnce = false;
|
||||
_autoSample = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
private static bool _sampleOnce = false;
|
||||
private static bool _autoSample = false;
|
||||
|
||||
|
||||
@@ -8,6 +8,14 @@ namespace YooAsset
|
||||
{
|
||||
internal class RemoteEditorConnection
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
private static void OnRuntimeInitialize()
|
||||
{
|
||||
_instance = null;
|
||||
}
|
||||
#endif
|
||||
|
||||
private static RemoteEditorConnection _instance;
|
||||
public static RemoteEditorConnection Instance
|
||||
{
|
||||
|
||||
@@ -8,6 +8,14 @@ namespace YooAsset
|
||||
{
|
||||
internal class RemotePlayerConnection
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
private static void OnRuntimeInitialize()
|
||||
{
|
||||
_instance = null;
|
||||
}
|
||||
#endif
|
||||
|
||||
private static RemotePlayerConnection _instance;
|
||||
public static RemotePlayerConnection Instance
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
@@ -9,6 +10,14 @@ namespace YooAsset
|
||||
|
||||
internal class DownloadSystemHelper
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
private static void OnRuntimeInitialize()
|
||||
{
|
||||
UnityWebRequestCreater = null;
|
||||
}
|
||||
#endif
|
||||
|
||||
public static UnityWebRequestDelegate UnityWebRequestCreater = null;
|
||||
public static UnityWebRequest NewUnityWebRequestGet(string requestURL)
|
||||
{
|
||||
@@ -28,7 +37,9 @@ namespace YooAsset
|
||||
string url;
|
||||
|
||||
// 获取对应平台的URL地址
|
||||
#if UNITY_EDITOR
|
||||
#if UNITY_EDITOR_OSX
|
||||
url = StringUtility.Format("file://{0}", path);
|
||||
#elif UNITY_EDITOR
|
||||
url = StringUtility.Format("file:///{0}", path);
|
||||
#elif UNITY_WEBGL
|
||||
url = path;
|
||||
|
||||
@@ -6,6 +6,14 @@ namespace YooAsset
|
||||
{
|
||||
internal class WebRequestCounter
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[UnityEngine.RuntimeInitializeOnLoadMethod(UnityEngine.RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
private static void OnRuntimeInitialize()
|
||||
{
|
||||
_requestFailedRecorder.Clear();
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// 记录网络请求失败事件的次数
|
||||
/// </summary>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 内置资源清单目录
|
||||
/// </summary>
|
||||
internal class DefaultBuildinFileCatalog : ScriptableObject
|
||||
[Serializable]
|
||||
internal class DefaultBuildinFileCatalog
|
||||
{
|
||||
[Serializable]
|
||||
public class FileWrapper
|
||||
|
||||
@@ -147,15 +147,15 @@ namespace YooAsset
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.APPEND_FILE_EXTENSION)
|
||||
{
|
||||
AppendFileExtension = (bool)value;
|
||||
AppendFileExtension = Convert.ToBoolean(value);
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.DISABLE_CATALOG_FILE)
|
||||
{
|
||||
DisableCatalogFile = (bool)value;
|
||||
DisableCatalogFile = Convert.ToBoolean(value);
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.COPY_BUILDIN_PACKAGE_MANIFEST)
|
||||
{
|
||||
CopyBuildinPackageManifest = (bool)value;
|
||||
CopyBuildinPackageManifest = Convert.ToBoolean(value);
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.COPY_BUILDIN_PACKAGE_MANIFEST_DEST_ROOT)
|
||||
{
|
||||
@@ -239,6 +239,11 @@ namespace YooAsset
|
||||
if (Exists(bundle) == false)
|
||||
return null;
|
||||
|
||||
#if UNITY_ANDROID
|
||||
//TODO : 安卓平台内置文件属于APK压缩包内的文件。
|
||||
YooLogger.Error($"Android platform not support read buildin bundle file data !");
|
||||
return null;
|
||||
#else
|
||||
if (bundle.Encrypted)
|
||||
{
|
||||
if (DecryptionServices == null)
|
||||
@@ -261,6 +266,7 @@ namespace YooAsset
|
||||
string filePath = GetBuildinFileLoadPath(bundle);
|
||||
return FileUtility.ReadAllBytes(filePath);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
public virtual string ReadBundleFileText(PackageBundle bundle)
|
||||
{
|
||||
@@ -270,6 +276,11 @@ namespace YooAsset
|
||||
if (Exists(bundle) == false)
|
||||
return null;
|
||||
|
||||
#if UNITY_ANDROID
|
||||
//TODO : 安卓平台内置文件属于APK压缩包内的文件。
|
||||
YooLogger.Error($"Android platform not support read buildin bundle file text !");
|
||||
return null;
|
||||
#else
|
||||
if (bundle.Encrypted)
|
||||
{
|
||||
if (DecryptionServices == null)
|
||||
@@ -292,6 +303,7 @@ namespace YooAsset
|
||||
string filePath = GetBuildinFileLoadPath(bundle);
|
||||
return FileUtility.ReadAllText(filePath);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#region 内部方法
|
||||
@@ -326,8 +338,8 @@ namespace YooAsset
|
||||
}
|
||||
public string GetCatalogFileLoadPath()
|
||||
{
|
||||
string fileName = Path.GetFileNameWithoutExtension(DefaultBuildinFileSystemDefine.BuildinCatalogFileName);
|
||||
return YooAssetSettingsData.GetYooResourcesLoadPath(PackageName, fileName);
|
||||
string fileName = DefaultBuildinFileSystemDefine.BuildinCatalogFileName;
|
||||
return PathUtility.Combine(YooAssetSettingsData.GetRequestYooDefaultBuildinRoot(), PackageName, fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -5,22 +5,16 @@ using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public class DefaultBuildinFileSystemBuild : UnityEditor.Build.IPreprocessBuildWithReport
|
||||
public class DefaultBuildinFileSystemBuild
|
||||
{
|
||||
public int callbackOrder { get { return 0; } }
|
||||
|
||||
/// <summary>
|
||||
/// 在构建应用程序前自动生成内置资源目录文件。
|
||||
/// 原理:搜索StreamingAssets目录下的所有资源文件,然后将这些文件信息写入文件,并存储在Resources目录下。
|
||||
/// 输出包裹的内置资源目录文件
|
||||
/// </summary>
|
||||
public void OnPreprocessBuild(UnityEditor.Build.Reporting.BuildReport report)
|
||||
/// <exception cref="System.Exception"></exception>
|
||||
public static void ExportBuildinCatalogFile()
|
||||
{
|
||||
YooLogger.Log("Begin to create catalog file !");
|
||||
|
||||
string savePath = YooAssetSettingsData.GetYooResourcesFullPath();
|
||||
if (UnityEditor.AssetDatabase.DeleteAsset(savePath))
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
|
||||
string rootPath = YooAssetSettingsData.GetYooDefaultBuildinRoot();
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
|
||||
if (rootDirectory.Exists == false)
|
||||
@@ -87,7 +81,7 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
// 创建内置清单实例
|
||||
var buildinFileCatalog = ScriptableObject.CreateInstance<DefaultBuildinFileCatalog>();
|
||||
var buildinFileCatalog = new DefaultBuildinFileCatalog();
|
||||
buildinFileCatalog.PackageName = packageName;
|
||||
buildinFileCatalog.PackageVersion = packageVersion;
|
||||
|
||||
@@ -111,6 +105,8 @@ namespace YooAsset
|
||||
continue;
|
||||
if (fileInfo.Name == $"{packageName}_{packageVersion}.report")
|
||||
continue;
|
||||
if (fileInfo.Name == DefaultBuildinFileSystemDefine.BuildinCatalogFileName)
|
||||
continue;
|
||||
|
||||
string fileName = fileInfo.Name;
|
||||
if (fileMapping.TryGetValue(fileName, out string bundleGUID))
|
||||
@@ -125,18 +121,13 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
// 创建输出目录
|
||||
string fullPath = YooAssetSettingsData.GetYooResourcesFullPath();
|
||||
string fullPath = YooAssetSettingsData.GetYooDefaultBuildinRoot();
|
||||
string saveFilePath = $"{fullPath}/{packageName}/{DefaultBuildinFileSystemDefine.BuildinCatalogFileName}";
|
||||
FileUtility.CreateFileDirectory(saveFilePath);
|
||||
|
||||
// 创建输出文件
|
||||
UnityEditor.AssetDatabase.CreateAsset(buildinFileCatalog, saveFilePath);
|
||||
UnityEditor.EditorUtility.SetDirty(buildinFileCatalog);
|
||||
#if UNITY_2019
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
#else
|
||||
UnityEditor.AssetDatabase.SaveAssetIfDirty(buildinFileCatalog);
|
||||
#endif
|
||||
File.WriteAllText(saveFilePath, JsonUtility.ToJson(buildinFileCatalog, false));
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
|
||||
Debug.Log($"Succeed to save buildin file catalog : {saveFilePath}");
|
||||
return true;
|
||||
|
||||
@@ -6,6 +6,6 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 内置清单文件名称
|
||||
/// </summary>
|
||||
public const string BuildinCatalogFileName = "BuildinCatalog.asset";
|
||||
public const string BuildinCatalogFileName = "BuildinCatalog.json";
|
||||
}
|
||||
}
|
||||
@@ -176,6 +176,12 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.LoadBuildinRawBundle)
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
//TODO : 安卓平台内置文件属于APK压缩包内的文件。
|
||||
_steps = ESteps.Done;
|
||||
Result = new RawBundleResult(_fileSystem, _bundle);
|
||||
Status = EOperationStatus.Succeed;
|
||||
#else
|
||||
string filePath = _fileSystem.GetBuildinFileLoadPath(_bundle);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
@@ -190,6 +196,7 @@ namespace YooAsset
|
||||
Error = $"Can not found buildin raw bundle file : {filePath}";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
@@ -8,9 +9,11 @@ namespace YooAsset
|
||||
{
|
||||
None,
|
||||
LoadCatalog,
|
||||
WaitForRequest,
|
||||
Done,
|
||||
}
|
||||
|
||||
private UnityWebRequest _request;
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
@@ -28,12 +31,39 @@ namespace YooAsset
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
string catalogFilePath = _fileSystem.GetCatalogFileLoadPath();
|
||||
|
||||
if (_steps == ESteps.LoadCatalog)
|
||||
{
|
||||
string catalogFilePath = _fileSystem.GetCatalogFileLoadPath();
|
||||
var catalog = Resources.Load<DefaultBuildinFileCatalog>(catalogFilePath);
|
||||
_request = UnityWebRequest.Get(catalogFilePath);
|
||||
_request.SendWebRequest();
|
||||
_steps = ESteps.WaitForRequest;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.WaitForRequest)
|
||||
{
|
||||
// 等待请求完成
|
||||
if (!_request.isDone)
|
||||
return;
|
||||
|
||||
if (_request.result != UnityWebRequest.Result.Success)
|
||||
{
|
||||
_request.Dispose();
|
||||
_request = null;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load catalog file: {_request.error}";
|
||||
return;
|
||||
}
|
||||
|
||||
// 解析 JSON
|
||||
string jsonText = _request.downloadHandler.text;
|
||||
var catalog = JsonUtility.FromJson<DefaultBuildinFileCatalog>(jsonText);
|
||||
if (catalog == null)
|
||||
{
|
||||
_request.Dispose();
|
||||
_request = null;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load catalog file : {catalogFilePath}";
|
||||
@@ -42,6 +72,8 @@ namespace YooAsset
|
||||
|
||||
if (catalog.PackageName != _fileSystem.PackageName)
|
||||
{
|
||||
_request.Dispose();
|
||||
_request = null;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Catalog file package name {catalog.PackageName} cannot match the file system package name {_fileSystem.PackageName}";
|
||||
@@ -55,6 +87,8 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
YooLogger.Log($"Package '{_fileSystem.PackageName}' buildin catalog files count : {catalog.Wrappers.Count}");
|
||||
_request.Dispose();
|
||||
_request = null;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
|
||||
@@ -190,19 +190,19 @@ namespace YooAsset
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.APPEND_FILE_EXTENSION)
|
||||
{
|
||||
AppendFileExtension = (bool)value;
|
||||
AppendFileExtension = Convert.ToBoolean(value);
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.DOWNLOAD_MAX_CONCURRENCY)
|
||||
{
|
||||
DownloadMaxConcurrency = (int)value;
|
||||
DownloadMaxConcurrency = Convert.ToInt32(value);
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.DOWNLOAD_MAX_REQUEST_PER_FRAME)
|
||||
{
|
||||
DownloadMaxRequestPerFrame = (int)value;
|
||||
DownloadMaxRequestPerFrame = Convert.ToInt32(value);
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.RESUME_DOWNLOAD_MINMUM_SIZE)
|
||||
{
|
||||
ResumeDownloadMinimumSize = (long)value;
|
||||
ResumeDownloadMinimumSize = Convert.ToInt64(value);
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.RESUME_DOWNLOAD_RESPONSE_CODES)
|
||||
{
|
||||
|
||||
@@ -85,15 +85,22 @@ namespace YooAsset
|
||||
|
||||
// 创建验证元素类
|
||||
string fileRootPath = chidDirectory.FullName;
|
||||
string dataFilePath = $"{fileRootPath}/{ DefaultCacheFileSystemDefine.BundleDataFileName}";
|
||||
string infoFilePath = $"{fileRootPath}/{ DefaultCacheFileSystemDefine.BundleInfoFileName}";
|
||||
string dataFilePath = $"{fileRootPath}/{DefaultCacheFileSystemDefine.BundleDataFileName}";
|
||||
string infoFilePath = $"{fileRootPath}/{DefaultCacheFileSystemDefine.BundleInfoFileName}";
|
||||
|
||||
// 存储的数据文件追加文件格式
|
||||
if (_fileSystem.AppendFileExtension)
|
||||
{
|
||||
string dataFileExtension = FindDataFileExtension(chidDirectory);
|
||||
if (string.IsNullOrEmpty(dataFileExtension) == false)
|
||||
if (string.IsNullOrEmpty(dataFileExtension))
|
||||
{
|
||||
//注意:覆盖安装的情况下,缓存文件可能会没有后缀格式,需要删除重新下载!
|
||||
dataFilePath = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
dataFilePath += dataFileExtension;
|
||||
}
|
||||
}
|
||||
|
||||
var element = new VerifyFileElement(_fileSystem.PackageName, bundleGUID, fileRootPath, dataFilePath, infoFilePath);
|
||||
|
||||
@@ -94,11 +94,11 @@ namespace YooAsset
|
||||
{
|
||||
if (name == FileSystemParametersDefine.ASYNC_SIMULATE_MIN_FRAME)
|
||||
{
|
||||
_asyncSimulateMinFrame = (int)value;
|
||||
_asyncSimulateMinFrame = Convert.ToInt32(value);
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.ASYNC_SIMULATE_MAX_FRAME)
|
||||
{
|
||||
_asyncSimulateMaxFrame = (int)value;
|
||||
_asyncSimulateMaxFrame = Convert.ToInt32(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace YooAsset
|
||||
{
|
||||
if (name == FileSystemParametersDefine.DISABLE_UNITY_WEB_CACHE)
|
||||
{
|
||||
DisableUnityWebCache = (bool)value;
|
||||
DisableUnityWebCache = Convert.ToBoolean(value);
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.REMOTE_SERVICES)
|
||||
{
|
||||
|
||||
@@ -110,7 +110,7 @@ namespace YooAsset
|
||||
{
|
||||
if (name == FileSystemParametersDefine.DISABLE_UNITY_WEB_CACHE)
|
||||
{
|
||||
DisableUnityWebCache = (bool)value;
|
||||
DisableUnityWebCache = Convert.ToBoolean(value);
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.DECRYPTION_SERVICES)
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
@@ -12,9 +13,11 @@ namespace YooAsset
|
||||
{
|
||||
None,
|
||||
LoadCatalog,
|
||||
WaitForRequest,
|
||||
Done,
|
||||
}
|
||||
|
||||
private UnityWebRequest _request;
|
||||
private readonly DefaultWebServerFileSystem _fileSystem;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
@@ -36,12 +39,39 @@ namespace YooAsset
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
string catalogFilePath = _fileSystem.GetCatalogFileLoadPath();
|
||||
|
||||
if (_steps == ESteps.LoadCatalog)
|
||||
{
|
||||
string catalogFilePath = _fileSystem.GetCatalogFileLoadPath();
|
||||
var catalog = Resources.Load<DefaultBuildinFileCatalog>(catalogFilePath);
|
||||
_request = UnityWebRequest.Get(catalogFilePath);
|
||||
_request.SendWebRequest();
|
||||
_steps = ESteps.WaitForRequest;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.WaitForRequest)
|
||||
{
|
||||
// 等待请求完成
|
||||
if (!_request.isDone)
|
||||
return;
|
||||
|
||||
if (_request.result != UnityWebRequest.Result.Success)
|
||||
{
|
||||
_request.Dispose();
|
||||
_request = null;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load web server catalog file: {_request.error}";
|
||||
return;
|
||||
}
|
||||
|
||||
// 解析 JSON
|
||||
string jsonText = _request.downloadHandler.text;
|
||||
var catalog = JsonUtility.FromJson<DefaultBuildinFileCatalog>(jsonText);
|
||||
if (catalog == null)
|
||||
{
|
||||
_request.Dispose();
|
||||
_request = null;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load web server catalog file : {catalogFilePath}";
|
||||
@@ -50,6 +80,8 @@ namespace YooAsset
|
||||
|
||||
if (catalog.PackageName != _fileSystem.PackageName)
|
||||
{
|
||||
_request.Dispose();
|
||||
_request = null;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Web server catalog file package name {catalog.PackageName} cannot match the file system package name {_fileSystem.PackageName}";
|
||||
@@ -64,6 +96,8 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
YooLogger.Log($"Package '{_fileSystem.PackageName}' catalog files count : {catalog.Wrappers.Count}");
|
||||
_request.Dispose();
|
||||
_request = null;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
|
||||
@@ -83,6 +83,6 @@ namespace YooAsset
|
||||
/// 文件系统初始化参数列表
|
||||
/// 注意:列表最后一个元素作为主文件系统!
|
||||
/// </summary>
|
||||
public List<FileSystemParameters> FileSystemParameterList;
|
||||
public readonly List<FileSystemParameters> FileSystemParameterList = new List<FileSystemParameters>();
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,14 @@ namespace YooAsset
|
||||
{
|
||||
internal class OperationSystem
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[UnityEngine.RuntimeInitializeOnLoadMethod(UnityEngine.RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
private static void OnRuntimeInitialize()
|
||||
{
|
||||
DestroyAll();
|
||||
}
|
||||
#endif
|
||||
|
||||
private static readonly List<AsyncOperationBase> _operations = new List<AsyncOperationBase>(1000);
|
||||
private static readonly List<AsyncOperationBase> _newList = new List<AsyncOperationBase>(1000);
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal static class HandleFactory
|
||||
{
|
||||
private static readonly Dictionary<Type, Func<ProviderOperation, HandleBase>> _handleFactory = new Dictionary<Type, Func<ProviderOperation, HandleBase>>()
|
||||
{
|
||||
{ typeof(AssetHandle), op => new AssetHandle(op) },
|
||||
{ typeof(SceneHandle), op => new SceneHandle(op) },
|
||||
{ typeof(SubAssetsHandle), op => new SubAssetsHandle(op) },
|
||||
{ typeof(AllAssetsHandle), op => new AllAssetsHandle(op) },
|
||||
{ typeof(RawFileHandle), op => new RawFileHandle(op) }
|
||||
};
|
||||
|
||||
public static HandleBase CreateHandle(ProviderOperation operation, Type type)
|
||||
{
|
||||
if (_handleFactory.TryGetValue(type, out var factory) == false)
|
||||
{
|
||||
throw new NotImplementedException($"Handle type {type.FullName} is not supported.");
|
||||
}
|
||||
return factory(operation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4d6ef91e069948c48b7ca60be4c218ee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
@@ -69,8 +69,8 @@ namespace YooAsset
|
||||
|
||||
private ESteps _steps = ESteps.None;
|
||||
private readonly LoadBundleFileOperation _mainBundleLoader;
|
||||
private readonly List<LoadBundleFileOperation> _bundleLoaders = new List<LoadBundleFileOperation>();
|
||||
private readonly List<HandleBase> _handles = new List<HandleBase>();
|
||||
private readonly List<LoadBundleFileOperation> _bundleLoaders = new List<LoadBundleFileOperation>(10);
|
||||
private readonly HashSet<HandleBase> _handles = new HashSet<HandleBase>();
|
||||
|
||||
|
||||
public ProviderOperation(ResourceManager manager, string providerGUID, AssetInfo assetInfo)
|
||||
@@ -220,20 +220,7 @@ namespace YooAsset
|
||||
// 引用计数增加
|
||||
RefCount++;
|
||||
|
||||
HandleBase handle;
|
||||
if (typeof(T) == typeof(AssetHandle))
|
||||
handle = new AssetHandle(this);
|
||||
else if (typeof(T) == typeof(SceneHandle))
|
||||
handle = new SceneHandle(this);
|
||||
else if (typeof(T) == typeof(SubAssetsHandle))
|
||||
handle = new SubAssetsHandle(this);
|
||||
else if (typeof(T) == typeof(AllAssetsHandle))
|
||||
handle = new AllAssetsHandle(this);
|
||||
else if (typeof(T) == typeof(RawFileHandle))
|
||||
handle = new RawFileHandle(this);
|
||||
else
|
||||
throw new System.NotImplementedException();
|
||||
|
||||
HandleBase handle = HandleFactory.CreateHandle(this, typeof(T));
|
||||
_handles.Add(handle);
|
||||
return handle as T;
|
||||
}
|
||||
@@ -258,9 +245,9 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public void ReleaseAllHandles()
|
||||
{
|
||||
for (int i = _handles.Count - 1; i >= 0; i--)
|
||||
List<HandleBase> tempers = _handles.ToList();
|
||||
foreach (var handle in tempers)
|
||||
{
|
||||
var handle = _handles[i];
|
||||
handle.Release();
|
||||
}
|
||||
}
|
||||
@@ -276,7 +263,7 @@ namespace YooAsset
|
||||
|
||||
// 注意:创建临时列表是为了防止外部逻辑在回调函数内创建或者释放资源句柄。
|
||||
// 注意:回调方法如果发生异常,会阻断列表里的后续回调方法!
|
||||
List<HandleBase> tempers = new List<HandleBase>(_handles);
|
||||
List<HandleBase> tempers = _handles.ToList();
|
||||
foreach (var hande in tempers)
|
||||
{
|
||||
if (hande.IsValid)
|
||||
|
||||
@@ -3,6 +3,16 @@ namespace YooAsset
|
||||
{
|
||||
public class AssetInfo
|
||||
{
|
||||
internal enum ELoadMethod
|
||||
{
|
||||
None = 0,
|
||||
LoadAsset,
|
||||
LoadSubAssets,
|
||||
LoadAllAssets,
|
||||
LoadScene,
|
||||
LoadRawFile,
|
||||
}
|
||||
|
||||
private readonly PackageAsset _packageAsset;
|
||||
private string _providerGUID;
|
||||
|
||||
@@ -21,6 +31,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public string Error { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 加载方法
|
||||
/// </summary>
|
||||
internal ELoadMethod LoadMethod;
|
||||
|
||||
/// <summary>
|
||||
/// 资源对象
|
||||
/// </summary>
|
||||
|
||||
@@ -174,7 +174,7 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源依赖列表
|
||||
/// 获取依赖列表
|
||||
/// 注意:传入的资源对象一定合法有效!
|
||||
/// </summary>
|
||||
public PackageBundle[] GetAllDependencies(PackageAsset packageAsset)
|
||||
@@ -188,6 +188,21 @@ namespace YooAsset
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取依赖列表
|
||||
/// 注意:传入的资源包对象一定合法有效!
|
||||
/// </summary>
|
||||
public PackageBundle[] GetAllDependencies(PackageBundle packageBundle)
|
||||
{
|
||||
List<PackageBundle> result = new List<PackageBundle>(packageBundle.DependBundleIDs.Length);
|
||||
foreach (var dependID in packageBundle.DependBundleIDs)
|
||||
{
|
||||
var dependBundle = GetMainPackageBundle(dependID);
|
||||
result.Add(dependBundle);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试获取包裹的资源
|
||||
/// </summary>
|
||||
|
||||
@@ -176,7 +176,17 @@ namespace YooAsset
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var depends = ActiveManifest.GetAllDependencies(assetInfo.Asset);
|
||||
PackageBundle[] depends;
|
||||
if (assetInfo.LoadMethod == AssetInfo.ELoadMethod.LoadAllAssets)
|
||||
{
|
||||
var mainBundle = ActiveManifest.GetMainPackageBundle(assetInfo.Asset);
|
||||
depends = ActiveManifest.GetAllDependencies(mainBundle);
|
||||
}
|
||||
else
|
||||
{
|
||||
depends = ActiveManifest.GetAllDependencies(assetInfo.Asset);
|
||||
}
|
||||
|
||||
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
||||
foreach (var packageBundle in depends)
|
||||
{
|
||||
|
||||
@@ -610,6 +610,7 @@ namespace YooAsset
|
||||
private SceneHandle LoadSceneInternal(AssetInfo assetInfo, bool waitForAsyncComplete, LoadSceneMode sceneMode, LocalPhysicsMode physicsMode, bool suspendLoad, uint priority)
|
||||
{
|
||||
DebugCheckAssetLoadType(assetInfo.AssetType);
|
||||
assetInfo.LoadMethod = AssetInfo.ELoadMethod.LoadScene;
|
||||
var loadSceneParams = new LoadSceneParameters(sceneMode, physicsMode);
|
||||
var handle = _resourceManager.LoadSceneAsync(assetInfo, loadSceneParams, suspendLoad, priority);
|
||||
if (waitForAsyncComplete)
|
||||
@@ -720,6 +721,7 @@ namespace YooAsset
|
||||
private AssetHandle LoadAssetInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
|
||||
{
|
||||
DebugCheckAssetLoadType(assetInfo.AssetType);
|
||||
assetInfo.LoadMethod = AssetInfo.ELoadMethod.LoadAsset;
|
||||
var handle = _resourceManager.LoadAssetAsync(assetInfo, priority);
|
||||
if (waitForAsyncComplete)
|
||||
handle.WaitForAsyncComplete();
|
||||
@@ -829,6 +831,7 @@ namespace YooAsset
|
||||
private SubAssetsHandle LoadSubAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
|
||||
{
|
||||
DebugCheckAssetLoadType(assetInfo.AssetType);
|
||||
assetInfo.LoadMethod = AssetInfo.ELoadMethod.LoadSubAssets;
|
||||
var handle = _resourceManager.LoadSubAssetsAsync(assetInfo, priority);
|
||||
if (waitForAsyncComplete)
|
||||
handle.WaitForAsyncComplete();
|
||||
@@ -938,6 +941,7 @@ namespace YooAsset
|
||||
private AllAssetsHandle LoadAllAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
|
||||
{
|
||||
DebugCheckAssetLoadType(assetInfo.AssetType);
|
||||
assetInfo.LoadMethod = AssetInfo.ELoadMethod.LoadAllAssets;
|
||||
var handle = _resourceManager.LoadAllAssetsAsync(assetInfo, priority);
|
||||
if (waitForAsyncComplete)
|
||||
handle.WaitForAsyncComplete();
|
||||
|
||||
@@ -5,6 +5,14 @@ namespace YooAsset
|
||||
{
|
||||
public static class YooAssetSettingsData
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[UnityEngine.RuntimeInitializeOnLoadMethod(UnityEngine.RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
private static void OnRuntimeInitialize()
|
||||
{
|
||||
_setting = null;
|
||||
}
|
||||
#endif
|
||||
|
||||
private static YooAssetSettings _setting = null;
|
||||
internal static YooAssetSettings Setting
|
||||
{
|
||||
@@ -212,6 +220,26 @@ namespace YooAsset
|
||||
else
|
||||
return PathUtility.Combine(Application.streamingAssetsPath, Setting.DefaultYooFolderName);
|
||||
}
|
||||
|
||||
internal static string GetRequestYooDefaultBuildinRoot()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
|
||||
return GetRequestStreamingAssetsPath();
|
||||
else
|
||||
return PathUtility.Combine(GetRequestStreamingAssetsPath(), Setting.DefaultYooFolderName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取UnityWebRequest StreamingAssets的路径 (OSX and iOS 需要加 file://)
|
||||
/// </summary>
|
||||
internal static string GetRequestStreamingAssetsPath()
|
||||
{
|
||||
#if UNITY_STANDALONE_OSX || UNITY_IOS
|
||||
return $"file://{Application.streamingAssetsPath}";
|
||||
#else
|
||||
return Application.streamingAssetsPath;
|
||||
#endif
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,22 @@
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"versionDefines": [
|
||||
{
|
||||
"name": "com.tuyoogame.yooasset",
|
||||
"expression": "",
|
||||
"define": "YOO_ASSET_2"
|
||||
},
|
||||
{
|
||||
"name": "com.tuyoogame.yooasset",
|
||||
"expression": "2.3",
|
||||
"define": "YOO_ASSET_2_3"
|
||||
},
|
||||
{
|
||||
"name": "com.tuyoogame.yooasset",
|
||||
"expression": "2.3",
|
||||
"define": "YOO_ASSET_2_3_OR_NEWER"
|
||||
}
|
||||
],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -2,12 +2,23 @@ using System;
|
||||
using System.Diagnostics;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public static partial class YooAssets
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
private static void OnRuntimeInitialize()
|
||||
{
|
||||
_isInitialize = false;
|
||||
_packages.Clear();
|
||||
_defaultPackage = null;
|
||||
}
|
||||
#endif
|
||||
|
||||
private static bool _isInitialize = false;
|
||||
private static GameObject _driver = null;
|
||||
private static readonly List<ResourcePackage> _packages = new List<ResourcePackage>();
|
||||
@@ -77,9 +88,9 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建资源包
|
||||
/// 创建资源包裹
|
||||
/// </summary>
|
||||
/// <param name="packageName">资源包名称</param>
|
||||
/// <param name="packageName">包裹名称</param>
|
||||
public static ResourcePackage CreatePackage(string packageName)
|
||||
{
|
||||
CheckException(packageName);
|
||||
@@ -93,9 +104,9 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源包
|
||||
/// 获取资源包裹
|
||||
/// </summary>
|
||||
/// <param name="packageName">资源包名称</param>
|
||||
/// <param name="packageName">包裹名称</param>
|
||||
public static ResourcePackage GetPackage(string packageName)
|
||||
{
|
||||
CheckException(packageName);
|
||||
@@ -106,9 +117,9 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试获取资源包
|
||||
/// 尝试获取资源包裹
|
||||
/// </summary>
|
||||
/// <param name="packageName">资源包名称</param>
|
||||
/// <param name="packageName">包裹名称</param>
|
||||
public static ResourcePackage TryGetPackage(string packageName)
|
||||
{
|
||||
CheckException(packageName);
|
||||
@@ -116,9 +127,17 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除资源包
|
||||
/// 获取所有资源包裹
|
||||
/// </summary>
|
||||
/// <param name="packageName">资源包名称</param>
|
||||
public static List<ResourcePackage> GetAllPackages()
|
||||
{
|
||||
return _packages.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除资源包裹
|
||||
/// </summary>
|
||||
/// <param name="packageName">包裹名称</param>
|
||||
public static bool RemovePackage(string packageName)
|
||||
{
|
||||
CheckException(packageName);
|
||||
@@ -130,9 +149,9 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除资源包
|
||||
/// 移除资源包裹
|
||||
/// </summary>
|
||||
/// <param name="package">资源包实例对象</param>
|
||||
/// <param name="package">包裹实例对象</param>
|
||||
public static bool RemovePackage(ResourcePackage package)
|
||||
{
|
||||
CheckException(package);
|
||||
@@ -149,9 +168,9 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测资源包是否存在
|
||||
/// 检测资源包裹是否存在
|
||||
/// </summary>
|
||||
/// <param name="packageName">资源包名称</param>
|
||||
/// <param name="packageName">包裹名称</param>
|
||||
public static bool ContainsPackage(string packageName)
|
||||
{
|
||||
CheckException(packageName);
|
||||
|
||||
@@ -5,6 +5,14 @@ namespace YooAsset
|
||||
{
|
||||
internal class YooAssetsDriver : MonoBehaviour
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
private static void OnRuntimeInitialize()
|
||||
{
|
||||
LastestUpdateFrame = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
private static int LastestUpdateFrame = 0;
|
||||
|
||||
void Update()
|
||||
|
||||
@@ -23,7 +23,10 @@ namespace YooAsset
|
||||
{
|
||||
if (_assetBundle != null)
|
||||
{
|
||||
_assetBundle.TTUnload(true);
|
||||
if (_packageBundle.Encrypted)
|
||||
_assetBundle.Unload(true);
|
||||
else
|
||||
_assetBundle.TTUnload(true);
|
||||
}
|
||||
}
|
||||
public override string GetBundleFilePath()
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace YooAsset
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly PackageBundle _packageBundle;
|
||||
private readonly AssetBundle _assetBundle;
|
||||
|
||||
|
||||
public WXAssetBundleResult(IFileSystem fileSystem, PackageBundle packageBundle, AssetBundle assetBundle)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
@@ -23,7 +23,10 @@ namespace YooAsset
|
||||
{
|
||||
if (_assetBundle != null)
|
||||
{
|
||||
_assetBundle.WXUnload(true);
|
||||
if (_packageBundle.Encrypted)
|
||||
_assetBundle.Unload(true);
|
||||
else
|
||||
_assetBundle.WXUnload(true);
|
||||
}
|
||||
}
|
||||
public override string GetBundleFilePath()
|
||||
|
||||
@@ -3,9 +3,6 @@ using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.U2D;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using YooAsset;
|
||||
|
||||
@@ -231,6 +228,7 @@ public class WebFileStreamDecryption : IWebDecryptionServices
|
||||
{
|
||||
public WebDecryptResult LoadAssetBundle(WebDecryptFileInfo fileInfo)
|
||||
{
|
||||
/*
|
||||
byte[] copyData = new byte[fileInfo.FileData.Length];
|
||||
Buffer.BlockCopy(fileInfo.FileData, 0, copyData, 0, fileInfo.FileData.Length);
|
||||
|
||||
@@ -242,5 +240,15 @@ public class WebFileStreamDecryption : IWebDecryptionServices
|
||||
WebDecryptResult decryptResult = new WebDecryptResult();
|
||||
decryptResult.Result = AssetBundle.LoadFromMemory(copyData);
|
||||
return decryptResult;
|
||||
*/
|
||||
|
||||
for (int i = 0; i < fileInfo.FileData.Length; i++)
|
||||
{
|
||||
fileInfo.FileData[i] ^= BundleStream.KEY;
|
||||
}
|
||||
|
||||
WebDecryptResult decryptResult = new WebDecryptResult();
|
||||
decryptResult.Result = AssetBundle.LoadFromMemory(fileInfo.FileData);
|
||||
return decryptResult;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "com.tuyoogame.yooasset",
|
||||
"displayName": "YooAsset",
|
||||
"version": "2.3.3-preview",
|
||||
"version": "2.3.4-preview",
|
||||
"unity": "2019.4",
|
||||
"description": "unity3d resources management system.",
|
||||
"author": {
|
||||
|
||||
Reference in New Issue
Block a user