public void Render() { ProcessDrag(); if (DraggedState != null) { FSMEditorState hoverState = MyFSMStatesControl.FindStateUnderMouse(); if (hoverState != null) { FSMLineRender.DrawTransition(DraggedState.GetEventRect(DraggedTransitionIndex, null), hoverState.GetHeaderRect(DraggedState)); } else { Vector2 position = FSMEditorEvent.Instance.MousePosition; position.y += MyFSMStatesControl.ScrollPos.y - MyFSMStatesControl.Position.y; position.x += MyFSMStatesControl.ScrollPos.x; FSMLineRender.DrawTransition(DraggedState.GetEventRect(DraggedTransitionIndex, null), new Rect(position.x, position.y, 1, 1)); } if (FSMEditorEvent.Instance.EditorEventType == FSMEditorEventType.MouseUp) { if (hoverState != null && hoverState != DraggedState) { DraggedState.State.Transitions[DraggedTransitionIndex].ToState = hoverState.State.StateName; } DraggedState = null; } } }
public static void DrawTransition(Rect wr, Rect wr2) { // CurveFromTo(wr2, wr3, new Color(0.7f,0.2f,0.3f)); FSMLineRender.BezierLine( new Vector2(wr.x + wr.width, wr.y + wr.height / 2), new Vector2(wr.x + wr.width, wr.y + wr.height / 2), //new Vector2(wr.x + wr.width + Mathf.Abs(wr2.x - (wr.x + wr.width)) / 2, wr.y + wr.height / 2), new Vector2(wr2.x, wr2.y + wr2.height / 2), new Vector2(wr2.x, wr2.y + wr2.height / 2), // new Vector2(wr2.x - Mathf.Abs(wr2.x - (wr.x + wr.width)) / 2, wr2.y + wr2.height / 2), new Color(0.7f, 0.2f, 0.3f), 2, true, 1 ); }
public static void BezierLine(Vector2 start, Vector2 startTangent, Vector2 end, Vector2 endTangent, Color color, float width, bool antiAlias, int segments) { Vector2 lastV = CubeBezier(start, startTangent, end, endTangent, 0); for (int i = 1; i <= segments; ++i) { Vector2 v = CubeBezier(start, startTangent, end, endTangent, i / (float)segments); FSMLineRender.DrawLine( lastV, v, color, width, antiAlias); lastV = v; } }
public void Render() { Vector2 viewport = CalculateViewport(); GUI.Box(new Rect(0, Position.y, MyFSMEditor.position.width, this.MyFSMEditor.position.height - Position.y), ""); ScrollPos = GUI.BeginScrollView(new Rect(0, Position.y, MyFSMEditor.position.width, this.MyFSMEditor.position.height - Position.y), ScrollPos, new Rect(0, 0, viewport.x + Position.y + 100, viewport.y + Position.y + 100)); MyFSMEditor.BeginWindows(); foreach (FSMEditorState editorState in MyFSMEditor.EditorStates) { editorState.Render(); } MyFSMEditor.EndWindows(); foreach (var fromEditorState in MyFSMEditor.EditorStates) { int i = 0; foreach (var transition in fromEditorState.State.Transitions) { if (transition.ToState != "") { if (MyFSMEditor.EditorStatesIndex.ContainsKey(transition.ToState)) { var toEditorState = MyFSMEditor.EditorStatesIndex[transition.ToState]; FSMLineRender.DrawTransition(fromEditorState.GetEventRect(i, toEditorState), toEditorState.GetHeaderRect(fromEditorState)); } } i++; } } FSMDragStateControl.Render(); GUI.EndScrollView(); }