Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: vikti on December 01, 2014, 03:14:05 AM

Title: Load atlas, make a sprite and add to hierarchie
Post by: vikti on December 01, 2014, 03:14:05 AM
Hi,

I am looking for a good code example to :

1- Load an atlas in Resource by its name
2- create a new sprite (or widget, what is the best here, drawcalling speaking ?) using the sprite name.
3- Attach to the hierarchy.

This will be in a loop to create hundred of icons on a map.

I need help for the two first steps. Thanks for your time :)
Title: Re: Load atlas, make a sprite and add to hierarchie
Post by: ArenMook on December 02, 2014, 11:23:31 AM
Assuming your atlas is in the Resources folder,
  1. GameObject atlasGameObject = Resources.Load("name of your atlas") as GameObject;
  2. UIAtlas actualAtlas = atlasGameObject.GetComponent<UIAtlas>();
  3. UISprite sprite = NGUITools.AddChild<UISprite>(objectInYourUItoAddTo);
  4. sprite.atlas = actualAtlas;
  5. sprite.spriteName = "Some Sprite";