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.

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…