void OnDisable()
    {
        MecanimEventEditorPopup.Destroy();

        if (eventInspector != null)
        {
            eventInspector.SetPreviewMotion(null);
            eventInspector.SaveData();
        }
    }
    void Reset()
    {
        displayEvents = null;

        targetController   = null;
        targetStateMachine = null;
        targetState        = null;
        targetEvent        = null;

        selectedLayer = 0;
        selectedState = 0;
        selectedEvent = 0;

        MecanimEventEditorPopup.Destroy();
    }
    void OnGUI()
    {
        if (eventInspector == null)
        {
            Reset();
            ShowNotification(new GUIContent("Select a MecanimEventData object first."));
            return;
        }

        RemoveNotification();

        GUILayout.BeginHorizontal();
        {
            EditorGUI.BeginChangeCheck();

            DrawControllerPanel();

            DrawLayerPanel();

            DrawStatePanel();

            if (EditorGUI.EndChangeCheck())
            {
                MecanimEventEditorPopup.Destroy();
            }

            DrawEventPanel();
        }
        GUILayout.EndHorizontal();

        if (targetState != null && targetState.motion != null)
        {
            eventInspector.SetPreviewMotion(targetState.motion);
        }
        else
        {
            eventInspector.SetPreviewMotion(null);
        }

        GUILayout.Space(5);

        GUILayout.BeginHorizontal(GUILayout.MaxHeight(100));
        {
            DrawTimelinePanel();
        }
        GUILayout.EndHorizontal();
    }