Skip to content

Commit 2ee950b

Browse files
committed
if fbx already exists, don't re-export
1 parent c217443 commit 2ee950b

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@ public static GameObject[] CreateInstantiatedModelPrefab (
8686
var wasExported = new List<GameObject>();
8787
foreach(var go in toExport) {
8888
try {
89+
if(go.transform.parent == null){
90+
PrefabType unityPrefabType = PrefabUtility.GetPrefabType(go);
91+
if (unityPrefabType == PrefabType.ModelPrefabInstance) {
92+
// don't re-export fbx
93+
// create prefab out of model instance in scene, link to existing fbx
94+
var mainAsset = PrefabUtility.GetPrefabParent(go) as GameObject;
95+
SetupFbxPrefab(go, mainAsset, AssetDatabase.GetAssetOrScenePath(mainAsset), AssetDatabase.GetAssetOrScenePath(mainAsset));
96+
continue;
97+
}
98+
}
99+
89100
wasExported.Add(Convert(go,
90101
directoryFullPath: directoryFullPath));
91102
} catch(System.Exception xcp) {
@@ -161,6 +172,14 @@ public static GameObject Convert (
161172
// Copy the mesh/materials from the FBX
162173
UpdateFromSourceRecursive (toConvert, unityMainAsset);
163174

175+
SetupFbxPrefab (toConvert, unityMainAsset, projectRelativePath, fbxFullPath);
176+
177+
toConvert.name = Path.GetFileNameWithoutExtension (fbxFullPath);
178+
return toConvert;
179+
}
180+
181+
182+
public static void SetupFbxPrefab(GameObject toConvert, GameObject unityMainAsset, string projectRelativePath, string fbxFullPath){
164183
// Set up the FbxPrefab component so it will auto-update.
165184
// Make sure to delete whatever FbxPrefab history we had.
166185
var fbxPrefab = toConvert.GetComponent<FbxPrefab>();
@@ -179,9 +198,6 @@ public static GameObject Convert (
179198
string.Format("Failed to create prefab asset in [{0}] from fbx [{1}]",
180199
prefabFileName, fbxFullPath));
181200
}
182-
183-
toConvert.name = Path.GetFileNameWithoutExtension (fbxFullPath);
184-
return toConvert;
185201
}
186202

187203
/// <summary>

0 commit comments

Comments
 (0)