Hello Guest

Author Topic: runtime container resizing  (Read 4455 times)

bochicoine

  • Newbie
  • *
  • Posts: 15
    • View Profile
runtime container resizing
« 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?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: runtime container resizing
« Reply #1 on: October 30, 2013, 09:59:22 am »
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.

bochicoine

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: runtime container resizing
« Reply #2 on: October 30, 2013, 10:45:19 am »
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:

Quote
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?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: runtime container resizing
« Reply #3 on: October 30, 2013, 10:47:36 am »
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?

bochicoine

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: runtime container resizing
« Reply #4 on: October 30, 2013, 11:01:35 am »
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)

??

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: runtime container resizing
« Reply #5 on: October 30, 2013, 07:42:38 pm »
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.