First I want to say @sngdan thanks for helping on this
Lets say that user is using a device (my Samsung 10.1 1280x800 pixels), now the image I might be using is 1969x1926 so this is larger than the screen, so I must allow zooming, BUT if the user Zooms they MUST only zoom out if the image e.g “GameObject” is larger “Out of view” than the screen so if for example I zoom out but now I can see all the image horizontally, I should only be able to scroll “move the image with my finger” in the vertical way.
I’ve uploaded my editor image “Editor-Image” and the Second Image “Editor-Image2” when I’ve zoomed out, this is to do with the information I have just explained.
public void AreaUpdate()
{
mRenderer = Drawing.GetComponent<SpriteRenderer>();
Single mWidth = mRenderer.bounds.size.x + 4;
Single mHeight = mRenderer.bounds.size.y + 4;
Single mLeft = Drawing.transform.position.x - (mWidth * 0.5f);
Single mTop = Drawing.transform.position.y - (mHeight * 0.5f);
mSelectorArea = new Rect(mLeft, mTop + 2, mWidth, mHeight);
}
This Calculates the Area “World Space” of the Drawing you see “This does not change”.
private void UpdateSketchPosition()
{
switch (mZoomLock)
{
case ZoomLock.None:
this.transform.position = new Vector3(Mathf.Clamp(this.transform.position.x, mSelectorArea.xMin + mCameraHalfWidth, mSelectorArea.xMax - mCameraHalfWidth), Mathf.Clamp(this.transform.position.y, mSelectorArea.yMin + mCameraHalfHeight, mSelectorArea.yMax - mCameraHalfHeight), this.transform.position.z);
break;
case ZoomLock.Vertical:
this.transform.position = new Vector3(Mathf.Clamp(this.transform.position.x, mSelectorArea.xMin + mCameraHalfWidth, mSelectorArea.xMax - mCameraHalfWidth), 0F, this.transform.position.z);
break;
case ZoomLock.Horizontal:
this.transform.position = new Vector3(0, Mathf.Clamp(this.transform.position.y, mSelectorArea.yMin + mCameraHalfHeight, mSelectorArea.yMax - mCameraHalfHeight), this.transform.position.z);
break;
case ZoomLock.Both:
this.transform.position = new Vector3(0F, 0F, this.transform.position.z);
break;
}
}
Now the above code positions including zoom of the object of the screen, so if no Zoom lock is need we can freely move the object with our finger or mouse(“this is for testing etc”).
I hope this makes more sense and is a better guide?
Cheers.