Skip to content

Commit bb44de2

Browse files
authored
Merge pull request #335 from Unity-Technologies/Uni-39667-ValidationContextMenus
Uni-39667-ValidationContextMenus-Added validation methods for contextual menus
2 parents 717a515 + d92d526 commit bb44de2

File tree

1 file changed

+62
-28
lines changed

1 file changed

+62
-28
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2973,6 +2973,24 @@ static void OnClipContextClick(MenuCommand command)
29732973
}
29742974
}
29752975

2976+
/// <summary>
2977+
/// Validate the menu item defined by the function OnClipContextClick.
2978+
/// </summary>
2979+
[MenuItem(TimelineClipMenuItemName, true, 31)]
2980+
static bool ValidateOnClipContextClick()
2981+
{
2982+
Object[] selectedObjects = Selection.objects;
2983+
2984+
foreach (Object editorClipSelected in selectedObjects)
2985+
{
2986+
if (editorClipSelected.GetType().Name.Contains("EditorClip"))
2987+
{
2988+
return true;
2989+
}
2990+
}
2991+
return false;
2992+
}
2993+
29762994
public static bool ExportSingleEditorClip(Object editorClipSelected)
29772995
{
29782996
if (editorClipSelected.GetType().Name.Contains("EditorClip"))
@@ -3052,6 +3070,31 @@ public static void OnPlayableDirectorGameObjectContextClick(MenuCommand command)
30523070
}
30533071
}
30543072

3073+
/// <summary>
3074+
/// Validate the menu item defined by the function OnPlayableDirectorGameObjectContextClick.
3075+
/// </summary>
3076+
[MenuItem(ClipMenuItemName, true, 31)]
3077+
public static bool ValidateClipContextClick()
3078+
{
3079+
Object[] selection = Selection.objects;
3080+
3081+
if (selection == null || selection.Length == 0)
3082+
{
3083+
return false;
3084+
}
3085+
3086+
foreach (Object obj in selection)
3087+
{
3088+
GameObject gameObj = obj as GameObject;
3089+
if (gameObj != null && gameObj.GetComponent<PlayableDirector>() != null)
3090+
{
3091+
return true;
3092+
}
3093+
}
3094+
3095+
return false;
3096+
}
3097+
30553098
public static void ExportAllTimelineClips(GameObject objectWithPlayableDirector, string folderPath)
30563099
{
30573100
PlayableDirector pd = objectWithPlayableDirector.GetComponent<PlayableDirector>();
@@ -3078,31 +3121,6 @@ public static void ExportAllTimelineClips(GameObject objectWithPlayableDirector,
30783121
}
30793122
}
30803123
}
3081-
3082-
/// <summary>
3083-
/// Validate the menu item defined by the function above.
3084-
/// </summary>
3085-
[MenuItem(ClipMenuItemName, true, 31)]
3086-
public static bool ValidateClipContextClick()
3087-
{
3088-
Object[] selection = Selection.objects;
3089-
3090-
if (selection == null || selection.Length == 0)
3091-
{
3092-
return false;
3093-
}
3094-
3095-
foreach (Object obj in selection)
3096-
{
3097-
GameObject gameObj = obj as GameObject;
3098-
if (gameObj !=null && gameObj.GetComponent<PlayableDirector>() != null)
3099-
{
3100-
return true;
3101-
}
3102-
}
3103-
3104-
return false;
3105-
}
31063124

31073125
/// <summary>
31083126
/// Add a menu item "Export Model..." to a GameObject's context menu.
@@ -3119,7 +3137,7 @@ static void OnContextItem (MenuCommand command)
31193137
}
31203138

31213139
/// <summary>
3122-
/// Validate the menu item defined by the function above.
3140+
/// Validate the menu item defined by the function OnContextItem.
31233141
/// </summary>
31243142
[MenuItem (MenuItemName, true, 30)]
31253143
public static bool OnValidateMenuItem ()
@@ -3142,7 +3160,7 @@ static void ModelOnlyOnContextItem (MenuCommand command)
31423160
}
31433161

31443162
/// <summary>
3145-
/// Validate the menu item defined by the function above.
3163+
/// Validate the menu item defined by the function ModelOnlyOnContextItem.
31463164
/// </summary>
31473165
[MenuItem (ModelOnlyMenuItemName, true, 30)]
31483166
public static bool ModelOnlyOnValidateMenuItem ()
@@ -3172,7 +3190,23 @@ static void OnAnimOnlyContextItem (MenuCommand command)
31723190
[MenuItem (AnimOnlyMenuItemName, true, 30)]
31733191
public static bool OnValidateAnimOnlyMenuItem ()
31743192
{
3175-
return true;
3193+
Object[] selection = Selection.objects;
3194+
3195+
if (selection == null || selection.Length == 0)
3196+
{
3197+
return false;
3198+
}
3199+
3200+
foreach (Object obj in selection)
3201+
{
3202+
GameObject gameObj = obj as GameObject;
3203+
if (gameObj != null && (gameObj.GetComponent<Animation>() != null || gameObj.GetComponent<Animator>() != null))
3204+
{
3205+
return true;
3206+
}
3207+
}
3208+
3209+
return false;
31763210
}
31773211

31783212
public static void DisplayNoSelectionDialog()

0 commit comments

Comments
 (0)