• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by LeoGurung · Nov 25, 2014 at 08:37 AM · synchronize

How to sync two independent NGUI Scroll Views?

Hey Guys, I want to sync two different NGUI ScrollViews in Horizontal manner. In my app, 2 scroll views having grid with equal number of items are in the same screen, they need to be linked through some logic so that, if I move/swipe an item (say index 3) of scrollview1 then item with index 3 of ScrollView2 should also move with it, without me ever touching that ScrollView2.

Also, I need a spring effect at the both ends of both the scroll views when I swipe either of the two scroll views at first or last item of the grid.

So far I've done this for the end spring effect through tween positioning, but it's not working accordingly and the bottom grid is repositioning itself at the center.

 if(mainGrid.GetComponent <UICenterOnChild> ().index==0)// || mainGrid.GetComponent <UICenterOnChild> ().index==(mainGrid.transform.childCount-1))
 {
     if(Input.touchCount>0)
     {
         Touch touch = Input.GetTouch(0);
         switch (touch.phase) 
         {
             case TouchPhase.Began:
             startPos = touch.position;
             bottomGrid.AddComponent<TweenPosition> ();
             bottomGrid.GetComponent<TweenPosition> ().from = new Vector3(0,-500,0);
             bottomGrid.transform.localPosition = new Vector3 (0,-500,0);
             break;
 
             case TouchPhase.Moved:
             distanceMoved += 6;
             swipeValue = Mathf.Sign(touch.position.x - startPos.x);
             //    bottomGrid.AddComponent<TweenPosition>();
             if (swipeValue > 0)
             {
                 bottomGrid.GetComponent<TweenPosition> ().from = new Vector3(initDistance,-500,0);
                 bottomGrid.GetComponent<TweenPosition>().to = new Vector3(distanceMoved,-500,0);
                 bottomGrid.GetComponent<TweenPosition> ().duration = 0.15f;
                 bottomGrid.GetComponent<TweenPosition> ().PlayForward ();
         //        StartCoroutine(ArtificialSpringRight());
                 rightMove = true;
             }
             startPos = touch.position;
             initDistance += distanceMoved;
             break;
                                         
             case TouchPhase.Ended:
         //    bottomGrid.AddComponent<TweenPosition>();
             if(rightMove)
             {
             //    bottomGrid.GetComponent<TweenPosition> ().duration = 0.2f;
                 bottomGrid.GetComponent<TweenPosition> ().from = new Vector3(distanceMoved,-500,0);
                 bottomGrid.GetComponent<TweenPosition>().to = new Vector3(0,-500,0);
                 bottomGrid.GetComponent<TweenPosition> ().duration = 0.2f;
                 bottomGrid.GetComponent<TweenPosition> ().PlayForward ();
                 yield return new WaitForSeconds(0.2f);
                 Destroy (bottomGrid.GetComponent<TweenPosition> ());
                 rightMove = false;
             }
             initDistance = 0;
             distanceMoved = 0;    
 
             break;
         }
     }
 }


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Particle rendering based on Animation 1 Answer

Photon PUN2, Rpc score can't correctly. 1 Answer

Networking sync enabled state? 1 Answer

UNET - Sync [ClientRPC] with new players 1 Answer

Interpolating Positions, Networking 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges