Forum rules - please read before posting.

Using the Force Aspect Ratio with non-AC Unity UI Canvases

I'm using @pixelcrusher 's Dialog System and Unity UI for its subtitles. 
I want to use AC's force Aspect Ratio - but when i do that, it doesn't affect Unity UI's and the black bars on the top and bottom go over the subtitles. - for example:

image

how do i make these UI's abide by the same force aspect ratio algorithm?

Comments

  • I don't know, actually.  But it would be to do with the way your non-AC UIs are set up - and that would be a question for the Unity forums rather than here.
  • well, my question is is there a way to ride off on AC's already handling that and just add some component to Unity UI for that?
    How does AC treat it's own Unity UI menus when you use Force aspect ratio?
  • You can use the MainCamera's LimitToAspect function to convert a 2D screen position into one that's aspect-ratio corrected.
  • Chris -

    What's the proper way to fit AC-controlled Unity UI menus? (Legacy Unity GUI fit into the aspect ratio just fine.)

    I suppose I could use this code if nothing's built into AC:

    ---begin(FitUIToAspectRatio.cs)---
    using UnityEngine;

    public class FitUIToAspectRatio : MonoBehaviour
    {

        public RectTransform mainPanel;
        private bool m_started = false;

        void Start()
        {
            m_started = true;
            Fit();
        }
        void OnEnable()
        {
            if (m_started) Fit();
        }

        void Fit()
        {
            if (mainPanel == null)
            {
                Debug.LogError("Assign Main Panel", this);
                return;
            }
            var rect = AC.KickStarter.mainCamera.LimitMenuToAspect(new Rect(0, 0, Screen.width, Screen.height));
            mainPanel.sizeDelta = new Vector2(-2 * rect.x, -2 * rect.y);
        }
    }
    ---end---

    To use it, I created a Unity UI Canvas with a Panel that stretches over the entire screen (Rect Transform: Stretch in all directions, Left/Top/Right/Bottom all zero) and added the script above.Then I added the actual menu elements as children of this panel. 

    Thanks,
    Tony



  • Thanks for the post, Tony - I'd imagine it'd go down well if you posted it on the Extending the Editor forum, too.  There's not much to suggest in terms of the "proper" way, but the one thing to keep in mind is to ensure the Menus are already built before the Fit function is called.  If you place the script on the UI itself, then you'll be fine - since the Start() function won't run until AC instantiates the UI anyway.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.