Пример #1
0
 private DeviceOrientation ToDeviceOrientation(UnityEngine.DeviceOrientation orientation)
 {
     return(orientation switch
     {
         UnityEngine.DeviceOrientation.Portrait => DeviceOrientation.Portrait,
         UnityEngine.DeviceOrientation.PortraitUpsideDown => DeviceOrientation.PortraitUpsideDown,
         UnityEngine.DeviceOrientation.LandscapeLeft => DeviceOrientation.LandscapeLeft,
         UnityEngine.DeviceOrientation.LandscapeRight => DeviceOrientation.LandscapeRight,
         _ => throw new ArgumentOutOfRangeException(nameof(orientation), orientation, null)
     });
Пример #2
0
        /// <summary>A standard test to see if the device is oriented landscape.</summary>
        public static bool IsLandscape()
        {
            // Get orientation:
            UnityEngine.DeviceOrientation orient = UnityEngine.Input.deviceOrientation;

            if (orient == UnityEngine.DeviceOrientation.Unknown)
            {
                // Unknown - check for landscape based on width being bigger:
                return(UnityEngine.Screen.width > UnityEngine.Screen.height);
            }

            return(orient == UnityEngine.DeviceOrientation.LandscapeLeft || orient == UnityEngine.DeviceOrientation.LandscapeRight);
        }
Пример #3
0
        /// <summary>Converts from a Unity type.</summary>
        public static string fromUnity(UnityEngine.DeviceOrientation so)
        {
            switch (so)
            {
            case DeviceOrientation.Portrait:
                return("portrait-primary");

            case DeviceOrientation.PortraitUpsideDown:
                return("portrait-secondary");

            case DeviceOrientation.LandscapeRight:
                return("landscape-secondary");
            }

            // Assume landscape:
            return("landscape-primary");
        }
Пример #4
0
        public JSScreenOrientation()
        {
            // Get orientation:
            UnityEngine.DeviceOrientation orient = UnityEngine.Input.deviceOrientation;

            if (orient == UnityEngine.DeviceOrientation.Unknown)
            {
                // Unknown - check for landscape based on width being bigger:
                if (UnityEngine.Screen.width > UnityEngine.Screen.height)
                {
                    orient = UnityEngine.DeviceOrientation.LandscapeLeft;
                }
                else
                {
                    orient = UnityEngine.DeviceOrientation.LandscapeRight;
                }
            }

            type = fromUnity(orient);
        }
Пример #5
0
        /*
         * Private.
         */

        private void CheckOrientation()
        {
            if (CheckDeviceOrientationValid(Input.deviceOrientation) && _deviceOrientation != Input.deviceOrientation)
            {
                Log.Debug(o => $"CheckOrientation: for Device {o}", Input.deviceOrientation);

                _deviceOrientation = Input.deviceOrientation;
                DeviceOrientation  = ToDeviceOrientation(Input.deviceOrientation);

                EventMap.Dispatch(OrientationEvent.DeviceOrientationChanged, DeviceOrientation);
            }

            if (_screenOrientation != Screen.orientation)
            {
                Log.Debug(o => $"CheckOrientation: for Screen {o}", Screen.orientation);

                _screenOrientation = Screen.orientation;
                ScreenOrientation  = ToScreenOrientation(_screenOrientation);

                EventMap.Dispatch(OrientationEvent.ScreenOrientationChanged, ScreenOrientation);
            }
        }