2D Toolkit Forum
2D Toolkit => Support => Topic started by: bochicoine on October 30, 2013, 09:25:32 am
-
Version: 2.2.3
I have a set of objects, held within a UI Container Sizer placed in the middle of a screen with ratio 5:3.
When I change the aspect ratio to something else (say: 3:2) the width of the screen increases but the Container Sizer does not (despite having dynamic objects inside it).
Do you think it would be possible to modify the UI Container Sizer script to resize itself to the width/height (or both?) of the screen?
-
That will probably be in a later version, but it won't be part of the container scripts at all - it will likely just be a separate script completely.
Check UI demo 2, that resizes a layout to fit the screen - you can simply use the same / similar code to do it for now.
-
Ok I've taken the code which resizes the window (minus the tweening and the nextButton - which isn't needed) and I'm left with:
public class GUI_Resizer : MonoBehaviour {
public tk2dUILayout windowLayout;
Vector3[] rectMin = new Vector3[] {
Vector3.zero,
new Vector3(-1.0f, -1.0f, 0),
Vector3.zero,
};
Vector3[] rectMax = new Vector3[] {
Vector3.one,
new Vector3(1.0f, 1.0f, 0),
Vector3.one,
};
int currRect = 0;
void Start() {
// Read the current window bounds
rectMin[0] = windowLayout.GetMinBounds();
rectMax[0] = windowLayout.GetMaxBounds();
}
void LateUpdate() {
// Get screen extents
int last = rectMin.Length - 1;
rectMin[last].Set(tk2dCamera.Instance.ScreenExtents.xMin, tk2dCamera.Instance.ScreenExtents.yMin, 0);
rectMax[last].Set(tk2dCamera.Instance.ScreenExtents.xMax, tk2dCamera.Instance.ScreenExtents.yMax, 0);
}
}
It should be simple enough to set the size of 'windowLayout' to be the ScreenExtents.... How do I do that? Does it need to be during an Update method?
-
Setting it to ScreenExtents should be enough. It doesn't have to be in an update loop, but shouldn't be any harm doing it there? What do you get?
-
That's just it... I don't know how to set the width/height to the screen extents, would it be something like this:
windowLayout.Set(tk2dCamera.Instance.ScreenExtents.xMin, tk2dCamera.Instance.ScreenExtents.yMin, 0)
windowLayout.Set(tk2dCamera.Instance.ScreenExtents.xMax, tk2dCamera.Instance.ScreenExtents.yMax, 0)
??
-
You missed the line that actually does it :)
layout.SetBounds( minBounds, maxBounds );
That example has an animation, so that function call is inside the coroutine.