Skip to content

Instantly share code, notes, and snippets.

@junaid109
Created May 25, 2023 09:40
Show Gist options
  • Save junaid109/65706c9442cd7c8f3eac9d4019acc00e to your computer and use it in GitHub Desktop.
Save junaid109/65706c9442cd7c8f3eac9d4019acc00e to your computer and use it in GitHub Desktop.
GLTFImportMenu
using UnityEditor;
using UnityEngine;
public class GLTFImportMenu : EditorWindow
{
[MenuItem("Custom/GLTF Import")]
static void Init()
{
GLTFImportMenu window = (GLTFImportMenu)EditorWindow.GetWindow(typeof(GLTFImportMenu));
window.Show();
}
private string gltfPath;
void OnGUI()
{
GUILayout.Label("GLTF Import", EditorStyles.boldLabel);
gltfPath = EditorGUILayout.TextField("GLTF File Path:", gltfPath);
if (GUILayout.Button("Import GLTF"))
{
ImportGLTF();
}
}
private void ImportGLTF()
{
if (string.IsNullOrEmpty(gltfPath))
{
Debug.LogError("GLTF file path is empty!");
return;
}
GameObject gltfObject = GLTFUtility.ImportGLTF(gltfPath);
if (gltfObject != null)
{
gltfObject.name = System.IO.Path.GetFileNameWithoutExtension(gltfPath);
Selection.activeGameObject = gltfObject;
Debug.Log("GLTF imported successfully!");
}
else
{
Debug.LogError("Failed to import GLTF!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment