Author Topic: NGUI Texture background behind gameobjects with multi uicameras  (Read 4798 times)

joduffy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Hi guys,

I am creating a 2D game.
Everything is done but I want to change the way I do one part. I am currently applying a texture to a plane object and having it act as the background for my game.

What I would like to do is replace this with an ngui simple texture.

I have tried to create my own shader but I am new at it and the results were not that good. I also tried to setup two uicameras. One for the standard ui elements and another for the background.

To get one uicamera to work as the background I just change its depth. The problem is the simple texture keeps updating or changing from background layer to gui layer at runtime.

Any ideas on how to fix this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Texture background behind gameobjects with multi uicameras
« Reply #1 on: March 15, 2014, 06:18:56 PM »
Just add a UITexture (ALT+SHIFT+T), choose your texture, and move it back in depth so that it's behind everything. No need to create any extra cameras.

Also when instantiating any NGUI object at run-time make sure to use NGUITools.AddChild, or NGUITools.AddWidget. It sets the layers properly.

Lastly, all widgets underneath a panel always assume the panel's layer. So if the panel is on the GUI layer, then the widgets will also adopt the GUI layer.

joduffy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: NGUI Texture background behind gameobjects with multi uicameras
« Reply #2 on: March 28, 2014, 03:34:42 AM »
Hi dude,

Sorry for late reply. I got swamped by assignments. I cannot seem to control the textures depth at all. The box is grayed out
and while it is behind all the ngui elements. It is not behind the the unity2d sprite objects.

Am I missing something?

joduffy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: NGUI Texture background behind gameobjects with multi uicameras
« Reply #3 on: March 28, 2014, 03:52:44 AM »
An update to NGUI fixed the grayed out box issue. But I am still trying to figure out how to get the texture to show up behind the unity2d sprites

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Texture background behind gameobjects with multi uicameras
« Reply #4 on: March 28, 2014, 09:38:19 AM »
If the 2D sprites are drawn using UI2DSprite, then it will work out of the box. If the sprites are drawn using Unity 2D, then it's more complicated and involves messing with panel's render queue. There is another thread on this: http://www.tasharen.com/forum/index.php?topic=8761.0

joduffy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: NGUI Texture background behind gameobjects with multi uicameras
« Reply #5 on: March 28, 2014, 05:49:00 PM »
Hi dude,

I tried using the script but it didnt work.

I can understand what you mean by it being tricky if you have a main camera and a ngui camera. Due to how they draw elements or order of draw. So just to clarify, I am using two cameras - one for unity sprites and the other for ngui gui's.

It seems that what I have to do is create a 3rd camera to act as a background camera for  drawing the background image. I could try moving all the elements into the ngui system i guess. Which would then allow me to use the depth draw call.

So my options are:

1) 3 cameras.
or
2) one camera which is ngui to draw everything.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Texture background behind gameobjects with multi uicameras
« Reply #6 on: March 29, 2014, 06:03:23 AM »
If your objects are drawn using different cameras then there is no way to make them mix, as I explained at the end of the thread I linked.

Yes, those are the two options.