Skip to content

Commit a3cebff

Browse files
committed
Added validation methods for contextual menus
1 parent 0afcfd2 commit a3cebff

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
@@ -2964,6 +2964,24 @@ static void OnClipContextClick(MenuCommand command)
29642964
}
29652965
}
29662966

2967+
/// <summary>
2968+
/// Validate the menu item defined by the function OnClipContextClick.
2969+
/// </summary>
2970+
[MenuItem(TimelineClipMenuItemName, true, 31)]
2971+
static bool ValidateOnClipContextClick()
2972+
{
2973+
Object[] selectedObjects = Selection.objects;
2974+
2975+
foreach (Object editorClipSelected in selectedObjects)
2976+
{
2977+
if (editorClipSelected.GetType().Name.Contains("EditorClip"))
2978+
{
2979+
return true;
2980+
}
2981+
}
2982+
return false;
2983+
}
2984+
29672985
public static bool ExportSingleEditorClip(Object editorClipSelected)
29682986
{
29692987
if (editorClipSelected.GetType().Name.Contains("EditorClip"))
@@ -3043,6 +3061,31 @@ public static void OnPlayableDirectorGameObjectContextClick(MenuCommand command)
30433061
}
30443062
}
30453063

3064+
/// <summary>
3065+
/// Validate the menu item defined by the function OnPlayableDirectorGameObjectContextClick.
3066+
/// </summary>
3067+
[MenuItem(ClipMenuItemName, true, 31)]
3068+
public static bool ValidateClipContextClick()
3069+
{
3070+
Object[] selection = Selection.objects;
3071+
3072+
if (selection == null || selection.Length == 0)
3073+
{
3074+
return false;
3075+
}
3076+
3077+
foreach (Object obj in selection)
3078+
{
3079+
GameObject gameObj = obj as GameObject;
3080+
if (gameObj != null && gameObj.GetComponent<PlayableDirector>() != null)
3081+
{
3082+
return true;
3083+
}
3084+
}
3085+
3086+
return false;
3087+
}
3088+
30463089
public static void ExportAllTimelineClips(GameObject objectWithPlayableDirector, string folderPath)
30473090
{
30483091
PlayableDirector pd = objectWithPlayableDirector.GetComponent<PlayableDirector>();
@@ -3069,31 +3112,6 @@ public static void ExportAllTimelineClips(GameObject objectWithPlayableDirector,
30693112
}
30703113
}
30713114
}
3072-
3073-
/// <summary>
3074-
/// Validate the menu item defined by the function above.
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-
}
30973115

30983116
/// <summary>
30993117
/// Add a menu item "Export Model..." to a GameObject's context menu.
@@ -3110,7 +3128,7 @@ static void OnContextItem (MenuCommand command)
31103128
}
31113129

31123130
/// <summary>
3113-
/// Validate the menu item defined by the function above.
3131+
/// Validate the menu item defined by the function OnContextItem.
31143132
/// </summary>
31153133
[MenuItem (MenuItemName, true, 30)]
31163134
public static bool OnValidateMenuItem ()
@@ -3133,7 +3151,7 @@ static void ModelOnlyOnContextItem (MenuCommand command)
31333151
}
31343152

31353153
/// <summary>
3136-
/// Validate the menu item defined by the function above.
3154+
/// Validate the menu item defined by the function ModelOnlyOnContextItem.
31373155
/// </summary>
31383156
[MenuItem (ModelOnlyMenuItemName, true, 30)]
31393157
public static bool ModelOnlyOnValidateMenuItem ()
@@ -3163,7 +3181,23 @@ static void OnAnimOnlyContextItem (MenuCommand command)
31633181
[MenuItem (AnimOnlyMenuItemName, true, 30)]
31643182
public static bool OnValidateAnimOnlyMenuItem ()
31653183
{
3166-
return true;
3184+
Object[] selection = Selection.objects;
3185+
3186+
if (selection == null || selection.Length == 0)
3187+
{
3188+
return false;
3189+
}
3190+
3191+
foreach (Object obj in selection)
3192+
{
3193+
GameObject gameObj = obj as GameObject;
3194+
if (gameObj != null && (gameObj.GetComponent<Animation>() != null || gameObj.GetComponent<Animator>() != null))
3195+
{
3196+
return true;
3197+
}
3198+
}
3199+
3200+
return false;
31673201
}
31683202

31693203
public static void DisplayNoSelectionDialog()

0 commit comments

Comments
 (0)