Author Topic: Clip view problem (urgent, please help!)  (Read 6758 times)

AXE

  • Guest
Clip view problem (urgent, please help!)
« on: January 09, 2013, 12:07:31 PM »
Hi,

I have this strange problem here.

I have a clip view and a grid; if I manually add children to the grid in the editor, everything looks fine (the clip view bounds are marked in yellow in the first picture).

http://imageshack.us/photo/my-images/252/nguiproblem01.jpg/

While at runtime, one of the objects in the hierarchy won't be clipped away. (Picture 2)

http://imageshack.us/photo/my-images/507/nguiproblem2.jpg/

The shader I'm using is "Unlit - Transparent Colored (HardClip)". In the hierarchy there is another object (the glass square), which uses the same shader and is behaving correctly. Both these objects are meshes (not sprites) with their own material and texture.

I guess there is something wrong in the code instantiating the icons at runtime. Here's is the code I use:

  1. GameObject spellInHand = NGUITools.AddChild(handGrid, (GameObject)Resources.Load("SpellIcon_Container"));
  2. spellInHand.name = player.OnHandCards[i].Id.ToString();
  3. Transform iconBackground = spellInHand.transform.FindChild("Background");
  4. iconBackground.gameObject.renderer.material.SetTexture("_MainTex", (Texture2D)Resources.Load("Textures/Illustrations/Cards/" + player.OnHandCards[i].Id.ToString()));
  5. spellInHand.GetComponent<SpellIcon>().spellCard = player.OnHandCards[i];
  6.  

AXE

  • Guest
Re: Clip view problem (urgent, please help!)
« Reply #1 on: January 09, 2013, 02:23:46 PM »
Looks like it has to do with the number of materials. In this case, every icon uses a different material (I need that because every icon uses a different texture which is being loaded dinamically). If I instantiate the same icon (with the same material) N times, the clip view and the grid behave correctly, while if I instantiate 7 or more icons with different materials, the problem appears.

Is there a limit to the number of materials I can use in a clip view?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Clip view problem (urgent, please help!)
« Reply #2 on: January 09, 2013, 03:31:17 PM »
1. Don't use the HardClip shader. Android devices shit a brick when you use it on some.
2. Clipping won't work if you're running it on GLES 1.1 / ARMv6. You need GLES 2.0 / ARMv7.
3. Clipping won't work if the panel's game object, or one of the objects leading up to it has a non-uniform scale (ie: 2, 1, 1 instead of 1, 1, 1).
4. When instantiating things, use NGUITools.AddChild, as it sets the layer properly for you.

AXE

  • Guest
Re: Clip view problem (urgent, please help!)
« Reply #3 on: January 09, 2013, 03:40:13 PM »
1. Don't use the HardClip shader. Android devices shit a brick when you use it on some.
2. Clipping won't work if you're running it on GLES 1.1 / ARMv6. You need GLES 2.0 / ARMv7.
3. Clipping won't work if the panel's game object, or one of the objects leading up to it has a non-uniform scale (ie: 2, 1, 1 instead of 1, 1, 1).
4. When instantiating things, use NGUITools.AddChild, as it sets the layer properly for you.

What can I use, then? I need to have some mesh objects with textures, not sprites. Is there any other shader I can use with that? If I don't use HardClip, those objects won't be clipped in a clip view...

Also, I'm already using AddChild...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Clip view problem (urgent, please help!)
« Reply #4 on: January 09, 2013, 03:42:15 PM »
"Unlit/Tranpsparent Colored" <-- this is the default shader with NGUI, and it automatically switches itself for clipped panels. On the panel itself, specify alpha clipping, or soft clipping with a border of 1.