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.ViewingTimelineState)
                        {
                            ((TimelineState)_editedState.GetEditableObject())._timeline = _timelineEditor.ConvertToTimeline();
                        }

                        //Update state machine name to reflect filename
                        StateMachine stateMachine = ConvertToStateMachine();

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

                        ClearDirtyFlag();
                        _timelineEditor.ClearDirtyFlag();

                        GetEditorWindow().DoRepaint();

                        //Hack, save string on save scene
                        Localisation.SaveStrings();
                    }
                    else
                    {
                        SaveAs();
                    }
                }
Beispiel #2
0
                private void RenderLinksForState(StateEditorGUI state)
                {
                    StateMachineEditorLink[] links = state.GetEditableObject().GetEditorLinks();

                    if (links != null)
                    {
                        float fraction = 1.0f / (links.Length + 1.0f);
                        float current  = fraction;

                        foreach (StateMachineEditorLink link in links)
                        {
                            StateRef stateRef = link.GetStateRef();

                            if (stateRef.IsInternal())
                            {
                                StateEditorGUI toState = FindStateForLink(stateRef);

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

                            current += fraction;
                        }
                    }
                }
                private Vector3 GetLinkStartPosition(StateEditorGUI state, int linkIndex = 0)
                {
                    float fraction     = 1.0f / (state.GetEditableObject().GetEditorLinks().Length + 1.0f);
                    float edgeFraction = fraction * (1 + linkIndex);

                    Rect stateRect = GetScreenRect(state.GetBounds());

                    return(new Vector3(Mathf.Round(stateRect.x + stateRect.width * edgeFraction), Mathf.Round(stateRect.y + stateRect.height - StateEditorGUI.kShadowSize - 1.0f), 0));
                }
                protected override State CreateCopyFrom(SerializedObjectEditorGUI <State> editorGUI)
                {
                    StateEditorGUI timeLineGUI = (StateEditorGUI)editorGUI;
                    State          newState    = Serializer.CreateCopy(timeLineGUI.GetEditableObject());

                    newState._editorDescription = timeLineGUI.GetStateDescription() + " (Copy)";
                    newState._stateId           = GenerateNewStateId();

                    return(newState);
                }
                private void SwitchViewsIfNeeded()
                {
                    if (_requestSwitchViews)
                    {
                        if (_requestSwitchViewsStateId != -1)
                        {
                            StateEditorGUI state = GetStateGUI(_requestSwitchViewsStateId);

                            if (state != null)
                            {
                                if (state.GetEditableObject() is TimelineState)
                                {
                                    TimelineState timelineState = (TimelineState)state.GetEditableObject();

                                    _currentMode = eMode.ViewingTimelineState;
                                    _editedState = state;
                                    _timelineEditor.SetTimeline(timelineState._timeline);

                                    _editorPrefs._stateId = _requestSwitchViewsStateId;
                                    SaveEditorPrefs();

                                    foreach (StateEditorGUI stateView in _selectedObjects)
                                    {
                                        GetEditorWindow().OnDeselectObject(stateView);
                                    }
                                }
                                else
                                {
                                    SetViewToStatemachine();
                                    _selectedObjects.Clear();
                                    _selectedObjects.Add(state);
                                    Selection.activeObject = state;
                                }
                            }
                        }
                        else
                        {
                            SetViewToStatemachine();
                        }

                        _requestSwitchViews = false;
                    }
                }
                protected override void OnLeftMouseDown(UnityEngine.Event inputEvent)
                {
                    //Dragging state links
                    for (int i = 0; i < _editableObjects.Count; i++)
                    {
                        StateEditorGUI state = (StateEditorGUI)_editableObjects[i];

                        StateMachineEditorLink[] links = state.GetEditableObject().GetEditorLinks();

                        if (links != null)
                        {
                            float scale      = 1.0f;
                            float linkRadius = Mathf.Round(kLinkIconWidth * 0.5f * scale) + 2.0f;

                            for (int j = 0; j < links.Length; j++)
                            {
                                Vector3 startPos = GetLinkStartPosition(state, j);
                                Vector2 toField  = inputEvent.mousePosition - new Vector2(startPos.x, startPos.y);

                                if (toField.magnitude < linkRadius)
                                {
                                    _dragMode               = eDragType.Custom;
                                    _draggingState          = state;
                                    _draggingStateLink      = links[j];
                                    _draggingStateLinkIndex = j;
                                    _dragPos      = inputEvent.mousePosition;
                                    _dragAreaRect = new Rect(-1.0f, -1.0f, 0.0f, 0.0f);
                                    _selectedObjects.Clear();
                                    return;
                                }
                            }
                        }
                    }

                    //Normal input
                    base.OnLeftMouseDown(inputEvent);

                    //Double clicking
                    StateEditorGUI clickedOnState = _draggedObject as StateEditorGUI;

                    if (clickedOnState != null)
                    {
                        if (_lastClickedState == clickedOnState && (EditorApplication.timeSinceStartup - _lastClickTime) < kDoubleClickTime)
                        {
                            OnDoubleClickState(clickedOnState as StateEditorGUI);
                        }

                        _lastClickedState = clickedOnState;
                        _lastClickTime    = EditorApplication.timeSinceStartup;
                    }
                }
                private void RenderLinksForState(StateEditorGUI state)
                {
                    StateMachineEditorLink[] links = state.GetEditableObject().GetEditorLinks();

                    if (links != null)
                    {
                        for (int j = 0; j < links.Length; j++)
                        {
                            StateRef stateRef = links[j].GetStateRef();

                            if (stateRef.IsInternal())
                            {
                                StateEditorGUI toState = FindStateForLink(stateRef);
                                RenderLink(links[j].GetDescription(), state, toState, j);
                            }
                            else
                            {
                                RenderExternalLink(links[j], state, j);
                            }
                        }
                    }
                }