Hello again!
I've been creating a custom setup for my game's menu systems through code and am stuck on one little hiccup. I am attempting to grab the Page Texture from a Document via script and cannot for the life of me figure out how to implement the code that gets me there. For context, I'm creating a simple "forum" type system, in which the original post/OP is defined by the Document's main texture/text, and the replies to the post are defined by the subsequent Document pages/image textures.
Through the AC scripting guide, the only way I can see to grab a Page Texture is through this line of code referencing DocumentInstance:
Texture2D AC.DocumentInstance.GetPageTexture (int pageNumber)
The way I currently have my script set up, I'm grabbing the Document ID that I want based on the inventory slot button the player clicks on (which then assigns the slot number to the "WhichPost" int I have in my code below.)
MenuInventoryBox DocumentMenu = PlayerMenus.GetElementWithName("PC_Styx", "InventoryBox") as MenuInventoryBox;
Document ActiveDocument = DocumentMenu.GetDocument(WhichPost);
//OPImage is hooked up to the Document's main texture, not a page texture. This appears on screen as expected and there are no errors.
Texture2D OPImage = ActiveDocument.texture;
OPImageBox.sprite = Sprite.Create(OPImage, new Rect(0, 0, 104, 104), new Vector2());//set
It seems to me that there is no way to grab the individual page texture images through the Document class, even though I can grab the page text through this class? I've attempted to implement the DocumentInstance class instead and access the page textures, but I don't understand how I can hook up the Document I'm already accessing to the DocumentInstance class. I've attempted to do it this way, and just attempt to reference the currently open Document instead of the one I've defined:
Texture2D Reply1Image = KickStarter.runtimeDocuments.ActiveDocumentInstance.GetPageTexture(1);
Which does compile, but on load it gives me a NullReferenceException, I'm guessing because it's not identifying the currently open Document for some reason? I'm not really sure why that would be the case, because I do have the "Auto-open Document When Clicked?" option toggled in this inventory box. I also definitely have a page texture assigned to the page I'm trying to reference, so that also shouldn't be undefined. I am thinking I might be entirely misunderstanding how to implement this code?
In short, is it possible for me to access a Document's page textures via the Document class? If not, how would I properly access them via the DocumentInstance class?
Thanks in advance!
EDIT: OK, just as a quick update, I figured out why I was getting a NullReferenceException-- I needed to add a line of code that explicitly made sure the open document was the Document I was referring to. Now it is behaving as expected. My new code looks like this:
MenuInventoryBox DocumentMenu = PlayerMenus.GetElementWithName("PC_Styx", "InventoryBox") as MenuInventoryBox;
Document ActiveDocument = DocumentMenu.GetDocument(WhichPost);
KickStarter.runtimeDocuments.OpenDocument(ActiveDocument);
Texture2D OPImage = ActiveDocument.texture;
Texture2D Reply1Image = KickStarter.runtimeDocuments.ActiveDocumentInstance.GetPageTexture(1)
OPImageBox.sprite = Sprite.Create(OPImage, new Rect(0, 0, 104, 104), new Vector2());//set
Reply1ImageBox.sprite = Sprite.Create(Reply1Image, new Rect(0, 0, 104, 104), new Vector2());//set
Even though this is working, I'd love to know if there's a way to access a specific Document's page textures as opposed to only being able to grab the currently open Document's textures via Kickstarter, just for future reference!
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
You can use the GetCollectedDocumentInstance function to get the DocumentInstance equivalent of a given Document (or ID):
Quick note, though: accessing the DocumentInstance is only necessary if you've made changes to the assigned texture at runtime (via the SetPageTexture function). If you just want to extract the texture from the original Document definition in the Inventory Manager, you can just use: