Author Topic: How to proper move widget from ScrollView to aonther panel run-time?  (Read 3962 times)

papatriz

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 10
    • View Profile
Hello,

I have a Scrollview with a bunch of widgets inside. Each widget actually is a button which start associated game level.
I want to add visual effect when button clicked. E.g. moving and scaling its image and shadowing all other staff.

......
 |___ ShadowPanel (depth 1)
 |___ ScrollView panel (depth 0)
         |___ Grid
                   |_ Icon01
                    ......
                   |_ IconNN

So, I have to move IconXX from ScrollView to ShadowPanel (otherwise it will be shadowed, and dont be tweened properly), and when tween it somehow.
First, I did it in this way:

  1. IconTransform.SetParent(ShadowPanel.transform);
  2.  
  3. foreach (UIWidget widget in IconTransform.GetComponentsInChildren<UIWidget>())
  4. {
  5.    ShadowPanel.AddWidget(widget);
  6. }
  7.  

This one works almost fine for my needs - actually i see one icon staying at place and "new" instance doing tween things.
But if icon transform moves outside ScrollView rect (via scaling or changing position) - it "jump" back to scroll panel: i.e. become shadowed and affected by clipping.

Of course, I tried ScrollViewPanel.RemoveWidget, but in this case NGUI stop updating widget on screen.

I tried to use panel.Refresh, panel.RebuildDrawCalls and so on, but all this things doesnt matter at all.

So my question is simple - what I do wrong? :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to proper move widget from ScrollView to aonther panel run-time?
« Reply #1 on: July 22, 2017, 02:57:40 PM »
You set its transform's parent and do NGUITools.MarkParentAsChanged on its game object to let NGUI know that you've done so.

papatriz

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: How to proper move widget from ScrollView to aonther panel run-time?
« Reply #2 on: July 22, 2017, 03:41:50 PM »
Thank you very much!

I looked into NGUI tools, but unfortunately miss this one.