コード例 #1
0
        public SimulatorControlPanel(VisualElement rootElement, DeviceInfo deviceInfo, SystemInfoSimulation systemInfoSimulation, ScreenSimulation screenSimulation,
                                     ApplicationSimulation applicationSimulation,
                                     SimulationPlayerSettings playerSettings, SimulatorSerializationStates states)
        {
            m_RootElement = rootElement;

            m_DeviceSpecifications         = new SimulatorDeviceSpecificationsUI(m_RootElement.Q <Foldout>("device-specifications"), deviceInfo, systemInfoSimulation);
            m_SimulatorScreenSettings      = new SimulatorScreenSettingsUI(m_RootElement.Q <Foldout>("screen-settings"), deviceInfo, screenSimulation, playerSettings);
            m_SimulatorApplicationSettings = new SimulatorApplicationSettingsUI(m_RootElement.Q <Foldout>("application-settings"), applicationSimulation, states);
            m_SimulatorExtensions          = new SimulatorExtensions();

            foreach (var extension in m_SimulatorExtensions.Extensions)
            {
                var foldout = new Foldout()
                {
                    text  = extension.extensionTitle,
                    value = false
                };
                foldout.AddToClassList("unity-device-simulator__control-panel_foldout");

                m_RootElement.Add(foldout);
                m_ExtensionFoldouts.Add(extension.GetType().ToString(), foldout);

                if (states != null && states.extensions.TryGetValue(extension.GetType().ToString(), out var serializedExtension))
                {
                    JsonUtility.FromJsonOverwrite(serializedExtension, extension);
                }

                extension.OnExtendDeviceSimulator(foldout);
            }
        }
コード例 #2
0
ファイル: SystemInfoSimulation.cs プロジェクト: qu7500/Garena
        public SystemInfoSimulation(DeviceInfo deviceInfo, SimulationPlayerSettings playerSettings, List <string> shimmedAssemblies)
        {
            m_ShimmedAssemblies = shimmedAssemblies;

            m_DeviceInfo = deviceInfo;
            if (m_DeviceInfo?.SystemInfo?.graphicsDependentData?.Length > 0)
            {
                if (deviceInfo.IsAndroidDevice())
                {
                    m_GraphicsDeviceType = (
                        from selected in playerSettings.androidGraphicsAPIs
                        from device in m_DeviceInfo.SystemInfo.graphicsDependentData
                        where selected == device.graphicsDeviceType select device).FirstOrDefault();
                }
                else if (deviceInfo.IsiOSDevice())
                {
                    m_GraphicsDeviceType = (
                        from selected in playerSettings.iOSGraphicsAPIs
                        from device in m_DeviceInfo.SystemInfo.graphicsDependentData
                        where selected == device.graphicsDeviceType select device).FirstOrDefault();
                }
                if (m_GraphicsDeviceType == null)
                {
                    Debug.LogWarning("Could not pick GraphicsDeviceType, the game would fail to launch");
                }
            }
            Enable();
        }
コード例 #3
0
        internal static SimulationPlayerSettings InitDefaultPlayerSettings()
        {
            var defaultPlayerSettings = new SimulationPlayerSettings();

            var serializedSettings = PlayerSettings.GetSerializedObject();

            serializedSettings.Update();

            defaultPlayerSettings.resolutionScalingMode    = (ResolutionScalingMode)serializedSettings.FindProperty("resolutionScalingMode").intValue;
            defaultPlayerSettings.targetDpi                = serializedSettings.FindProperty("targetPixelDensity").intValue;
            defaultPlayerSettings.androidStartInFullscreen = serializedSettings.FindProperty("androidStartInFullscreen").boolValue;

            defaultPlayerSettings.defaultOrientation        = PlayerSettings.defaultInterfaceOrientation;
            defaultPlayerSettings.allowedPortrait           = PlayerSettings.allowedAutorotateToPortrait;
            defaultPlayerSettings.allowedPortraitUpsideDown = PlayerSettings.allowedAutorotateToPortraitUpsideDown;
            defaultPlayerSettings.allowedLandscapeLeft      = PlayerSettings.allowedAutorotateToLandscapeLeft;
            defaultPlayerSettings.allowedLandscapeRight     = PlayerSettings.allowedAutorotateToLandscapeRight;

            if (!PlayerSettings.GetUseDefaultGraphicsAPIs(BuildTarget.Android))
            {
                defaultPlayerSettings.androidGraphicsAPIs = PlayerSettings.GetGraphicsAPIs(BuildTarget.Android);
            }
            if (!PlayerSettings.GetUseDefaultGraphicsAPIs(BuildTarget.iOS))
            {
                defaultPlayerSettings.iOSGraphicsAPIs = PlayerSettings.GetGraphicsAPIs(BuildTarget.iOS);
            }

            return(defaultPlayerSettings);
        }
コード例 #4
0
        // Only gets called during initialization and switching device.
        public void Update(DeviceInfo deviceInfo, ScreenSimulation screenSimulation, SimulationPlayerSettings playerSettings)
        {
            UpdateResolution(screenSimulation.Width, screenSimulation.Height);
            UpdateFullScreenToggle(deviceInfo, playerSettings);
            UpdateOrientationVisualElements(screenSimulation.AutoRotation);
            UpdateAllowedOrientationVisualElements();

            // Register callbacks.
            screenSimulation.OnOrientationChanged        += UpdateOrientationVisualElements;
            screenSimulation.OnAllowedOrientationChanged += UpdateAllowedOrientationVisualElements;
            screenSimulation.OnResolutionChanged         += UpdateResolution;
            screenSimulation.OnFullScreenChanged         += UpdateFullScreenToggle;
        }
コード例 #5
0
        public SimulatorControlPanel(VisualElement rootElement, DeviceInfo deviceInfo, SystemInfoSimulation systemInfoSimulation, ScreenSimulation screenSimulation,
                                     ApplicationSimulation applicationSimulation,
                                     SimulationPlayerSettings playerSettings)
        {
            m_RootElement = rootElement;

            InitDeviceSpecifications();
            UpdateDeviceSpecifications(deviceInfo, systemInfoSimulation);

            m_SimulatorScreenSettings      = new SimulatorScreenSettingsUI(m_RootElement.Q <VisualElement>("screen-settings"), deviceInfo, screenSimulation, playerSettings);
            m_SimulatorApplicationSettings = new SimulatorApplicationSettingsUI(m_RootElement, applicationSimulation);

            InitDeviceSimulatorExtensions();
        }
コード例 #6
0
        private void UpdateFullScreenToggle(DeviceInfo deviceInfo, SimulationPlayerSettings playerSettings)
        {
            bool isAndroid = deviceInfo.SystemInfo.operatingSystem.ToLower().Contains("android");

            if (isAndroid)
            {
                m_FullScreenToggle.SetValueWithoutNotify(playerSettings.androidStartInFullscreen);
                m_FullScreenToggle.SetEnabled(true);
            }
            else
            {
                m_FullScreenToggle.SetValueWithoutNotify(true);
                m_FullScreenToggle.SetEnabled(false);
            }
        }
コード例 #7
0
 private void InitPlayerSettings(SimulatorJsonSerialization states)
 {
     // Initialize customized player settings.
     if (states != null)
     {
         m_CustomizedPlayerSettings = states.customizedPlayerSettings;
     }
     else
     {
         m_CustomizedPlayerSettings = new SimulationPlayerSettings()
         {
             targetDpi = (int)m_DeviceInfo.Screens[0].dpi
         };
     }
 }
コード例 #8
0
        private void Init(DeviceInfo deviceInfo, ScreenSimulation screenSimulation, SimulationPlayerSettings playerSettings)
        {
            m_ScreenWidthField  = m_RootElement.Q <IntegerField>("screen-width");
            m_ScreenHeightField = m_RootElement.Q <IntegerField>("screen-height");

            m_ScreenSetResolution           = m_RootElement.Q <Button>("screen-set-resolution-button");
            m_ScreenSetResolution.clickable = new Clickable(SetResolution);

            m_FullScreenToggle = m_RootElement.Q <Toggle>("full-screen");
            m_FullScreenToggle.RegisterValueChangedCallback(SetFullScreen);

            m_AutoRotationToggle = m_RootElement.Q <Toggle>("auto-rotation");
            m_AutoRotationToggle.RegisterValueChangedCallback(SetAutoRotation);

            m_ScreenOrientationEnumField = m_RootElement.Q <EnumField>("screen-orientations");
            m_ScreenOrientationEnumField.Init(RenderedScreenOrientation.Portrait);
            m_ScreenOrientationEnumField.RegisterValueChangedCallback(SetScreenOrientation);

            m_RenderedOrientationContainer = m_RootElement.Q <VisualElement>("rendered-orientation-container");
            m_RendererOrientation          = m_RootElement.Q <Label>("rendered-orientation");

            m_AllowedOrientationsSection = m_RootElement.Q <VisualElement>("allowed-orientations");

            m_AllowedPortrait = m_RootElement.Q <Toggle>("orientation-allow-portrait");
            m_AllowedPortrait.RegisterValueChangedCallback((evt) => { Screen.autorotateToPortrait = evt.newValue; });

            m_AllowedPortraitUpsideDown = m_RootElement.Q <Toggle>("orientation-allow-portrait-upside-down");
            m_AllowedPortraitUpsideDown.RegisterValueChangedCallback((evt) => { Screen.autorotateToPortraitUpsideDown = evt.newValue; });

            m_AllowedLandscapeLeft = m_RootElement.Q <Toggle>("orientation-allow-landscape-left");
            m_AllowedLandscapeLeft.RegisterValueChangedCallback((evt) => { Screen.autorotateToLandscapeLeft = evt.newValue; });

            m_AllowedLandscapeRight = m_RootElement.Q <Toggle>("orientation-allow-landscape-right");
            m_AllowedLandscapeRight.RegisterValueChangedCallback((evt) => { Screen.autorotateToLandscapeRight = evt.newValue; });

            // Initialized the control states.
            UpdateOrientationVisualElements(screenSimulation.AutoRotation);
            UpdateAllowedOrientationVisualElements();

            Update(deviceInfo, screenSimulation, playerSettings);
        }
コード例 #9
0
        public SystemInfoSimulation(DeviceInfo deviceInfo, SimulationPlayerSettings playerSettings, List <string> shimmedAssemblies)
        {
            const string dll = ".dll";

            m_ShimmedAssemblies = shimmedAssemblies;
            m_ShimmedAssemblies.RemoveAll(string.IsNullOrEmpty);

            for (int i = 0; i < m_ShimmedAssemblies.Count; i++)
            {
                m_ShimmedAssemblies[i] = m_ShimmedAssemblies[i].ToLower();
                if (!m_ShimmedAssemblies[i].EndsWith(dll))
                {
                    m_ShimmedAssemblies[i] += dll;
                }
            }

            m_DeviceInfo = deviceInfo;
            if (m_DeviceInfo?.SystemInfo?.GraphicsDependentData?.Length > 0)
            {
                if (deviceInfo.IsAndroidDevice())
                {
                    m_GraphicsDeviceType = (
                        from selected in playerSettings.androidGraphicsAPIs
                        from device in m_DeviceInfo.SystemInfo.GraphicsDependentData
                        where selected == device.graphicsDeviceType select device).FirstOrDefault();
                }
                else if (deviceInfo.IsiOSDevice())
                {
                    m_GraphicsDeviceType = (
                        from selected in playerSettings.iOSGraphicsAPIs
                        from device in m_DeviceInfo.SystemInfo.GraphicsDependentData
                        where selected == device.graphicsDeviceType select device).FirstOrDefault();
                }
                if (m_GraphicsDeviceType == null)
                {
                    Debug.LogWarning("Could not pick GraphicsDeviceType, the game would fail to launch");
                }
            }
            Enable();
        }
コード例 #10
0
        // Only gets called during initialization and switching device.
        public void Update(DeviceInfo deviceInfo, SystemInfoSimulation systemInfoSimulation, ScreenSimulation screenSimulation, SimulationPlayerSettings playerSettings)
        {
            if (deviceInfo == null)
            {
                return;
            }

            UpdateDeviceSpecifications(deviceInfo, systemInfoSimulation);
            m_SimulatorScreenSettings.Update(deviceInfo, screenSimulation, playerSettings);
        }
コード例 #11
0
        public ScreenSimulation(DeviceInfo device, IInputProvider inputProvider, SimulationPlayerSettings playerSettings)
        {
            m_DeviceInfo = device;
            m_Screen     = device.Screens[0];

            m_InputProvider             = inputProvider;
            m_InputProvider.OnRotation += Rotate;

            m_SupportedOrientations = new Dictionary <ScreenOrientation, OrientationData>();
            foreach (var o in m_Screen.orientations)
            {
                m_SupportedOrientations.Add(o.orientation, o);
            }

            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);

            // Set the full screen mode.
            m_IsFullScreen = !m_DeviceInfo.IsAndroidDevice() || playerSettings.androidStartInFullscreen;

            // 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_SupportedOrientations.ContainsKey(newOrientation) && m_AllowedAutoRotation[newOrientation])
                {
                    ForceNewOrientation(newOrientation);
                }
                else
                {
                    SetFirstAvailableAutoOrientation();
                }
            }
            else if (m_SupportedOrientations.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_SupportedOrientations.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;

            if (!m_IsFullScreen)
            {
                CalculateScreenResolutionForScreenMode(out m_CurrentWidth, out m_CurrentHeight);
                CalculateInsets();
            }
            CalculateSafeAreaAndCutouts();

            ShimManager.UseShim(this);
        }
コード例 #12
0
 public SimulatorScreenSettingsUI(VisualElement rootElement, DeviceInfo deviceInfo, ScreenSimulation screenSimulation, SimulationPlayerSettings playerSettings)
 {
     m_RootElement = rootElement;
     Init(deviceInfo, screenSimulation, playerSettings);
 }