Author Topic: [Solved] ScrollView not clipping child items.  (Read 6005 times)

Abnaxus

  • Guest
[Solved] ScrollView not clipping child items.
« on: April 25, 2013, 09:59:50 AM »
Quote
Quote
Why is my stuff not getting clipped by my clipped panel?
1. Check to make sure that you have shaders turned on. This means NOT targeting GLES 1.1, and NOT having your quality set to Fastest.
2. Make sure that the atlas used by your widgets is using the Unlit/Transparent Colored shader. If you have Simple Textures (UITextures) in there, make sure that they too use this shader.
3. Make sure the clipped panel uses uniform scale: (1, 1, 1).
4. Your widgets that you want clipped must not have an extra panel in between of them and the clipped panel. Open the Panel Tool, select one of your widgets that should be clipped, and note which panel gets highlighted in the Panel Tool. If it's not your clipped panel, then you have an extra panel in there that you should remove.
5. Make sure that the shaders can be loaded properly. Did you move the NGUI's Resources folder somewhere?

Hi there,

I'm currently doing a scrollview GameObject (0) containing GameObjects (1) (with sprite objects as child) which also contains a GameObject (2) (with sprite and UILabel as child).
And the prob is that the GameObject (2) doesn't clip.
Obviously, the error comes from the "4" in the quote; but the problem is that when I'm instanciating the UILabel on a child of GameObject (2), it automatically add UIPanel component to my GameObject (2) and doesn't use the one as parent (the Draggable Panel / GameObject (0)).

Do you have any idea why it creates a new Panel instead of using the closest parent Panel ?

Thanks in advance for your answer.

Yours sincerely,
Abnaxus.
« Last Edit: May 13, 2013, 05:26:03 AM by Abnaxus »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [Problem] ScrollView not clipping child items.
« Reply #1 on: April 25, 2013, 12:58:11 PM »
Without seeing how you add this child, as well as other objects, I can't help much.

Abnaxus

  • Guest
Re: [Problem] ScrollView not clipping child items.
« Reply #2 on: April 26, 2013, 02:49:59 AM »
I have my dragPanel (UIPanel + Draggable Panel) which contains dropZones (simple GameObject).
And some dropZone has prefabUsedLetter child.

Well, It's a simple prefab with a sprite as child and whom I wanna add a UILabel.

From now, I show you the code, gonna be easier. ^^'

  1. public static GameObject createLetter(string letter, UIFont currentFont)
  2.         {
  3.                 GameObject newLetter = GameObject.Instantiate(Edit_SceneManager.prefabUsedLetterStatic) as GameObject;
  4.                 newLetter.name = "Used Letter";
  5.                 newLetter.AddComponent<Rigidbody>();
  6.                 newLetter.rigidbody.useGravity = false;
  7.                
  8.                 GameObject text = new GameObject();
  9.                 text.transform.parent = newLetter.transform;
  10.                
  11.                 UILabel label = text.AddComponent<UILabel>();
  12.                 //label.panel = Edit_SceneManager.dragPanelStatic.GetComponent<UIPanel>();
  13.                 label.font = currentFont;
  14.                 label.text = letter;
  15.                 label.MakePixelPerfect();
  16.                 label.name = "UILabel";
  17.  
  18.                 label.transform.localPosition = new Vector3(0f, -10f, -0.1f);
  19.                 label.transform.localScale = new Vector3(150f,150f,1);
  20.                
  21.                 newLetter.AddComponent<Edit_DragItem>().init (false, currentFont, letter);
  22.                
  23.                 return newLetter;
  24.         }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [Problem] ScrollView not clipping child items.
« Reply #3 on: April 26, 2013, 01:28:08 PM »
1. You need to instantiate using NGUITools.AddChild(parent, child). It does parenting and setting of layers properly, the latter of which you don't do at all.

2. You should be adding widgets using NGUITools.AddWidget. However I really don't recommend doing what you're doing to begin with. Create your desired label object in the scene, save it as a prefab, then instantiate this prefab. Creating things dynamically like you are doing is a giant pain in the ass.

3. When you add a label, you have to make sure that the object has already been parented to the UI hierarchy. I don't see where you're parenting it to the hierarchy at all. I assume you are doing it outside this function, by which point it's too late already.

Abnaxus

  • Guest
Re: [Problem] ScrollView not clipping child items.
« Reply #4 on: April 30, 2013, 07:52:58 AM »
First of all, thanks for answering my question !

Then I have few questions:

About 1), what's the difference between NGUITools.AddChild(parent, child) and parent.transform.parent = child.transform ?

About 2), I've been adding my Widget like that for few scenes and it works perfectly well. So, is there an undesired problem I didn't yet encountered ?
About the dynamically, I have no other choice (or I don't know Unity enough).

About 3), Thanks ! It was the actual prob. :)
I guess he couldn't find the previously declared UIPanel, since it wasn't parented. ^^'


So everything's solved, but I applied 1 out of 3 of your advices. So if you could lighten me about the rest, would be lovely.

Thanks again.
Best regards,
Abnaxus

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [Problem] ScrollView not clipping child items.
« Reply #5 on: April 30, 2013, 10:36:08 PM »
1. I explained it in the previous post. If you want to know more, just open the function. NGUI comes in source code form for a reason after all.

2. The way you are doing it = a lot more code. I offered a more visual solution.