public void Save()
                {
                    if (!string.IsNullOrEmpty(_currentFileName))
                    {
                        //If we're in state view first need to apply state changes to state machine view
                        if (_currentMode == eMode.ViewingState)
                        {
                            _editedState.GetEditableObject()._timeline = _stateEditor.ConvertToTimeline();
                        }

                        //Update state machine name to reflect filename
                        TimelineStateMachine stateMachine = ConvertToTimelineStateMachine();
                        stateMachine._name = System.IO.Path.GetFileNameWithoutExtension(_currentFileName);

                        //Save to file
                        SerializeConverter.ToFile(stateMachine, _currentFileName);

                        ClearDirtyFlag();
                        _stateEditor.ClearDirtyFlag();

                        GetEditorWindow().DoRepaint();

                        //Hack, save string on save scene
                        Localisation.SaveStrings();
                    }
                    else
                    {
                        SaveAs();
                    }
                }
                private void RenderLinksForState(TimelineStateEditorGUI state)
                {
                    Timeline timeline = state.GetEditableObject()._timeline;

                    if (timeline != null)
                    {
                        Event[] events = timeline._events;

                        List <EditorStateLink> stateLinks = new List <EditorStateLink>();

                        foreach (IStateMachineEvent evnt in events)
                        {
                            EditorStateLink[] links = evnt.GetEditorLinks();

                            if (links != null)
                            {
                                stateLinks.AddRange(links);
                            }
                        }

                        float fraction = 1.0f / (stateLinks.Count + 1.0f);
                        float current  = fraction;

                        foreach (EditorStateLink link in stateLinks)
                        {
                            if (link._timeline.IsInternal())
                            {
                                TimelineStateEditorGUI toState = FindStateForLink(link);

                                if (toState != null)
                                {
                                    RenderLink(link._description, state, toState, current);
                                }
                            }
                            else
                            {
                                RenderExternalState(link, state, current);
                            }

                            current += fraction;
                        }
                    }
                }
                public void SwitchToStateView(int stateId)
                {
                    TimelineStateEditorGUI state = GetTimelineStateGUI(stateId);

                    if (state != null)
                    {
                        _currentMode = eMode.ViewingState;
                        _editedState = state;
                        _stateEditor.SetTimeline(_editedState.GetEditableObject()._timeline);

                        _editorPrefs._stateId = stateId;
                        SaveEditorPrefs();

                        foreach (TimelineStateEditorGUI stateView in _selectedObjects)
                        {
                            GetEditorWindow().OnDeselectObject(stateView);
                        }
                    }
                }
                protected override TimelineState CreateCopyFrom(SerializedObjectEditorGUI <TimelineState> editorGUI)
                {
                    TimelineStateEditorGUI timeLineGUI = (TimelineStateEditorGUI)editorGUI;
                    TimelineState          newState    = SerializeConverter.CreateCopy(timeLineGUI.GetEditableObject());

                    if (timeLineGUI.IsNote)
                    {
                        newState._editorDescription = timeLineGUI.GetEditorDescrition();
                    }
                    else
                    {
                        newState._editorDescription = timeLineGUI.GetEditorDescrition() + " (Copy)";
                        newState._stateId           = GenerateNewStateId();
                    }

                    return(newState);
                }