@@ -86,30 +86,61 @@ macroScript UnityExport category:"File-Export"
86
86
-- Setup UI
87
87
importMenuName = " File-Import"
88
88
exportMenuName = " File-Export"
89
- importMenu = menuMan.findMenu importMenuName
90
- exportMenu = menuMan.findMenu exportMenuName
91
- if importMenu != undefined and exportMenu != undefined do
92
- (
93
- id = genClassID returnValue: true
94
- if menuMan.registerMenuContext id[1 ] then
89
+ fn setupUnityPluginUI = (
90
+ importMenu = menuMan.findMenu importMenuName
91
+ exportMenu = menuMan.findMenu exportMenuName
92
+ if importMenu != undefined and exportMenu != undefined do
95
93
(
96
- global unityImportAction = menuMan.createActionItem " UnityImport" importMenuName -- create an ActionItem from the MacroScript
97
- unityImportAction.setTitle " Import from Unity"
98
- unityImportAction.setUseCustomTitle true
94
+ unityImportTitle = " Import from Unity"
95
+ unityExportTitle = " Export to Unity"
99
96
100
- global unityExportAction = menuMan.createActionItem " UnityExport" exportMenuName
101
- unityExportAction.setTitle " Export to Unity"
102
- unityExportAction.setUseCustomTitle true
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
+ )
103
116
104
- importMenu.addItem unityImportAction - 1 -- add the ActionItem to the menu
105
- exportMenu.addItem unityExportAction - 1
106
- menuMan.updateMenuBar() -- update the menu bar
117
+ if foundUnityImport == false or foundUnityExport == false then (
118
+ id = genClassID returnValue: true
119
+ if menuMan.registerMenuContext id[1 ] then
120
+ (
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
+ )
133
+ menuMan.updateMenuBar() -- update the menu bar
134
+ )
135
+ )
107
136
)
108
- )
137
+ );
138
+ setupUnityPluginUI()
139
+
109
140
-- Make sure that Menu gets removed at shutdown, force menu to reload each time Max is opened
110
141
callbacks.addScript #preSavingMenus (
111
- " importMenu = menuMan.findMenu \" File-Import \" ; \
112
- exportMenu = menuMan.findMenu \" File-Export \" ; \
142
+ " importMenu = menuMan.findMenu \" " + importMenuName + " \" ; \
143
+ exportMenu = menuMan.findMenu \" " + exportMenuName + " \" ; \
113
144
if importMenu != undefined and unityImportAction != undefined then( \
114
145
importMenu.removeItem unityImportAction; \
115
146
) \
0 commit comments