Skip to content

Commit 8b4da7a

Browse files
authored
Merge pull request #376 from Unity-Technologies/UNI-43868-compatible-naming-convert-confirmation
Uni 43868 compatible naming convert warning dialog
2 parents 0112b9a + 567b456 commit 8b4da7a

File tree

5 files changed

+62
-13
lines changed

5 files changed

+62
-13
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static GameObject Convert (
104104
string fbxFullPath = null,
105105
string prefabDirectoryFullPath = null,
106106
string prefabFullPath = null,
107-
EditorTools.IExportOptions exportOptions = null
107+
EditorTools.ConvertToPrefabSettingsSerialize exportOptions = null
108108
)
109109
{
110110
// Only create the prefab (no FBX export) if we have selected the root of a model prefab instance.
@@ -139,7 +139,7 @@ public static GameObject Convert (
139139
// The import back in to Unity would do this automatically but
140140
// we prefer to control it so that the Maya artist can see the
141141
// same names as exist in Unity.
142-
EnforceUniqueNames (new GameObject[] {toConvert});
142+
EnforceUniqueNames(new GameObject[] { toConvert });
143143

144144
// Export to FBX. It refreshes the database.
145145
{
@@ -282,23 +282,28 @@ public static string IncrementFileName(string path, string filename)
282282
/// <param name="exportSet">Export set.</param>
283283
public static void EnforceUniqueNames(IEnumerable<GameObject> exportSet)
284284
{
285-
Dictionary<string, int> NameToIndexMap = new Dictionary<string, int> ();
285+
Dictionary<string, int> NameToIndexMap = new Dictionary<string, int>();
286286
string format = "{0} {1}";
287287

288-
Queue<GameObject> queue = new Queue<GameObject> (exportSet);
288+
Queue<GameObject> queue = new Queue<GameObject>(exportSet);
289289

290-
while(queue.Count > 0){
291-
var go = queue.Dequeue ();
290+
while (queue.Count > 0)
291+
{
292+
var go = queue.Dequeue();
292293
var name = go.name;
293-
if (NameToIndexMap.ContainsKey (name)) {
294-
go.name = string.Format (format, name, NameToIndexMap [name]);
295-
NameToIndexMap [name]++;
296-
} else {
297-
NameToIndexMap [name] = 1;
294+
if (NameToIndexMap.ContainsKey(name))
295+
{
296+
go.name = string.Format(format, name, NameToIndexMap[name]);
297+
NameToIndexMap[name]++;
298+
}
299+
else
300+
{
301+
NameToIndexMap[name] = 1;
298302
}
299303

300-
foreach (Transform child in go.transform) {
301-
queue.Enqueue (child.gameObject);
304+
foreach (Transform child in go.transform)
305+
{
306+
queue.Enqueue(child.gameObject);
302307
}
303308
}
304309
}

Assets/FbxExporters/Editor/ConvertToPrefabEditorWindow.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ protected override void OnEnable ()
8282
m_prefabExtLabelWidth = m_fbxExtLabelStyle.CalcSize (new GUIContent (".prefab")).x;
8383
}
8484

85+
protected bool ExportSetContainsAnimation ()
86+
{
87+
foreach(var obj in ToExport)
88+
{
89+
var go = ModelExporter.GetGameObject(obj);
90+
if(go.GetComponentInChildren<Animation>() || go.GetComponentInChildren<Animator>())
91+
{
92+
return true;
93+
}
94+
}
95+
return false;
96+
}
97+
8598
protected override bool Export ()
8699
{
87100
if (string.IsNullOrEmpty (m_exportFileName)) {
@@ -105,6 +118,29 @@ protected override bool Export ()
105118
return false;
106119
}
107120

121+
if (SettingsObject.UseMayaCompatibleNames && SettingsObject.AllowSceneModification)
122+
{
123+
string warning = "Names of objects in the hierarchy may change with the Compatible Naming option turned on";
124+
if (ExportSetContainsAnimation())
125+
{
126+
warning = "Compatible Naming option turned on. Names of objects in hierarchy may change and break animations.";
127+
}
128+
129+
// give a warning dialog that indicates that names in the scene may change
130+
int result = UnityEditor.EditorUtility.DisplayDialogComplex(
131+
string.Format("{0} Warning", ModelExporter.PACKAGE_UI_NAME), warning, "OK", "Turn off and continue", "Cancel"
132+
);
133+
if (result == 1)
134+
{
135+
// turn compatible naming off
136+
SettingsObject.SetUseMayaCompatibleNames(false);
137+
}
138+
else if (result == 2)
139+
{
140+
return false;
141+
}
142+
}
143+
108144
if (ToExport.Length == 1) {
109145
var go = ModelExporter.GetGameObject (ToExport [0]);
110146

Assets/FbxExporters/Editor/ConvertToPrefabSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,6 @@ public class ConvertToPrefabSettingsSerialize : ExportOptionsSettingsSerializeBa
7676
public override ExportSettings.LODExportType LODExportType { get { return ExportSettings.LODExportType.All; } }
7777
public override ExportSettings.ObjectPosition ObjectPosition { get { return ExportSettings.ObjectPosition.Reset; } }
7878
public override bool ExportUnrendered { get { return true; } }
79+
public override bool AllowSceneModification { get { return true; } }
7980
}
8081
}

Assets/FbxExporters/Editor/ExportModelSettings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public interface IExportOptions {
105105
ExportSettings.ObjectPosition ObjectPosition { get; }
106106
bool AnimateSkinnedMesh { get; }
107107
bool UseMayaCompatibleNames { get; }
108+
bool AllowSceneModification { get; }
108109
bool ExportUnrendered { get; }
109110
Transform AnimationSource { get; }
110111
Transform AnimationDest { get; }
@@ -145,6 +146,7 @@ public abstract class ExportOptionsSettingsSerializeBase : IExportOptions
145146
public abstract ExportSettings.LODExportType LODExportType { get; }
146147
public abstract ExportSettings.ObjectPosition ObjectPosition { get; }
147148
public abstract bool ExportUnrendered { get; }
149+
public abstract bool AllowSceneModification { get; }
148150
}
149151

150152
[System.Serializable]
@@ -163,5 +165,6 @@ public class ExportModelSettingsSerialize : ExportOptionsSettingsSerializeBase
163165
public void SetObjectPosition(ExportSettings.ObjectPosition objPos){ this.objectPosition = objPos; }
164166
public override bool ExportUnrendered { get { return exportUnrendered; } }
165167
public void SetExportUnredererd(bool exportUnrendered){ this.exportUnrendered = exportUnrendered; }
168+
public override bool AllowSceneModification { get { return false; } }
166169
}
167170
}

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,6 +2212,10 @@ protected int ExportTransformHierarchy(
22122212
string fbxName = unityGo.name;
22132213
if (ExportOptions.UseMayaCompatibleNames) {
22142214
fbxName = ConvertToMayaCompatibleName (unityGo.name);
2215+
if (ExportOptions.AllowSceneModification)
2216+
{
2217+
unityGo.name = fbxName;
2218+
}
22152219
}
22162220

22172221
// create an FbxNode and add it as a child of parent

0 commit comments

Comments
 (0)