Skip to content

Commit eceefdb

Browse files
committed
code review fixes
- move implementation into Convert()
1 parent c52c346 commit eceefdb

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,6 @@ 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-
var mainAssetRelPath = AssetDatabase.GetAssetPath(mainAsset);
96-
var mainAssetAbsPath = Directory.GetParent(Application.dataPath) + "/" + mainAssetRelPath;
97-
SetupFbxPrefab(go, mainAsset, mainAssetRelPath, mainAssetAbsPath);
98-
99-
wasExported.Add(go);
100-
continue;
101-
}
102-
}
103-
10489
wasExported.Add(Convert(go,
10590
directoryFullPath: directoryFullPath));
10691
} catch(System.Exception xcp) {
@@ -132,6 +117,20 @@ public static GameObject Convert (
132117
string directoryFullPath = null,
133118
string fbxFullPath = null)
134119
{
120+
if(toConvert.transform.parent == null){
121+
PrefabType unityPrefabType = PrefabUtility.GetPrefabType(toConvert);
122+
if (unityPrefabType == PrefabType.ModelPrefabInstance) {
123+
// don't re-export fbx
124+
// create prefab out of model instance in scene, link to existing fbx
125+
var mainAsset = PrefabUtility.GetPrefabParent(toConvert) as GameObject;
126+
var mainAssetRelPath = AssetDatabase.GetAssetPath(mainAsset);
127+
var mainAssetAbsPath = Directory.GetParent(Application.dataPath) + "/" + mainAssetRelPath;
128+
SetupFbxPrefab(toConvert, mainAsset, mainAssetRelPath, mainAssetAbsPath);
129+
130+
return toConvert;
131+
}
132+
}
133+
135134
if (string.IsNullOrEmpty(fbxFullPath)) {
136135
// Generate a unique filename.
137136
if (string.IsNullOrEmpty (directoryFullPath)) {
@@ -184,7 +183,7 @@ public static GameObject Convert (
184183

185184

186185
/// <summary>
187-
/// Create the fbx prefab and connect it to the given fbx asset.
186+
/// Create the prefab and connect it to the given fbx asset.
188187
/// </summary>
189188
/// <param name="toConvert">Hierarchy to convert.</param>
190189
/// <param name="unityMainAsset">Main asset in the FBX.</param>

Assets/FbxExporters/Editor/UnitTests/ConvertToModelTest.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,8 @@ public void TestConvertModelInstance()
288288
Assert.That (boxCollider, Is.Not.Null);
289289

290290
// convert to prefab
291-
GameObject[] converted = ConvertToModel.CreateInstantiatedModelPrefab (new GameObject[]{ fbxInstance }, Path.GetDirectoryName(filename));
292-
293-
Assert.That (converted.Length, Is.EqualTo(1));
294-
Assert.That (converted [0], Is.EqualTo (fbxInstance));
291+
GameObject converted = ConvertToModel.Convert (fbxInstance, Path.GetDirectoryName(filename));
292+
Assert.That (converted, Is.EqualTo (fbxInstance));
295293

296294
// check meshes link to original fbx
297295
var prefabCubeMesh = fbxInstance.GetComponent<MeshFilter>().sharedMesh;

0 commit comments

Comments
 (0)