Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: bariscigal on July 08, 2013, 02:06:11 PM

Title: need help for a good way for runtime generated enemy targeting HUD
Post by: bariscigal on July 08, 2013, 02:06:11 PM
Hello,
Sorry for a beginner question :

I am working on a dog-fight game. I am displaying some labels and textures on each enemy.

I don't want to manage every enemy in the scene one-by-one so i have created a script which reads all enemies based on tags and creates those information texts and textures on them at the start of the level.

 What i have right now works great but it has over 40 drawcalls with 4 enemies in the scene. Now i am trying to migrate to NGUI system.
But i am having problems creating the :

- needed labels for each enemy (distance, attack mode)
- different textures based on targeting hud objects based on the distance(can see->can fire->can lock missile) on each plane
- different textures based on friendly or enemy

on NGUI system.
I am not in search of a ready script but a pointer in the right direction.
How should i implement the needed steps?

any help would be appreciated.

(BTW i have ngui and Hud text addon)

 
Title: Re: need help for a good way for runtime generated enemy targeting HUD
Post by: ArenMook on July 08, 2013, 11:19:42 PM
NGUI's draw calls are created by panels. If you parent all of your UI to a common game object (as you normally would with NGUI -- the UIRoot at the very least), then all of your widgets should have the same UIPanel parent, resulting in only one draw call, not 40. If you have 40, then you have too many panels in the scene or you didn't use atlasing. Don't use UITextures.
Title: Re: need help for a good way for runtime generated enemy targeting HUD
Post by: bariscigal on July 09, 2013, 05:18:51 AM
Sorry i wasn't clear. I have made my ui with unity ui system. So 40 drawcalls is normal. Now i am trying to migrate my HUD to NGUI.

So i will create widget, and parent it to the same panel.
Should i use add widget or add child on the runtime?

I only need sprites and labels for runtime generated enemy HUDs.
 
Title: Re: need help for a good way for runtime generated enemy targeting HUD
Post by: bariscigal on July 09, 2013, 06:52:23 AM
Ok nevermind i think i solved it:

  1. if (GameObject.FindGameObjectsWithTag(targettag).Length > 0)
  2.             {
  3.                enemyObjs = GameObject.FindGameObjectsWithTag(targettag);
  4.                                 for (int i = 0; i < enemyObjs.Length; i++)
  5.                         {
  6.                                         GameObject enemyHUDs = NGUITools.AddChild(hareketliHUD, targetA);
  7.                                         enemyHUDs.name = "target." + enemyObjs[i].name;
  8.                                        
  9.                                         UIFollowTarget enemyFollower = enemyHUDs.GetComponent<UIFollowTarget>();
  10.                                         UISprite enemySprite = enemyHUDs.GetComponent<UISprite>();
  11.                                        
  12.                                         enemySprite.MakePixelPerfect();
  13.                                         enemyFollower.gameCamera = currentCamera;
  14.                                         enemyFollower.uiCamera = NGUICam;
  15.                                         enemyFollower.target = enemyObjs[i].transform;
  16.                                         }



This will create the needed target HUDs for each enemy object in the scene.

I would be glad if you can check and let me know if there is a better way for this?
Title: Re: need help for a good way for runtime generated enemy targeting HUD
Post by: ArenMook on July 09, 2013, 08:43:26 AM
Aside from your terrifying placement of {} brackets, looks fine to me. Whoever taught you to place brackets indented like that should be shot. Twice. :)