Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Populating UI panels with Text

Discussion in 'UGUI & TextMesh Pro' started by nathanjams, Mar 31, 2017.

  1. nathanjams

    nathanjams

    Joined:
    Jul 27, 2016
    Posts:
    304
    Hello,

    I have a rather vague question. I'm sure that if I knew the proper terms I'd be able to search and resolve this on my own. But I can't, so I'm here.

    I would like to have one generic UI panel that displayed the contents of image and text components that are attached to trigger game objects, ones that when clicked on open the UI panel.

    The game I'm working on is an educational type game, so when a player clicks on a certain object I would like a UI panel to appear giving information, basically an info box.

    Honestly, I have no idea how to search for this solution so any information is appreciated.

    Sincerely,
    Nathan
     
  2. Zonlib

    Zonlib

    Joined:
    Apr 15, 2014
    Posts:
    39
    You may need to use world space canvas. Like this:

     
    nathanjams likes this.
  3. nathanjams

    nathanjams

    Joined:
    Jul 27, 2016
    Posts:
    304
    @BiDuc

    Thanks for the link, that's a really great video. There's a lot of useful little bits in there.

    Unfortunately, that's not really what I was trying to describe. My issue is that I have, say, 100 triggers in a scene. Each trigger corresponds to a UI page that displays information, an image and a brief description of the image.

    How I have it now is there are 100 UI panels (they simply get turned on and off when the corresponding trigger is activated. It works but it's rather cumbersome as I have two folders: one for triggers in the game; and one in the UI Canvas. I need to make sure that each are sync'd.

    What I imagine is having one single UI panel that functions as a template and is fed, in real time, the contents from the triggers as they are activated. So the panel would display the info form a text box and image component that is a part of the trigger game object. I'd actually like to get from referencing a database, but baby steps.

    But thanks for you response, that video will help with other elements a lot.
    Nathan
     
  4. Zonlib

    Zonlib

    Joined:
    Apr 15, 2014
    Posts:
    39
    So, you create a UI template then create a database such as an .xml file that stores the id and image path and information like this:

    Code (CSharp):
    1. <imformations xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    2.   <info id="0" photo_path="photo/thumb1.png" >
    3.       Description 0
    4.   </info>
    5.   <info id="1" photo_path="photo/thumb2.png" >
    6.       Description 1
    7.   </info>
    8.   <info id="2" photo_path="photo/thumb3.png" >
    9.       Description 2
    10.   </info>
    11. </imformations>
    When a user clicks on a trigger, the application retrieves the information from the xml file based on the id attribute and loads it into the UI
     
    nathanjams likes this.
  5. nathanjams

    nathanjams

    Joined:
    Jul 27, 2016
    Posts:
    304
    Thanks again, @BiDuc

    Out of curiosity, is this your code or is there a link to more information about this? I'm not a strong programmer but if I have examples or materials to work with I can piece my way together. This is exactly what I was hoping to get to eventually, but if I can actually do it now I might as well put my energy into it now.

    Thanks again!

    Nathan
     
  6. Zonlib

    Zonlib

    Joined:
    Apr 15, 2014
    Posts:
    39
    That is my code. I used to do the same thing and I'm ready to make a tutorial if you need it :)
     
    nathanjams likes this.
  7. nathanjams

    nathanjams

    Joined:
    Jul 27, 2016
    Posts:
    304
    Hey, @BiDuc

    That is extremely generous of you and would be amazing if it's not too much work. I should be able to put the pieces together if you just give me the general idea of how to go about this.

    For example, one thing that still completely escapes me is to have the content displayed in the generic UI panel.

    Let me know if I can help at all or return the favour somehow.

    Nathan
     
  8. Zonlib

    Zonlib

    Joined:
    Apr 15, 2014
    Posts:
    39
    Sorry for late @nathanjams
    Today I have time to make the promise, hope you still need it.
    I made a small video tutorial for you and who needed it.

     
    nathanjams likes this.
  9. nathanjams

    nathanjams

    Joined:
    Jul 27, 2016
    Posts:
    304
    Holy crap! Biduc.

    Thank you so much for doing this. Yes, I still have a need for it. I won't get a chance to tackle this until later in the week, but i'll let you know how it all goes.

    Seriously, seriously, seriously. Thank you.

    Nathan
     
  10. nathanjams

    nathanjams

    Joined:
    Jul 27, 2016
    Posts:
    304
    Just a little bump for this thread. This is an awesome example for those unfamiliar with incorporating XML databases into their unity projects. The tutorial is very straightforward and easy to follow and provides you with a very easy to understand foundation for further modification.

    Big ups to BiDuc for going way beyond on this.