|
Post by debmarkproductions on Sept 9, 2022 21:31:20 GMT
I would like to have a progressive diary in my game where the player goes to a place and talks with a person and then after leaving the person, a pre-written page is placed in the diary and if the player clicks on the diary button on the game canvas, it switches to the book camera and opens the book to the newly created page. Using the same logic as the Demo02 scene, specifically, how it turns pages, has a table of contents, and how you click on the page and it turns. I want to create an entry in the Table of Contents when that newly created page is inserted. And as in the demo, he can go back to the table of contents at any time to look at other pages of the diary where he has already been. Closing the book will return him to the game and the main camera. I was thinking of bringing in the demo02 assets and modifying a bunch of stuff to insert pages and modify the table of contents. To start with, I have already placed the book in the scene, on a table in a house, put a book-camera above it and a point light to illuminate it. I know how to make the diary button bring up the book and when the player is done reading whatever he wants and closes the book it exits that location and goes back to the main camera. I have also made all of the page materials to be inserted when the person leaves each location. How would you recommend bringing in the operations of the demo02 scene into my project and how to insert the pages using the code when the person leaves the location he has visited. I may be asking a lot. I think it would help others to know how to do this. It might even be good to be an addition your users manual. Thanks.
|
|
|
Post by echo17 on Sept 10, 2022 11:23:50 GMT
To modify the pages at runtime, take a look at the methods in the EndlessBook.cs script:
AddPageData InsertPageData SetPageData RemovePageData MovePageData
You can look at the script for internal documentation on how to use these methods. Basically they are methods to change the materials and their locations inside the book.
In order to dynamically change a table of contents page, you will need to set up a scene like in Demo 2 for the table of contents. You can then render that scene to a rendertexture and use that in a material for your book. The table of contents scene can be as dynamic as any other scene in Unity, showing only the elements that you wish. By scene, I really mean camera, since you can have more than one camera in a scene, one rendering your main scene and one rendering the page texture.
Keep in mind that making these changes at runtime won't persist to your next game session. For that, you will need to integrate some kind of data system, whether that be a database or just storing text files, that would be up to you. That's outside the scope of this plugin, but you can find lots of tutorials online that have covered saving / restoring data in a game.
|
|
|
Post by debmarkproductions on Sept 13, 2022 2:11:51 GMT
Thank you for the information. I wish it were technically easier to implement these ideas than you suggested. I'm still learning to do a lot of things. I've never heard of creating a scene to render in a texture. I know about data files and their implementation. In any case, I will take these suggestions a step at a time and investigate how to implement them.
|
|
|
Post by rodric on Sept 17, 2022 19:19:30 GMT
I’ve been trying to find solutions to the dynamic journal as well.
What do you think about using the new UI Builder which has a setting to output to RenderTexture.
root = document.rootVisualElement;
pageHolder = root.Q<Label>("pageText");
pageHolder.text = “My new journal entry”;
settings = document.panelSettings;
renderTexture = settings.targetTexture;
book.AddPageData(renderTexture);
the xml for the ui
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False"> <Style src="project://database/Assets/Images/Book/book.uss?fileID=7433441132597879392&guid=c27e1b5979b8e4c4098a596307f0fbaf&type=3#book" /> <ui:Label display-tooltip-when-elided="true" name="pageText" text="this is a test" class="journal" /> </ui:UXML>
the uss for the menu
.journal { width: 100%; height: 100%; font-size: 18px; -unity-font: url('project://database/Assets/TextMesh%20Pro/Examples%20&%20Extras/Fonts/Bangers.ttf?fileID=12800000&guid=5dd49b3eacc540408c98eee0de38e0f1&type=3#Bangers'); color: rgb(56, 56, 56); -unity-font-style: bold; padding-left: 10px; padding-right: 10px; padding-top: 10px; padding-bottom: 10px; }
|
|
|
Post by rodric on Sept 17, 2022 20:41:22 GMT
Below is the class that works as long as the page is already created. Need to do a bit more work on it to make generic, but it allows for text to be rendered directly into the book.
public class BookPageController : MonoBehaviour { public UIDocument document; public string textToDisplay; private VisualElement root; private Label pageHolder; private PanelSettings settings; private RenderTexture renderTexture; private string lastRender = string.Empty;
void Awake() { root = document.rootVisualElement; pageHolder = root.Q<Label>("pageText"); settings = document.panelSettings; renderTexture = settings.targetTexture; ClearOutRenderTexture(renderTexture); }
private void Update() { ClearOutRenderTexture(renderTexture); pageHolder.text = textToDisplay; renderTexture.Create(); }
public void ClearOutRenderTexture(RenderTexture renderTexture) { if (!lastRender.Equals(textToDisplay)) { RenderTexture rt = RenderTexture.active; RenderTexture.active = renderTexture; GL.Clear(true, true, Color.clear); RenderTexture.active = rt; lastRender = textToDisplay; } } }
|
|
|
Post by echo17 on Sept 18, 2022 11:10:55 GMT
Very nice! Thanks for sharing
|
|