Author Topic: Unity 2d sprite and NGUI  (Read 17806 times)

Moradom

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 15
    • View Profile
Unity 2d sprite and NGUI
« on: January 12, 2014, 12:20:12 AM »
Hello,

I am trying to find information on how to handle having Unity 2D sprites with a NGUI framework. All of my menus and interacting widgets are NGUI, but I also need to use Unity's 2D sprites in the game scene. I have seen a few posts from ArenMook stating that there are issues with this currently and that Unity 4.5 might address this. I can't wait until 4.5 comes out  :(

One problem that I am having is the rendering order of NGUI components and Unity's 2D sprites. I can understand this since NGUI does not use Z depth for the draw order. One way I fix this is by adjusting the Z value on the Non-NGUI sprites so it is closer to the camera. I feel like this is playing with fire if it is within an NGUI framework (I have seen my sprites appear behind an NGUI component on one device and on top of it on another device). All of my sprites will need to be drawn last, so I can continue to adjust the Z value until this is consistent. How can I solve this problem the right way? Or is this an acceptable approach?

I would use UI2DSprite class but it is not integrated within Unity's sprite animation work flow. After using NGUI I do not want to go back to EZGUI. Anyone have suggestions on how this can be done correctly?

Best Regards!

 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Unity 2d sprite and NGUI
« Reply #1 on: January 12, 2014, 05:54:39 PM »
Unity's animation work flow supports the 2D sprite renderers because special handling was added to them. NGUI has a public UnityEngine.Sprite2D reference, but Unity's animation system is not picking it up. It's just one of many issues with the current implementation in 4.3. The people behind it wanted the system out as quickly as possible, without considering coders, let alone plugin devs like us.

If your 2D stuff should go on top of NGUI stuff, I would suggest keeping it simple and creating another camera to draw all the 2D stuff. Then you can work with NGUI elements using NGUI's sorting (by depth), and your 2D elements using 2D's sorting, without having them interfere with each other.

Moradom

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 15
    • View Profile
Re: Unity 2d sprite and NGUI
« Reply #2 on: January 12, 2014, 07:33:11 PM »
Hi  ArenMook,

Thanks for the reply I was thinking of that for the sprites that needs to be on top. Do you have any suggestions for Non-NGUI sprites that will be in between NGUI panels? I am trying to keep this to a minimum but I do have a few.

Best Regards 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Unity 2d sprite and NGUI
« Reply #3 on: January 13, 2014, 06:18:48 PM »
Non-NGUI sprites in between of NGUI panels is more difficult to do. You would need to manually change the panels to use specific render queues. I wouldn't recommend you doing this. You can use UI2DSprite to draw 2D sprites instead, which is using NGUI, but its functionality is pretty limited until Unity 4.5.

PabloAM

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 58
    • View Profile
Re: Unity 2d sprite and NGUI
« Reply #4 on: May 29, 2015, 05:26:32 PM »
Hello, Is there any solution for that?

I have a panel with NGUI, that it has a button animation do it with "unity2D render sprites".
Unity2D sprites there is on top, so if other panel is at top of the panel with the button with animation, the panel is behing the other panel but the button of back panel is in front of the other panel. :(

Any suggestion?

Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Unity 2d sprite and NGUI
« Reply #5 on: June 01, 2015, 08:34:41 PM »
Unity 2D sprites and NGUI sprites are different things. The only bridge between the two is UI2DSprite -- an NGUI widget that draws a Unity sprite.