protected override void OnStopDragging(UnityEngine.Event inputEvent, bool cancelled) { if (_dragMode == eDragType.Custom) { if (!cancelled) { Vector2 gridPos = GetEditorPosition(UnityEngine.Event.current.mousePosition); StateEditorGUI draggedOnToState = null; //Check mouse is over a state foreach (StateEditorGUI editorGUI in _editableObjects) { if (editorGUI.GetBounds().Contains(gridPos)) { draggedOnToState = editorGUI; // Check its moved more than break; } } if (draggedOnToState != null) { _draggingStateLink.SetStateRef(new StateRef(draggedOnToState.GetStateId())); } else { _draggingStateLink.SetStateRef(new StateRef()); } } inputEvent.Use(); _dragMode = eDragType.NotDragging; _draggingState = null; _draggingStateLink = new StateMachineEditorLink(); _draggingStateLinkIndex = 0; } else { base.OnStopDragging(inputEvent, cancelled); } }
private void RenderToolBar(Vector2 windowSize) { EditorGUILayout.BeginVertical(); { EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); { string titleText = _title + " - <b>" + System.IO.Path.GetFileName(_currentFileName); if (HasChanges() || _timelineEditor.HasChanges()) { titleText += "*"; } titleText += "</b>"; EditorGUILayout.LabelField(titleText, _style._titleStyle); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); { if (GUILayout.Button("New", EditorStyles.toolbarButton)) { if (ShowOnLoadSaveChangesDialog()) { New(); } } if (GUILayout.Button("Load", EditorStyles.toolbarButton)) { if (ShowOnLoadSaveChangesDialog()) { string fileName = EditorUtility.OpenFilePanel("Open File", Application.dataPath + "/gamedata", "xml"); if (fileName != null && fileName != string.Empty) { LoadFile(fileName); } } } if (GUILayout.Button("Save", EditorStyles.toolbarButton)) { Save(); } if (GUILayout.Button("Save As", EditorStyles.toolbarButton)) { SaveAs(); } EditorGUILayout.Space(); _editorPrefs._debug = GUILayout.Toggle(_editorPrefs._debug, "Debug StateMachine", EditorStyles.toolbarButton); StateMachineComponent currentDbugObject = _editorPrefs._debugObject.GetComponent(); StateMachineComponent debugObject = (StateMachineComponent)EditorGUILayout.ObjectField(currentDbugObject, typeof(StateMachineComponent), true); if (currentDbugObject != debugObject) { _editorPrefs._debugObject = new ComponentRef <StateMachineComponent>(GameObjectRef.eSourceType.Scene, debugObject); if (debugObject != null && _editorPrefs._debugObject.GetComponent() == null) { _editorPrefs._debugObject = new ComponentRef <StateMachineComponent>(GameObjectRef.eSourceType.Prefab, debugObject); } SaveEditorPrefs(); } _editorPrefs._debugLockFocus = GUILayout.Toggle(_editorPrefs._debugLockFocus, "Lock Focus", EditorStyles.toolbarButton); GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); { if (_currentMode == eMode.ViewingTimelineState) { if (GUILayout.Button("Back", EditorStyles.toolbarButton)) { SwitchToStatemachineView(); } else { EditorGUILayout.Space(); string stateText = "state" + ((int)(_editedState.GetStateId())).ToString("000") + " - <b>" + StringUtils.GetFirstLine(_editedState.GetStateDescription()) + "</b>"; GUILayout.Toggle(true, stateText, _style._toolbarStyle); GUILayout.FlexibleSpace(); } } else { GUILayout.Button("Zoom", EditorStyles.toolbarButton); float zoom = EditorGUILayout.Slider(_currentZoom, 0.5f, 1.5f); if (GUILayout.Button("Reset Zoom", EditorStyles.toolbarButton)) { zoom = 1.0f; } if (_currentZoom != zoom) { _currentZoom = zoom; _editorPrefs._zoom = _currentZoom; SaveEditorPrefs(); } if (GUILayout.Button("Center", EditorStyles.toolbarButton)) { CenterCamera(); } GUILayout.FlexibleSpace(); } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); }