/// <summary> /// Called when a right swipe is detected. Turns the left page if there are pages left. Plays the pageTurn audio clip.</summary> public void onSwipeRight() { if (currentSheetNum == 2) { AudioSource.PlayClipAtPoint(pageTurn, Vector3.zero); currentSheetNum--; PageScript temp = pageRightScript; pageRightScript = pageLeftScript; GameObject obj = (GameObject)Instantiate(pagePrefab, new Vector3(-0.75f, 0, 0), Quaternion.Euler(new Vector3(0, 180, 0))); pageLeftScript = obj.GetComponent <PageScript> (); pageLeftScript.mInitialize(currentSheetNum - 1, null, null); pageRightScript.rotateRight(40, temp.gameObject); } else if (currentSheetNum > 1) { AudioSource.PlayClipAtPoint(pageTurn, Vector3.zero); currentSheetNum--; PageScript temp = pageRightScript; pageRightScript = pageLeftScript; GameObject obj = (GameObject)Instantiate(pagePrefab, new Vector3(-0.75f, 0, 0), Quaternion.Euler(new Vector3(0, 180, 0))); pageLeftScript = obj.GetComponent <PageScript> (); pageLeftScript.mInitialize(currentSheetNum - 1, imageList [(currentSheetNum - 1) * 2 - 2], imageList [(currentSheetNum - 1) * 2 - 1]); pageRightScript.rotateRight(40, temp.gameObject); } }
/// <summary> /// Called when a left swipe is detected. Turns the right page if there are pages left. Plays the pageTurn audio clip.</summary> public void onSwipeLeft() { if (currentSheetNum * 2 + 2 <= imageList.Length) { AudioSource.PlayClipAtPoint(pageTurn, Vector3.zero); currentSheetNum++; PageScript temp = pageLeftScript; pageLeftScript = pageRightScript; GameObject obj = (GameObject)Instantiate(pagePrefab, new Vector3(0.75f, 0, 0), Quaternion.identity); pageRightScript = obj.GetComponent <PageScript> (); pageRightScript.mInitialize(currentSheetNum, imageList [currentSheetNum * 2 - 2], imageList [currentSheetNum * 2 - 1]); pageLeftScript.rotateLeft(40, temp.gameObject); } }
/// <summary> /// Initializes the book by creating the first left and right pages. Loads the images into imageList.</summary> public void mInitialize() { currentSheetNum = 1; // string relativeFolder = "/Users/lakhshya/Documents/Code/Virtual-Photo-Library---Leap-Unity/Assets/Resources/" + folderName; // imageList = Directory.GetFiles (@relativeFolder, "*.JPG"); // for (int i = 0; i < imageList.Length; i++) { // imageList [i] = folderName + "/" + Path.GetFileNameWithoutExtension (imageList[i]); // } imageList = new string[40]; int init = 0; if (folderName.Contains("0")) { init = 1; } else if (folderName.Contains("1")) { init = 41; } else if (folderName.Contains("2")) { init = 81; } if (folderName.Contains("3")) { init = 121; } for (int i = 0; i < 40; i++) { imageList [i] = folderName + "/" + "Digital Universe (" + (i + init) + ")"; } GameObject obj = (GameObject)Instantiate(pagePrefab, new Vector3(0.75f, 0, 0), Quaternion.identity); pageLeftScript = obj.GetComponent <PageScript> (); pageLeftScript.mInitialize(0, null, null); obj = (GameObject)Instantiate(pagePrefab, new Vector3(0.75f, 0, 0), Quaternion.identity); pageRightScript = obj.GetComponent <PageScript> (); pageRightScript.mInitialize(1, imageList [0], imageList [1]); }