-
-
Save Dandarawy/4b00870938f9b1f1d617a59d6f0b59b8 to your computer and use it in GitHub Desktop.
Add Paper To BookPro dynamically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class AddDynamicPages : MonoBehaviour { | |
public GameObject FrontPagePrefab; | |
public GameObject BackPagePrefab; | |
// Use this for initialization | |
void Start () { | |
} | |
public void AddPaper(BookPro book) | |
{ | |
GameObject frontPage = Instantiate(FrontPagePrefab); | |
GameObject backPage = Instantiate(BackPagePrefab); | |
frontPage.transform.SetParent(book.transform,false); | |
backPage.transform.SetParent(book.transform, false); | |
Paper newPaper = new Paper(); | |
newPaper.Front = frontPage; | |
newPaper.Back = backPage; | |
Paper[] papers = new Paper[book.papers.Length + 1]; | |
for(int i=0;i< book.papers.Length;i++) | |
{ | |
papers[i] = book.papers[i]; | |
} | |
papers[papers.Length-1] = newPaper; | |
book.papers = papers; | |
//update the flipping range to contain the new added paper | |
book.EndFlippingPaper = book.papers.Length - 1; | |
book.UpdatePages(); | |
} | |
// Update is called once per frame | |
void Update () { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1)-Create a new gameobject in the scene and attach the script on it
2)-Create a prefab for the front and back pages (should be similar to the the page object that is created by the editor and i.e. has the same components)
3)-Assign the front and back prefabs to this component
4)Call the function AddPaper when you want to add a new paper in the book
5)you may need to customize this function to add a paper in specific position in the book or to change some parts of the front and back prefabs dynamically