Author Topic: Tweening panel issue  (Read 12705 times)

Orfen

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Tweening panel issue
« on: March 28, 2014, 09:45:50 AM »
Hello i have an issue with a panel im tweening. I have 2 panels in my scene, and when the first one is disabled it moves to the left to make room for the second one. It works great, but sometimes when i play around with activating/deactivating the panels, the SpringPanel script will appear and the panel im tweening will just launch off into the unknown, never to return. I know this is associated with the momentum and spring behavior, but without the spring the scrollview kinda loses its appeal. Is there any way to get around this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tweening panel issue
« Reply #1 on: March 28, 2014, 09:48:26 AM »
Sounds unusual. Have you tried adding a Debug.Log into SpringPanel.Begin to see where it's being called from? My guess is that it happens from some Awake() function, as Awake() is generally a really bad place for that.

Orfen

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Tweening panel issue
« Reply #2 on: March 28, 2014, 10:00:30 AM »
Im not directly using SpringPanel.Begin if thats what you mean, im using TweenPosition.Begin and its not on Awake, it gets called from the UIEventListener when a click registers. By putting a debuglog inside the springpanel script i can see its normally called twice everytime im tweening the panel,and sometimes it gets called, well, a lot of times. Thats when the SpringPanel script appears attached to my panel in the inspector and everything gets messy.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tweening panel issue
« Reply #3 on: March 28, 2014, 10:04:54 AM »
What's the call stack of when it gets attached many times? It should only happen when you release the mouse after dragging the scroll view.

Orfen

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Tweening panel issue
« Reply #4 on: March 28, 2014, 10:16:59 AM »
Its getting called 24 times. I think i figured out whats causing my issue, the children in my scrollview are the ones that fire the event that starts the tweening process when clicked. If there is momentum in the scrollview the tweening or i guess the springpanel just shoots the panel way off.

Orfen

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Tweening panel issue
« Reply #5 on: March 28, 2014, 10:29:44 AM »
But setting currentmomentum to vector3.zero and then calling the tween doesnt seem to fix the problem. Any suggestions?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tweening panel issue
« Reply #6 on: March 29, 2014, 05:40:15 AM »
Well again, what's the call stack? And what's your code that triggers the spring?

Orfen

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Tweening panel issue
« Reply #7 on: March 31, 2014, 05:25:26 AM »
The method which triggers the spring is the following:

  1. public void OnClick(GameObject go){
  2.                 button=go;
  3.                 UIScrollView scroll=FirstPanel.GetComponent<UIScrollView>();
  4.                 scroll.currentMomentum=Vector3.zero;
  5.                 tween=TweenPosition.Begin(FirstPanel,0.3F,new Vector3(FirstPanel.transform.localPosition.x-645,FirstPanel.transform.localPosition.y,0));
  6.                 EventDelegate.Add(tween.onFinished,SwitchPanels);
  7.                 Return(button);
  8.  
  9.         }


and the code that populates the scroll view and assigns the onclick event is the following:

  1. public void ArticlesToView(Dictionary<int,Article> dict){
  2.                 Debug.Log("populating main view");
  3.                 tempItem=this.gameObject;
  4.  
  5.                         for(x=0;x<dict.Count;x++){
  6.                         GameObject obj=null;
  7.                         if(TotalPrefabs<dict.Count){
  8.                                 while(TotalPrefabs<dict.Count){
  9.                                 obj=CreatePrefabs(count);
  10.                                 count++;
  11.                                 trans=obj.transform.GetChild(1);
  12.                                 artbutton=trans.gameObject;
  13.                                 UIEventListener.Get(artbutton).onClick += logic.OnClick;
  14.                                 UIEventListener.Get(artbutton).onClick += topmenu.OnArticleView;
  15.                                 }
  16.                                 x--;
  17.                                 }
  18.                         else if(TotalPrefabs>dict.Count){
  19.                         while(TotalPrefabs>dict.Count){
  20.                                 DestroyPrefabs(dict.Count);
  21.                                         count--;
  22.                                 }
  23.                                 x--;
  24.                                 }
  25.                         else {
  26.                                 obj=GetPrefab(x);
  27.                                 label=obj.GetComponentInChildren<UILabel>();
  28.                                 label.text=dict[x].Title;
  29.                                 UITexture temptex=tempItem.transform.FindChild(obj.name).GetComponentInChildren<UITexture>();
  30.                                 StartCoroutine(GetImage(temptex,dict[x]));
  31.                         }
  32.  
  33.  
  34.                 }
  35.                 if(repopulate){
  36.                 scroll.ResetPosition();
  37.                 UIGrid grid=this.gameObject.GetComponent<UIGrid>();
  38.                 grid.Reposition();
  39.                 }
  40.                 repopulate=true;
  41.  
  42.         }

My issue is fixed if i use Reposition() on the scroll view just before the tween,but when i enable it its scrolled all the way down. And could you walk me through getting the call stack to you?Im not sure what you mean.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tweening panel issue
« Reply #8 on: March 31, 2014, 06:50:55 AM »
Whenever you have a Debug.Log entry, it's accompanied by the call stack that led to the entry being printed. Simply clicking on it in the console log lets you select the text and copy it via CTRL+C.

Orfen

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Tweening panel issue
« Reply #9 on: March 31, 2014, 08:08:33 AM »
I got those two:

Springed
UnityEngine.Debug:Log(Object)
SpringPanel:Begin(GameObject, Vector3, Single) (at Assets/NGUI/Scripts/Internal/SpringPanel.cs:111)
UICenterOnChildModified:CenterOn(Transform, Vector3) (at Assets/4.Scripts/UICenterOnChildModified.cs:183)
UICenterOnChildModified:Recenter() (at Assets/4.Scripts/UICenterOnChildModified.cs:156)
UICenterOnChildModified:OnEnable() (at Assets/4.Scripts/UICenterOnChildModified.cs:43)
UnityEngine.GameObject:SetActive(Boolean)
NGUITools:SetActiveSelf(GameObject, Boolean) (at Assets/NGUI/Scripts/Internal/NGUITools.cs:1122)
NGUITools:Activate(Transform) (at Assets/NGUI/Scripts/Internal/NGUITools.cs:969)
NGUITools:SetActive(GameObject, Boolean) (at Assets/NGUI/Scripts/Internal/NGUITools.cs:1023)
ButtonLogic:SwitchPanels() (at Assets/4.Scripts/ButtonLogic.cs:57)
EventDelegate:Execute() (at Assets/NGUI/Scripts/Internal/EventDelegate.cs:235)
EventDelegate:Execute(List`1) (at Assets/NGUI/Scripts/Internal/EventDelegate.cs:302)
UITweener:Update() (at Assets/NGUI/Scripts/Tweening/UITweener.cs:222)



Springed
UnityEngine.Debug:Log(Object)
SpringPanel:Begin(GameObject, Vector3, Single) (at Assets/NGUI/Scripts/Internal/SpringPanel.cs:111)
UICenterOnChildModified:CenterOn(Transform, Vector3) (at Assets/4.Scripts/UICenterOnChildModified.cs:183)
UICenterOnChildModified:CenterOn(Transform) (at Assets/4.Scripts/UICenterOnChildModified.cs:198)
<CenterOn>c__Iterator1:MoveNext() (at Assets/4.Scripts/CustomPanelMovement.cs:90)

Orfen

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Tweening panel issue
« Reply #10 on: April 01, 2014, 08:22:42 AM »
bump

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tweening panel issue
« Reply #11 on: April 01, 2014, 10:03:57 AM »
Yeah that just points to your custom script, I can't help you much with that.

Orfen

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Tweening panel issue
« Reply #12 on: April 02, 2014, 02:02:49 PM »
If you mean the UICenterOnChildModified, i just commented out a Recenter function after the drag is finished. If you mean one of my other scripts i guess im doing something stupid somewhere. Sorry to keep pestering you, but could you give me some general guidelines on whats the proper way to tween a scroll view so that the panel moves along with the grid? If you can i ll try and figure it out from there.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tweening panel issue
« Reply #13 on: April 02, 2014, 03:55:44 PM »
"So that the panel moves along with the grid"?

Remember you can always tween the scroll view's parent into place instead of the scroll view itself. Doing so will avoid whatever issue you're running into.