|
1 | 1 | -- MacroScripts that will perform actions
|
2 |
| -macroScript UnityImport category:"File-Import" |
| 2 | +macroScript UnityImport category:"Unity" |
3 | 3 | (
|
4 | 4 | origObjects = #()
|
5 | 5 |
|
@@ -45,7 +45,7 @@ macroScript UnityImport category:"File-Import"
|
45 | 45 | callbacks.removeScripts #postImport id:#unityPlugin
|
46 | 46 | )
|
47 | 47 | )
|
48 |
| -macroScript UnityExport category:"File-Export" |
| 48 | +macroScript UnityExport category:"Unity" |
49 | 49 | (
|
50 | 50 | fn loadUnityFbxExportSettings = (
|
51 | 51 | fbxExportSettings = getINISetting (GetMAXIniFile()) "Unity" "UnityFbxExportSettings"
|
@@ -83,68 +83,135 @@ macroScript UnityExport category:"File-Export"
|
83 | 83 | )
|
84 | 84 | )
|
85 | 85 |
|
86 |
| --- Setup UI |
87 |
| -importMenuName = "File-Import" |
88 |
| -exportMenuName = "File-Export" |
89 |
| -fn setupUnityPluginUI = ( |
90 |
| - importMenu = menuMan.findMenu importMenuName |
91 |
| - exportMenu = menuMan.findMenu exportMenuName |
92 |
| - if importMenu != undefined and exportMenu != undefined do |
93 |
| - ( |
94 |
| - unityImportTitle = "Import from Unity" |
95 |
| - unityExportTitle = "Export to Unity" |
96 |
| - |
97 |
| - -- check if menu items already exists |
98 |
| - foundUnityImport = false |
99 |
| - for i=1 to importMenu.numItems() do( |
100 |
| - mi = importMenu.getItem i |
101 |
| - if mi.getTitle() == unityImportTitle then( |
102 |
| - foundUnityImport = true |
103 |
| - global unityImportAction = mi |
104 |
| - break |
105 |
| - ) |
106 |
| - ) |
107 |
| - foundUnityExport = false |
108 |
| - for i=1 to exportMenu.numItems() do( |
109 |
| - mi = exportMenu.getItem i |
110 |
| - if mi.getTitle() == unityExportTitle then( |
111 |
| - foundUnityExport = true |
112 |
| - global unityExportAction = mi |
113 |
| - break |
114 |
| - ) |
115 |
| - ) |
116 |
| - |
117 |
| - if foundUnityImport == false or foundUnityExport == false then( |
| 86 | +fn createUnityActionItem macroName category title parentMenu = ( |
| 87 | + local unityAction = menuMan.createActionItem macroName category; --create an ActionItem from the MacroScript |
| 88 | + unityAction.setTitle title; |
| 89 | + unityAction.setUseCustomTitle true; |
| 90 | + parentMenu.addItem unityAction -1; |
| 91 | + unityAction |
| 92 | +); |
| 93 | + |
| 94 | +fn createUnityImportAction title parentMenu = ( |
| 95 | + createUnityActionItem "UnityImport" "Unity" title parentMenu; |
| 96 | +); |
| 97 | + |
| 98 | +fn createUnityExportAction title parentMenu = ( |
| 99 | + createUnityActionItem "UnityExport" "Unity" title parentMenu; |
| 100 | +); |
| 101 | + |
| 102 | +-- Setup UI in existing Import/Export menus if using 3ds Max 2018+ |
| 103 | +if (maxVersion())[1] >= 20000 then( |
| 104 | + global importMenuName = "File-Import" |
| 105 | + global exportMenuName = "File-Export" |
| 106 | + |
| 107 | + -- get the import menu |
| 108 | + global getImportMenu |
| 109 | + fn getImportMenu = ( |
| 110 | + menuMan.findMenu importMenuName |
| 111 | + ); |
| 112 | + |
| 113 | + -- get the export menu |
| 114 | + global getExportMenu |
| 115 | + fn getExportMenu = ( |
| 116 | + menuMan.findMenu exportMenuName |
| 117 | + ); |
| 118 | + |
| 119 | + -- Setup UI |
| 120 | + fn setupUnityPluginUI = ( |
| 121 | + local importMenu = getImportMenu() |
| 122 | + local exportMenu = getExportMenu() |
| 123 | + if importMenu != undefined and exportMenu != undefined do |
| 124 | + ( |
| 125 | + local unityImportTitle = "Import from Unity" |
| 126 | + local unityExportTitle = "Export to Unity" |
| 127 | + |
| 128 | + -- check if menu items already exist, delete if they do |
| 129 | + local foundUnityImport = false |
| 130 | + for i=1 to importMenu.numItems() while not foundUnityImport do( |
| 131 | + local mi = importMenu.getItem i |
| 132 | + if mi.getTitle() == unityImportTitle then( |
| 133 | + importMenu.removeItem mi |
| 134 | + foundUnityImport = true |
| 135 | + ) |
| 136 | + ) |
| 137 | + local foundUnityExport = false |
| 138 | + for i=1 to exportMenu.numItems() while not foundUnityExport do( |
| 139 | + local mi = exportMenu.getItem i |
| 140 | + if mi.getTitle() == unityExportTitle then( |
| 141 | + exportMenu.removeItem mi |
| 142 | + foundUnityExport = true |
| 143 | + ) |
| 144 | + ) |
| 145 | + |
118 | 146 | id = genClassID returnValue:true
|
119 | 147 | if menuMan.registerMenuContext id[1] then
|
120 | 148 | (
|
121 |
| - if foundUnityImport == false do ( |
122 |
| - global unityImportAction = menuMan.createActionItem "UnityImport" importMenuName; --create an ActionItem from the MacroScript |
123 |
| - unityImportAction.setTitle unityImportTitle; |
124 |
| - unityImportAction.setUseCustomTitle true; |
125 |
| - importMenu.addItem unityImportAction -1; --add the ActionItem to the menu |
126 |
| - ) |
127 |
| - if foundUnityExport == false do ( |
128 |
| - global unityExportAction = menuMan.createActionItem "UnityExport" exportMenuName; |
129 |
| - unityExportAction.setTitle unityExportTitle; |
130 |
| - unityExportAction.setUseCustomTitle true; |
131 |
| - exportMenu.addItem unityExportAction -1; |
132 |
| - ) |
| 149 | + global unityImportAction = createUnityImportAction unityImportTitle importMenu |
| 150 | + global unityExportAction = createUnityExportAction unityExportTitle exportMenu |
| 151 | + |
133 | 152 | menuMan.updateMenuBar() --update the menu bar
|
134 | 153 | )
|
135 |
| - ) |
136 |
| - ) |
137 |
| -); |
138 |
| -setupUnityPluginUI() |
| 154 | + ) |
| 155 | + ); |
| 156 | + setupUnityPluginUI() |
139 | 157 |
|
140 |
| --- Make sure that Menu gets removed at shutdown, force menu to reload each time Max is opened |
141 |
| -callbacks.addScript #preSavingMenus ( |
142 |
| - "importMenu = menuMan.findMenu \""+importMenuName+"\"; \ |
143 |
| - exportMenu = menuMan.findMenu \""+exportMenuName+"\"; \ |
144 |
| - if importMenu != undefined and unityImportAction != undefined then( \ |
145 |
| - importMenu.removeItem unityImportAction; \ |
146 |
| - ) \ |
147 |
| - if exportMenu != undefined and unityExportAction != undefined then( \ |
148 |
| - exportMenu.removeItem unityExportAction; \ |
149 |
| - )" |
| 158 | + -- Make sure that Menu gets removed at shutdown, force menu to reload each time Max is opened |
| 159 | + callbacks.addScript #preSavingMenus ( |
| 160 | + "importMenu = getImportMenu(); \ |
| 161 | + exportMenu = getExportMenu(); \ |
| 162 | + if importMenu != undefined and unityImportAction != undefined then( \ |
| 163 | + importMenu.removeItem unityImportAction; \ |
| 164 | + ) \ |
| 165 | + if exportMenu != undefined and unityExportAction != undefined then( \ |
| 166 | + exportMenu.removeItem unityExportAction; \ |
| 167 | + )" |
| 168 | + ) |
| 169 | +) |
| 170 | +else if (maxVersion())[1] == 19000 then ( |
| 171 | + -- for 3ds Max 2017 |
| 172 | + |
| 173 | + global unityMenuName = "Unity" |
| 174 | + |
| 175 | + global getUnityMenu |
| 176 | + fn getUnityMenu = ( |
| 177 | + menuMan.findMenu unityMenuName |
| 178 | + ); |
| 179 | + |
| 180 | + -- Setup UI |
| 181 | + fn setupUnityPluginUI = ( |
| 182 | + local unityMenu = getUnityMenu() |
| 183 | + local unityImportTitle = "Import" |
| 184 | + local unityExportTitle = "Export" |
| 185 | + if unityMenu != undefined do |
| 186 | + ( |
| 187 | + -- remove the menu if it still exists |
| 188 | + menuMan.unRegisterMenu unityMenu |
| 189 | + ) |
| 190 | + |
| 191 | + id = genClassID returnValue:true |
| 192 | + if menuMan.registerMenuContext id[1] then |
| 193 | + ( |
| 194 | + local mainMenuBar = menuMan.getMainMenuBar() |
| 195 | + local unityMenu = menuMan.createMenu unityMenuName |
| 196 | + local unityMenuItem = menuMan.createSubMenuItem unityMenuName unityMenu |
| 197 | + mainMenuBar.addItem unityMenuItem -1 |
| 198 | + |
| 199 | + createUnityImportAction unityImportTitle unityMenu |
| 200 | + createUnityExportAction unityExportTitle unityMenu |
| 201 | + |
| 202 | + menuMan.updateMenuBar() --update the menu bar |
| 203 | + ) |
| 204 | + ); |
| 205 | + setupUnityPluginUI() |
| 206 | + |
| 207 | + -- Make sure that Menu gets removed at shutdown, force menu to reload each time Max is opened |
| 208 | + callbacks.addScript #preSavingMenus ( |
| 209 | + "unityMenu = getUnityMenu(); \ |
| 210 | + if unityMenu != undefined do ( \ |
| 211 | + menuMan.unRegisterMenu unityMenu; \ |
| 212 | + )" |
| 213 | + ) |
| 214 | +) |
| 215 | +else( |
| 216 | + print "Error: Unity Integration only supports 3ds Max 2017 or later" |
150 | 217 | )
|
0 commit comments