Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 ATMEthan · Dec 14, 2012 at 10:08 PM · c#listscrollezgui

How can I make my scroll list scroll 1 item per button click?

Hello Unity Community,

Once again I come to this website in search of help. I am working on a scroll list that displays three items at once. Per button click I want to scroll one item in from the left or right depending if they click the right or left scroll button. I am really close to that functionality but there is a bit of inconsistency in my scroll list. Depending where I am in the scroll list the scroll list may or may not scroll 1 item. Sometimes it scrolls 2 items. I've been staring at this code all day and decided to ask the Unity Community. Please let me know if you help me in any sort.

So if this is my scroll list: < | item 2 item 3 item 4 | > I hit the left button ( < ) < | item 3 item 4 item 5 | > as you can see the list moved by 1 item. But sometimes this happens < | item 2 item 3 item 4 | > I hit the left button ( < ) < | item 4 item 5 item 6 | > as you can see the list moved by 2 items.

Also I should note that my list has the ability to wrap and can continuously scroll if the left/right scroll button is held down. But I believe through many debug statements that doesn't have any effect(affect?) on the inconsistency of the scrolling.

Oh, and I'm using the AnBSoft EZ GUI API using the UIScrollList.

If any one needs any addition details please ask I shall proved them. Thank you very much Unity Community! Any help is greatly appreciated!!!!

Here is how I scroll the items:

     public void gameScrollRight(){
         int currentIndex = (int)(gameScroller.ScrollPosition * gameScroller.Count);
         int toIndex = currentIndex + 2;
         print("SCROLL TO " + toIndex);
         if(toIndex >= gameScroller.Count) {
             toIndex = gameScroller.Count - 2;
             IUIListObject leftObj = gameScroller.GetItem(0);
             gameScroller.RemoveItem(0, false);
             gameScroller.AddItem(leftObj);
             leftObj.gameObject.SetActiveRecursively(true);
         }
         gameScroller.ScrollToItem(toIndex, .75f);
     }
     public void gameScrollLeft(){
         int currentIndex = (int)(gameScroller.ScrollPosition * gameScroller.Count);
         int toIndex = currentIndex - 2;
         print("SCROLL TO " + toIndex);
         if(toIndex < 0) {
             float itemWidth = gameScroller.ContentExtents / gameScroller.Count;
             toIndex = 0;
             IUIListObject rightObj = gameScroller.GetItem(gameScroller.Count - 1);
             rightObj.gameObject.SetActiveRecursively(true);
             gameScroller.RemoveItem(gameScroller.Count - 1, false);
             gameScroller.InsertItem(rightObj, 0);
             gameScroller.PositionItems();
             gameScroller.ScrollPosition += 1.0f / (gameScroller.Count - (gameScroller.viewableArea.x / itemWidth));
         }
         gameScroller.ScrollToItem(toIndex, .751f);
     }


 
Comment
Add comment · Show 10
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
avatar image ATMEthan · Dec 17, 2012 at 02:10 PM 0
Share

mmm... anyone?

avatar image XienDev · Dec 17, 2012 at 02:14 PM 0
Share

gameScroller.ScrollPosition = itemId * itemHeight > Or.. scrollPosition += itemHeight;

avatar image ATMEthan · Dec 17, 2012 at 04:58 PM 0
Share

I'm sorry can you clarify the above comment. gameScroller.ScrollPosition = itemID * itemHeight? What variable is itemID and what variable is itemHeight? I assume you mean itemWidth ins$$anonymous$$d of itemHeight.

avatar image XienDev · Dec 17, 2012 at 05:38 PM 0
Share

first question is gameScrollRight() -> currentIndex + 2; why is plus 2 ? and in gameScrollLeft() why is it - 2; ... ok..

trying to understand:

currentIndex -> is index of first item to show;

toIndex -> currentIndex - 2; -> here may be a problem...

what is gameScroller.Count is it number of items ? or size of horisontal width of item ? or what is it ??

avatar image ATMEthan · Dec 17, 2012 at 06:00 PM 0
Share

Ok let me explain. First, gameScrollerRight/Left have +/-2 respectively because currently we use that magic number to move the items. Without the two the items wouldn't move. If it was 3 items would move more than expected and if it was 1 the items wouldn't move at all. The two should represent the number of indexes you want to move.

CurrentIndex is the index of the first shown item. toIndex is where the scrollList should scroll to (obviously this doesn't always happen or I wouldnt' be asking this question)

gameScoller.Count is the number of items in the scrollList gameScoller.viewable.x(or y) is the width of the viewable area

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by XienDev · Dec 20, 2012 at 06:12 PM

try this:

     public void gameScrollRight(){
         
         int currentIndex = (int)(gameScroller.ScrollPosition * (gameScroller.Count - 2));
                 
         int toIndex = currentIndex + 2;
         
         //print("SCROLL TO " + toIndex);
         if(toIndex >= (gameScroller.Count - 1)){
             
             toIndex = gameScroller.Count - 2; // sroll to before last
             IUIListObject leftObj = gameScroller.GetItem(0);
             
             gameScroller.RemoveItem(0, false);
             gameScroller.AddItem(leftObj);
             
             leftObj.gameObject.SetActiveRecursively(true);
         }
         
         gameScroller.ScrollToItem(toIndex, .75f);
     }
     
     public void gameScrollLeft() {
         int currentIndex = (int)(gameScroller.ScrollPosition * (gameScroller.Count - 2));
 
         int toIndex = currentIndex;
         //print("SCROLL TO " + toIndex);
         if(toIndex <= 0){
             toIndex = 1;
             //float itemWidth = gameScroller.ContentExtents / gameScroller.Count;
             
             IUIListObject rightObj = gameScroller.GetItem(gameScroller.Count - 1);
             rightObj.gameObject.SetActiveRecursively(true);
             
             gameScroller.RemoveItem(gameScroller.Count - 1, false);
             gameScroller.InsertItem(rightObj, 0);
             gameScroller.PositionItems();
             gameScroller.ScrollPosition += 1.0f / (gameScroller.Count - 2);
         }
         gameScroller.ScrollToItem(toIndex, 1f);
     }
Comment
Add comment · Share
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

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.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

A node in a childnode? 1 Answer

List of C# scripting definitions 1 Answer

Object Method returning null when calling Object List from another Class 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges