Skip to content

Commit d9be185

Browse files
committed
code review fixes
- made some strings/chars const variables - added a tooltip for the maya compatible name setting + moved the warning into the tooltip
1 parent b677614 commit d9be185

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public class ConvertToModel : System.IDisposable
2121
const string MenuItemName1 = "Assets/Convert To Model";
2222
const string MenuItemName2 = "GameObject/Convert To Model";
2323

24+
const string RegexCharStart = "[";
25+
const string RegexCharEnd = "]";
26+
2427
/// <summary>
2528
/// Clean up this class on garbage collection
2629
/// </summary>
@@ -139,7 +142,8 @@ private static List<GameObject> OnConvertInPlace (GameObject [] unityActiveGOs)
139142

140143
private static string ConvertToValidFilename(string filename)
141144
{
142-
return System.Text.RegularExpressions.Regex.Replace (filename, "[" + new string(Path.GetInvalidFileNameChars()) + "]", "_");
145+
return System.Text.RegularExpressions.Regex.Replace (filename,
146+
RegexCharStart + new string(Path.GetInvalidFileNameChars()) + RegexCharEnd, "_");
143147
}
144148

145149
private static void SetupImportedGameObject(GameObject orig, GameObject imported)

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ public override void OnInspectorGUI() {
1616

1717
exportSettings.weldVertices = EditorGUILayout.Toggle ("Weld Vertices:", exportSettings.weldVertices);
1818
exportSettings.embedTextures = EditorGUILayout.Toggle ("Embed Textures:", exportSettings.embedTextures);
19-
exportSettings.mayaCompatibleNames = EditorGUILayout.Toggle ("Convert to Maya Compatible Naming on export:",
19+
exportSettings.mayaCompatibleNames = EditorGUILayout.Toggle (
20+
new GUIContent("Convert to Maya Compatible Naming:",
21+
"In Maya some symbols such as spaces and accents get replaced when importing an FBX " +
22+
"(e.g. \"foo bar\" becomes \"fooFBXASC032bar\"). " +
23+
"On export, convert the names of GameObjects so they are Maya compatible." +
24+
(exportSettings.mayaCompatibleNames? "" :
25+
"\n\nWARNING: Disabling this feature may result in lost material connections," +
26+
" and unexpected character replacements in Maya.")
27+
),
2028
exportSettings.mayaCompatibleNames);
2129

22-
if (!exportSettings.mayaCompatibleNames) {
23-
EditorGUILayout.HelpBox (
24-
"Disabling this feature may result in lost material connections, and unexpected character replacements in Maya.",
25-
MessageType.Warning);
26-
}
27-
2830
if (GUI.changed) {
2931
EditorUtility.SetDirty (exportSettings);
3032
exportSettings.Save ();

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public class ModelExporter : System.IDisposable
3636

3737
const string ProgressBarTitle = "Fbx Export";
3838

39+
const char InvalidCharReplacement = '_';
40+
41+
const char MayaNamespaceSeparator = ':';
42+
3943
/// <summary>
4044
/// Create instance of example
4145
/// </summary>
@@ -1021,6 +1025,12 @@ private static void EnsureDirectory (string path)
10211025
}
10221026
}
10231027

1028+
/// <summary>
1029+
/// Removes the diacritics (i.e. accents) from letters.
1030+
/// e.g. é becomes e
1031+
/// </summary>
1032+
/// <returns>Text with accents removed.</returns>
1033+
/// <param name="text">Text.</param>
10241034
private static string RemoveDiacritics(string text)
10251035
{
10261036
var normalizedString = text.Normalize(System.Text.NormalizationForm.FormD);
@@ -1043,15 +1053,15 @@ private static string ConvertToMayaCompatibleName(string name)
10431053
string newName = RemoveDiacritics (name);
10441054

10451055
if (char.IsDigit (newName [0])) {
1046-
newName = newName.Insert (0, "_");
1056+
newName = newName.Insert (0, InvalidCharReplacement.ToString());
10471057
}
10481058

10491059
for (int i = 0; i < newName.Length; i++) {
10501060
if (!char.IsLetterOrDigit (newName, i)) {
1051-
if (i < newName.Length-1 && newName [i] == ':') {
1061+
if (i < newName.Length-1 && newName [i] == MayaNamespaceSeparator) {
10521062
continue;
10531063
}
1054-
newName = newName.Replace (newName [i], '_');
1064+
newName = newName.Replace (newName [i], InvalidCharReplacement);
10551065
}
10561066
}
10571067
return newName;

0 commit comments

Comments
 (0)