Forum rules - please read before posting.

Some issue about 'Fullscreen mode' and 'Render outside safe area' with AC version 1.70.2 on Android

Hi,

I'm working on an old project, working on Unity 2019.4.40 with AC 1.70.2,
When I check the 'Render outside safe area' in Project Settings->Player->Resolution and Presentation area, it didn't change anything of my game running on a Android device.
So I build this script below
void Start()
{
SetFullscreen(true);

        Application.focusChanged += OnFocusChanged;
    }

    private void OnFocusChanged(bool hasFocus)
    {
        if (hasFocus /*&& !isFullscreen*/)
        {
            StartCoroutine(RestoreFullscreen());
        }
    }

    IEnumerator RestoreFullscreen()
    {
        yield return new WaitForSeconds(2);

        SetFullscreen(true);
    }

    private void SetFullscreen(bool fullscreen)
    {
        #if UNITY_ANDROID && !UNITY_EDITOR
        AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
        AndroidJavaObject window = currentActivity.Call<AndroidJavaObject>("getWindow");

        if (fullscreen)
        {
            AndroidJavaClass layoutParams = new AndroidJavaClass("android.view.WindowManager$LayoutParams");
            int flagFullscreen = layoutParams.GetStatic<int>("FLAG_FULLSCREEN");
            int flagLayoutNoLimits = layoutParams.GetStatic<int>("FLAG_LAYOUT_NO_LIMITS");
            window.Call("addFlags", flagFullscreen);
            window.Call("addFlags", flagLayoutNoLimits);

            if (Application.isMobilePlatform)
            {
                Screen.fullScreen = true;
            }
        }
        else
        {
            if (Application.isMobilePlatform)
            {
                Screen.fullScreen = false;
            }
        }

        isFullscreen = fullscreen;
        #endif
    }    

And now my game will render with fullscreen mode on the first time running, but if I switch my game to background, and switch it back in, the screen won't be fullscreen any more.
I also tried to make some scripts on the Android side, including reset the screen in the onResume method, etc... but they won't work either.

I noticed that there is an option 'Limit display to safe area' in AC 1.84.0, but since this is an old project, there will be so much things to do along with upgrading AC engine.

So I wonder if there is way to modify some scripts of AC 1.70.2 to keep the fullsrceen mode when my game switch back in from background.

Thanks a lot.

Comments

  • It sounds like the option to limit display to the safe area is the opposite of what you want. This feature causes the the game to only occupy the safe area - menus included - against the default behaviour which is to render full-screen.

    Are you enforcing an aspect ratio in the Settings Manager? If not, and if "Render border camera?" is unchecked (if shown), then AC shouldn't be affecting the size of the game view.

    Does the game turn full-screen permanently if you brute force it via an Update loop?

  • My awful English, sorry....

    I'll try to explain all my tests one by one,

    Test 1, Unity 2019.4.40
    I build an empty scene with only a camera game object, without any scripts or custom settings, then I export this project to an android project, the result is, this build can run full-screen mode pretty well, both in the first time launch and switch to background then switch back.

    Test 2, Unity 2019.4.40, AC 1.70.2
    I run the 2D demo scene of AC, also without any scripts or custom settings, export and build in Android Studio, this build can run with full-screen mode in the first time launch, but failed when I switch it to background, then switch back. There would be a black system bar on the top of the screen.
    BTW, I've uncheck 'Force aspect ratio' option in AC settings->Camera settings, there is no 'border camera' setting in this version.

    Test 3, Unity 2022.3.53, AC 1.84.0
    Again, I test with the 2D demo scene, this time it works fine both in the first time launch and switch to background then switch back.
    And I unchecked 'Limit display to safe area' option in the camera setting.

    From these tests, especially the first two tests, a simple scene works well with full-screen mode, while a AC scene doesn't. And a higher version AC works well too, wich unchecking an option.
    So I think maybe I could modify some scripts of AC 1.70.2 to make it work well too ?

    Many thanks.

  • edited June 23

    Thanks for the details, though I'm afraid I can't reproduce such an issue.

    It's a very big difference in version, but the core scripts you'd want to look at are MainCamera and ACScreen.

    v1.70.2 is very old now, but it's likely the setting of Camera.rect that you'll want to look at, which is inside MainCamera's SetCameraRect function. This refers to ACScreen for determining the current screen size, so I'd say playing around with those two areas are your best bet.

  • thank you for your information, I'll try my luck. :)

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.