Skip to content

Commit 8ef62ad

Browse files
authored
Merge pull request #72 from Unity-Technologies/UNI-22861-remove-menu-items-from-Assets
UNI-22861 remove menu items from Assets menu
2 parents 1fd2a33 + 5d07447 commit 8ef62ad

File tree

2 files changed

+31
-54
lines changed

2 files changed

+31
-54
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,51 +18,30 @@ namespace Editor
1818
{
1919
public class ConvertToModel : System.IDisposable
2020
{
21-
const string MenuItemName1 = "Assets/Convert To Prefab";
22-
const string MenuItemName2 = "GameObject/Convert To Prefab";
21+
const string MenuItemName1 = "GameObject/Convert To Prefab";
2322

2423
/// <summary>
2524
/// Clean up this class on garbage collection
2625
/// </summary>
2726
public void Dispose () { }
2827

29-
/// <summary>
30-
/// create menu item in the File menu
31-
/// </summary>
32-
[MenuItem (MenuItemName1, false)]
33-
public static void OnMenuItem ()
34-
{
35-
GameObject [] unityGameObjectsToConvert = Selection.GetFiltered<GameObject> (SelectionMode.Editable | SelectionMode.TopLevel);
36-
if (unityGameObjectsToConvert.Length <= 0) {
37-
ModelExporter.DisplayNoSelectionDialog ();
38-
return;
39-
}
40-
41-
Object[] result = CreateInstantiatedModelPrefab (unityGameObjectsToConvert);
42-
if (result.Length > 0) {
43-
Selection.objects = result;
44-
}
45-
}
46-
47-
/// <summary>
48-
// Validate the menu item defined by the function above.
49-
/// </summary>
50-
[MenuItem (MenuItemName1, true)]
51-
public static bool OnValidateMenuItem ()
52-
{
53-
return true;
54-
}
55-
5628
// Add a menu item called "Export Model..." to a GameObject's context menu.
5729
// OnContextItem gets called once per selected object
5830
// (if the parent and child are selected, then OnContextItem will only be called on the parent)
59-
[MenuItem (MenuItemName2, false, 30)]
31+
[MenuItem (MenuItemName1, false, 30)]
6032
static void OnContextItem (MenuCommand command)
6133
{
6234
if (command == null || command.context == null) {
6335
// We were actually invoked from the top GameObject menu,
6436
// not the context menu, so treat it as such.
65-
OnMenuItem();
37+
GameObject [] unityGameObjectsToConvert = Selection.GetFiltered<GameObject> (SelectionMode.Editable | SelectionMode.TopLevel);
38+
if (unityGameObjectsToConvert.Length <= 0) {
39+
ModelExporter.DisplayNoSelectionDialog ();
40+
return;
41+
}
42+
Object[] result = CreateInstantiatedModelPrefab (unityGameObjectsToConvert);
43+
if (result.Length>0)
44+
Selection.objects = result;
6645
return;
6746
}
6847

@@ -71,10 +50,19 @@ static void OnContextItem (MenuCommand command)
7150
Debug.LogError (string.Format("Error: {0} is not a GameObject and cannot be converted", command.context.name));
7251
return;
7352
}
74-
GameObject[] result = CreateInstantiatedModelPrefab (new GameObject[]{selected});
75-
if (result.Length>0)
76-
Selection.objects = result;
53+
GameObject[] result1 = CreateInstantiatedModelPrefab (new GameObject[]{selected});
54+
if (result1.Length>0)
55+
Selection.objects = result1;
56+
57+
}
7758

59+
/// <summary>
60+
// Validate the menu item defined by the function above.
61+
/// </summary>
62+
[MenuItem (MenuItemName1, true, 30)]
63+
public static bool OnValidateMenuItem ()
64+
{
65+
return true;
7866
}
7967

8068
/// <summary>

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ public class ModelExporter : System.IDisposable
3232

3333
const string ReadmeRelativePath = "FbxExporters/README.txt";
3434

35-
const string MenuItemName = "Assets/Export Model...";
35+
// NOTE: The ellipsis at the end of the Menu Item name prevents the context
36+
// from being passed to command, thus resulting in OnContextItem()
37+
// being called only once regardless of what is selected.
38+
const string MenuItemName = "GameObject/Export Model...";
3639

3740
const string FileBaseName = "Untitled";
3841

@@ -1107,10 +1110,11 @@ private void ReplaceFile ()
11071110
}
11081111

11091112
/// <summary>
1110-
/// create menu item in the File menu
1113+
/// Add a menu item to a GameObject's context menu.
11111114
/// </summary>
1112-
[MenuItem (MenuItemName, false)]
1113-
public static void OnMenuItem ()
1115+
/// <param name="command">Command.</param>
1116+
[MenuItem (MenuItemName, false, 30)]
1117+
static void OnContextItem (MenuCommand command)
11141118
{
11151119
if (Selection.objects.Length <= 0) {
11161120
DisplayNoSelectionDialog ();
@@ -1122,34 +1126,19 @@ public static void OnMenuItem ()
11221126
/// <summary>
11231127
// Validate the menu item defined by the function above.
11241128
/// </summary>
1125-
[MenuItem (MenuItemName, true)]
1129+
[MenuItem (MenuItemName, true, 30)]
11261130
public static bool OnValidateMenuItem ()
11271131
{
11281132
return true;
11291133
}
11301134

1131-
// Add a menu item called "Export Model..." to a GameObject's context menu.
1132-
// NOTE: The ellipsis at the end of the Menu Item name prevents the context
1133-
// from being passed to command, thus resulting in OnContextItem()
1134-
// being called only once regardless of what is selected.
1135-
[MenuItem ("GameObject/Export Model...", false, 30)]
1136-
static void OnContextItem (MenuCommand command)
1137-
{
1138-
if (Selection.objects.Length <= 0) {
1139-
DisplayNoSelectionDialog ();
1140-
return;
1141-
}
1142-
OnExport ();
1143-
}
1144-
11451135
public static void DisplayNoSelectionDialog()
11461136
{
11471137
UnityEditor.EditorUtility.DisplayDialog (
11481138
"Fbx Exporter Warning",
11491139
"No GameObjects selected for export.",
11501140
"Ok");
11511141
}
1152-
11531142
//
11541143
// export mesh info from Unity
11551144
//

0 commit comments

Comments
 (0)