Ejemplo n.º 1
0
 private static void ApplyChanges()
 {
     if (!Fullscreen)
     {
         if (Width <= Engine.Graphics.GraphicsDevice.Adapter.CurrentDisplayMode.Width &&
             Height <= Engine.Graphics.GraphicsDevice.Adapter.CurrentDisplayMode.Height)
         {
             Engine.Graphics.PreferredBackBufferWidth  = Width;
             Engine.Graphics.PreferredBackBufferHeight = Height;
             Engine.Graphics.IsFullScreen = false;
             Engine.Graphics.ApplyChanges();
             OnResolutionChange?.Invoke();
         }
         else
         {
             throw new InvalidOperationException("Cannot set resolution larger than the current display resolution.");
         }
     }
     else
     {
         if (Engine.Graphics.GraphicsDevice.Adapter.SupportedDisplayModes.Any(x => x.Width == Width && x.Height == Height))
         {
             Engine.Graphics.PreferredBackBufferWidth  = Width;
             Engine.Graphics.PreferredBackBufferHeight = Height;
             Engine.Graphics.IsFullScreen = true;
             Engine.Graphics.ApplyChanges();
             OnResolutionChange?.Invoke();
         }
         else
         {
             throw new InvalidOperationException("Display does not support this full-screen resolution.");
         }
     }
 }
Ejemplo n.º 2
0
    private IEnumerator CheckForChange()
    {
        _resolution  = new Vector2Int(Screen.width, Screen.height);
        _orientation = Input.deviceOrientation;

        while (_isAlive)
        {
            // Check for a Resolution Change
            if (_resolution.x != Screen.width || _resolution.y != Screen.height)
            {
                _resolution = new Vector2Int(Screen.width, Screen.height);
                OnResolutionChange?.Invoke(_resolution);
            }

            // Check for an Orientation Change
            switch (Input.deviceOrientation)
            {
            case DeviceOrientation.Unknown:    // Ignore
            case DeviceOrientation.FaceUp:     // Ignore
            case DeviceOrientation.FaceDown:   // Ignore
                break;

            default:
                if (_orientation != Input.deviceOrientation)
                {
                    _orientation = Input.deviceOrientation;
                    OnOrientationChange?.Invoke(_orientation);
                }

                break;
            }

            yield return(new WaitForSeconds(CheckDelay));
        }
    }
Ejemplo n.º 3
0
        // todo: multiple SceneView
        private void HandleOnSceneGUI(SceneView view)
        {
            var curResolution = new Vector2(Screen.width, Screen.height);

            if (curResolution != previousSceneResolution)
            {
                OnResolutionChange?.Invoke(curResolution);
                previousSceneResolution = curResolution;
            }
            OnSceneGui?.Invoke();
            OnGui?.Invoke();
        }
Ejemplo n.º 4
0
        //public void DelayedCall(float secsToDelay,  Action action) {
        //  this.Invoke()
        //}
        //============================================================
        private void OnGUI()
        {
            var curResolution = new Vector2(Screen.width, Screen.height);

            if (curResolution != previousGameResolution)
            {
                OnResolutionChange?.Invoke(curResolution);
                previousGameResolution = curResolution;
            }
            OnGameGui?.Invoke();
            OnGui?.Invoke();
        }
Ejemplo n.º 5
0
 void Start()
 {
     prop = OnResolutionChange.OnResolution();
 }