Author Topic: Load SpriteRenderers From Atlas?  (Read 10872 times)

Ace

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 24
    • View Profile
Load SpriteRenderers From Atlas?
« on: August 04, 2014, 10:23:23 PM »
Hello!

I have been trying to re-use the same Atlas (that I made with the atlas maker) to create Sprite objects (i.e. SpriteRenderers that get their sprite from an NGUI made atlas).

Is this possible?

I tried loading texture file that came with the atlas but it only has 1 main texture (the whole atlas). (Whereas, for example, if I import a sprite sheet from Texture Packer, I can iterate through each texture in the sprite sheet).

So how can I pull out just 1 texture from an NGUI atlas and make it into a sprite object?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Load SpriteRenderers From Atlas?
« Reply #1 on: August 05, 2014, 01:16:23 PM »
Nope, they are different things. NGUI atlas sprites are drawn using UISprite. Unity 2D sprites are drawn using SpriteRenderer.

NGUI's sprites are what pull individual sprite textures from the atlas texture. Why are you trying to use Sprite Renderers anyway? ALT+SHIFT+S to make your sprite, choose the atlas, choose the sprite, and you're done.

Ace

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 24
    • View Profile
Re: Load SpriteRenderers From Atlas?
« Reply #2 on: August 05, 2014, 01:43:13 PM »
I am trying to map a 'sprite' on to a plane and use it in a 3D environment.

Using NGUI sprites will be used in the GUI where I was I want this to be the surface of a plane (hence why Ive been using Sprite Renderers).

Can I turn NGUI sprites into 3D objects?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Load SpriteRenderers From Atlas?
« Reply #3 on: August 05, 2014, 01:51:18 PM »
You can use NGUI's widgets in a 3D environment.

Create a game object, attach UIPanel to it, and now you can add child widgets to it freely.

Ace

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 24
    • View Profile
Re: Load SpriteRenderers From Atlas?
« Reply #4 on: August 05, 2014, 07:11:16 PM »
That's a great idea!

Is there an advanced tutorial set or documentation on this?

Id really love to look at the more advanced features of NGUI.

And hurry up with Unity 5 man! (haha so glad you're working on it!!!)

Ace

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 24
    • View Profile
Re: Load SpriteRenderers From Atlas?
« Reply #5 on: August 05, 2014, 07:50:45 PM »
One issue Im running into (and I looked at all the other 3D sprite posts), is how to get it working properly.

I have created a widget, and added a UI panel to it.

Then I add a sprite.

The sprite does not let me freely position it and it creates a second render in the project window.

Could you elaborate on the steps or point me to the documentation on making a 3D sprite (I am definately messing up one step haha).

I dont have free movement widget (it moves around in hard values and way out of scale)



ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Load SpriteRenderers From Atlas?
« Reply #6 on: August 06, 2014, 09:31:19 PM »
You should never add widgets and panels to the same game object. Panel needs to be on a separate game object, above the widget in the hierarchy.

It should be like this:

GameObject (UIPanel, scaled to something small like 0.01, 0.01, 0.01)
- UISprite, or anything else you need below it

Also, I am not working at Unity anymore -- I left in November of last year. NGUI has been my full time job. ;)

lzt120

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 68
    • View Profile
Re: Load SpriteRenderers From Atlas?
« Reply #7 on: August 07, 2014, 02:33:54 AM »
Have any idear of Atlas for 2D Sprite ? As it draw with Sprite Renderer and one sprite need one DC which is not allowed for mobile games even the PC games. What I can do is waiting for Unity 4.6 ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Load SpriteRenderers From Atlas?
« Reply #8 on: August 07, 2014, 04:00:48 AM »
You need to enable sprite packing for Unity to actually batch sprites.

Edit -> Project Settings -> Editor. Change Sprite Packer mode to "Always Enabled".

Not an NGUI question btw.

lzt120

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 68
    • View Profile
Re: Load SpriteRenderers From Atlas?
« Reply #9 on: August 07, 2014, 08:51:44 PM »
UnityException: Sprite is not rectangle-packed. TextureRect is invalid.
UI2DSprite.OnFill (.BetterList`1 verts, .BetterList`1 uvs, .BetterList`1 cols) (at Assets/NGUI/Scripts/UI/UI2DSprite.cs:302)
UIWidget.UpdateGeometry (Int32 frame) (at Assets/NGUI/Scripts/Internal/UIWidget.cs:1421)
UIPanel.UpdateWidgets () (at Assets/NGUI/Scripts/UI/UIPanel.cs:1478)
UIPanel.UpdateSelf () (at Assets/NGUI/Scripts/UI/UIPanel.cs:1157)
UIPanel.LateUpdate () (at Assets/NGUI/Scripts/UI/UIPanel.cs:1116)


Using 2DSprite with Unity 2D atlas packing tools, Exception as above. Does NGUI 2DSprite do not support for atlas ? or this is Unity's issue ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Load SpriteRenderers From Atlas?
« Reply #10 on: August 08, 2014, 08:42:56 AM »

lzt120

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 68
    • View Profile
Re: Load SpriteRenderers From Atlas?
« Reply #11 on: August 09, 2014, 08:47:02 AM »
Thanks. If I want change 2D Sprite, Must the way as to change UITexture ? I have to has one script and there is one list to hold all the 2d Sprite  in project window and select one from that list ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Load SpriteRenderers From Atlas?
« Reply #12 on: August 09, 2014, 05:20:44 PM »
Sorry, I don't understand the question.

lzt120

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 68
    • View Profile
Re: Load SpriteRenderers From Atlas?
« Reply #13 on: August 10, 2014, 09:46:16 AM »
How Can I change the 2D Sprite of NGUI at runtime ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Load SpriteRenderers From Atlas?
« Reply #14 on: August 10, 2014, 05:47:49 PM »
GetComponent<UI2DSprite>().sprite2D = someNewSprite?