Skip to content

Commit

Permalink
check prefab root matches GO instead of if parent null
Browse files Browse the repository at this point in the history
- this ensures that it is possible to convert a model instance parented under a different GO.
- also added a comment explaining why
  • Loading branch information
vkovec committed Feb 23, 2018
1 parent eceefdb commit d32b6a1
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions Assets/FbxExporters/Editor/ConvertToModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,27 @@ public static GameObject Convert (
string directoryFullPath = null,
string fbxFullPath = null)
{
if(toConvert.transform.parent == null){
PrefabType unityPrefabType = PrefabUtility.GetPrefabType(toConvert);
if (unityPrefabType == PrefabType.ModelPrefabInstance) {
// don't re-export fbx
// create prefab out of model instance in scene, link to existing fbx
var mainAsset = PrefabUtility.GetPrefabParent(toConvert) as GameObject;
var mainAssetRelPath = AssetDatabase.GetAssetPath(mainAsset);
var mainAssetAbsPath = Directory.GetParent(Application.dataPath) + "/" + mainAssetRelPath;
SetupFbxPrefab(toConvert, mainAsset, mainAssetRelPath, mainAssetAbsPath);

return toConvert;
}
// Only create the prefab (no FBX export) if we have selected the root of a model prefab instance.
// Children of model prefab instances will also have "model prefab instance"
// as their prefab type, so it is important that it is the root that is selected.
//
// e.g. If I have the following hierarchy:
// Cube
// -- Sphere
//
// Both the Cube and Sphere will have ModelPrefabInstance as their prefab type.
// However, when selecting the Sphere to convert, we don't want to connect it to the
// existing FBX but create a new FBX containing just the sphere.
PrefabType unityPrefabType = PrefabUtility.GetPrefabType(toConvert);
if (unityPrefabType == PrefabType.ModelPrefabInstance && toConvert.Equals(PrefabUtility.FindPrefabRoot(toConvert))) {
// don't re-export fbx
// create prefab out of model instance in scene, link to existing fbx
var mainAsset = PrefabUtility.GetPrefabParent(toConvert) as GameObject;
var mainAssetRelPath = AssetDatabase.GetAssetPath(mainAsset);
var mainAssetAbsPath = Directory.GetParent(Application.dataPath) + "/" + mainAssetRelPath;
SetupFbxPrefab(toConvert, mainAsset, mainAssetRelPath, mainAssetAbsPath);

return toConvert;
}

if (string.IsNullOrEmpty(fbxFullPath)) {
Expand Down

0 comments on commit d32b6a1

Please sign in to comment.