Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: catacomber on July 12, 2012, 07:26:11 PM

Title: HUD Text in the Asset Store
Post by: catacomber on July 12, 2012, 07:26:11 PM
Thank you so much for this! Just in case no one saw it yet in the Asset Store---the minute I saw it, I checked my paypal balance.  :  )

I'll probably have questions, because I always do.

But once more, thank you!!! 

I now routinely check NGUI in search bar in the Asset Store to see if there's anything new.  :  )
Title: Re: HUD Text in the Asset Store
Post by: ArenMook on July 12, 2012, 07:31:43 PM
I have quite a few things like this... dynamic stylized game minimap for example...

But when it comes to preparing a package for the asset store I have to create tutorials, documentation, screenshots, icons, and later -- support them, which result in me just focusing on other tasks... :X
Title: Re: HUD Text in the Asset Store
Post by: catacomber on July 12, 2012, 07:44:16 PM
Waiting for minimap. :  )  Some people have stores on their website and also on asset store. Whatever you do, I am following.  :  )  Thank you again!!!

F.e., Mr. Necturus. Mostly I buy from asset store but sometimes from his website. I try to support useful things in any way I can.
Title: Re: HUD Text in the Asset Store
Post by: catacomber on July 14, 2012, 10:05:46 PM
I need a little help here when I have NGUI and Hud Text both imported into my project--it's a test project. I posted in the Hud Text thread and don't want to duplicate my post.  :  ) 
Title: Re: HUD Text in the Asset Store
Post by: ArenMook on July 14, 2012, 10:07:02 PM
Oh you just reminded me what I was doing on Friday... making a video about it... hang on.
Title: Re: HUD Text in the Asset Store
Post by: catacomber on July 14, 2012, 10:09:57 PM
Hanging by my last cat hair. Thank you for the solution---will delete that.  :  )
Title: Re: HUD Text in the Asset Store
Post by: catacomber on July 14, 2012, 10:15:05 PM
It's useful especially for NPC's if they're walking around.  :  )
Title: Re: HUD Text in the Asset Store
Post by: catacomber on July 14, 2012, 10:24:39 PM
Just reopened project and new errors:

Assets/HUD Text/NGUI/Scripts/Editor/UIWidgetInspector.cs(16,19): error CS0433: The imported type `UIWidget' is defined multiple times
Assets/NGUI/Scripts/Editor/BMFontReader.cs(47,34): error CS0433: The imported type `BMFont' is defined multiple times


I'm sure this is easy to fix---just don't know how. I'm really happy to have this though and will patiently await the advice. Only reason I'm posting here is so that you'll see it.  :  )  If you will recheck that thread under HUD Text up top, I'll just put any comments there.
Title: Re: HUD Text in the Asset Store
Post by: ArenMook on July 14, 2012, 10:27:15 PM
I assume you're putting NGUI into the HUDText's project? You need to follow the same instructions as for upgrading NGUI:

1. Start a new scene.
2. Delete the NGUI folder.
3. Import NGUI from the updated package.
Title: Re: HUD Text in the Asset Store
Post by: catacomber on July 14, 2012, 10:36:43 PM
I still get those two console errors. I deleted NGUI. Created a new scene. I have Hud Text in the project already. Reimported updated NGUI and still same.

I could try it with a new project. Just let me know.

PS. Never updated NGUI before--have only had it for a week. :  )  Thanks for letting me know how to do that.
Title: Re: HUD Text in the Asset Store
Post by: catacomber on July 14, 2012, 10:50:32 PM
I created a new project and imported Hud Text and updated NGUI and still get those two errors. Just letting you know. :  ) Am the essence of patience and value your work. When I look at some of the complete projects in Unity and their GUItextures stuff, I think how simple it would be to do that with NGUI and I'm quite content to wait for your solutions.  :  ) 
Title: Re: HUD Text in the Asset Store
Post by: ArenMook on July 14, 2012, 11:11:49 PM
I just put up an update on the Asset Store. There were 3 discrepancies with the upgrade. LookAtTarget script (fixed by making its GUID match NGUI's), Orc prefab's GUID matching NGUI (which it shouldn't have been), and orc armor material's GUID matching NGUI (also shouldn't have been). I fixed the first two issues, and left the last one in there on purpose. Now when the upgrade is successful, the orc's armor will turn white instead of its original red (just to make it obvious that you've changed something by upgrading).

That said, the upgrade process works fine. If you grab the update and it still happens for you, then you are not deleting the DLL that comes with the distribution version of NGUI (packaged with the HUD Text). Make sure you are deleting the NGUI folder from a new scene. Nothing should remain. After you delete it, you should see 3 errors show up in the console log that will remain there until you import NGUI again from another package (full one).
Title: Re: HUD Text in the Asset Store
Post by: catacomber on July 14, 2012, 11:30:12 PM
I grabbed the update and created a new project with both HUD text and NGUI in it and deleted the NGUI dll from Hud Text file and now all I get is this:

Assets/NGUI/Scripts/Tweening/TweenFOV.cs(14,25): error CS0246: The type or namespace name `UITweener' could not be found. Are you missing a using directive or an assembly reference?

Does it make sense?
Title: Re: HUD Text in the Asset Store
Post by: catacomber on July 15, 2012, 12:35:07 AM
I'm trying a few different ways to get this to work but it's late and I'm really tired. If I make a new project and add just the Hud text and delete the NGUI dll from it and then import my full NGUI, it seems to repopulate the NGUI folder in the HUD text as well as adding the NGUI folder that should be there.  But again it's late and am folding......
Title: Re: HUD Text in the Asset Store
Post by: catacomber on July 15, 2012, 02:35:47 AM
Not willing to be defeated by the Error Monster, I tried one more time. Made a new project with the Standard Assets. Saved the scene and project. Imported the Hud Text. Saved a new scene---not save as--just save--that was my problem maybe----deleted the NGUI folder from HUD text project. Imported NGUI.

My only error now is that stupid Third Person Controller script error that Unity let slip through.  :  ) 

Everything else is fine.  Thanks!
Title: Re: HUD Text in the Asset Store
Post by: ArenMook 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.
Title: Re: HUD Text in the Asset Store
Post by: catacomber 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.
Title: Re: HUD Text in the Asset Store
Post by: ArenMook 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. }
Title: Re: HUD Text in the Asset Store
Post by: ArenMook on July 15, 2012, 02:27:56 PM
P.S. This script would be attached to the same object as your HUDText.
Title: Re: HUD Text in the Asset Store
Post by: JRoch 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.
Title: Re: HUD Text in the Asset Store
Post by: ArenMook 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.
Title: Re: HUD Text in the Asset Store
Post by: catacomber 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.   :)
Title: Re: HUD Text in the Asset Store
Post by: ArenMook 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.
Title: Re: HUD Text in the Asset Store
Post by: catacomber 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.  :  ) 
Title: Re: HUD Text in the Asset Store
Post by: catacomber 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.
Title: Re: HUD Text in the Asset Store
Post by: ArenMook 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.
Title: Re: HUD Text in the Asset Store
Post by: JRoch 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.
Title: Re: HUD Text in the Asset Store
Post by: ArenMook 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.
Title: Re: HUD Text in the Asset Store
Post by: JRoch 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.  
Title: Re: HUD Text in the Asset Store
Post by: JRoch on July 16, 2012, 12:54:57 PM
PM sent to Aren with suggestions added to code.
Title: Re: HUD Text in the Asset Store
Post by: ArenMook on July 16, 2012, 02:41:53 PM
The disabling of the HUD when it's off-screen should be your game code. Ideally you will want to have a root object that will do this, and this root object will have children, among which is your unit's health bar, any and all on-screen elements (such as Unit's name), and of course -- HUDText. This script will be enabling/disabling only children, leaving itself enabled at all times (otherwise it won't be able to re-enable itself after it gets disabled). This object will also have the UIFollowTarget script on it.

P.S. I'll add this in though, controlled by a boolean flag.
Title: Re: HUD Text in the Asset Store
Post by: ArenMook on July 16, 2012, 02:51:17 PM
http://www.youtube.com/watch?v=diql3UP1KQM

I forgot to boost the volume. Too quiet?
Title: Re: HUD Text in the Asset Store
Post by: JRoch on July 16, 2012, 10:13:53 PM
It's a little quiet, yes.

Also, I had to mod UIFollowTarget with the following:

  1.                         pos = transform.localPosition;
  2.                         pos.x = Mathf.FloorToInt(pos.x);
  3.             pos.y = Mathf.FloorToInt(pos.y);
  4.                         pos.z = 0f;
  5.                         transform.localPosition = pos;
  6.  

This is to prevent the HUD item from jittering if the target object is sweeping through space with the camera rigidly attached.  Little rounding errors of the transform position make the calculated center bounce around +/- 1 pixel if using mathf.round().  Using FloorToInt or CeilToInt prevents that behavior.
Title: Re: HUD Text in the Asset Store
Post by: catacomber on July 17, 2012, 12:34:59 AM
Thank you for the video tutorial-----a little louder would be good. But I was able to follow.   :  )  I was out without my computer today. Only just got a chance to watch it and download the updated HUD Text.
Title: Re: HUD Text in the Asset Store
Post by: ArenMook on July 17, 2012, 10:21:06 AM
Ok I will change it to be "FloorToInt" in the next update, thanks.
Title: Re: HUD Text in the Asset Store
Post by: JRoch on July 18, 2012, 12:34:22 AM
EDIT:  Okay, I definitely need to get a better understanding of the coordinate system translations that are taking place, because the changes below definitely have some wonky behavior.  Ignore for now.


Aren, a bit of a correction, as just using Ceil or Floor doesn't fix it completely.  This does:

  1.             // prevent jitter by only moving the object if it's more than one pixel
  2.             if (Mathf.Abs(transform.localPosition.x - pos.x) > 1.5f || Mathf.Abs(transform.localPosition.y - pos.y) > 1.5f)
  3.             {
  4.  
  5.                             transform.position = _mUiCamera.ViewportToWorldPoint(pos);
  6.                             pos = transform.localPosition;
  7.                             pos.x = Mathf.CeilToInt(pos.x);
  8.                 pos.y = Mathf.CeilToInt(pos.y);
  9.                             pos.z = 0f;
  10.                 transform.localPosition = pos;
  11.  
  12.             }
  13.  

It's essentially making sure the delta in pixels in either the X or Y direction is more than one pixel, so that it doesn't jitter.  Might need a little more fine tuning.
Title: Re: HUD Text in the Asset Store
Post by: JRoch on July 18, 2012, 01:48:37 AM
Alright, I think I understand the logic here.  Jumping the camera around was causing the UIFollowTarget script to act weird with the earlier mods because of the Z value not being compared.  Here's what I came up with:

Note:  _lastZPosition is a private float used to track changes in Z between cycles and determine if a significant change requires recalculating the position of the follow.

  1.             // prevent jitter by only moving the object if it's more than one pixel
  2.             if (Mathf.Abs(transform.localPosition.x - pos.x) > 1.5f || Mathf.Abs(transform.localPosition.y - pos.y) > 1.5f || Mathf.Abs(_lastZPosition - pos.z) > 1.5f)
  3.             {
  4.                 _lastZPosition = pos.z;
  5.                             transform.position = _mUiCamera.ViewportToWorldPoint(pos);
  6.                             pos = transform.localPosition;
  7.                             pos.x = Mathf.CeilToInt(pos.x);
  8.                 pos.y = Mathf.CeilToInt(pos.y);
  9.                             pos.z = 0f;
  10.                 transform.localPosition = pos;
  11.  
  12.             }
  13.