Search Unity

C# - Infinite Scrolling List with Elements of Different Sizes

Discussion in 'Scripting' started by drhodor, May 7, 2014.

  1. drhodor

    drhodor

    Joined:
    Aug 18, 2013
    Posts:
    39
    So I'm thinking this is a bit more of a fundamental C# question than something related to a given Unity or 3rd party tool...

    Basically I want to take a list of 2d objects that are in a line and make it scrollable (either through touch input or programatically) but make the individual elements, which are pooled, go to the front or back of the list of elements as they are scrolled so that they can loop forever. Since they are different sizes I don't necessarily know the size of the whole list of elements.

    I've been pulling my hair out trying to figure this out for a while and can't seem to grasp what I'm missing...

    Sometimes I want this to scroll quite quickly, due to user or progamattic input, so I'd prefer the solution be somewhat performant...
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    I'm not sure what your question is... you don't have to know the length of the list, there are list types which can change length dynamically as you need them. If your pooler runs out of pooled objects it just needs to create a few more and carry on. You'll have a little performance hit when instancing the new objects but it's a one off if the pool size is exceeded. Or you can work out the probably pool size based on scroll speed of the level being loaded (assuming the game gets harder by getting faster etc.) or just play test it to see what a good value for the pool size is.


    Unity peeps did a teaching vid on object pooling which had a bit on expanding the pool if it runs out of objects, I'd suggest having a look at that, Mike is quite good at explaining things.