Skip to content

Commit 057f6f9

Browse files
authored
Merge pull request #20 from Unity-Technologies/UNI-21177-convert-default-selection-behavior
Uni 21177 convert default selection behavior
2 parents 54c5276 + 031e8ee commit 057f6f9

File tree

2 files changed

+37
-26
lines changed

2 files changed

+37
-26
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,40 @@ private static List<GameObject> OnConvertInPlace ()
5757

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

60+
var exportSet = ModelExporter.RemoveDuplicateObjects (unityActiveGOs);
61+
GameObject[] gosToExport = new GameObject[exportSet.Count];
62+
exportSet.CopyTo (gosToExport);
63+
6064
// find common ancestor root & filePath;
61-
string filePath = "";
65+
string[] filePaths = new string[gosToExport.Length];
6266
string dirPath = Path.Combine (Application.dataPath, "Objects");
6367

64-
GameObject unityCommonAncestor = null;
65-
int siblingIndex = -1;
66-
67-
foreach (GameObject goObj in unityActiveGOs) {
68-
siblingIndex = goObj.transform.GetSiblingIndex ();
69-
unityCommonAncestor = (goObj.transform.parent != null) ? goObj.transform.parent.gameObject : null;
70-
filePath = Path.Combine (dirPath, goObj.name + ".fbx");
68+
Transform[] unityCommonAncestors = new Transform[gosToExport.Length];
69+
int[] siblingIndices = new int[gosToExport.Length];
7170

72-
break;
71+
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");
7376
}
7477

75-
string fbxFileName = FbxExporters.Editor.ModelExporter.ExportObjects (filePath, unityActiveGOs) as string;
78+
string[] fbxFileNames = new string[filePaths.Length];
79+
80+
for (int j = 0; j < gosToExport.Length; j++) {
81+
fbxFileNames[j] = FbxExporters.Editor.ModelExporter.ExportObjects (filePaths[j],
82+
new UnityEngine.Object[] {gosToExport[j]}) as string;
83+
}
7684

77-
if (fbxFileName != null)
85+
List<GameObject> selection = new List<GameObject> ();
86+
for(int i = 0; i < fbxFileNames.Length; i++)
7887
{
88+
var fbxFileName = fbxFileNames [i];
89+
if (fbxFileName == null) {
90+
Debug.Log (string.Format ("Warning: Export failed for GameObject {0}", gosToExport [i].name));
91+
continue;
92+
}
93+
7994
// make filepath relative to project folder
8095
if (fbxFileName.StartsWith (Application.dataPath, System.StringComparison.CurrentCulture))
8196
{
@@ -100,33 +115,29 @@ private static List<GameObject> OnConvertInPlace ()
100115
unityGO.name = unityMainAsset.name;
101116

102117
// configure transform and maintain local pose
103-
if (unityCommonAncestor != null) {
104-
unityGO.transform.SetParent (unityCommonAncestor.transform, false);
105-
}
118+
unityGO.transform.SetParent (unityCommonAncestors[i], false);
106119

107-
unityGO.transform.SetSiblingIndex (siblingIndex);
120+
unityGO.transform.SetSiblingIndex (siblingIndices[i]);
108121

109122
result.Add (unityObj as GameObject);
110123

111-
// remove (now redundant) gameobjects
112-
for (int i = 0; i < unityActiveGOs.Length; i++) {
124+
// remove (now redundant) gameobject
113125
#if UNI_19965
114-
Object.DestroyImmediate (unityActiveGOs [i]);
126+
Object.DestroyImmediate (unityActiveGOs [i]);
115127
#else
116-
// rename and put under scene root in case we need to check values
117-
unityActiveGOs [i].name = "_safe_to_delete_" + unityActiveGOs [i].name;
118-
unityActiveGOs [i].transform.parent = null;
119-
unityActiveGOs [i].SetActive (false);
128+
// rename and put under scene root in case we need to check values
129+
gosToExport [i].name = "_safe_to_delete_" + gosToExport[i].name;
130+
gosToExport [i].SetActive (false);
120131
#endif
121-
}
122-
123132
// select the instanced Model Prefab
124-
Selection.objects = new GameObject[] { unityGO };
133+
selection.Add(unityGO);
125134
}
126135
}
127136

128137
}
129138

139+
Selection.objects = selection.ToArray ();
140+
130141
return result;
131142
}
132143
}

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ public MeshInfo (GameObject gameObject, Mesh mesh)
838838
/// <summary>
839839
/// Get the GameObject
840840
/// </summary>
841-
private GameObject GetGameObject (Object obj)
841+
private static GameObject GetGameObject (Object obj)
842842
{
843843
if (obj is UnityEngine.Transform) {
844844
var xform = obj as UnityEngine.Transform;

0 commit comments

Comments
 (0)