Skip to content

Commit e86eeb8

Browse files
committed
fix so copy component works well with default export behavior
with multi file export we don't have to worry about the hierarchy being the same, everything should just match
1 parent 6aa72d6 commit e86eeb8

File tree

2 files changed

+10
-21
lines changed

2 files changed

+10
-21
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,16 @@ private static List<GameObject> OnConvertInPlace ()
5757

5858
GameObject [] unityActiveGOs = Selection.GetFiltered<GameObject> (SelectionMode.Editable | SelectionMode.TopLevel);
5959

60-
var exportSet = ModelExporter.RemoveDuplicateObjects (unityActiveGOs);
60+
var exportSet = ModelExporter.RemoveRedundantObjects (unityActiveGOs);
6161
GameObject[] gosToExport = new GameObject[exportSet.Count];
6262
exportSet.CopyTo (gosToExport);
6363

6464
// find common ancestor root & filePath;
6565
string[] filePaths = new string[gosToExport.Length];
6666
string dirPath = Path.Combine (Application.dataPath, "Objects");
6767

68-
Transform[] unityCommonAncestors = new Transform[gosToExport.Length];
69-
int[] siblingIndices = new int[gosToExport.Length];
70-
7168
for(int n = 0; n < gosToExport.Length; n++){
72-
GameObject goObj = gosToExport[n];
73-
unityCommonAncestors[n] = goObj.transform.parent;
74-
siblingIndices [n] = goObj.transform.GetSiblingIndex ();
75-
filePaths[n] = Path.Combine (dirPath, goObj.name + ".fbx");
69+
filePaths[n] = Path.Combine (dirPath, gosToExport[n].name + ".fbx");
7670
}
7771

7872
string[] fbxFileNames = new string[filePaths.Length];
@@ -110,28 +104,23 @@ private static List<GameObject> OnConvertInPlace ()
110104
{
111105
GameObject unityGO = unityObj as GameObject;
112106
Transform unityGOTransform = unityGO.transform;
107+
Transform origGOTransform = gosToExport [i].transform;
113108

114109
// Set the name to be the name of the instantiated asset.
115110
// This will get rid of the "(Clone)" if it's added
116111
unityGO.name = unityMainAsset.name;
117112

118113
// configure transform and maintain local pose
119-
unityGO.transform.SetParent (unityCommonAncestors[i], false);
114+
unityGOTransform.SetParent (origGOTransform.parent, false);
120115

121-
unityGO.transform.SetSiblingIndex (siblingIndices[i]);
116+
unityGOTransform.SetSiblingIndex (origGOTransform.GetSiblingIndex());
122117

123118
// copy the components over, assuming that the hierarchy order is unchanged
124-
if (unityActiveGOs.Length == 1) {
125-
CopyComponentsRecursive (unityActiveGOs [0], unityGO);
126-
} else {
127-
if (unityActiveGOs.Length != unityGOTransform.childCount) {
128-
Debug.LogWarning (string.Format ("Warning: Exported {0} objects, but only imported {1}",
129-
unityActiveGOs.Length, unityGOTransform.childCount));
130-
}
131-
for (int i = 0, c = unityGOTransform.childCount; i < c; i++) {
132-
CopyComponentsRecursive (unityActiveGOs [i], unityGOTransform.GetChild (i).gameObject);
133-
}
119+
if (origGOTransform.hierarchyCount != unityGOTransform.hierarchyCount) {
120+
Debug.LogWarning (string.Format ("Warning: Exported {0} objects, but only imported {1}",
121+
origGOTransform.hierarchyCount, unityGOTransform.hierarchyCount));
134122
}
123+
CopyComponentsRecursive (gosToExport[i], unityGO);
135124

136125
result.Add (unityObj as GameObject);
137126

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ public int GetHierarchyCount (HashSet<GameObject> exportSet)
508508
/// </summary>
509509
/// <returns>The revised export set</returns>
510510
/// <param name="unityExportSet">Unity export set.</param>
511-
protected HashSet<GameObject> RemoveRedundantObjects(IEnumerable<UnityEngine.Object> unityExportSet)
511+
public static HashSet<GameObject> RemoveRedundantObjects(IEnumerable<UnityEngine.Object> unityExportSet)
512512
{
513513
// basically just remove the descendents from the unity export set
514514
HashSet<GameObject> toExport = new HashSet<GameObject> ();

0 commit comments

Comments
 (0)