-
Notifications
You must be signed in to change notification settings - Fork 474
/
ImportContext.cs
69 lines (59 loc) · 1.54 KB
/
ImportContext.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
using System.Collections.Generic;
using GLTF.Schema;
using UnityEditor;
#if UNITY_EDITOR
using UnityEditor.AssetImporters;
#endif
namespace UnityGLTF.Plugins
{
public class GLTFImportContext
{
#if UNITY_EDITOR
public readonly AssetImportContext AssetContext;
public string FilePath => AssetContext.assetPath;
public readonly AssetImporter SourceImporter;
#endif
public readonly List<GLTFImportPluginContext> Plugins;
public GLTFSceneImporter SceneImporter;
public GLTFRoot Root => SceneImporter?.Root;
private List<GLTFImportPluginContext> InitializePlugins(GLTFSettings settings)
{
var plugins = new List<GLTFImportPluginContext>();
foreach (var plugin in settings.ImportPlugins)
{
if (plugin != null && plugin.Enabled)
{
var instance = plugin.CreateInstance(this);
if (instance != null) plugins.Add(instance);
}
}
return plugins;
}
#if UNITY_EDITOR
internal GLTFImportContext(AssetImportContext assetImportContext, GLTFSettings settings)
{
AssetContext = assetImportContext;
if (assetImportContext != null)
SourceImporter = AssetImporter.GetAtPath(assetImportContext.assetPath);
Plugins = InitializePlugins(settings);
}
#endif
internal GLTFImportContext(GLTFSettings settings)
{
Plugins = InitializePlugins(settings);
}
public bool TryGetPlugin<T>(out GLTFImportPluginContext o) where T: GLTFImportPluginContext
{
foreach (var plugin in Plugins)
{
if (plugin is T t)
{
o = t;
return true;
}
}
o = null;
return false;
}
}
}