29using System.Collections;
37 [MenuItem(
"GameObject/FBX Exporter/Only GameObject",
false, 40)]
40 ExportCurrentGameObject(
false,
false);
43 [MenuItem(
"GameObject/FBX Exporter/With new Materials",
false, 41)]
46 ExportCurrentGameObject(
true,
false);
49 [MenuItem(
"GameObject/FBX Exporter/With new Materials and Textures",
false, 42)]
52 ExportCurrentGameObject(
true,
true);
56 [MenuItem(
"Assets/FBX Exporter/Only GameObject",
false, 30)]
59 ExportCurrentGameObject(
false,
false);
62 [MenuItem(
"Assets/FBX Exporter/With new Materials",
false, 31)]
65 ExportCurrentGameObject(
true,
false);
68 [MenuItem(
"Assets/FBX Exporter/With new Materials and Textures",
false, 32)]
71 ExportCurrentGameObject(
true,
true);
74 private static void ExportCurrentGameObject(
bool copyMaterials,
bool copyTextures)
76 if(Selection.activeGameObject ==
null)
78 EditorUtility.DisplayDialog(
"No Object Selected",
"Please select any GameObject to Export to FBX",
"Okay");
82 GameObject currentGameObject = Selection.activeObject as GameObject;
84 if(currentGameObject ==
null)
86 EditorUtility.DisplayDialog(
"Warning",
"Item selected is not a GameObject",
"Okay");
101 public static string ExportGameObject(GameObject gameObj,
bool copyMaterials,
bool copyTextures,
string oldPath =
null)
105 EditorUtility.DisplayDialog(
"Object is null",
"Please select any GameObject to Export to FBX",
"Okay");
109 string newPath = GetNewPath(gameObj, oldPath);
111 if(newPath !=
null && newPath.Length != 0)
120 EditorUtility.DisplayDialog(
"Warning",
"The extension probably wasn't an FBX file, could not export.",
"Okay");
131 private static string GetNewPath(GameObject gameObject,
string oldPath =
null)
135 string name = gameObject.name;
137 string newPath =
null;
139 newPath = EditorUtility.SaveFilePanelInProject(
"Export FBX File", name +
".fbx",
"fbx",
"Export " + name +
" GameObject to a FBX file");
142 if(oldPath.StartsWith(
"/Assets"))
144 oldPath = Application.dataPath.Remove(Application.dataPath.LastIndexOf(
"/Assets"), 7) + oldPath;
145 oldPath = oldPath.Remove(oldPath.LastIndexOf(
'/'), oldPath.Length - oldPath.LastIndexOf(
'/'));
147 newPath = EditorUtility.SaveFilePanel(
"Export FBX File", oldPath, name +
".fbx",
"fbx");
150 int assetsIndex = newPath.IndexOf(
"Assets");
156 newPath = newPath.Remove(0, assetsIndex);
static bool ExportGameObjToFBX(GameObject gameObj, string newPath, bool copyMaterials=false, bool copyTextures=false)