Introduction
If you have ever needed an animated book in your game then MegaBook is what you need, it is a complete procedural book builder and animator with an advanced page turning animation system and content builder.
MegaBook allows you to quickly and easily create multiple page books with page turning animation in Unity. You can have any number of pages and have the system generate the page meshes for you or you can provide your own custom page meshes or objects and the system will animate those and create a complete book for you. You have complete control over the textures used for the pages and there are options to allow you to have background textures and content textures merged with a mask option. You also have complete control over the generated page meshes with options to control the size of the page and how many vertices are used to build it. Also included is a system to swap pages out for ones with holes in so for big books overdraw is greatly reduced.
The page turning animation can also be controlled so you can define how much a page turns, where it starts to turn etc, MegaBook has dozens of parametes you can tweak to change how the book works all of which can be changed in Editor mode or at runtime if you need. You can also attach objects to each page so it is easy to add GUI elements or even 3d objects to each page and the book system will manage those for you, turning them with the page and disabling them when they cant be seen.
There is an API of methods you can use to easily control the book such as NextPage, PrevPage, SetPage also methods to replace content textures per page or even download new textures direct to a page from the internet or from files.
Creating a Book
To create a new book just go to the GameObject/Create Other menu and select MegaBook. A new default Book will be created in your scene. If you drag the Page slider you will see the pages turn. All the pages will be the same at this point.
The first thing to do is set the number of pages you want in your book so to do this change the Num Pages option until you have the desired page count. Next we need to set the size of the book by opening the Mesh Params section in the inspector. Here you can change the width and length of the pages as well as set the number of vertices to use for each page. When you have set the size and adjusted the number of vertices then you should open the Pages foldout in the inspector. This is where we actually add the content for the book. There will be one page already added for you. It is important to note that if the actual number of content pages does not equal the actual number of physical pages in the book then the book will repeat page content until the book is filled. To change the content for the front and back of the page you just need to select the textures you want to use in the front and back texture boxes. You should see the page contents update as you select your textures.
When you have selected your textures you can add further pages to the book by clicking the ‘Add Page’ button. When you have more than one content page in your book you can choose which one you are currently editing by changing the ‘Edit Page’ slider. You will see the inspector change to show the values for the page you select.
Once you have finished adding your content then your book is ready to use. To control which page is displayed you just need to change the ‘Flip’ float value in the MegaBookBuilder component. The book component has some API methods you can call to control the book such as NextPage, PrevPage, SetPage etc. See below for definitions of the methods. Also included in the system is an example BookControl script which shows how you can control your newly created book.
Once you have a working book then you can play with the values in the Page Turn Options to see how they effect the page turn animation. See below for a description of all the params in the system and what they do.
New Features
Since the first release we have been adding new systems to MegaBook to keep improving it. MegaBook now has support for custom hard front and back cover objects and also support for adding text to each page using any text rendering system that supports meshes.
Page Backgrounds
When creating a book the default behaviour is to just use the textures you provide for each page as the content for the book so filling each page. You may though want to have a standard page background and then position your content on that page so we have added a page background system. This allows you to set a default background for the front and back of a page then define the region to copy the page contents into on the page, you also have the option to use a mask texture to add things such as rounded corners. If you use backgrounds then it is important to note that the final resolution of the textures will be at the res of the background texture. Also if you do use backgrounds then the textures used for the backgrounds and mask as well as the content textures all need to be set to readable. If you are not using backgrounds then the main content textures do not need to be readable.
Depending on the size of your textures and the number of pages in your book it can take a few seconds for the page textures to be generated.
Book Params
These are the general params for the book as well as holding the more advanced settings foldouts.
Page
The page the book is opened to. The whole part of the number is the actual page you are looking at and the fraction part is how far the next page is turned so a value of 6.25 would mean the book is opened at page 6 and it is 1 quarter of its way through turning the page to page 7.
Snap
When setting the page value you can either choose for the system to use the exact value so allowing partial turned pages or if this value is set then the system will always open fully to the selected page.
Turn Time
When you tell the system to change a page this is how long it will take to turn that page, a value of 0 will be an instant change higher values will cause the pages to turn slower.
Num Pages
The number of actual page meshes that will be built for the book. If the number of pages defined below does not match the number of pages here the book will repeat pages till it is full.
Mesh Options
This will open the param options that control the building of the page meshes, see below for full param explanation.
Page Turn Options
This will open the param options that control how the pages turn, see below for full param explanation.
Texture Backgrounds
This will open the background texture options, see below for more details.
Cover Params
This will open the options that control any front and back cover objects you may want to use with your book.
Dynam Mesh
This will open the options that allow you to add dynamic mesh data to each page of your book. Please also see the Complex Page section for more info on using this feature.
Rebuild
Clicking this button will force a rebuild of the entire book, you shouldn’t need to use this as the book will rebuild itself on any param change but if for some reason the book needs a full rebuild then just click this button.
Mesh Options
This section of params controls how the meshes for each page are generated, You have the option of having the system create the pages for you and you can specify how many vertices are to be used along with the size and thickness of the page. Or you can select a custom mesh or object for the system to use. In the page setup section below you can override the values used here to specify a custom mesh or object for each page if you require.
Page Length
The length of the pages in the book. If you are using a custom mesh or object for the page this value will scale that accordingly.
Page Width
The width of the pages in the book. If you are using a custom mesh or object for the page this value will scale that accordingly.
Page Height
The thickness of each page in the book. If you are using a custom mesh or object for the page this value will scale that accordingly.
Width Segs
How many segments the page mesh will be split into across the width. The more segments you have here the smoother the page curl effect will be. You can use the vertex distribution curve below to control where the vertices are positioned so for example it is usually better to have more vertices around the area of the page that curves the most. By default the distribution is linear.
Length Segs
How many segments the page mesh is split to along the other major axis of the page. If you dont have much of a page flip angle applied to your book then you can use a lower value here.
Height Segs
How many vertices to use in the page thickness, there should be no reason to use a value other than 1 here.
Spine Edge
By default the edge of the page polys will be added to the mesh, but if you have a spine object you may not want those so un checking this option will stop those polys being added the mesh.
Page Hole Mesh
If you have a book with a lot of pages then there could be a lot of overdraw so this option allows for a page mesh with a hole in the middle to be used by the book when the book detects the page is hidden. Use the values below to define the region of the hole.
X Hole
This value and the one below controls how many vertices in from each edge the hole will start, a value of 0 will mean the page will just be an edge. Only use values up to half the width segs above.
Y Hole
This value and the one below controls how many vertices in from each edge the hole will start, a value of 0 will mean the page will just be an edge. Only use values up to half the width segs above.
Variation
By default each page in the book will be created the same size, but you can define a variation to be applied to each page given the book an older hand cut look. These values control the max variation in size on each axis. These values also work for custom mesh and objects.
Vertex Dist
This curve controls how the vertices are distributed across the width of the page.
Page Mesh
You may use your own custom mesh for each page in the book so pick the mesh you wish to use here, you can override this per page in the Page section below. The mesh should have enough vertices in it that it can be bent nicely by the page flip system. If you use a mesh then the materials below will be used. Your mesh should have at least three materials ie a front and a back so the textures can be set, the third material will be the edge material.
Hole Mesh
If you are using a custom mesh you can also pick a mesh with a hole in it for reduced overdraw.
Page Object
You may use your own custom object for each page in the book so pick the object you wish to use here, you can override this per page in the Page section below. The object should have enough vertices in it that it can be bent nicely by the page flip system.
Hole Object
If you are using a custom object you can also pick an object with a hole in it for reduced overdraw.
Front Mat ID
If using a custom object you can say which material index to use for the front.
Back Mat ID
If using a custom object you can say which material index to use for the back.
Rotate
It might be that your custom mesh or object is not in the right orientation for the system, if so you can alter that with this value.
Front Material
The material to use for the front of each page. The texture will be changed per page.
Back Material
The material to use for the back of each page. The texture will be changed per page.
Edge Material
The material to use for the edge of the page.
Page Gap
The values controls the gap between each page in the book if the Use Book Thickness option is not selected.
Spine Radius
You can specify a radius for the spine if you dont want a flat edge.
Use Book Thickness
If you select this option then the spacing of the pages will be calculated to fit in the thickness defined below.
Book Thickness
The thickness of the whole book to use when the Use Book Thickness option is selected.
Page Colliders
This option will generate a mesh collider for each page of the book.
Allow Color
When using dynamic mesh content your content may be using the vertex colors, if so you will need to check this book so that the book system knows to include vertex color in the page mesh data.
Color
You can use this value to set a tint to your pages if the vertex color option is enabled above.
Turn Options
The params in this section control how the pages turn. The animation of the page turn is split into three sections, turn, open and flip. Turn is the main turning of the page. Open is the how the page ends its turn so how it comes to rest. The flip controls the extra flourish that happens to a page as it is turned.
Spine Angle
The angle of the spine of the book. This value can only be changed if the Change Spine Angle option is off.
Max Spine Angle
When the Change Spine angle option is on this is the spine angle for when the book is full read, most cases 180 will be the correct value.
Change Spine Angle
With this option on the book system will automatically rotate the spine to match the page of the book being read.
Turn Center
This value controls the point across the page where the main turning of the page will take place, a value of 0 will mean the turn will be right on the spine, a value of 1 will be on the very right edge of the page.
Turn Size
This controls how tight the turn radius is, a low value here will cause the page to lie quite flat, a larger value will make the book look more like it is being leafed through.
Turn Max Angle
The angle of the page when it is fully turned, 180 is a good value to start with.
Turn Min Angle
The angle of the page when it is not turned at all, 0 is a good value to start with.
Turn Spread
This factor controls how much the pages spread apart as the book is opened.
Open Origin
The point on the page where the open animation will start.
Open Size
The size of the area effected by the open animation.
Open Max Angle
The max angle the page will use when ending its turn.
Open Min Angle
The angle the page will use when staring the end of its turn.
Flip Origin
The point on the page where the extra page flip animation will start.
Flip Size
The area effected by the extra page flip animation.
Flip Max Angle
The max angle the flip animation will apply. If this value is too large it could result in pages passing through one another as they turn.
Flip Random
You can tell the system to use a different flip angle on each page in the book, check this option to turn that on.
Flip Random Seed
The random number seed to use.
Flip Random Ang
The maximum Flip angle the random generator will use on a page.
Pages
This section allows you to add pages to your book, choose the content textures and set any overrides for the mesh or object options.
Edit Page
This slider will change the page you are editing so it will change the params below to reflect the page selected here.
Add Page
Click this button to add a new page of content to the book.
Page Mesh
If want this page to have a different mesh to the rest of the book ie you can pick a mesh to be used for just this page here.
Hole Mesh
You can also select a custom mesh to use to reduce overdraw.
Page Object
If want this page to have a different object to the rest of the book ie you can pick an object to be used for just this page here.
Hole Object
You can also select a custom object to use to reduce overdraw.
Front Mat Index
If using a different mesh you can say the material index to use for the front of the page.
Back Mat Index
If using a different mesh you can say the material index to use for the back of the page.
Rotate
When using a custom mesh or object it could be the the orientation of the object does not match what the book expects so you can use this value to get it positioned correctly.
Front Material
The material to use for the front of the page. If not set then the default value set in the mesh options will be used.
Back Material
The material to use for the back of the page. If not set then the default value set in the mesh options will be used.
Front
This is where you actually select the texture to use for the content of the front page. The first texture is the main content texture, the second one is a custom background if you want to use one. If using backgrounds textures must be readable, if you try and select a texture that is not readable a warning will pop up.
Back
This is where you actually select the texture to use for the content of the back page. The first texture is the main content texture, the second one is a custom background if you want to use one. If using backgrounds textures must be readable, if you try and select a texture that is not readable a warning will pop up.
Swap Sides
It could be the materials are around the wrong way if so you can swap the front and back quickly by selecting this option.
Front Back Ground
If you want the front page to use either the default background texture or the one set above you will need to have this option checked. If this is not checked then just the content texture will be used on the front page.
Copy Area
If using a background this is where you define where the content texture will be copied onto the background texture. This allows you to position the content anywhere on the page.
Back Ground
If you want the back page to use either the default background texture or the one set above you will need to have this option checked. If this is not checked then just the content texture will be used on the back page.
Copy Area Back
If using a background this is where you define where the content texture will be copied onto the background texture. This allows you to position the content anywhere on the page.
Page Objects
This section holds the params for any objects that you want to have attached to the page, for example GUI objects or any 3d object that you wish to stick to the page as it turns. See below for more information on the attach system.
Visible Low
The point in the page turn below which objects attached to this page will be turned off. This can be overridden per object in the settings below.
Visible High
The point in the page turn above which objects attached to this page will be turned off. This can be overridden per object in the settings below.
Insert
Clicking this button will Insert a new page before this one.
Delete
This will delete the page.
Up
Move the page up one in the list.
Down
Move the page down one in the list.
Page Objects
The book system allows you to attach any objects with a transform to the page. So this makes it easy to say add GUI objects to a page such as a Next Page button, or to have game option check boxes, or even full 3d models to appear when the book is open at the page. The system will automatically enable and disable any objects as the page they are attached to is open or closed.
Visible Low
This value will control the point at which objects will appear when the page appears, so a value of -1 will turn the objects on as soon as the page before starts to turn, this might result in objects appearing through the page if they have any height to them, so setting the value tp say -0.75 will mean the objects will be turned on when the page before is a quarter of the way through its turn.
Visible High
The point at which the attached objects will turn of as the page completes its turn, so a value of 1 will mean they turn off when the page is fully turned.
Add Object
Click this to add a new object to the page.
Object
The object you wish to attach to the page.
Pos
The position on the page. The values are between 0 and 100 and define the normalized position on the page with 0,0,0 being the bottom left edge and 100,100,100 being the top right edge. A Y value of 0 means the object will be attached to the back of the page, a Y value of 100 will attach the object to the front of the page.
Rot
You can control the orientation of the object on the page by changing this value.
Offset
Depending on your objects pivot point you may need to offset the object from the surface of the page. Use this value to do that.
Fwd
This is a hint value to tell the system which way is forward, you will probably not need to change this but if you are getting some rotation problems with attached objects then try adjusting this value.
Use Obj Visi
By default the system will use the page visibility settings for turning on and off attached objects, but sometimes you may need special values for some objects, in that case check this box and use the values below to control when this object is turned on and off.
Visibility Low
The page turn point at which this object will be turned on.
Visibility High
The page turn point at which this object will be turned off.
Message
The system can be asked to pass a message to the object that is being turned on or off so you can for example start an animation of that object. If this is enabled a message will be sent to any method on the target object called ‘BookVisibility’ with a float param that is the current turn amount of the page.
Delete Page Object
Remove the object from the page.
Texture Backgrounds
This section controls the default backgrounds to use for the pages in the book as well as the mask texture to use. When using backgrounds a new texture is created using the page background and then the content texture data is copied on top of that using the mask texture if one is set to control the blending.
No Backgrounds
Check this box to stop any backgrounds from being added to the pages. Pages with backgrounds can take a little time to create if the textures are high res so while testing it can be useful to have this option to make it quicker to test your book.
Background
The default background to use for the front of a page. This texture must be readable.
Background back
The default background texture to use for the back of the page. This texture must be readable.
Mask
You can choose to use a mask to control how the content texture is copied onto the background, so for example adding rounded corners. Pick your mask texture here, it will need to be readable.
Copy Area
The is the default area to copy the content textures onto for each front page, this can be changed per page in pages section above.
Copy Area Back
The is the default area to copy the content textures onto for each back page, this can be changed per page in pages section above.
Clear
This will clear any generated textures from the book.
Make Pages
This will calculate and apply any textures that use backgrounds.
Cover Params
The system can be asked to control two objects that will be the front and back cover objects, you can use any objects you like for these or they could be bones in a skinned mesh for a fancy cover.
Front Cover
The object to use as the front cover, this can be a normal mesh object or possibly a bone in a skinned mesh.
Front Ang
The angle the object will be turned to when open.
Front Pivot
You can adjust the pivot point for the rotation using this value.
Back Cover
The object to use as the front cover, this can be a normal mesh object or possibly a bone in a skinned mesh.
Back Ang
The angle the object will be turned to when open.
Back Pivot
You can adjust the pivot point for the rotation using this value.
Dynam Mesh
Sometimes you may need more than just textures for the content of your books, if so you can now add any meshes you like as content for each page of your book. The system will automatically combine these meshes and their materials into the page mesh so that it will turn along with the animated page. To learn more about using mesh data for your content please see the Complex Page section.
Enabled
Enable or disable adding mesh content to the pages.
Text Object
The object that has the MBComplexPage component attached.
Front Offset
You can adjust the offset to use for any mesh data added to the front of the page. This allows you to easily adjust the positioning of any mesh data on the page.
Front Rotate
You can adjust the rotation to use for any mesh data added to the front of the page.
Front Scale
You can adjust the scaling to use for any mesh data added to the front of the page.
Back Offset
You can adjust the offset to use for any mesh data added to the back of the page. This allows you to easily adjust the positioning of any mesh data on the page.
Back Rotate
You can adjust the rotation to use for any mesh data added to the back of the page.
Back Scale
You can adjust the scaling to use for any mesh data added to the front of the page.
MegaBook API
This section gives details on the methods you can call to control aspects of your book. This API will be extended in future updates.
Returns the number of pages in the book.
Returns the current page being viewed.
Returns how far through the turn of a page the system is, 0 is no turn 0.999 nearly completed turn to next page.
This will advance the book one page.
This will turn back one page in the book.
force – Force an instant change to the new value.
Use this value to control which page of the book is displayed. The whole part of the value set is the actual page to open to the book to and the fractional part is how far that page is turned. So a value of 1.0 will show page 1 with no turn, a value of 1.25 will show page 1 a quarter of the way through turning to page 2.
This will return the current page the book is showing.
This allows you to change whether the book page turn snaps to a full open page or whether you can have intermediate values. By default the book control will snap to open pages.
Gets the current snap setting for the book.
The book control system will automatically smoothly turn the pages for you, the time value will control how quickly the turn to a new page will take. Higher values will take longer, a value of 0 will be instant.
Returns the current page turn time for the book.
p – The page whose texture we will be replacing.
front – if true the front texture for the page will be changed if false then the back.
This method allows you to fetch a texture for a page from a url, that url can be an http page or a file location. This a coroutine so should be called like:
front – If true will return the front page texture, if false the back page.
Returns the texture currently being used by the page.
p – The page whose texture we will be replacing.
front – If true then the front page texture will be changed, if false the back.
Allows you to change the content texture for a page.
Videos
This video is a quick introduction to MegaBook and some of its features, other videos will be added soon. Click the image below to play the video.
More advanced mesh content being added to each page.
You must be logged in to post a comment.