123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- #if !UNITY_2018_3_OR_NEWER
- using UnityEngine;
- using UnityEditor;
- using System.Collections.Generic;
- using UnityEngine.Formats.Fbx.Exporter;
- using System.Linq;
- namespace UnityEditor.Formats.Fbx.Exporter
- {
- internal class ManualUpdateEditorWindow : EditorWindow
- {
- int[] selectedNodesToDestroy;
- int[] selectedNodesToRename;
- FbxPrefabUtility m_fbxPrefabUtility;
- FbxPrefab m_fbxPrefab;
- GUIContent[] options;
- List<string> m_nodesToCreate;
- List<string> m_nodesToDestroy;
- List<string> m_nodesToRename;
- List<string> m_nodeNameToSuggest;
- public bool Verbose { get { return UnityEditor.Formats.Fbx.Exporter.ExportSettings.instance.VerboseProperty; } }
- public void Init(FbxPrefabUtility fbxPrefabUtility, FbxPrefab fbxPrefab)
- {
- if(fbxPrefab == null)
- {
- return;
- }
- FbxPrefabUtility.UpdateList updates = new FbxPrefabUtility.UpdateList(new FbxRepresentation(fbxPrefab.FbxHistory), fbxPrefab.FbxModel.transform, fbxPrefab);
- m_fbxPrefabUtility = fbxPrefabUtility;
- m_fbxPrefab = fbxPrefab;
- // Convert Hashset into List
- m_nodesToCreate = updates.NodesToCreate.ToList();
- m_nodesToDestroy = updates.NodesToDestroy.ToList();
- m_nodesToRename = updates.NodesToRename.ToList();
- // Create the dropdown list
- m_nodeNameToSuggest = new List<string>();
- m_nodeNameToSuggest.AddRange(m_nodesToCreate);
- m_nodeNameToSuggest.AddRange(m_nodesToRename);
- // Keep track of the selected combo option in each type
- selectedNodesToDestroy = new int[m_nodesToDestroy.Count];
- selectedNodesToRename = new int[m_nodesToRename.Count];
- // Default option for nodes to rename. Shows the current name mapping
- for (int i = 0; i < m_nodesToRename.Count; i++)
- {
- for (int j = 0; j < m_nodeNameToSuggest.Count; j++)
- {
- if (m_nodeNameToSuggest[j] == m_nodesToRename[i])
- {
- // Add extra 1 for the [Delete] option
- selectedNodesToRename[i] = j + 1;
- }
- }
- }
- }
- void OnGUI()
- {
- // If there is nothing to map, sync prefab automatically and close the window
- if (m_nodesToDestroy.Count == 0 && m_nodesToRename.Count == 0)
- {
- m_fbxPrefabUtility.SyncPrefab();
- Close();
- }
- //Titles of the columns
- GUILayout.BeginHorizontal();
- GUILayout.Label("Unity Names", EditorStyles.boldLabel);
- GUILayout.Label("FBX Names", EditorStyles.boldLabel);
- GUILayout.EndHorizontal();
- // List of nodes that will be destroyed on the Unity object, unless the user wants to map them
- for (int i = 0; i < m_nodesToDestroy.Count; i++)
- {
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(m_nodesToDestroy[i]);
- List<GUIContent> listFbxNames = new List<GUIContent>();
- listFbxNames.Add(new GUIContent("[Delete]"));
- for (int j = 0; j < m_nodeNameToSuggest.Count; j++)
- {
- listFbxNames.Add(new GUIContent(m_fbxPrefabUtility.GetFBXObjectName(m_nodeNameToSuggest[j])));
- }
- options = listFbxNames.ToArray();
- selectedNodesToDestroy[i] = EditorGUILayout.Popup(selectedNodesToDestroy[i], options);
- GUILayout.EndHorizontal();
- }
- // List of nodes that will be renamed on the Unity object, unless the user wants to map them or delete them
- for (int i = 0; i < m_nodesToRename.Count; i++)
- {
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(m_fbxPrefabUtility.GetUnityObjectName(m_nodesToRename[i]));
- List<GUIContent> listFbxNames = new List<GUIContent>();
- listFbxNames.Add(new GUIContent("[Delete]"));
- for (int j = 0; j < m_nodeNameToSuggest.Count; j++)
- {
- listFbxNames.Add(new GUIContent(m_fbxPrefabUtility.GetFBXObjectName(m_nodeNameToSuggest[j])));
- }
- options = listFbxNames.ToArray();
- selectedNodesToRename[i] = EditorGUILayout.Popup(selectedNodesToRename[i], options);
- GUILayout.EndHorizontal();
- }
- GUILayout.BeginHorizontal();
- if (GUILayout.Button("Apply Changes"))
- {
- ApplyChanges();
- //Close editor window
- Close();
- }
- if (GUILayout.Button("Cancel"))
- {
- //Close editor window
- Close();
- }
- GUILayout.EndHorizontal();
- }
- void ApplyChanges()
- {
- // Nodes to Destroy have Unity names
- for (int i = 0; i < m_nodesToDestroy.Count; i++)
- {
- // != [Delete]
- if (selectedNodesToDestroy[i] != 0)
- {
- StringPair stringpair = new StringPair();
- stringpair.FBXObjectName = options[selectedNodesToDestroy[i]].text;
- stringpair.UnityObjectName = m_nodesToDestroy[i];
- m_fbxPrefab.NameMapping.Add(stringpair);
- if (Verbose)
- {
- Debug.Log("Mapped Unity: " + stringpair.UnityObjectName + " to FBX: " + stringpair.FBXObjectName);
- }
- }
- }
- // Nodes to Rename have FBX names
- for (int i = 0; i < m_nodesToRename.Count; i++)
- {
- string currentUnityNodeName = m_fbxPrefabUtility.GetUnityObjectName(m_nodesToRename[i]);
- // == [Delete]
- if (selectedNodesToRename[i] == 0)
- {
- // Remove previous mapping
- m_fbxPrefabUtility.RemoveMappingUnityObjectName(currentUnityNodeName);
- }
- else
- {
- if (currentUnityNodeName != m_fbxPrefabUtility.GetUnityObjectName(options[selectedNodesToRename[i]].text))
- {
- m_fbxPrefabUtility.RemoveMappingUnityObjectName(currentUnityNodeName);
- StringPair stringpair = new StringPair();
- stringpair.FBXObjectName = options[selectedNodesToRename[i]].text;
- stringpair.UnityObjectName = currentUnityNodeName;
- m_fbxPrefab.NameMapping.Add(stringpair);
- if (Verbose)
- {
- Debug.Log("Mapped Unity: " + stringpair.UnityObjectName + " to FBX: " + stringpair.FBXObjectName);
- }
- }
- else
- {
- if (Verbose)
- {
- Debug.Log("ALREADY Mapped Unity: " + currentUnityNodeName + " to FBX: " + options[selectedNodesToRename[i]].text);
- }
- }
- }
- }
- m_fbxPrefabUtility.SyncPrefab();
- }
- }
- }
- #endif // !UNITY_2018_3_OR_NEWER
|