Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Which part of content window you can see when Scrolling

Discussion in 'UI Toolkit' started by Dankowski92, Jun 24, 2020.

  1. Dankowski92

    Dankowski92

    Joined:
    Jun 12, 2019
    Posts:
    2
    I'm displaying a timeline that can be rescaled and enlarged horizontally. When the timeline content window enlarges, it grows larger than the viewport and becomes scrollable.

    I would like to display information from the timeline based on wherever one browses their mouse over. Unfortunately I do not know which section of the timeline I'm browsing over as I only know my mouse position relative to the viewport window and not the content window.

    Is there anyway to know exactly which section of a content window is being displayed in a scroll view?
     
  2. danm36

    danm36

    Joined:
    May 18, 2016
    Posts:
    10
    ScrollViews have a
    scrollOffset
    property as a Vector2. Adding that to your mouse position should get you the correct position on the scrollable element that the mouse is over.
     
    Last edited: Jun 25, 2020
  3. uMathieu

    uMathieu

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    384
    You can use the ChangeCoordinatesTo extension method to move from one element local space to the other. WorlToLocal/LocalToWorld might be of use as well
     
  4. Dankowski92

    Dankowski92

    Joined:
    Jun 12, 2019
    Posts:
    2
    I have declared a public ScrollView object in script but it is not showing as a property in the Inspector window in the script component. There are no compile errors and I made sure I have saved it.
     
  5. uMathieu

    uMathieu

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    384
    As VisualElements are not serializable, you can't see them in the inspector