게임엔진관련/유니티 엔진

[Unity] 유니티 소프트키 관련

AlrepondTech 2019. 11. 13. 16:00
반응형

 

 

 

 

 

 

=======================

=======================

=======================

 

 

 

 

 

출처: https://m.blog.naver.com/PostView.nhn?blogId=uponsky&logNo=220334847464&proxyReferer=https%3A%2F%2Fwww.google.com%2F

 

소프트키를 사용하는 폰의 경우 전체화면 설정.

// Toggle fullscreen
Screen.fullScreen = !Screen.fullScreen ;
 
// set fullscreen
Screen.fullScreen = true ; 

전체화면 설정한 후
홈버튼으로 앱을 숨겼다가 다시 활성화 시켰을 때,
넥서스5에서 소프트키가 다시 올라오는 현상이 있습니다.

function OnApplicationPause(pauseStatus: boolean) {
    
    if (pauseStatus == false) {
 
        Screen.fullScreen = true ;            
            
    }
 
}

그래서 요딴식으로 다시 resume이 될 때 fullScreen을 한 번 더 해 줘 봅니다.

 

 

 

 

=======================

=======================

=======================

 

 

 

출처: https://asata.tistory.com/m/507


안드로이드에서 소프트키를 보여주지 않아야 할 경우가 있을 때 아래 코드로 파일을 하나 생성 해 줍니다.



using UnityEngine;

public class DisableSystemUI {
#if UNITY_ANDROID
static AndroidJavaObject activityInstance;
static AndroidJavaObject windowInstance;
static AndroidJavaObject viewInstance;

const int SYSTEM_UI_FLAG_HIDE_NAVIGATION = 2;
const int SYSTEM_UI_FLAG_LAYOUT_STABLE = 256;
const int SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION = 512;
const int SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN = 1024;
const int SYSTEM_UI_FLAG_IMMERSIVE = 2048;
const int SYSTEM_UI_FLAG_IMMERSIVE_STICKY = 4096;
const int SYSTEM_UI_FLAG_FULLSCREEN = 4;

public delegate void RunPtr();

public static void Run() {
if (viewInstance != null) {
viewInstance.Call("setSystemUiVisibility", 
                  SYSTEM_UI_FLAG_LAYOUT_STABLE
                  | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                  | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                  | SYSTEM_UI_FLAG_HIDE_NAVIGATION
                  | SYSTEM_UI_FLAG_FULLSCREEN
                  | SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}

}
#endif  

public static void DisableNavUI() {
if (Application.platform != RuntimePlatform.Android)
return;
#if UNITY_ANDROID
using (AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
activityInstance = unityPlayerClass.GetStatic("currentActivity");
windowInstance = activityInstance.Call("getWindow");
viewInstance = windowInstance.Call("getDecorView");

AndroidJavaRunnable RunThis;
RunThis = new AndroidJavaRunnable(new RunPtr(Run));
activityInstance.Call("runOnUiThread", RunThis);
}
#endif
}
}


그리고 처음 호출하는 부분에서 

DisableSystemUI.DisableNavUI();

를 불러주면 소프트키를 숨겨줍니다.

해당 폰에서 소프트키를 다시 볼려면 화면 상단을 아래로 스와이프를 해 주면 됩니다.

 

 

 

 

 

반응형

 

 

728x90

 

 

 

 

 

=======================

=======================

=======================

 

 

 

출처: https://m.blog.naver.com/PostView.nhn?blogId=ateliersera&logNo=220477980266&proxyReferer=https%3A%2F%2Fwww.google.com%2F

 

퍼온 자료 입니다.

 

하단에 소프트키로 구성된 제품의 경우에 사용해 주면 됩니다.

 

void OnApplicationFocus(bool focusStatus)

    {

        if (focusStatus)

        {

            DisableSystemUI.DisableNavUI();

        }

    }

 

위와 같은 코드를 처음 실행되는 스크립트 부분에서 적어주면 호출 됩니다.

 

아래는 DisableSystemUI.cs 의 내용 입니다.

 

 

 

using UnityEngine;

 

public class DisableSystemUI

{

#if UNITY_ANDROID

    static AndroidJavaObject activityInstance;

    static AndroidJavaObject windowInstance;

    static AndroidJavaObject viewInstance;

 

    const int SYSTEM_UI_FLAG_HIDE_NAVIGATION = 2;

    const int SYSTEM_UI_FLAG_LAYOUT_STABLE = 256;

    const int SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION = 512;

    const int SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN = 1024;

    const int SYSTEM_UI_FLAG_IMMERSIVE = 2048;

    const int SYSTEM_UI_FLAG_IMMERSIVE_STICKY = 4096;

    const int SYSTEM_UI_FLAG_FULLSCREEN = 4;

 

    public delegate void RunPtr();

 

    public static void Run()

    {

        if (viewInstance != null) {

            viewInstance.Call("setSystemUiVisibility",

                              SYSTEM_UI_FLAG_LAYOUT_STABLE

                              | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

                              | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                              | SYSTEM_UI_FLAG_HIDE_NAVIGATION

                              | SYSTEM_UI_FLAG_FULLSCREEN

                              | SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

        }

 

    }

#endif  

    public static void DisableNavUI()

    {

        if (Application.platform != RuntimePlatform.Android)

            return;

#if UNITY_ANDROID

        using (AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))

        {

            activityInstance = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");

            windowInstance = activityInstance.Call<AndroidJavaObject>("getWindow");

            viewInstance = windowInstance.Call<AndroidJavaObject>("getDecorView");

 

            AndroidJavaRunnable RunThis;

            RunThis = new AndroidJavaRunnable(new RunPtr(Run));

            activityInstance.Call("runOnUiThread", RunThis);

        }

#endif

    }

 

}

 

 

 

 

=======================

=======================

=======================

 

 

 

*기타관련링크

- https://docs.unity3d.com/kr/530/Manual/MobileKeyboard.html

 

 

 

=======================

=======================

=======================

 

 

 

반응형