Author Topic: UIDragScrollView resets scrollView  (Read 13297 times)

Markov

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
UIDragScrollView resets scrollView
« on: December 03, 2013, 12:16:14 PM »
Hi!
after last update, if I set UIDragScrollView.scrollView manually:
  1. outlinesObject.scrollView = gameObject.GetComponent<UIScrollView>();

and if there is no UIScrollView in parents, the UIDragScrollView script resets scrollView paremeter to null.
in this line of UIDragScrollView.Press function:
  1. if (!pressed && mAutoFind) scrollView = NGUITools.FindInParents<UIScrollView>(mTrans);

can you fix it and add scrollView!= null in this condition?

if (!pressed && mAutoFind && scrollView!= null) scrollView = NGUITools.FindInParents<UIScrollView>(mTrans);

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDragScrollView resets scrollView
« Reply #1 on: December 03, 2013, 06:30:28 PM »
Thanks, try the attached script.

zazery

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: UIDragScrollView resets scrollView
« Reply #2 on: December 03, 2013, 07:11:28 PM »
Those changes also fixed the problem I encountered yesterday where scrollView wasn't set when adding a child using NGUITools.AddChild.

ComicSans

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 6
    • View Profile
Re: UIDragScrollView resets scrollView
« Reply #3 on: January 14, 2014, 04:02:56 PM »
I found another small bug in UIDragScrollView.  NGUI version 3.0.8f7

When UIDragScrollView is first enabled and has no scrollView, mAutoFind is set to true.  If you then manually set scrollView and UIDragScrollView goes through another disable/enable cycle before being pressed, mAutoFind remains set to true at the end of FindScrollView, even though the auto-found view does not match the manual view.

I fixed this in my copy by adding a final else clause to the branches in FindScrollView, setting mAutoFind to false.

Have a good day!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDragScrollView resets scrollView
« Reply #4 on: January 14, 2014, 09:15:39 PM »
Thanks, but if you can remind me about this after the 16th, I'd much appreciate it.

Isamson

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 52
    • View Profile
Re: UIDragScrollView resets scrollView
« Reply #5 on: January 28, 2014, 05:48:31 PM »
Bump in case you've forgotten about this :)
Unity 4.5.3f
NGUI 3.7.0

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDragScrollView resets scrollView
« Reply #6 on: January 29, 2014, 10:05:57 AM »
I think a more appropriate fix for this would be to only call FindScrollView() if 'mScroll' is null in OnEnable:
  1. if (mAutoFind || mScroll == null) FindScrollView();

renanse

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 1
  • Posts: 14
    • View Profile
Re: UIDragScrollView resets scrollView
« Reply #7 on: March 25, 2014, 02:57:08 PM »
Sorry for a little necro'ing, but just in case other folks hit this issue, I'm finding that even with your patch above I don't get the desired behavior in at least one case. I have a draggable panel I am adding via code as a sibling GameObject of the GameObject holding my scroll view.  When I add a new draggable area via code (eg, something like this:)

  1.                 dragArea = new GameObject("Drag Area");
  2.                 dragArea.AddComponent<UIDragScrollView>().scrollView = scrollView;

OnEnable is called as soon as I call AddComponent - before the assignment of scrollView.  Thus, FindScrollView enters the if (scrollView == null) and sets mAutoFind to true.  I worked around that issue by setting the GameObject to inactive before adding the component:

  1.                 dragArea = new GameObject("Drag Area");
  2.                 dragArea.SetActive(false);
  3.                 dragArea.AddComponent<UIDragScrollView>().scrollView = scrollView;
  4.                 ...
  5.                 dragArea.SetActive(true);

Hope that helps someone. :)