Пример #1
0
        public ScreenSimulation(DeviceInfo device, IInputProvider inputProvider, SimulationPlayerSettings playerSettings, ISimulatorWindow window)
        {
            this.m_DeviceInfo = device;
            m_Screen          = device.Screens[0];

            m_Window = window;

            m_InputProvider               = inputProvider;
            m_InputProvider.OnRotation   += Rotate;
            m_InputProvider.OnTouchEvent += HandleTouch;

            m_AllowedAutoRotation = new Dictionary <ScreenOrientation, bool>();
            m_AllowedAutoRotation.Add(ScreenOrientation.Portrait, playerSettings.allowedPortrait);
            m_AllowedAutoRotation.Add(ScreenOrientation.PortraitUpsideDown, playerSettings.allowedPortraitUpsideDown);
            m_AllowedAutoRotation.Add(ScreenOrientation.LandscapeLeft, playerSettings.allowedLandscapeLeft);
            m_AllowedAutoRotation.Add(ScreenOrientation.LandscapeRight, playerSettings.allowedLandscapeRight);

            // Calculate the right orientation.
            var settingOrientation = SimulatorUtilities.ToScreenOrientation(playerSettings.defaultOrientation);

            if (settingOrientation == ScreenOrientation.AutoRotation)
            {
                m_AutoRotation = true;
                var newOrientation = SimulatorUtilities.RotationToScreenOrientation(m_InputProvider.Rotation);
                if (m_Screen.orientations.ContainsKey(newOrientation) && m_AllowedAutoRotation[newOrientation])
                {
                    ForceNewOrientation(newOrientation);
                }
                else
                {
                    SetFirstAvailableAutoOrientation();
                }
            }
            else if (m_Screen.orientations.ContainsKey(settingOrientation))
            {
                m_AutoRotation = false;
                ForceNewOrientation(settingOrientation);
            }
            else
            {
                // At least iPhone X responds to this absolute corner case by crashing, we will not do that.
                m_AutoRotation = false;
                ForceNewOrientation(m_Screen.orientations.Keys.ToArray()[0]);
            }

            // Calculate the right resolution.
            var initWidth  = m_Screen.width;
            var initHeight = m_Screen.height;

            if (playerSettings.resolutionScalingMode == ResolutionScalingMode.FixedDpi && playerSettings.targetDpi < m_Screen.dpi)
            {
                m_DpiRatio = playerSettings.targetDpi / m_Screen.dpi;
                initWidth  = (int)(initWidth * m_DpiRatio);
                initHeight = (int)(initHeight * m_DpiRatio);
            }
            m_CurrentWidth  = IsRenderingLandscape ? initHeight : initWidth;
            m_CurrentHeight = IsRenderingLandscape ? initWidth : initHeight;

            // Set the full screen mode.
            m_IsFullScreen = !m_DeviceInfo.IsAndroidDevice() || playerSettings.androidStartInFullscreen;
            if (!m_IsFullScreen)
            {
                CalculateScreenResolutionForScreenMode(out m_CurrentWidth, out m_CurrentHeight);
            }

            CalculateSafeAreaAndCutouts();

            m_Window.TargetOrientation = m_RenderedOrientation;
            m_Window.TargetSize        = new Vector2(m_CurrentWidth, m_CurrentHeight);

            ShimManager.UseShim(this);
        }
Пример #2
0
 public SimulatorPlayerSettingsUI(VisualElement rootElement, DeviceInfo deviceInfo, SimulatorJsonSerialization states)
 {
     m_RootElement = rootElement;
     m_DeviceInfo  = deviceInfo;
     Init(states);
 }
        public SimulatorPreviewPanel(VisualElement rootElement, InputProvider inputProvider, DeviceInfo deviceInfo, SimulatorJsonSerialization states)
        {
            m_RootElement   = rootElement;
            m_InputProvider = inputProvider;
            m_DeviceInfo    = deviceInfo;

            var userSettings = DeviceSimulatorUserSettingsProvider.LoadOrCreateSettings();

            m_HighlightSafeAreaColor     = userSettings.SafeAreaHighlightColor;
            m_HighlightSafeAreaLineWidth = userSettings.SafeAreaHighlightLineWidth;

            Init(states);
        }
 public SimulatorScreenSettingsUI(Foldout rootElement, DeviceInfo deviceInfo, ScreenSimulation screenSimulation, SimulationPlayerSettings playerSettings)
 {
     m_RootElement = rootElement;
     Init(deviceInfo, screenSimulation, playerSettings);
 }