Author Topic: A few questions  (Read 16106 times)

SoullessDreamer

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: A few questions
« Reply #15 on: September 12, 2014, 06:18:44 PM »
Ok another question, with this one I hope to be less of a thorn in your side.

I have made my inventory, looks amazing! It works amazing, thank you! I however come up with another problem. How do I make another UI root and camera that goes with it? Here is what I am trying to do:

I have a camera on my inventory UI, that works just fine(via NGUI). I was wondering how I am able to make a inventory and then a HUD  this way. Every time I create a new panel, UI, etc, through NGUI it always attaches itself to the original UI root. So what I am asking is if there is a way to make another UI root so I can stick another camera on it and make another viewport for the HUD. I know how to toggle the prefabs through "SetActive" and it works. That way both the HUD and the Inventory are on the same UI root. Sadly everything under the one UI root has to be(and reverts back no matter what) to the layer the UI root is. I was just hoping to have 2 'viewports' as it were so things are not all in one space. If not possible I understand, honestly I was just trying to make it look clean.

Another way to ask my question would be, how would you set this up to be 'clean' looking? Thank you for your time again!

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: A few questions
« Reply #16 on: September 12, 2014, 06:45:26 PM »
Generally you wouldn't do it as two different roots, as you would then run into trouble when positions and scales don't match anymore. Keep everything under the same root and handle multiple sections under there.

If you want to subdivide the screen into multiple parts, you can set a Clipping region on uipanels (or use a parent widget) which you can anchor the child widgets to. You can even tween the parent widgets or panels if you need things to animate in (just remember to check Offset on the panels, if you want it to move).

SoullessDreamer

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: A few questions
« Reply #17 on: September 18, 2014, 06:14:20 PM »
Thank you Nicki. I am just going to have all the UI elements on one panel and turn each item off with "SetActive" that way when you hit "I" It fades the HUD for the Inventory. Thank you for the help though.

I do have two other short questions:
1) With a UILabel, how do you send a number to it? I have tried this
  1. UILabel lbl = GetComponent<UILabel>();
  2. lbl.text = "Hello world!";
but the 'lbl.text' does not work with numbers(obviously). I have looked around this site and could not find anything. I even dove into UILabel and UISlider.

2) Also if there is a way to make the UISlider "Value" to be more than 0-1? Something like 0-1000? If not I can multiply the value before it gets to the UILabel. I just need to know how to send numbers to a UILabel before that can happen.

Thank you in advance.

SoullessDreamer

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: A few questions
« Reply #18 on: September 19, 2014, 04:24:07 PM »
Ok so I figured it out. I filtered the UISlider script to send it's value to a script I wrote:
  1. using UnityEngine;
  2. using System.Collections;
  3. using Assets.Code.Interfaces;
  4. using Assets.Code.States;
  5. using System;
  6.  
  7. public class MakeLableWholeNumber : MonoBehaviour
  8. {
  9.         public GameObject label1;
  10.  
  11.                 // Use this for initialization
  12.                 void Start ()
  13.                 {
  14.                         label1 = GameObject.Find ("/GameManager/UI Root/Control - Colored Progress Bar/Thumb/Label1");
  15.                 }
  16.        
  17.                 // Update is called once per frame
  18.                 public void Update ()
  19.                 {
  20.                        
  21.                 }
  22.  
  23.                 public void MakeItemAmount()
  24.                 {
  25.                         UILabel label = label1.GetComponent<UILabel> ();
  26.                         label.text = Mathf.RoundToInt(UIProgressBar.current.value * 1000f) + "";
  27.                 }
  28. }
This gave me not only the amount I needed(1000 items max) but will allow me to do more with everything later. Now I don't need it right at this moment, but I see a problem with it going past 1000. So my original question about setting the Value in UISlider, being 0-1, is still valid. Is there a way to up it? That way I can do above 1000?

Thank you again for your time.

Edit: Ok I found the value from the '1-0 Value slider' in UIProgressBarEditor. Sadly if changed from 0-1 to 0-100 it automatically sets the value to 1(In inspector) and you can't change it. If someone could point me in the right direction on where to edit to get the value slider to do more than 0-1 that would be amazing.

Another issue I am having is how to get the UISlider's Value to start at 0.001 vs 0.01(default). If someone could point me to the script and line where to change this, I would be most appreciative. Thank you.
« Last Edit: September 19, 2014, 06:10:42 PM by SoullessDreamer »

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: A few questions
« Reply #19 on: September 19, 2014, 06:29:20 PM »
Any value can stringified. For any given number just do

  1. label.text = 12.ToString();
  2.  

As for UISlider, no, the entire idea of a progressbar is that it's always 0-1. That said, you shouldn't use the UI to hold actual data - it should just represent your underlying dataset. So, say if you want to show 768 out of 1000 you would fill it in from your data like so:

  1. mySlider.value = 768f / 1000f;
  2.  

And if you want to make it a little nicer:

  1. public int MyMaxSliderValue = 1000;
  2. public int MyCurrentSliderValue = 500;
  3.  
  4. public void SetSlider()
  5. {
  6.   mySlider.value = MyCurrenSliderValue / MyMaxSliderValue;
  7. }
  8.  

Where you would set the max and current from wherever, and then call the SetSlider. Of course there are cleverer ways of doing it (like use properties that automatically update the slider, or a single method that sets everything and updates) but there you go.

SoullessDreamer

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: A few questions
« Reply #20 on: September 19, 2014, 09:06:43 PM »
No, the data is from my GameManager from a few scripts I made and attached to it. I have an idea on how to go about this. I do thank you for your help. I will post back if I have anymore questions.

Thank you again.