Skip to content

Commit ae35d60

Browse files
committed
First release of UI EditorWindow for remapping
1 parent c308e58 commit ae35d60

File tree

4 files changed

+192
-12
lines changed

4 files changed

+192
-12
lines changed

Assets/FbxExporters/Editor/FbxPrefabAutoUpdater.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,9 @@ public string GetUnityObjectName(string fbxObjectName)
265265
return newNameInUnity;
266266
}
267267

268-
268+
/// <summary>
269+
/// Utility function: remove the name mapping matching the unity name specified
270+
/// </summary>
269271
public void RemoveMappingFBXObjectName(string fbxObjectName)
270272
{
271273
FbxPrefab.StringPair stockNameMapping = new FbxPrefab.StringPair();
@@ -283,13 +285,14 @@ public void RemoveMappingFBXObjectName(string fbxObjectName)
283285
}
284286
if (foundMapping)
285287
{
286-
Debug.Log("Successfully removed: " + stockNameMapping.UnityObjectName + " /FBX: " + stockNameMapping.FBXObjectName);
287288
m_fbxPrefab.NameMapping.Remove(stockNameMapping);
288289
}
289290
}
290291
}
291292

292-
293+
/// <summary>
294+
/// Utility function: remove the name mapping matching the FBX name specified
295+
/// </summary>
293296
public void RemoveMappingUnityObjectName(string unityObjectName)
294297
{
295298
FbxPrefab.StringPair stockNameMapping = new FbxPrefab.StringPair();
@@ -307,7 +310,6 @@ public void RemoveMappingUnityObjectName(string unityObjectName)
307310
}
308311
if (foundMapping)
309312
{
310-
Debug.Log("Successfully removed: " + stockNameMapping.UnityObjectName + " /FBX: " + stockNameMapping.FBXObjectName);
311313
m_fbxPrefab.NameMapping.Remove(stockNameMapping);
312314
}
313315
}
@@ -1207,17 +1209,11 @@ public HashSet<GameObject> ImplementUpdates(FbxPrefab prefabInstance)
12071209
}
12081210
}
12091211
}
1210-
1211-
// Rename old nodes (unity names) into new nodes (FBX names).
1212-
/*foreach (var FBXNodeNameToRename in m_nodesToRename)
1213-
{
1214-
prefabNodes[m_fbxPrefabUtility.GetUnityObjectName(FBXNodeNameToRename)].name = FBXNodeNameToRename;
1215-
Log("Renamed {0} into {1}", m_fbxPrefabUtility.GetUnityObjectName(FBXNodeNameToRename), FBXNodeNameToRename);
1216-
}*/
12171212

12181213
// Create or update the new components.
12191214
foreach (var kvp in m_componentsToUpdate) {
12201215
var componentName = kvp.Key;
1216+
// We rename the node before the loop, so the component name now has the FBX object name, instead of the unity one that was saved
12211217
componentName = m_fbxPrefabUtility.GetFBXObjectName(componentName);
12221218
Debug.Log("Component: " + componentName);
12231219
var fbxComponents = kvp.Value;

Assets/FbxExporters/Editor/FbxPrefabInspector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public override void OnInspectorGUI() {
3232

3333
EditorGUILayout.PropertyField(m_GameObjectProp, true);
3434

35+
#if FBXEXPORTER_DEBUG
3536
if (GUILayout.Button("Update prefab manually..."))
3637
{
3738
// Get existing open window or if none, make a new one:
@@ -40,7 +41,6 @@ public override void OnInspectorGUI() {
4041
window.Show();
4142
}
4243

43-
#if FBXEXPORTER_DEBUG
4444
EditorGUILayout.LabelField ("Debug info:");
4545
try {
4646
fbxPrefabUtility.GetFbxHistory().ToJson();
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
using UnityEngine;
2+
using UnityEditor;
3+
using System.Collections.Generic;
4+
using FbxExporters;
5+
using System.Linq;
6+
7+
public class ManualUpdateEditorWindow : EditorWindow
8+
{
9+
int[] selectedNodesToDestroy;
10+
int[] selectedNodesToRename;
11+
12+
FbxPrefabAutoUpdater.FbxPrefabUtility m_fbxPrefabUtility;
13+
FbxPrefab m_fbxPrefab;
14+
GUIContent[] options;
15+
List<string> m_nodesToCreate;
16+
List<string> m_nodesToDestroy;
17+
List<string> m_nodesToRename;
18+
19+
List<string> m_nodeNameToSuggest;
20+
21+
public void Init(FbxPrefabAutoUpdater.FbxPrefabUtility fbxPrefabUtility, FbxPrefab fbxPrefab)
22+
{
23+
FbxPrefabAutoUpdater.FbxPrefabUtility.UpdateList updates = new FbxPrefabAutoUpdater.FbxPrefabUtility.UpdateList(new FbxPrefabAutoUpdater.FbxPrefabUtility.FbxRepresentation(fbxPrefab.FbxHistory), fbxPrefab.FbxModel.transform, fbxPrefab);
24+
25+
m_fbxPrefabUtility = fbxPrefabUtility;
26+
m_fbxPrefab = fbxPrefab;
27+
// Convert Hashset into List
28+
m_nodesToCreate = updates.GetNodesToCreate().ToList();
29+
m_nodesToDestroy = updates.GetNodesToDestroy().ToList();
30+
m_nodesToRename = updates.GetNodesToRename().ToList();
31+
// Create the dropdown list
32+
m_nodeNameToSuggest = new List<string>();
33+
m_nodeNameToSuggest.AddRange(m_nodesToCreate);
34+
m_nodeNameToSuggest.AddRange(m_nodesToRename);
35+
36+
// Add extra 1 for the [Delete] option
37+
selectedNodesToDestroy = new int[m_nodeNameToSuggest.Count + 1];
38+
selectedNodesToRename = new int[m_nodeNameToSuggest.Count + 1];
39+
40+
// Default option for nodes to rename. Shows the current name mapping
41+
for (int i = 0; i < m_nodesToRename.Count; i++)
42+
{
43+
for (int j = 0; j < m_nodeNameToSuggest.Count; j++)
44+
{
45+
if (m_nodeNameToSuggest[j] == m_nodesToRename[i])
46+
{
47+
// Add extra 1 for the [Delete] option
48+
selectedNodesToRename[i] = j + 1;
49+
}
50+
}
51+
}
52+
}
53+
54+
void OnGUI()
55+
{
56+
if (m_nodesToDestroy.Count == 0 && m_nodesToRename.Count == 0)
57+
{
58+
m_fbxPrefabUtility.SyncPrefab();
59+
Close();
60+
}
61+
62+
//Titles of the columns
63+
GUILayout.BeginHorizontal();
64+
GUILayout.Label("Unity Names", EditorStyles.boldLabel);
65+
GUILayout.Label("FBX Names", EditorStyles.boldLabel);
66+
GUILayout.EndHorizontal();
67+
68+
// List of nodes that will be destroyed on the Unity object, unless the user wants to map them
69+
for (int i = 0; i < m_nodesToDestroy.Count; i++)
70+
{
71+
GUILayout.BeginHorizontal();
72+
EditorGUILayout.LabelField(m_nodesToDestroy[i]);
73+
74+
List<GUIContent> listFbxNames = new List<GUIContent>();
75+
listFbxNames.Add(new GUIContent("[Delete]"));
76+
77+
for(int j = 0; j < m_nodeNameToSuggest.Count; j++)
78+
{
79+
listFbxNames.Add(new GUIContent(m_fbxPrefabUtility.GetFBXObjectName(m_nodeNameToSuggest[j])));
80+
}
81+
82+
options = listFbxNames.ToArray();
83+
selectedNodesToDestroy[i] = EditorGUILayout.Popup(selectedNodesToDestroy[i], options);
84+
85+
GUILayout.EndHorizontal();
86+
}
87+
88+
for (int i = 0; i < m_nodesToRename.Count; i++)
89+
{
90+
GUILayout.BeginHorizontal();
91+
EditorGUILayout.LabelField(m_fbxPrefabUtility.GetUnityObjectName(m_nodesToRename[i]));
92+
93+
List<GUIContent> listFbxNames = new List<GUIContent>();
94+
listFbxNames.Add(new GUIContent("[Delete]"));
95+
96+
for (int j = 0; j < m_nodeNameToSuggest.Count; j++)
97+
{
98+
listFbxNames.Add(new GUIContent(m_fbxPrefabUtility.GetFBXObjectName(m_nodeNameToSuggest[j])));
99+
}
100+
101+
options = listFbxNames.ToArray();
102+
103+
selectedNodesToRename[i] = EditorGUILayout.Popup(selectedNodesToRename[i], options);
104+
105+
GUILayout.EndHorizontal();
106+
}
107+
108+
GUILayout.BeginHorizontal();
109+
110+
if (GUILayout.Button("Apply Changes"))
111+
{
112+
ApplyChanges();
113+
//Close editor window
114+
Close();
115+
}
116+
117+
if (GUILayout.Button("Cancel"))
118+
{
119+
//Close editor window
120+
Close();
121+
}
122+
GUILayout.EndHorizontal();
123+
}
124+
125+
void ApplyChanges()
126+
{
127+
// Nodes to Destroy have Unity names
128+
for (int i = 0; i < m_nodesToDestroy.Count; i++)
129+
{
130+
// != [Delete]
131+
if (selectedNodesToDestroy[i] != 0)
132+
{
133+
FbxPrefab.StringPair stringpair = new FbxPrefab.StringPair();
134+
stringpair.FBXObjectName = options[selectedNodesToDestroy[i]].text;
135+
stringpair.UnityObjectName = m_nodesToDestroy[i];
136+
137+
m_fbxPrefab.NameMapping.Add(stringpair);
138+
Debug.Log("Mapped Unity: " + stringpair.UnityObjectName + " to FBX: " + stringpair.FBXObjectName);
139+
}
140+
}
141+
142+
// Nodes to Rename have FBX names
143+
for (int i = 0; i < m_nodesToRename.Count; i++)
144+
{
145+
string currentUnityNodeName = m_fbxPrefabUtility.GetUnityObjectName(m_nodesToRename[i]);
146+
// == [Delete]
147+
if (selectedNodesToRename[i] == 0)
148+
{
149+
// Remove previous mapping
150+
m_fbxPrefabUtility.RemoveMappingUnityObjectName(currentUnityNodeName);
151+
}
152+
else
153+
{
154+
if (currentUnityNodeName != m_fbxPrefabUtility.GetUnityObjectName(options[selectedNodesToRename[i]].text))
155+
{
156+
m_fbxPrefabUtility.RemoveMappingUnityObjectName(currentUnityNodeName);
157+
FbxPrefab.StringPair stringpair = new FbxPrefab.StringPair();
158+
stringpair.FBXObjectName = options[selectedNodesToRename[i]].text;
159+
stringpair.UnityObjectName = currentUnityNodeName;
160+
m_fbxPrefab.NameMapping.Add(stringpair);
161+
162+
Debug.Log("Mapped Unity: " + stringpair.UnityObjectName + " to FBX: " + stringpair.FBXObjectName);
163+
}
164+
else
165+
{
166+
Debug.Log("ALREADY Mapped Unity: " + currentUnityNodeName + " to FBX: " + options[selectedNodesToRename[i]].text);
167+
}
168+
}
169+
}
170+
171+
m_fbxPrefabUtility.SyncPrefab();
172+
}
173+
}

Assets/FbxExporters/Editor/ManualUpdateEditorWindow.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)