TinaX.VFS
# TinaX.VFS
# 简介
TinaX.VFS
是TinaX Framework默认的资产管理服务包.
- 根据Unity Asset Path加载资产,
- 无感知的AssetBundle管理
- AssetBundle打包
- 资产热更新
package name: io.nekonya.tinax.vfs
VFS的主要服务接口:
TinaX.VFSKit.IVFS
namespace TinaX.VFSKit
{
public interface IVFS
{
VFSCustomizable Customizable { get; }
string DownloadWebAssetUrl { get; }
XRuntimePlatform Platform { get; }
string PlatformText { get; }
int DownloadWebAssetTimeout { get; set; }
#region About GC
void Release(UnityEngine.Object asset);
void UnloadUnusedAssets();
#endregion
#region Groups
IGroup[] GetAllGroups();
bool TryGetGroup(string groupName, out IGroup group);
#endregion
#region Extension Packages and Groups
string[] GetExtensionPackagesInVirtualDisk();
Task<bool> AddExtensionPackage(string group_name, bool available_web_vfs = true);
Task<bool> AddExtensionPackageByPath(string extension_package_path, bool available_web_vfs = true);
void AddExtensionPackage(string group_name, Action<bool,VFSException> callback);
string[] GetActiveExtensionGroupNames();
#endregion
#region Load IAsset Sync
IAsset LoadAsset<T>(string assetPath) where T : UnityEngine.Object;
IAsset LoadAsset(string assetPath, Type type);
#endregion
#region Load Asset Sync
T Load<T>(string assetPath) where T : UnityEngine.Object;
UnityEngine.Object Load(string assetPath, Type type);
#endregion
#region Load IAsset Async Task
Task<IAsset> LoadAssetAsync<T>(string assetPath) where T : UnityEngine.Object;
Task<IAsset> LoadAssetAsync(string assetPath, Type type);
#endregion
#region Load Asset Async Task
Task<T> LoadAsync<T>(string assetPath) where T : UnityEngine.Object;
Task<UnityEngine.Object> LoadAsync(string assetPath, Type type);
#endregion
#region Load IAsset Async Callback
void LoadAssetAsync<T>(string assetPath, Action<IAsset> callback) where T : UnityEngine.Object;
void LoadAssetAsync<T>(string assetPath, Action<IAsset, VFSException> callback) where T : UnityEngine.Object;
void LoadAssetAsync(string assetPath, Type type, Action<IAsset, VFSException> callback);
void LoadAssetAsync(string assetPath, Type type, Action<IAsset> callback);
#endregion
#region Load Asset Async Callback
void LoadAsync<T>(string assetPath, Action<T> callback) where T : UnityEngine.Object;
void LoadAsync<T>(string assetPath, Action<T, VFSException> callback) where T : UnityEngine.Object;
void LoadAsync(string assetPath, Type type, Action<UnityEngine.Object, VFSException> callback);
void LoadAsync(string assetPath, Type type, Action<UnityEngine.Object> callback);
#endregion
#region Load Files
Task<byte[]> LoadFileFromStreamingAssetsAsync(string path);
void LoadFileFromStreamingAssetsAsync(string path, Action<byte[], VFSException> callback);
#endregion
#region Patch
void InstallPatch(string path);
#endregion
#region Load Scene
Task<ISceneAsset> LoadSceneAsync(string scenePath);
void LoadSceneAsync(string scenePath, Action<ISceneAsset, XException> callback);
ISceneAsset LoadScene(string scenePath);
#endregion
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
主要服务接口的Facade
TinaX.VFSKit.VFS
1
加载Unity资产:
IAsset txt_asset = vfs.LoadAsset<TextAsset>("Assets/Data/demo.json"); //对象"vfs" (类型为 IVFS)可通过依赖注入等方式获取,或者使用Facade.
TextAsset myText = txt_asset.Get<TextAsset>();
//or TextAsset myText = txt_asset.Asset as TextAsset;
Debug.Log(myText.text);
txt_asset.Release(); //使用后释放资产,以免内存泄漏
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
异步方式加载资产(async/await)
IAsset txt_asset = await vfs.LoadAssetAsync<TextAsset>("Assets/Data/demo.json")
//对象"vfs" (类型为 IVFS)可通过依赖注入等方式获取,或者使用Facade.
Debug.Log(txt_asset.Get<TextAsset>().text);
txt_asset.Release();
1
2
3
4
2
3
4
异步方式加载资产 (回调)
vfs.LoadAssetAsync("Assets/Data/demo.json", typeof(TextAsset), (txt, err) =>
{
//对象"vfs" (类型为 IVFS)可通过依赖注入等方式获取,或者使用Facade.
if (err == null)
{
Debug.Log(txt.Get<TextAsset>().text);
txt.Release();
}
});
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
简化 IAsset.Release()
using(txt_asset = await vfs.LoadAssetAsync<TextAsset>("Assets/Data/demo.json"))
{
Debug.Log(txt_asset.Get<TextAsset>().text);
}
//对象"vfs" (类型为 IVFS)可通过依赖注入等方式获取,或者使用Facade.
1
2
3
4
5
2
3
4
5
不加载 IAsset 接口, 而是直接获取资产本身.
TextAsset myText = vfs.LoadAsync<TextAsset>("Assets/Data/demo.json");
//对象"vfs" (类型为 IVFS)可通过依赖注入等方式获取,或者使用Facade.
Debug.Log(myText.text);
vfs.Release(myText);
1
2
3
4
2
3
4
# VFS面板
# VFS版本管理
# VFS资源打包
上次更新: 2023/10/17, 14:09:52 访问次数: 0