-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAssetTypeManager.cs
88 lines (73 loc) · 2.92 KB
/
AssetTypeManager.cs
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
88
using AssetsTools.NET;
using AssetsTools.NET.Extra;
using AssetStudio;
using AssetStudioExporter.AssetTypes;
using AssetStudioExporter.AssetTypes.Feature;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Object = AssetStudioExporter.AssetTypes.Object;
namespace AssetStudioExporter;
public class AssetTypeManager
{
public string VersionString => Version.ToString();
public UnityVersion Version { get; }
readonly AssetsManager am;
public AssetTypeManager(string version, AssetsManager manager)
{
Version = new UnityVersion(version);
am = manager;
}
public T ReadAsset<T>(AssetTypeValueField valueField) where T : IAssetType
{
var type = T.AssetClassID;
return (T)ReadAsset(type, valueField);
}
public IAssetType ReadAsset(AssetClassID type, AssetTypeValueField valueField)
{
return type switch
{
AssetClassID.Object => Object.EmptyObject.Read(valueField, Version),//0
AssetClassID.GameObject => GameObject.Read(valueField, Version),//1
AssetClassID.Component => Component.Read(valueField, Version),//2
AssetClassID.Texture2D => Texture2D.Read(valueField, Version),//28
AssetClassID.TextAsset => TextAsset.Read(valueField, Version),//49
AssetClassID.AudioClip => AudioClip.Read(valueField, Version),//83
AssetClassID.MonoBehaviour => MonoBehaviour.Read(valueField, Version),//114
AssetClassID.MonoScript => MonoScript.Read(valueField, Version),//115
AssetClassID.Font => Font.Read(valueField, Version),//128
AssetClassID.AssetBundle => AssetBundle.Read(valueField, Version),//142
AssetClassID.ResourceManager => ResourceManager.Read(valueField, Version),//147
AssetClassID.Sprite => Sprite.Read(valueField, Version),//213
AssetClassID.SpriteAtlas => SpriteAtlas.Read(valueField, Version),//687078895
_ => Object.EmptyObject.Read(valueField, Version),
};
}
public T ReadObject<T>(AssetTypeValueField valueField) where T : IAssetTypeReader<T>
{
return T.Read(valueField, Version);
}
public bool TryGetExporter(IAssetType asset, [NotNullWhen(true)]out IAssetTypeExporter? exporter)
{
exporter = null;
if (asset is IAssetTypeExporter exporterSelf)
exporter = exporterSelf;
else if (asset is Sprite sprite)
exporter = sprite.CreateExporter(am);
else
return false;
return true;
}
public static bool CanExport<T>()
{
return typeof(T).IsAssignableTo(typeof(IAssetTypeExporter));
}
public static bool CanExport(IAssetType asset)
{
return asset.GetType().IsAssignableTo(typeof(IAssetTypeExporter));
}
}