Example #1
0
    public static void setRootManualHeight(int manualHeight)
    {
        UIRoot [] roots = Resources.FindObjectsOfTypeAll(typeof(UIRoot)) as UIRoot[];
        if (roots == null || roots.Length == 0)
        {
            Debug.LogWarning("Could not find the UIRoot. Please set the UIRoot manual height property to :" + manualHeight);
        }
        else
        {
            foreach (UIRoot root in roots)
            {
                retinaProIgnoreUIRoot ignore = root.gameObject.GetComponent <retinaProIgnoreUIRoot>();
                if (ignore != null && ignore.ignoreUIRoot)
                {
                    continue;
                }

                root.scalingStyle  = UIRoot.Scaling.FixedSize;
                root.manualHeight  = manualHeight;
                root.minimumHeight = manualHeight;
                root.maximumHeight = manualHeight;
            }
        }
    }
    public void fixRoot()
    {
        // get the height of the screen, adjusted for pixel size
        int  width;
        int  height;
        bool usePortLand;

        if (rt.deviceList[activeDeviceIdx].rootAuto)
        {
            width       = rt.deviceList[activeDeviceIdx].screens[activeScreenIdx].width;
            height      = rt.deviceList[activeDeviceIdx].screens[activeScreenIdx].height;
            usePortLand = rt.deviceList[activeDeviceIdx].screens[activeScreenIdx].useForBothLandscapePortrait;
        }
        else
        {
            width       = rt.deviceList[activeDeviceIdx].rootWidth;
            height      = rt.deviceList[activeDeviceIdx].rootHeight;
            usePortLand = rt.deviceList[activeDeviceIdx].rootUseBothPortLand;
        }

        int manualHeight = (int)(height * rt.deviceList[activeDeviceIdx].pixelSize);

        if (usePortLand)
        {
            float aspect       = ((float)Screen.width) / ((float)Screen.height);
            float deviceAspect = ((float)rt.deviceList[activeDeviceIdx].screens[activeScreenIdx].width) / ((float)rt.deviceList[activeDeviceIdx].screens[activeScreenIdx].height);

            // if the screen is orientated differently from the device settings, calculate the UIRoot height based on the screen width
            float d = Mathf.Abs(aspect - deviceAspect);

            if (d > 0.01f)
            {
                manualHeight = (int)(((float)width) * rt.deviceList[activeDeviceIdx].pixelSize);
            }
        }

#if RETINAPRO_ATLASCONTROLLER_DEBUGLOG
        Debug.Log("Setting manual height to: " + manualHeight);
#endif

        UIRoot [] roots = Resources.FindObjectsOfTypeAll(typeof(UIRoot)) as UIRoot[];
        if (roots == null || roots.Length == 0)
        {
            Debug.LogWarning("Could not find the UIRoot. Please add a UIRoot to your scene. The manual height will be set to :" + manualHeight);
        }
        else
        {
            foreach (UIRoot root in roots)
            {
                retinaProIgnoreUIRoot ignore = root.gameObject.GetComponent <retinaProIgnoreUIRoot>();
                if (ignore != null && ignore.ignoreUIRoot)
                {
                    continue;
                }

                root.scalingStyle  = UIRoot.Scaling.FixedSize;
                root.manualHeight  = manualHeight;
                root.minimumHeight = manualHeight;
                root.maximumHeight = manualHeight;
            }
        }
    }