Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: FOX_ITA on February 03, 2014, 11:38:02 AM

Title: ScrolloView scroll automatically to last children, please
Post by: FOX_ITA on February 03, 2014, 11:38:02 AM
Hello guys,

im having some troubles how the scrollview works and how to get my things works.

the scripts above :

  1. GameObject profile = NGUITools.AddChild(m_profilesGrid.gameObject, prefabPlayerProfile);
  2.                 UIButton button = profile.GetComponentInChildren<UIButton>();
  3.                 UIEventListener.Get(button.gameObject).onClick += this.OnPlayerSelection;
  4.                 m_profilesGrid.repositionNow = true;
  5.  
  6.                 UILabel profileLabel = profile.GetComponentInChildren<UILabel>();
  7.                 Debugger.Assert(profileLabel != null);
  8.  
  9.                 profileLabel.text = Game.State.GetProfile(profileIndex).Name;
  10.  
  11.                 UIPanel mPanel;
  12.                 UICenterOnChild mCenter;
  13.                
  14.  
  15.                 mCenter = NGUITools.FindInParents<UICenterOnChild>(profile.gameObject);
  16.                 mPanel = NGUITools.FindInParents<UIPanel>(profile.gameObject);
  17.  
  18.                 mCenter.CenterOn(profile.transform);
  19.                 SpringPanel.Begin(mPanel.cachedGameObject, mPanel.cachedTransform.InverseTransformPoint(profile.transform.position), 6f);
  20.  

The child is added correctly in row but if i move the slider to last one or another position, all the time brings me to the first.

Instead of this behaviour i'd like to move to the last one added.

Can you help me please?

many thanks!
Title: Re: ScrolloView scroll automatically to last children, please
Post by: ArenMook on February 04, 2014, 02:29:25 AM
I don't quite understand what you're trying to do. If it's just center on a specific object, UICenterOnChild.CenterOn is enough. Why are you doing a SpringPanel as well? When you use a scroll bar and release it, UICenterOnChild kicks in, and it won't run your custom code.
Title: Re: ScrolloView scroll automatically to last children, please
Post by: FOX_ITA on February 05, 2014, 08:22:25 AM
Hi,

thanks to reply. I just wanna center on the last child. Now i'm only using UICenterOnChild.CenterOn using the last object ( profile ) but all the time is centered on the first child..!

i removed the SpringPanel...

thanks

EDIT : i've fixed. Was simple. I just wanna center instantly after the item creation, but i understood that the place of creation was under the first item and then moved. So i delayed the OnCenter call and everything work now!!