public void DragLeftPageToPoint(Vector3 point) { if (currentPaper <= StartFlippingPaper) { return; } pageDragging = true; mode = FlipMode.LeftToRight; f = point; UpdatePages(); ClippingPlane.rectTransform.pivot = new Vector2(0, 0.35f); Right = papers[currentPaper - 1].Back.GetComponent <Image>(); BookUtility.ShowPage(Right.gameObject); Right.transform.position = LeftPageTransform.transform.position; Right.transform.localEulerAngles = new Vector3(0, 0, 0); Right.transform.SetAsFirstSibling(); Left = papers[currentPaper - 1].Front.GetComponent <Image>(); BookUtility.ShowPage(Left.gameObject); Left.gameObject.SetActive(true); Left.rectTransform.pivot = new Vector2(1, 0); Left.transform.position = LeftPageTransform.transform.position; Left.transform.localEulerAngles = new Vector3(0, 0, 0); if (enableShadowEffect) { ShadowLTR.gameObject.SetActive(true); } ClippingPlane.gameObject.SetActive(true); UpdateBookLTRToPoint(f); }
public void DragRightPageToPoint(Vector3 point) { if (currentPaper > EndFlippingPaper) { return; } pageDragging = true; mode = FlipMode.RightToLeft; f = point; ClippingPlane.rectTransform.pivot = new Vector2(1, 0.35f); currentPaper += 1; UpdatePages(); Left = papers[currentPaper - 1].Front.GetComponent <Image>(); BookUtility.ShowPage(Left.gameObject); Left.rectTransform.pivot = new Vector2(0, 0); Left.transform.position = RightPageTransform.transform.position; Left.transform.eulerAngles = new Vector3(0, 0, 0); Right = papers[currentPaper - 1].Back.GetComponent <Image>(); BookUtility.ShowPage(Right.gameObject); Right.transform.position = RightPageTransform.transform.position; Right.transform.eulerAngles = new Vector3(0, 0, 0); if (enableShadowEffect) { Shadow.gameObject.SetActive(true); } UpdateBookRTLToPoint(f); }
private void DrawElement(Rect rect, int index, bool isActive, bool isFocused) { BookPro book = target as BookPro; var serialzedpaper = list.serializedProperty.GetArrayElementAtIndex(index); rect.y += 2; GUIStyle style = new GUIStyle(); EditorGUI.DrawRect(new Rect(rect.x, rect.y, rect.width, rect.height - 6), new Color(0.8f, 0.8f, 0.8f)); EditorGUI.LabelField(new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight), "Paper#" + index); if (index == book.CurrentPaper) { EditorGUI.DrawRect(new Rect(rect.x, rect.y + EditorGUIUtility.singleLineHeight, 140, EditorGUIUtility.singleLineHeight), new Color(1, 0.3f, 0.3f)); } EditorGUI.LabelField(new Rect(rect.x, rect.y + EditorGUIUtility.singleLineHeight, 40, EditorGUIUtility.singleLineHeight), "Front:"); EditorGUI.PropertyField( new Rect(rect.x + 40, rect.y + EditorGUIUtility.singleLineHeight, 100, EditorGUIUtility.singleLineHeight), serialzedpaper.FindPropertyRelative("Front"), GUIContent.none); if (index == book.CurrentPaper - 1) { EditorGUI.DrawRect(new Rect(rect.x, rect.y + 3 * EditorGUIUtility.singleLineHeight, 140, EditorGUIUtility.singleLineHeight), new Color(1, 0.3f, 0.3f)); } EditorGUI.LabelField(new Rect(rect.x, rect.y + 3 * EditorGUIUtility.singleLineHeight, 35, EditorGUIUtility.singleLineHeight), "Back:"); EditorGUI.PropertyField( new Rect(rect.x + 40, rect.y + 3 * EditorGUIUtility.singleLineHeight, 100, EditorGUIUtility.singleLineHeight), serialzedpaper.FindPropertyRelative("Back"), GUIContent.none); style.padding = new RectOffset(2, 2, 2, 2); if (GUI.Button(new Rect(rect.x + 70, rect.y + 2 * EditorGUIUtility.singleLineHeight, 20, EditorGUIUtility.singleLineHeight), tex, GUIStyle.none)) { Debug.Log("Clicked at index:" + index); Paper paper = book.papers[index]; GameObject temp = paper.Back; paper.Back = paper.Front; paper.Front = temp; } if (GUI.Button(new Rect(rect.x + 150, rect.y + EditorGUIUtility.singleLineHeight, 80, (int)(1.5 * EditorGUIUtility.singleLineHeight)), "Show")) { Paper paper = book.papers[index]; BookUtility.ShowPage(paper.Back); paper.Back.transform.SetAsLastSibling(); BookUtility.ShowPage(paper.Front); paper.Front.transform.SetAsLastSibling(); book.LeftPageShadow.gameObject.SetActive(false); book.LeftPageShadow.transform.SetParent(book.transform); book.RightPageShadow.gameObject.SetActive(false); book.RightPageShadow.transform.SetParent(book.transform); } if (GUI.Button(new Rect(rect.x + 150, rect.y + (int)(2.5 * EditorGUIUtility.singleLineHeight), 80, (int)(1.5 * EditorGUIUtility.singleLineHeight)), "Set Current")) { book.CurrentPaper = index; } }
/// <summary> /// Update page orders /// This function should be called whenever the current page changed, the dragging of the page started or the page has been flipped /// </summary> public void UpdatePages() { int previousPaper = pageDragging ? currentPaper - 2 : currentPaper - 1; //Hide all pages for (int i = 0; i < papers.Length; i++) { BookUtility.HidePage(papers[i].Front); papers[i].Front.transform.SetParent(BookPanel.transform); BookUtility.HidePage(papers[i].Back); papers[i].Back.transform.SetParent(BookPanel.transform); } if (hasTransparentPages) { //Show the back page of all previous papers for (int i = 0; i <= previousPaper; i++) { BookUtility.ShowPage(papers[i].Back); papers[i].Back.transform.SetParent(BookPanel.transform); papers[i].Back.transform.SetSiblingIndex(i); BookUtility.CopyTransform(LeftPageTransform.transform, papers[i].Back.transform); } //Show the front page of all next papers for (int i = papers.Length - 1; i >= currentPaper; i--) { BookUtility.ShowPage(papers[i].Front); papers[i].Front.transform.SetSiblingIndex(papers.Length - i + previousPaper); BookUtility.CopyTransform(RightPageTransform.transform, papers[i].Front.transform); } } else { //show back of previous page only if (previousPaper >= 0) { BookUtility.ShowPage(papers[previousPaper].Back); //papers[previousPaper].Back.transform.SetParent(BookPanel.transform); //papers[previousPaper].Back.transform.SetSiblingIndex(previousPaper); BookUtility.CopyTransform(LeftPageTransform.transform, papers[previousPaper].Back.transform); } //show front of current page only if (currentPaper <= papers.Length - 1) { BookUtility.ShowPage(papers[currentPaper].Front); papers[currentPaper].Front.transform.SetSiblingIndex(papers.Length - currentPaper + previousPaper); BookUtility.CopyTransform(RightPageTransform.transform, papers[currentPaper].Front.transform); } } #region Shadow Effect if (enableShadowEffect) { //the shadow effect enabled if (previousPaper >= 0) { //has at least one previous page, then left shadow should be active LeftPageShadow.gameObject.SetActive(true); LeftPageShadow.transform.SetParent(papers[previousPaper].Back.transform, true); LeftPageShadow.rectTransform.anchoredPosition = new Vector3(); LeftPageShadow.rectTransform.localRotation = Quaternion.identity; } else { //if no previous pages, the leftShaow should be disabled LeftPageShadow.gameObject.SetActive(false); LeftPageShadow.transform.SetParent(BookPanel, true); } if (currentPaper < papers.Length) { //has at least one next page, the right shadow should be active RightPageShadow.gameObject.SetActive(true); RightPageShadow.transform.SetParent(papers[currentPaper].Front.transform, true); RightPageShadow.rectTransform.anchoredPosition = new Vector3(); RightPageShadow.rectTransform.localRotation = Quaternion.identity; } else { //no next page, the right shadow should be diabled RightPageShadow.gameObject.SetActive(false); RightPageShadow.transform.SetParent(BookPanel, true); } } else { //Enable Shadow Effect is Unchecked, all shadow effects should be disabled LeftPageShadow.gameObject.SetActive(false); LeftPageShadow.transform.SetParent(BookPanel, true); RightPageShadow.gameObject.SetActive(false); RightPageShadow.transform.SetParent(BookPanel, true); } #endregion }