Esempio n. 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="src"></param>
 /// <param name="prefabPath"></param>
 /// <param name="context"></param>
 static void ImportDelayed(string src, UnityPath prefabPath, ImporterContext context)
 {
     EditorApplication.delayCall += () =>
     {
         //
         // After textures imported(To ensure TextureImporter be accessible).
         //
         try
         {
             context.Load();
             context.SaveAsAsset(prefabPath);
             context.EditorDestroyRoot();
         }
         catch (UniGLTFNotSupportedException ex)
         {
             Debug.LogWarningFormat("{0}: {1}",
                                    src,
                                    ex.Message
                                    );
             context.EditorDestroyRootAndAssets();
         }
         catch (Exception ex)
         {
             Debug.LogErrorFormat("import error: {0}", src);
             Debug.LogErrorFormat("{0}", ex);
             context.EditorDestroyRootAndAssets();
         }
     };
 }
Esempio n. 2
0
        /// <summary>
        /// Import GLB.
        /// </summary>
        /// <returns></returns>
        public static void ImportGlb()
        {
            string path = EditorUtility.OpenFilePanel(title: "Open File Dialog", directory: "", extension: "glb");

            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;
                }

                string assetPath = EditorUtility.SaveFilePanel(title: "Save prefab", directory: "Assets", defaultName: Path.GetFileNameWithoutExtension(path), extension: "prefab");

                if (string.IsNullOrEmpty(path))
                {
                    return;
                }

                // import as asset
                GlbAssetPostprocessor.ImportAsset(src: path, prefabPath: UnityPath.FromFullpath(assetPath));
            }
        }