Search Unity

Is ScrollRect insufficient?

Discussion in 'UGUI & TextMesh Pro' started by secondbreakfast, Aug 22, 2014.

  1. secondbreakfast

    secondbreakfast

    Joined:
    Jan 5, 2013
    Posts:
    98
    I'm trying to make a menu similar to angry birds where it has a bunch of pages of level grids. I have the grid layout fine with the new ui component and I have 5 sets of grids in a panel side by side. Now I'm trying to get scroll text to 'lock' on to the closest center of each grid. My scroll rect is using elastic with deceleration. I've tried using a number of the interfaces such as IDragHandler. I get the drag events, but they stop immediately when you stop dragging and no events occur while it is decelerating. I also tried the scroll handler and that doesn't produce any events. It almost seems like in order to do what I'm trying to do, I have to ditch scroll rect and reimplement the entire mechanism myself. Is that true? Has anyone else built an angry birds style level menu with the new UI?
     
  2. Karriz

    Karriz

    Joined:
    May 24, 2013
    Posts:
    18
    I would like to know as well how to do something like this with the new UI system, haven't found anything which is surprising, considering that this type of menu is very common in mobile games.
     
  3. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Right, we should probably add an event that's invoked when the Scroll Rect changes scroll position.
     
    DanSuperGP likes this.
  4. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    @runevision "should probably" means it will be added in some upcoming beta, right? :)
    Also when is IScrollHandler supposed to be invoked (as its name implies that it should be invoked during scroll)?
     
  5. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    It will.

    It is. Scroll events from the OS that is. Not scrolling of any particular UI control.
     
    ortin likes this.
  6. bobmoff

    bobmoff

    Joined:
    Sep 23, 2014
    Posts:
    44
    Is there no way to extend the ScrollRects OnScroll method or do I have to wait for you guys to implement an event for it ?

    What is the reason for not making these methods virtual så that the community can easily extend it when needed ?

    I might be missing something obvious here, as I am totally new to Unity.

    I am trying to make the scrollrect affect the position of the camera. The reason for this is that when having ScrollRect content with many child objects the scroll performance is really poor. There seem to be a call to Graphic.OnRectTransformDimensionsChange() for each child object which adds up to be very expensive.

    Here is my previous question in the Answers site:
    http://answers.unity3d.com/questions/801417/translating-a-game-object-with-many-child-objects.html

    And a related question before that:
    http://answers.unity3d.com/questions/796021/a-game-entirely-made-with-the-new-ui.html
     
    Last edited: Oct 2, 2014
  7. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    The event callback discussed earlier in this thread was implemented a while ago:
    http://docs.unity3d.com/460/Documentation/ScriptReference/UI.ScrollRect-onValueChanged.html

    As for overriding the OnScroll method, it seems it was an oversight that is hasn't been made virtual. We'll look into making this more consistent.
     
  8. bobmoff

    bobmoff

    Joined:
    Sep 23, 2014
    Posts:
    44
    Ah, thats great. I missunderstood the documentation, and thought that it was when a connected slider to the scrollrect was changing position. stupid that I didnt even try it out, but I will now!

    http://glui.me/?i=x2zm5hljz8tgiby/2014-10-02_at_22.51.png/

    and... thanks for the superfast reply, but I missed it coz I didnt see the alert until now. Is there a way to get an email when there is an alert in this forum ?
     
  9. bobmoff

    bobmoff

    Joined:
    Sep 23, 2014
    Posts:
    44
    Ah, I forgot. Do you happen to know anything about the calls to Graphic.OnRectTransformDimensionsChange() on all child objects of the content object when scrolling ?

    Will it be possible, in the future, to have a "bunch" of objects inside the scrollrect without this performance cost ?
     
  10. bobmoff

    bobmoff

    Joined:
    Sep 23, 2014
    Posts:
    44
  11. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Weren't aware of that. Can you file a bug report?
     
  12. bobmoff

    bobmoff

    Joined:
    Sep 23, 2014
    Posts:
    44
    Sure!
     
  13. cboxgo

    cboxgo

    Joined:
    Oct 9, 2014
    Posts:
    8
    I would love to find a solution to this using a scrollrect as well. I was trying to write a horizontal sliding level menu, and ultimately gave up and simply centered the first level button and wrote a script to allow swiping to slide out the first and slide in the next button, which is located off screen. Having the Scrollrect perform this function could make the sliding-effect more smooth so I'm interested in seeing this when it can be done.

    Also, I find it hard to use a Scrollrect for text in a TextBox-like manner, because the text can keep scrolling to indefinitely... Is there any chance that there is a way to create scrolling text in a textbox, in Unity? Thanks!