Author Topic: HUD Text in the Asset Store  (Read 36403 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: HUD Text in the Asset Store
« Reply #15 on: July 15, 2012, 09:22:49 AM »
Sure thing, glad you figured it out. I passed out shortly after pushing that update last night.

catacomber

  • Guest
Re: HUD Text in the Asset Store
« Reply #16 on: July 15, 2012, 02:23:16 PM »
Thank you for the update!  :  )

I have a small problem, probably because I'm so new to NGUI----I have a Cat in my test scene and a First Person Controller. I like First Person because it's what I and my players are used to---at least for now.

I want the cat to talk to me like the Orc talks to the other Orc---in the example scene 1.  He looks at me and follows me if I'm close to him and move around but he doesn't say anything.   I need some simpler instructions on how to set up the scene if possible.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: HUD Text in the Asset Store
« Reply #17 on: July 15, 2012, 02:27:12 PM »
The conversation script there is just an example. I suggest you write your own simple one.

  1. using UnityEngine;
  2.  
  3. [RequireComponent(typeof(HUDText))]
  4. public class Test : MonoBehaviour
  5. {
  6.         HUDText mText;
  7.         float mNextUpdate = 0f;
  8.  
  9.         void Awake () { mText = GetComponent<HUDText>(); }
  10.  
  11.         void Update ()
  12.         {
  13.                 if (mNextUpdate < Time.time)
  14.                 {
  15.                         mNextUpdate = Time.time + 2f;
  16.                         mText.Add("\"Meow!\"", Color.white, 0f);
  17.                 }
  18.         }
  19. }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: HUD Text in the Asset Store
« Reply #18 on: July 15, 2012, 02:27:56 PM »
P.S. This script would be attached to the same object as your HUDText.

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: HUD Text in the Asset Store
« Reply #19 on: July 15, 2012, 04:41:45 PM »
Aren, your HUDText package has a "Rotate.cs" that collides with a script of the same name in PlayMaker.

Side note:  I really wish vendors would append a unique prefix to all of their scripts.  For example, it would be nice if all NGUI classes started with "NGUI_" or similar.  More cumbersome, yes, but ensuring that you'd likely never get a namespace collision with products from other vendors.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: HUD Text in the Asset Store
« Reply #20 on: July 15, 2012, 04:44:44 PM »
It's in the "examples" folder. You don't need it for HUDText to function. Just don't import that folder if you're merging it with other packages.

catacomber

  • Guest
Re: HUD Text in the Asset Store
« Reply #21 on: July 15, 2012, 07:05:39 PM »
Aren, your HUDText package has a "Rotate.cs" that collides with a script of the same name in PlayMaker.

Side note:  I really wish vendors would append a unique prefix to all of their scripts.  For example, it would be nice if all NGUI classes started with "NGUI_" or similar.  More cumbersome, yes, but ensuring that you'd likely never get a namespace collision with products from other vendors.

It works nicely except the text is too large---very large--- and backwards. Don't know what am doing wrong. I don't get any error mesages.

But I understand now how the Example Scenes are set up and left you five stars in the Asset Store.   :)
« Last Edit: July 15, 2012, 08:32:12 PM by catacomber »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: HUD Text in the Asset Store
« Reply #22 on: July 15, 2012, 07:25:04 PM »
You likely added the HUDRoot script to the wrong place. It needs to be below UIRoot somewhere (prefferably underneath a UIPanel).

P.S. I'll see about putting up a video tutorial for HUDText tomorrow.

catacomber

  • Guest
Re: HUD Text in the Asset Store
« Reply #23 on: July 15, 2012, 07:37:12 PM »
I think I did.  :  )  That's how my little kitty got his mighty roar. :  )  The tutorial would be great. Have a wonderful night.  :  ) 

catacomber

  • Guest
Re: HUD Text in the Asset Store
« Reply #24 on: July 15, 2012, 08:06:39 PM »
I can think of all sorts of wonderful things i can do with the examples! F.e., you could meet two statues in a dungeon and one could give you hints that are helpful and one hints that are all wrong, one could tell you how wonderful a hero you are and one could insult you. :  )  Just have to nail down the basics.  8)

Would like to see an example of how one npc for example would say something, other one answer, just like the orcs but dialogues would not repeat. I don't think this could be done in the chat manager but the chat manager is very nice for organizing the talk.
« Last Edit: July 15, 2012, 08:17:58 PM by catacomber »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: HUD Text in the Asset Store
« Reply #25 on: July 15, 2012, 08:21:21 PM »
The chat manager is just an example. It's not really meant to be used in a game -- just that particular example. The video tutorial I'll put up tomorrow-ish will show how to add HUDText to a project and use it from within your code.

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: HUD Text in the Asset Store
« Reply #26 on: July 16, 2012, 11:42:10 AM »
Aren, I'm using UIFollowTarget.cs separately, but had to modify it for my purposes a bit (such as clamping "isVisible" to 0.1 to 0.9 so that my panels weren't so chopped off as the target approached the viewport edges), but had a problem that PixelPerfect operations weren't working properly with the displayed widgets.  I seem to have fixed this by modifying the following lines with a 0.5f pixel offset:

      // If visible, update the position
      if (isVisible)
      {
         transform.position = mUICamera.ViewportToWorldPoint(pos);
         pos = transform.localPosition;
         pos.x = Mathf.RoundToInt(pos.x) + 0.5f;
         pos.y = Mathf.RoundToInt(pos.y) + 0.5f;
         pos.z = 0f;
         transform.localPosition = pos;
      }

Perhaps you use this class with your other scripts and do the 0.5 nudging there, but this seems to make the UIFollowTarget class work a bit better on its own.

Note:  I'm using UIFollowTarget as a child of the UICamera without having it a child of a UIAnchor object, which might be why I have to do this.
« Last Edit: July 16, 2012, 11:47:42 AM by JRoch »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: HUD Text in the Asset Store
« Reply #27 on: July 16, 2012, 11:53:24 AM »
Actually yes. There should be a UIAnchor on the HUD game object (same one that has HUDRoot). The anchor applies the half-pixel offset. I'll patch it in.

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: HUD Text in the Asset Store
« Reply #28 on: July 16, 2012, 12:24:17 PM »
Got it.  Having the UIAnchor in the mix makes my changes unnecessary.  However, you might add in public vars for UIFollowTarget that are the border/padding of the viewport to determine "isVisible".  In addition, I added in code that does a SetActive as a condition of isVisible so that items that go off-screen don't leave the NGUI panel orphaned on the edge of the screen where it lost visibility.

  1. // class variable
  2. private bool childrenEnabled = true;
  3.  
  4.  
  5. // ... this below is part of  "void Update()" ...
  6.  
  7.         // If visible, update the position
  8.         if (isVisible)
  9.         {
  10.             if (!childrenEnabled)
  11.             {
  12.                 childrenEnabled = true;
  13.                 for (int x = 0; x < this.transform.childCount;x++)
  14.                 {
  15.                     NGUITools.SetActive(this.transform.GetChild(x).gameObject, true);
  16.                 }
  17.             }
  18.  
  19.         transform.position = mUICamera.ViewportToWorldPoint(pos);
  20.         pos = transform.localPosition;
  21.         pos.x = Mathf.RoundToInt(pos.x);
  22.         pos.y = Mathf.RoundToInt(pos.y);
  23.         pos.z = 0f;
  24.         transform.localPosition = pos;
  25.         }
  26.         else
  27.         {
  28.             if (childrenEnabled)
  29.             {
  30.                 childrenEnabled = false;
  31.                 for (int x = 0; x < this.transform.childCount; x++)
  32.                 {
  33.                     NGUITools.SetActive(this.transform.GetChild(x).gameObject, false);
  34.                 }
  35.             }
  36.         }
  37.  
« Last Edit: July 16, 2012, 01:25:51 PM by JRoch »

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: HUD Text in the Asset Store
« Reply #29 on: July 16, 2012, 12:54:57 PM »
PM sent to Aren with suggestions added to code.