ImporterMenu.cs
1.47 KB
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
using System.IO;
using UnityEditor;
using UnityEngine;
namespace UniGLTF
{
public static class ImporterMenu
{
[MenuItem(UniGLTFVersion.MENU + "/Import", priority = 1)]
public static void ImportMenu()
{
var path = EditorUtility.OpenFilePanel("open gltf", "", "gltf,glb,zip");
if (string.IsNullOrEmpty(path))
{
return;
}
if (Application.isPlaying)
{
//
// load into scene
//
var context = new ImporterContext();
context.Load(path);
context.ShowMeshes();
Selection.activeGameObject = context.Root;
}
else
{
//
// save as asset
//
if (path.StartsWithUnityAssetPath())
{
Debug.LogWarningFormat("disallow import from folder under the Assets");
return;
}
var assetPath = EditorUtility.SaveFilePanel("save prefab", "Assets", Path.GetFileNameWithoutExtension(path), "prefab");
if (string.IsNullOrEmpty(path))
{
return;
}
// import as asset
gltfAssetPostprocessor.ImportAsset(path, Path.GetExtension(path).ToLower(), UnityPath.FromFullpath(assetPath));
}
}
}
}