Author Topic: Load atlas, make a sprite and add to hierarchie  (Read 1766 times)

vikti

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 25
    • View Profile
Load atlas, make a sprite and add to hierarchie
« 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 :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Load atlas, make a sprite and add to hierarchie
« Reply #1 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";