Unity/코드 예제들

NGUI 게임도중에 orientation을 이용해 가로세로전환

소나무꼴 2020. 6. 16. 19:02
    private void ChangeOrientation()
    {
        UIRoot mRoot = NGUITools.FindInParents<UIRoot>(transform);
        
        int backup = mRoot.manualWidth;
        mRoot.manualWidth = mRoot.manualHeight;
        mRoot.manualHeight = backup;

        UnityEngine.Screen.autorotateToLandscapeLeft = !UnityEngine.Screen.autorotateToLandscapeLeft;
        UnityEngine.Screen.autorotateToLandscapeRight = !UnityEngine.Screen.autorotateToLandscapeRight;
        UnityEngine.Screen.autorotateToPortrait = !UnityEngine.Screen.autorotateToPortrait;
        UnityEngine.Screen.autorotateToPortraitUpsideDown = !UnityEngine.Screen.autorotateToPortraitUpsideDown;

        if (UnityEngine.Screen.orientation != ScreenOrientation.Portrait)
        {
            UnityEngine.Screen.orientation = ScreenOrientation.Portrait;
        }
        else
        {
            UnityEngine.Screen.orientation = ScreenOrientation.Landscape;
            UnityEngine.Screen.orientation = ScreenOrientation.AutoRotation;
        }
    }