1
NGUI 3 Support / Re: Does using TweenScale reset the camera size?
« on: November 14, 2014, 11:59:56 AM »
OK great, thanks - I'm currently looking into this.
The way I'm approaching it is by first calculating the correct size Rect bounding box around the colliders of a set of buttons on the background. I would then like to scale the background up so that when scaled, it fills the screen with what's in the bounding box (I think this should be the same as how pinch-zooming works?).
I have implemented the Rect and it's surrounding the buttons correctly. However, I'm having some trouble calculating the scale that I need to use on the background. I know that I need to do some conversions to different coordinate systems but not sure where. I have tried converting the bounding box from screen to World coords but this doesn't seem to be working. My scaling function is as follows;
The way I'm approaching it is by first calculating the correct size Rect bounding box around the colliders of a set of buttons on the background. I would then like to scale the background up so that when scaled, it fills the screen with what's in the bounding box (I think this should be the same as how pinch-zooming works?).
I have implemented the Rect and it's surrounding the buttons correctly. However, I'm having some trouble calculating the scale that I need to use on the background. I know that I need to do some conversions to different coordinate systems but not sure where. I have tried converting the bounding box from screen to World coords but this doesn't seem to be working. My scaling function is as follows;
- float CalculateMapScale(Rect boundingBox)
- // float CalculateMapScale()
- {
- // Cache the map's size.
- Vector3 mapScale = Map.transform.localScale;
- // Find the Map width and height. - In World coords
- float mapWidth = RightAnchor.position.x - LeftAnchor.position.x;
- float mapHeight = TopAnchor.position.y - BottomAnchor.position.y;
- // Calculate the Map aspect ratio.
- float mapAspect = mapWidth / mapHeight;
- // Work out the Width and Height scales relative to the bounding box.
- float newMapWScale = mapWidth / Mathf.Abs(boundingBox.width);
- float newMapHScale = mapHeight / Mathf.Abs(boundingBox.height);
- /*
- Vector3 bbBottomLeft = NGUICam.ScreenToWorldPoint(new Vector3(boundingBox.xMin, boundingBox.yMin, 1));
- Debug.Log("bbBottomLeft = " + bbBottomLeft);
- Vector3 bbTopRight = NGUICam.ScreenToWorldPoint(new Vector3(boundingBox.xMax, boundingBox.yMax, 1));
- Debug.Log("bbTopRight = " + bbTopRight);
- Vector3 bbWidthHeight = bbTopRight - bbBottomLeft;
- Debug.Log("bbWidthHeight = " + bbWidthHeight);
- */
- float newMapScale = 0;
- if (newMapWScale >= newMapHScale)
- newMapScale = newMapWScale;
- else
- newMapScale = newMapHScale;
- return newMapScale;
- }
