Skip to content

Instantly share code, notes, and snippets.

@Dandarawy
Created September 3, 2017 12:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Dandarawy/4b00870938f9b1f1d617a59d6f0b59b8 to your computer and use it in GitHub Desktop.
Save Dandarawy/4b00870938f9b1f1d617a59d6f0b59b8 to your computer and use it in GitHub Desktop.
Add Paper To BookPro dynamically
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 () {
}
}
@aloksonu
Copy link

sir please explain how to use this script .....

@Dandarawy
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment