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 barbe63 · Feb 17, 2015 at 12:57 AM · editor-scriptingscrollbar

Help with scrollbar and offset

Hi there,

I'm having trouble developping a level editor for my game. I need to zoom on my editor and to use scrollbar to navigate on the map, so far so good but when it comes to transform my map I'm having trouble with including the scrollbar offset to the equation.

So here what my code looks like without the offset:

 floorMap[Mathf.FloorToInt(ev.mousePosition.x/(window.position.width*zoomLevel/sizeX), Mathf.FloorToInt(ev.mousePosition.y/(window.position.height*zoomLevel/sizeY))] = selectedFloorTile;


floorMap is a 2d array that stores the tile's types, window.position width and height are for the size of the window, sizeX and sizeY are the numbers of tiles per axis. So i can't manage to find how to include the offset variable in this equation which is set by this code btw:

  if(zoomLevel !=1)
                 {
                     offsetZoom.x = GUI.HorizontalScrollbar(new Rect(0, window.position.height-20, window.position.width, 20), offsetZoom.x, zoomLevel, 0, window.position.width);
                 }

(for now i only have the x offset) In addition in the last code i use window.position.width for the scrollbar limit which is not what i should have at the end but here again i didn't find yet what I should put in there so the offset stop right when the last tile is displayed on the right. So if someone can help me on any of those questions that would be really nice!

Thank you in advance for any help.

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

1 Reply

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

Answer by barbe63 · Feb 22, 2015 at 10:17 AM

I found it after a while, it was:

A) Add the offset to the mouse position directly before everything else.

B) the offset should be evaluated in 2 steps and like this:

 offsetScroll.x = GUI.HorizontalScrollbar(new Rect(0, window.position.height-40, window.position.width, 40), offsetScroll.x, zoomLevel, 0, window.position.width-window.position.width/zoomLevel);
                     offsetTotal.x = offsetScroll.x*zoomLevel;


Same goes for y of course...

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

19 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Custom EditorWindow Scrollbars not working with GUILayout areas 1 Answer

Ho do I make unity autolayout fields shrink with the area inside which they are? 0 Answers

can't Edit ScrollRect script 1 Answer

Undo.RecordObject is too slow on large arrays, alternatives? 1 Answer

How to change settings on editor using Enum with an array? 0 Answers


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