private void DisplayClipMenu(Rect position, int controlID, AnimationClip clip)
        {
            AnimationClip[] clips       = GetOrderedClipList();
            GUIContent[]    menuContent = GetClipMenuContent(clips);
            int             selected    = ClipToIndex(clips, clip);

            // Center popup menu around button widget
            if (Application.platform == RuntimePlatform.OSXEditor)
            {
                position.y = position.y - selected * EditorGUI.kSingleLineHeight - kMenuOffsetMac;
            }

            ClipPopupCallbackInfo.instance = new ClipPopupCallbackInfo(controlID);

            EditorUtility.DisplayCustomMenu(position, menuContent, null, selected, (userData, options, index) =>
            {
                if (index < clips.Length)
                {
                    ClipPopupCallbackInfo.SetSelectedClip(clips[index]);
                }
                else
                {
                    AnimationClip newClip = AnimationWindowUtility.CreateNewClip(state.selection.rootGameObject.name);
                    if (newClip)
                    {
                        AnimationWindowUtility.AddClipToAnimationPlayerComponent(state.activeAnimationPlayer, newClip);
                        ClipPopupCallbackInfo.SetSelectedClip(newClip);
                    }
                }

                ClipPopupCallbackInfo.SendEvent();
            }, null);
        }
        // (case 1029160) Modified version of EditorGUI.DoPopup to fit large data list query.
        private AnimationClip DoClipPopup(AnimationClip clip, GUIStyle style)
        {
            Rect position  = EditorGUILayout.GetControlRect(false, EditorGUI.kSingleLineHeight, style);
            int  controlID = GUIUtility.GetControlID(s_ClipPopupHash, FocusType.Keyboard, position);

            clip = ClipPopupCallbackInfo.GetSelectedClipForControl(controlID, clip);

            Event evt = Event.current;

            switch (evt.type)
            {
            case EventType.Repaint:
                Font originalFont = style.font;
                if (originalFont && EditorGUIUtility.GetBoldDefaultFont() && originalFont == EditorStyles.miniFont)
                {
                    style.font = EditorStyles.miniBoldFont;
                }

                GUIContent buttonContent = EditorGUIUtility.TempContent(CurveUtility.GetClipName(clip));
                buttonContent.tooltip = AssetDatabase.GetAssetPath(clip);

                style.Draw(position, buttonContent, controlID, false);

                style.font = originalFont;
                break;

            case EventType.MouseDown:
                if (evt.button == 0 && position.Contains(evt.mousePosition))
                {
                    DisplayClipMenu(position, controlID, clip);
                    GUIUtility.keyboardControl = controlID;
                    evt.Use();
                }
                break;

            case EventType.KeyDown:
                if (evt.MainActionKeyForControl(controlID))
                {
                    DisplayClipMenu(position, controlID, clip);
                    evt.Use();
                }
                break;
            }

            return(clip);
        }
            public static AnimationClip GetSelectedClipForControl(int controlID, AnimationClip clip)
            {
                Event evt = Event.current;

                if (evt.type == EventType.ExecuteCommand && evt.commandName == kPopupMenuChangedMessage)
                {
                    if (instance == null)
                    {
                        Debug.LogError("Popup menu has no instance");
                        return(clip);
                    }
                    if (instance.m_ControlID == controlID)
                    {
                        clip        = instance.m_SelectedClip;
                        instance    = null;
                        GUI.changed = true;
                        evt.Use();
                    }
                }
                return(clip);
            }