Author Topic: NGUI: HUD Text  (Read 192037 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #30 on: September 29, 2012, 04:17:52 PM »
Is your orthographic camera's range set up correctly? Maybe the label is always outside the view frustum, which is why it gets disabled.

steddyman

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: NGUI: HUD Text
« Reply #31 on: September 29, 2012, 05:28:04 PM »
The Ortho camera for the UI is the one created by the Create a new UI menu option.  It has a near plane of -2 and a far of 2.

As said, all the other items under this camera are appearing correctly and so are HUDText if they don't have a target set.

If I set a target AND set DisableIfInvisible=true then it all works and displays correctly.  If I set DisableIfInvisible=false (default) then the labels created underneath the HUDText are always disabled.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #32 on: September 29, 2012, 07:54:01 PM »
Right, but if you look at the code, nothing changes the enabled state of the labels if "disableIfInvisible" is set to 'false': line 83 of UIFollowTarget.

The only way they would be disabled is if you disabled them yourself somehow -- or had them start as disabled.

Goosery

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 35
    • View Profile
Re: NGUI: HUD Text
« Reply #33 on: October 02, 2012, 09:33:44 AM »
Hi there,

Awesome package!  However I am using it as a notification system that needs to display multi-line text.  I use it as below:
  1.                
  2. public void displayHudText(string key, string replacementValue, Color color, float time){
  3.         string textValue = MessageUI.getValue(key, replacementValue);
  4.                 HUDText ht = getInstance<HUDText>();
  5.                 ht.Add(textValue, color, time);
  6.                
  7.                 float scale = 447f/(float)Screen.height;
  8.                 float maxWidth = Screen.width*.35f* scale;
  9.                
  10.                 UILabel[] labels = ht.GetComponentsInChildren<UILabel>();
  11.                 UILabel label = labels[ labels.Length-1 ];             
  12.                 label.lineWidth=(int)maxWidth;
  13.                 label.pivot = UIWidget.Pivot.TopLeft;
  14. }
  15.  

Basically I get a HUDText object(or create one if doesn't exist) then I call the Add() method.  After that I do the line wrapping, which works just fine.  Everything works perfectly!

The problem comes in when my displayHudText() method is called again before the previous text has faded.  It only pops the previous message up by 1 line.  So this works fine for single line texts, but when the text is 2 or more lines, the previous text and the new text will overlap, except for the new text's last line, and the old text's first line.  Is there a way to make the previous text pop up more than 1 line, depending on how many lines the texts are?

Thanks!

Nepoez
« Last Edit: October 02, 2012, 09:43:46 AM by nepoez »

Goosery

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 35
    • View Profile
Re: NGUI: HUD Text
« Reply #34 on: October 02, 2012, 10:02:25 AM »
I have currently a work around, which is to use a dummy UILabel object to process the text, then grab the processed text and then split it by the '\n' then loop through each line and pass it to HudText.Add(), then it will work perfectly.  But perhaps there's already a built in way to avoid this that I don't know of?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #35 on: October 02, 2012, 04:03:24 PM »
Try changing line 248 of HUDText from:
  1. offset += Mathf.Round(ent.label.cachedTransform.localScale.y);
To:
  1. offset += Mathf.Round(ent.label.relativeSize.y * ent.label.cachedTransform.localScale.y);

kaywoods

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
How to stay HUDText and handling layer depth
« Reply #36 on: November 09, 2012, 10:44:38 PM »
Both NGUI and HUDText packages are imported successfully and works well..

And Two Questions.

1. How the hudText display the UILabel permanently ?
When I put the code like-" hudText.Add("Hello World!", Color.white, 1f);-- it disappeared the UIText after the one seconds duration(1f), I think..

But I'd like to display the text persistently before I manually destroy the text.
So, I set the third parameter to the zero, like this- hudText.Add("Hello World!", Color.white, 0f);,
But it didn't work..
How do I to do that???


2. I added  the hudText.Add() to the several enemies,
And all those have UILabel(produced by hudText.Add()), displayed the screen, even though some of the enemies are hidden behind the building...

I think, if the enemy is at the behind of the building, the hudText UILabel also should be placed at the behind of the building so that it doesn't seen to the players.

How can I do this???


Thanks...in advance... 
« Last Edit: November 10, 2012, 10:43:00 AM by kaywoods »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #37 on: November 10, 2012, 11:28:41 AM »
Don't use HUDText to display permanent things (such as unit's name). Just create a regular UILabel for that and use UIFollowTarget script on it to have it follow your 3D object.

It's up to you to check if you need checks like "is the unit behind a building?" -- generally doing a raycast into the screen to see if it hits your unit or not prior to calling hudText.Add() is the easiest solution.

Crazy Robot Games

  • Guest
Re: NGUI: HUD Text
« Reply #38 on: November 11, 2012, 04:44:49 PM »
Hey,

I have an object that changes rotation from 0 to 180, when it's at 180, the HUD GUI is backwards. What can I do to make it face the correct way towards the camera at all times?

Thanks,

JL

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #39 on: November 12, 2012, 11:16:19 AM »
I think you're missing a face camera script on your UI element.

h0p3y

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: NGUI: HUD Text
« Reply #40 on: November 24, 2012, 08:08:43 AM »
Hi there i'm very new to unity but very familiar with javascript is there a javascript "hello world" tutorial for HUD Text? I have looked around but have not been able to find anything.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #41 on: November 24, 2012, 08:24:21 AM »
I don't know Javascript, but it should be generally the same as C#. You will need to place HUDText into the Plugins folder along with the full version of NGUI set up for Javascript in the same fashion. You will then be able to call all of HUDText's functions, such as hudText.Add("your text");

h0p3y

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: NGUI: HUD Text
« Reply #42 on: November 24, 2012, 01:26:03 PM »
hey thanks i figured it out - i just wasn't sure how to access a c# method from inside the javascript - some research and fussing with compilation order and i got it! thanks!   :)

joduffy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: NGUI: HUD Text
« Reply #43 on: December 06, 2012, 12:36:47 AM »
I have NGUI and was about to buy this addon.

I just wanted to know if it would work with IOS and Android

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #44 on: December 06, 2012, 04:47:26 AM »
Yup, sure does. It's just an extension to NGUI, and NGUI runs everywhere.