ee
New Member
Posts: 3
|
Post by ee on Aug 3, 2023 21:28:59 GMT
Briefly, I have no idea how to use Delegate such as onCompleted.
I am not a programmer, nor am I an English speaker.
I would like to know how to use onCompleted in turnFoaward, etc. to invoke any function.
Preferably in a new script, written in a minimal string.
If I am not mistaken in my interpretation of Delegate, maybe that is how it can be done?
Oh, and one more question. This is a TurnForward or TurnBackward question.
When I turn a page, I can't open the next page until completion, is there any way to remove this limitation?
At the moment, I'm handling it by forcing the transition to complete and then continuing on to the next transition, but the behavior becomes unnatural when I go through a bunch of transitions in a row.
(Translated from DeepL)
|
|
|
Post by echo17 on Aug 4, 2023 9:25:57 GMT
A delegate is just a pointer to another function. That allows EndlessBook to call functions inside of your controller script, letting your script know when different actions occur, like onPageTurnEnd, etc.
Take a look at Demo #2 included with the asset. On lines #521 and #536 you will see examples of TurnBackward and TurnForward. They both pass delegates (pointers to your script's functions) in the parameters onCompleted, onPageTurnStart and onPageTurnEnd. On line #693 you can see an example of calling TurnToPage, which has delegate parameters for onCompleted (when all pages have stopped turning), onPageTurnStart, and onPageTurnEnd.
So if you just want to turn forward one page, you can call (assuming your book variable is called "book"):
book.TurnForward(1.0f, onCompleted: OnBookStateChanged, onPageTurnStart: OnPageTurnStart, onPageTurnEnd: OnPageTurnEnd);
Then you will need to set up your delegate functions in your script to match the values you passed in the above code. So you would need these three functions:
protected virtual void OnBookStateChanged(EndlessBook.StateEnum fromState, EndlessBook.StateEnum toState, int pageNumber) { // do something here for when the pages have completed turning }
protected virtual void OnPageTurnStart(Page page, int pageNumberFront, int pageNumberBack, int pageNumberFirstVisible, int pageNumberLastVisible, Page.TurnDirectionEnum turnDirection) { // do something here for when the page has started turning }
protected virtual void OnPageTurnEnd(Page page, int pageNumberFront, int pageNumberBack, int pageNumberFirstVisible, int pageNumberLastVisible, Page.TurnDirectionEnum turnDirection) { // do something here for when the page has stopped turning }
I'm not sure what you mean by "open the page until completion". By "open" do you mean display the page contents or interact with it by clicking? If the latter, then I assume you are referring to Demo #2. That demo has a touchpad that lets you click on it, sending signals to the book to do page turns. That isn't specific to EndlessBook, just that demo. You can see where the method ToggleTouchPad is called. Passing false to this method turns the touchpad off (so you cannot click on the book). Passing true turns it on (so you can click on the book). Just do a search for ToggleTouchPad and you can modify how and when you toggle it to get to your preferred process.
If you are new to programming or Unity in general, I would highly recommend going through some tutorials. Unity has some good ones for beginners, but the internet has millions on C#. It will help you in your journey to making a game immensely.
|
|
ee
New Member
Posts: 3
|
Post by ee on Aug 4, 2023 22:23:42 GMT
thank you for your reply. Thanks to your advice I was able to understand the handling of Delegate. However, there seems to have been a mistake in the translation of the other question, so it doesn't seem to have been communicated well. So let me explain that from the beginning. What I'm aiming for is to "continuously" perform the action of "turning one page with one click". Hmm, I don't think I translated it very well. I know that TurnForward goes forward one page. I also know that I can do it at any time. The problem is that between OnStart and OnEnd it is not accepting the next click. For example, if the player thinks "Let's turn 3 pages", the following actions are required. Click → Wait until the page is completely turned → Click → Wait for the page to be completely turned → Click → Wait for the page to be completely turned ibb.co/M8rs7FYThis is stress. So here's what you want to do: 3 clicks → wait until 3 pages are completely turned I want to do this with TurnForward or TurnBackward instead of TurnToPage. Here's a look back at my last post. Currently, I implement stress-free page turning by running StopTurningPages first. ibb.co/Fqk3xgmHowever, in this case, the shorter the interval between clicks, the more unnatural it will look. ibb.co/PGjyFpjOf course, if I implement the behavior I'm looking for, it will become strange when the player executes Backward while Forward is executing. I'll take care of that myself, so if there's a way to "turn multiple pages at the same time", please let me know. I'll write it again, but it's a way to run it using TurnForward. ibb.co/164m2Vn
|
|
|
Post by echo17 on Aug 5, 2023 11:49:37 GMT
Thank you for the clarification. Unfortunately, I am not sure of a way to accomplish this based on how the plugin is structured. Each time you turn a page, whether that is one page or many, the book goes into a transitioning state that doesn't update the book until the transition is completed. The transition is a coroutine, so having multiple transitions at the same time would put the book into conflicting parallel multi-threaded states. There may be a way to accomplish this, but I do not know of one.
One thing you could try would be to delay the page turn a little. Instead of starting the page turn immediately when the user clicks, you could put your controller script into a coroutine timer, waiting a second (or possibly milliseconds) to see if the user clicks again. If they do not click again within a certain time frame, maybe 300 milliseconds, then you can start turning the page forward one page. If they do click again within that time limit, you restart the timer and wait another 300 milliseconds, incrementing a page counter variable. Keep doing this until they stop clicking or the timer expires. Eventually you will have a count of how many pages they want in the page counter variable and you can then call TurnToPage, adding the page counter variable to the current page number. This method will have a slight delay from the user clicking to the page turning, but it might be better that waiting for the page turn to complete.
|
|
ee
New Member
Posts: 3
|
Post by ee on Aug 6, 2023 6:35:44 GMT
OK I understand. Thank you for your efforts.
I would like to cherish the response. So in this project, I'm going to deal with it by making the page-turning animation as quick as possible. That way I can alleviate some of the discomfort of page turning. If the player clicks too fast, I'll use visual support other than page-turning animations.
or,
In my case, I only need to be able to turn pages (I don't need the book itself), so I'm going to separate the page content as UI and duplicate the animation part each time. However, this way I lose most of the benefits of this plugin...
Anyway, thank you for your kind response!
|
|