Skip to content

Commit b155e8f

Browse files
committed
code review fixes
* remove name param from CreateDirectory() * prefix global variables with "unity" * make helper functions local in unityCommands
1 parent 1d38758 commit b155e8f

File tree

3 files changed

+102
-104
lines changed

3 files changed

+102
-104
lines changed

Assets/FbxExporters/Editor/InstallIntegration.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,21 +319,18 @@ private static void WriteFile(string FileName, List<string> Lines )
319319
/// </summary>
320320
/// <returns><c>true</c>, if directory was created, <c>false</c> otherwise.</returns>
321321
/// <param name="path">Path to create.</param>
322-
/// <param name="name">Display name of directory.</param>
323-
protected static bool CreateDirectory(string path, string name){
322+
protected static bool CreateDirectory(string path){
324323
try
325324
{
326325
System.IO.Directory.CreateDirectory(path);
327326
}
328327
catch (Exception xcp)
329328
{
330329
Debug.LogException(xcp);
331-
Debug.LogError(string.Format("Failed to create {0} Folder {1}", name, path));
332330
return false;
333331
}
334332

335333
if (!System.IO.Directory.Exists(path)) {
336-
Debug.LogError(string.Format("Failed to create {0} Folder {1}", name, path));
337334
return false;
338335
}
339336
return true;
@@ -427,7 +424,8 @@ public bool InstallMaya(bool verbose = false)
427424
if (!System.IO.Directory.Exists(modulePath))
428425
{
429426
if (verbose) { Debug.Log(string.Format("Creating Maya Modules Folder {0}", modulePath)); }
430-
if (!CreateDirectory (modulePath, "Maya Modules")) {
427+
if (!CreateDirectory (modulePath)) {
428+
Debug.LogError(string.Format("Failed to create Maya Modules Folder {0}", modulePath));
431429
return false;
432430
}
433431
installed = false;
@@ -498,7 +496,8 @@ private bool SetupUserStartupScript(bool verbose = false){
498496
if (!System.IO.Directory.Exists(MAYA_SCRIPTS_PATH))
499497
{
500498
if (verbose) { Debug.Log(string.Format("Creating Maya Scripts Folder {0}", MAYA_SCRIPTS_PATH)); }
501-
if (!CreateDirectory (MAYA_SCRIPTS_PATH, "Maya Scripts")) {
499+
if (!CreateDirectory (MAYA_SCRIPTS_PATH)) {
500+
Debug.LogError(string.Format("Failed to create Maya Scripts Folder {0}", MAYA_SCRIPTS_PATH));
502501
return false;
503502
}
504503
}

Assets/Integrations/Autodesk/maya/scripts/setupUnityUI.mel

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,25 @@
1313
// #
1414
// ########################################################################
1515

16-
global string $kMenuName = "UnityFbxForMaya";
17-
global string $kMenuDivider = "UnityFbxForMayaDivider";
18-
global string $kMenuLabel = "Unity";
19-
global string $kMenuInsertAfter = "exportActiveFileOptions";
16+
global string $unityMenuName = "UnityFbxForMaya";
17+
global string $unityMenuDivider = "UnityFbxForMayaDivider";
18+
global string $unityMenuLabel = "Unity";
19+
global string $unityMenuInsertAfter = "exportActiveFileOptions";
2020

21-
global string $kImportIconPath = "import.png";
22-
global string $kExportIconPath = "export.png";
23-
global string $kUnityIconPath = "unity.png";
21+
global string $unityImportIconPath = "import.png";
22+
global string $unityExportIconPath = "export.png";
23+
global string $unityIconPath = "unity.png";
2424

25-
global string $kFamilyLabel = "The UnityFbxForMaya plugin allows you to reliably exchange and review your work between Maya and Unity.";
26-
global string $kImportLabel = "Import FBX file from Unity Project and auto-configure for exporting";
27-
global string $kExportLabel = "Export Model to Unity";
25+
global string $unityFamilyLabel = "The UnityFbxForMaya plugin allows you to reliably exchange and review your work between Maya and Unity.";
26+
global string $unityImportLabel = "Import FBX file from Unity Project and auto-configure for exporting";
27+
global string $unityExportLabel = "Export Model to Unity";
2828

2929

30+
global proc string unityWhatsNewVersion(){
31+
return `about -q -version`;
32+
33+
}
34+
3035
global proc setupUnityUI(){
3136

3237
$isHeadless = `optionVar -q "UnityFbxForMaya_Headless"`;
@@ -37,15 +42,10 @@ global proc setupUnityUI(){
3742

3843
evalDeferred -lowestPriority "buildFileMenu; \
3944
$parentMenu = $gMainFileMenu; \
40-
$pluginVersion = whatsNewVersion(); \
45+
$pluginVersion = unityWhatsNewVersion(); \
4146
source \"unityCommands.mel\"; \
42-
menuItem -parent $parentMenu -insertAfter $kMenuInsertAfter -divider true -longDivider false -version $pluginVersion $kMenuDivider; \
43-
menuItem -parent $parentMenu -insertAfter $kMenuDivider -subMenu true -label $kMenuLabel -tearOff true -version $pluginVersion -image $kUnityIconPath -annotation $kFamilyLabel $kMenuName; \
44-
menuItem -parent $kMenuName -label \"Import\" -version $pluginVersion -image $kImportIconPath -annotation $kImportLabel -command \"unityImport\"; \
45-
menuItem -parent $kMenuName -label \"Export\" -version $pluginVersion -image $kExportIconPath -annotation $kExportLabel -command \"unityExport\";";
46-
}
47-
48-
global proc string whatsNewVersion(){
49-
return `about -q -version`;
50-
47+
menuItem -parent $parentMenu -insertAfter $unityMenuInsertAfter -divider true -longDivider false -version $pluginVersion $unityMenuDivider; \
48+
menuItem -parent $parentMenu -insertAfter $unityMenuDivider -subMenu true -label $unityMenuLabel -tearOff true -version $pluginVersion -image $unityIconPath -annotation $unityFamilyLabel $unityMenuName; \
49+
menuItem -parent $unityMenuName -label \"Import\" -version $pluginVersion -image $unityImportIconPath -annotation $unityImportLabel -command \"unityImport\"; \
50+
menuItem -parent $unityMenuName -label \"Export\" -version $pluginVersion -image $unityExportIconPath -annotation $unityExportLabel -command \"unityExport\";";
5151
}

Assets/Integrations/Autodesk/maya/scripts/unityCommands.mel

Lines changed: 77 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,83 @@ global string $UnityExportSet = "UnityFbxExportSet";
1717
global string $UnityFbxFilePathAttr = "unityFbxFilePath";
1818
global string $UnityFbxFileNameAttr = "unityFbxFileName";
1919

20+
// Load a specified settings file
21+
proc int loadUnityFbxSettings(string $fileName, string $settingType){
22+
// check if the file exists
23+
if (`file -q -ex $fileName` == false){
24+
error ("Failed to find Unity Fbx "+$settingType+" Settings at: " + $fileName);
25+
return false;
26+
}
27+
eval ("source \"" + $fileName + "\"");
28+
return true;
29+
}
30+
31+
32+
// Load the Export Settings from file
33+
proc int loadUnityFbxExportSettings(){
34+
$fileName = `optionVar -q "UnityFbxExportSettings"`;
35+
return loadUnityFbxSettings($fileName, "Export");
36+
}
37+
38+
39+
// Load the Import Settings from a file
40+
proc int loadUnityFbxImportSettings(){
41+
$fileName = `optionVar -q "UnityFbxImportSettings"`;
42+
return loadUnityFbxSettings($fileName, "Import");
43+
}
44+
45+
46+
proc string getAttribute(string $node, string $attr){
47+
if (`attributeExists $attr $node`){
48+
return `getAttr ($node + "." + $attr)`;
49+
}
50+
return "";
51+
}
52+
53+
54+
proc storeAttribute(string $node, string $attr, string $attrValue){
55+
$attrType="string";
56+
if (!attributeExists($attr, $node)){
57+
addAttr -shortName $attr -storable true -dataType $attrType $node;
58+
}
59+
setAttr ($node+"."+$attr) -type $attrType $attrValue;
60+
}
61+
62+
63+
proc int setExists(string $setName){
64+
return stringArrayContains($setName, `listSets -allSets`);
65+
}
66+
67+
68+
proc int loadUnityPlugin(string $plugin){
69+
if (`pluginInfo -q -loaded $plugin` == false){
70+
loadPlugin $plugin;
71+
if (`pluginInfo -q -loaded $plugin` == false){
72+
return false;
73+
}
74+
}
75+
return true;
76+
};
77+
78+
79+
proc int loadUnityDependencies(){
80+
// GamePipeline plugin 'SendToUnitySelection' command used in export
81+
$pluginsToLoad = {"GamePipeline", "fbxmaya"};
82+
83+
$ext = "mll";
84+
if (`about -macOS` == true){
85+
$ext = "bundle";
86+
}
87+
88+
// iterate over all the plugins, loading them with extenstion ext, and combining the results
89+
// to return if any of the loads failed
90+
$result = true;
91+
for($plugin in $pluginsToLoad){
92+
$result = $result && `loadUnityPlugin ($plugin + "." + $ext)`;
93+
}
94+
return $result;
95+
}
96+
2097
global proc unityImport(){
2198
// get the global variables
2299
global string $UnityExportSet;
@@ -138,82 +215,4 @@ global proc unityExport(){
138215
if (size($origSelection) > 0){
139216
select -add -ne $origSelection;
140217
}
141-
}
142-
143-
144-
// Load the Export Settings from file
145-
global proc int loadUnityFbxExportSettings(){
146-
$fileName = `optionVar -q "UnityFbxExportSettings"`;
147-
return loadUnityFbxSettings($fileName, "Export");
148-
}
149-
150-
151-
// Load the Import Settings from a file
152-
global proc int loadUnityFbxImportSettings(){
153-
$fileName = `optionVar -q "UnityFbxImportSettings"`;
154-
return loadUnityFbxSettings($fileName, "Import");
155-
}
156-
157-
158-
// Load a specified settings file
159-
global proc int loadUnityFbxSettings(string $fileName, string $settingType){
160-
// check if the file exists
161-
if (`file -q -ex $fileName` == false){
162-
error ("Failed to find Unity Fbx "+$settingType+" Settings at: " + $fileName);
163-
return false;
164-
}
165-
eval ("source \"" + $fileName + "\"");
166-
return true;
167-
}
168-
169-
170-
global proc string getAttribute(string $node, string $attr){
171-
if (`attributeExists $attr $node`){
172-
return `getAttr ($node + "." + $attr)`;
173-
}
174-
return "";
175-
}
176-
177-
178-
global proc storeAttribute(string $node, string $attr, string $attrValue){
179-
$attrType="string";
180-
if (!attributeExists($attr, $node)){
181-
addAttr -shortName $attr -storable true -dataType $attrType $node;
182-
}
183-
setAttr ($node+"."+$attr) -type $attrType $attrValue;
184-
}
185-
186-
187-
global proc int setExists(string $setName){
188-
return stringArrayContains($setName, `listSets -allSets`);
189-
}
190-
191-
192-
global proc int loadUnityPlugin(string $plugin){
193-
if (`pluginInfo -q -loaded $plugin` == false){
194-
loadPlugin $plugin;
195-
if (`pluginInfo -q -loaded $plugin` == false){
196-
return false;
197-
}
198-
}
199-
return true;
200-
};
201-
202-
203-
global proc int loadUnityDependencies(){
204-
// GamePipeline plugin 'SendToUnitySelection' command used in export
205-
$pluginsToLoad = {"GamePipeline", "fbxmaya"};
206-
207-
$ext = "mll";
208-
if (`about -macOS` == true){
209-
$ext = "bundle";
210-
}
211-
212-
// iterate over all the plugins, loading them with extenstion ext, and combining the results
213-
// to return if any of the loads failed
214-
$result = true;
215-
for($plugin in $pluginsToLoad){
216-
$result = $result && `loadUnityPlugin ($plugin + "." + $ext)`;
217-
}
218-
return $result;
219218
}

0 commit comments

Comments
 (0)