Unity make book page turn effect

Source: Internet
Author: User

Unity make book page turn effect

Unity C # Book effect 2D real flip-flop do not use plug-in homemade

Implementation Ideas :

The book is divided into two sides, one side of the page to achieve;

For the right of the book, with OA as the dividing line, the OAB is the next side of the lower left corner, OAC is the next side of the bottom of the lower corner;

Using the unity mask can be achieved, that is, assuming that this page is 1 (the left side of the page is 0), need to have an object as the bottom of the 3, an object is masked mask display 2 of the lower left corner of the OAB, an object is masked mask display 1 of the upper left part of the ◇oade;

The mask of the OAB section can be understood as: ◇OAFG is the MASK,◇OBCD is 2, when the page turn, ◇OAFG counterclockwise rotation, ◇OBCD as a sub-object of ◇OAFG, the same direction rotation of the same angle;

The other parts and the left page implementation of the principle of the same, there is the center of the book is the central point of the two pages in the middle of the rotation of the origin point;

implementation Steps :

1. Create a new 2D project and create a new canvas in the hierarchy panel, under which the following objects, from top to bottom meanings can be understood as the left bottom page, the left gradually disappear page (the parent object is the Mask child object is a picture), the left page appears gradually, the right bottom page, the right gradually disappear page (The parent object is a mask child object as a picture), the right side of the page, where the Leftpageshadow and Rightpageshadow is the shadow of the book, such as the Gray Line of 2, will follow the ◇OBCD together, but it is the opposite direction to the edge of the book crease Fit, The crease picture uses 3 to have the gradient;

2. The right part is spoken here and the left part is the same. Rightbottompage_appear do not need to modify, just set the coordinates, as the bottom surface can be. Set the width and Height to the desired size, posy to-height*0.5f, to the right side of the page, also need to set pivot to 0, 0, the center of rotation is set to the bottom of the book axis;

3.righttopcover_disappear set as follows, in order to take into account the rotation righttoppage_disappear will head, here simple rough width set to twice times, the same time to set the rotation center point at the bottom of the axis, pivot set to 0 , 0;

4.righttoppage_disappear set as follows, not much to say;

5.RightNextCover, Rightnextpage and Rightpageshadow are based on the same causes and effects where they occur, and can be understood during the setup process, with pivot and rotation in mind, Rightpageshadow can reduce the color transparency to lighten the shadow;

6. Create a script and mount it on Maincanvas, define the following variables, the image of the above section indicates the Image property of the corresponding name, sprite[] represents all pages, Turningtime indicates the page turn time, isturing indicates whether the page is currently being paged;

7. To the left of the code below, Setsiblingindex is to set the position of the object in the hierarchy panel, used for sorting, because the objects listed below will appear in front of the object above, Setsiblingindex specific instructions to see the unity document. The Offsetangle adjusts the amplitude of rotation according to the rotation time. Then there are various angles of superposition and rotation offset. The Resetbookimage function and the Resetpagesattribute function are followed. You can also use Setsiblingindex here to create two empty objects and then attach a canvas component, separate the left and right objects as sub-objects, and then adjust the sorting order to show which page is in front;

8. The code to the right of the left is as follows, so don't repeat it

The 9.ResetPagesAttribute code is as follows, resetting all image coordinates and angles;

10. Create the following variables, meaning the current number of pages, the maximum number of pages, and the left page and the right page to turn the association. The Resetbookimage function code is used to re-set the image corresponding to each image, where the comparison needs to be abstract and imagined, the idea is easy to understand;

11. Initialize the variable and reset the picture in start, then create two functions to start the paging function;

12. Create an empty object in the hierarchy panel and mount the new script Inputcontrol to control the click, the code is as follows. Here you use the graphic Raycaster (UI Ray) to detect the location of the click, and you need to create two empty image and move to the place where you want to respond to the page, where the left and right sides of the pages are One-fourth of the total width. X-ray detection through the comparison of name to enter a different page;

At this point, the ability to create a book page with unity native components is complete with the following effects

You can also refer to this friend's project on GitHub:

Https://github.com/Dandarawy/Unity3DBookPageCurl

Unity make book page turn effect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.