public override void DrawPreview(Rect rect) { // We first fix the ratio of the rect var viewport = rect.AdjustToRatio(800f / 600f); GUI.DrawTexture(viewport, backgroundPreview, ScaleMode.ScaleToFit); bool selected; if (Event.current.type == EventType.MouseDown) { SelectedArrow = -1; } // Draw the left arrow if (leftNormalArrow) { EditorGUI.BeginChangeCheck(); var leftArrowPos = DoArrow(workingBook.getPreviousPagePosition(), leftNormalArrow, leftOverArrow, viewport, false, out selected, "Arrow left".GetHashCode()); if (EditorGUI.EndChangeCheck()) { workingBook.setPreviousPagePosition(leftArrowPos); } if (selected) { SelectedArrow = BookDataControl.ARROW_LEFT; } } if (rightNormalArrow) { EditorGUI.BeginChangeCheck(); var isDefault = workingBook.getArrowImagePath(BookDataControl.ARROW_RIGHT, BookDataControl.ARROW_NORMAL) == SpecialAssetPaths.ASSET_DEFAULT_ARROW_NORMAL_RIGHT; var rightArrowPos = DoArrow(workingBook.getNextPagePosition(), rightNormalArrow, rightOverArrow, viewport, isDefault, out selected, "Arrow right".GetHashCode()); if (EditorGUI.EndChangeCheck()) { workingBook.setNextPagePosition(rightArrowPos); } if (selected) { SelectedArrow = BookDataControl.ARROW_RIGHT; } } }
void OnGUI() { // Dragging events if (Event.current.type == EventType.mouseDrag) { if (leftArrowRect.Contains(Event.current.mousePosition) || rightArrowRect.Contains(Event.current.mousePosition)) { if (!dragging) { dragging = true; startPos = currentPos; if (leftArrowRect.Contains(Event.current.mousePosition)) { arrowDragged = ArrowType.Left; } else { arrowDragged = ArrowType.Right; } } } currentPos = Event.current.mousePosition; } if (Event.current.type == EventType.mouseUp) { dragging = false; arrowDragged = ArrowType.None; } if (dragging) { OnBeingDragged(); } scrollPosition = GUILayout.BeginScrollView(scrollPosition); GUI.DrawTexture(imageBackgroundRect, backgroundPreviewTex); GUI.DrawTexture(leftArrowRect, leftArrowTex); GUI.DrawTexture(rightArrowRect, rightArrowTex); GUILayout.EndScrollView(); // Default arrow positions if (GUILayout.Button(TC.get("Behaviour.Normal"))) { OnDefaultClicked(); } GUILayout.BeginHorizontal(); GUILayout.Box(TC.get("Book.Previous"), GUILayout.Width(0.5f * backgroundPreviewTex.width)); GUILayout.Box(TC.get("Book.Next"), GUILayout.Width(0.5f * backgroundPreviewTex.width)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Box("X", GUILayout.Width(0.15f * backgroundPreviewTex.width)); x_prev = EditorGUILayout.IntField((int)bookRef.getPreviousPagePosition().x, GUILayout.Width(0.35f * backgroundPreviewTex.width)); GUILayout.Box("X", GUILayout.Width(0.15f * backgroundPreviewTex.width)); x_next = EditorGUILayout.IntField((int)bookRef.getNextPagePosition().x, GUILayout.Width(0.35f * backgroundPreviewTex.width)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Box("Y", GUILayout.Width(0.15f * backgroundPreviewTex.width)); y_prev = EditorGUILayout.IntField((int)bookRef.getPreviousPagePosition().y, GUILayout.Width(0.35f * backgroundPreviewTex.width)); GUILayout.Box("Y", GUILayout.Width(0.15f * backgroundPreviewTex.width)); y_next = EditorGUILayout.IntField((int)bookRef.getNextPagePosition().y, GUILayout.Width(0.35f * backgroundPreviewTex.width)); GUILayout.EndHorizontal(); bookRef.setPreviousPagePosition(new Vector2(x_prev, y_prev)); bookRef.setNextPagePosition(new Vector2(x_next, y_next)); CalculateArrowsPosition(); GUILayout.BeginHorizontal(); if (GUILayout.Button("End")) { reference.OnDialogOk("Applied"); this.Close(); } GUILayout.EndHorizontal(); }