Пример #1
0
        /// <summary>
        /// Update the screen Transformation.
        /// </summary>
        /// <param name="videoMode">Video mode.</param>
        /// <param name="verticalFieldOfView">Vertical FOV.</param>
        private void UpdateScreenTransformation(VideoMode.VideoModeAttributes videoMode, float verticalFieldOfView)
        {
            float fov = verticalFieldOfView;
            float distanceToScreen = gameObject.camera.farClipPlane;
            float frameAspect      = (float)videoMode.width / (float)videoMode.height;

            float scaleFactor = 1.0f;

            // Unity's Plane mesh default scale is 5
            float screenSize = 0.2f
                               * distanceToScreen
                               * Mathf.Tan(0.5f * fov * Mathf.Deg2Rad)
                               * scaleFactor;

            float screenWidth  = screenSize * frameAspect;
            float screenHeight = screenSize;

            Vector3 screenScale = new Vector3((Common.Mirroring ? 1 : -1) * screenWidth, 1f, screenHeight);

            screen.transform.localScale = screenScale;

            // We need this transformation dew to the way unity handles phone orientation
            screen.transform.localRotation = Common.worldRotation * Quaternion.AngleAxis(90f, Vector3.left);

            // distanceToScreen * 0.99f to make sure we are closer than camera far clipframe
            screen.transform.localPosition = new Vector3(0f, 0f, distanceToScreen * 0.99f);
        }
Пример #2
0
        /// <summary>
        /// Init Texture2D.
        /// </summary>
        /// <param name="qualityMode">Video quality.</param>
        /// <param name="videoMode">Video mode.</param>
        /// <param name="backgroundTexture">Reference to Texture2D.</param>
        private void InitTexture(Mode qualityMode, VideoMode.VideoModeAttributes videoMode, ref Texture2D backgroundTexture)
        {
            int           potWidth, potHeight;
            TextureFormat textureFormat;

            if (qualityMode == Mode.QualityOptimized)
            {
                potWidth      = Mathf.NextPowerOfTwo(videoMode.width);
                potHeight     = Mathf.NextPowerOfTwo(videoMode.height);
                textureFormat = TextureFormat.ARGB32;
            }
            else if (qualityMode == Mode.PerformanceAndQuality)
            {
                potWidth      = Mathf.ClosestPowerOfTwo(videoMode.width);
                potHeight     = Mathf.ClosestPowerOfTwo(videoMode.height);
                textureFormat = TextureFormat.RGB565;
            }
            else
            {
                potWidth      = 512;
                potHeight     = 512;
                textureFormat = TextureFormat.RGB565;
            }

            backgroundTexture            = new Texture2D(potWidth, potHeight, textureFormat, false);
            backgroundTexture.filterMode = FilterMode.Bilinear;
            backgroundTexture.wrapMode   = TextureWrapMode.Clamp;
        }
Пример #3
0
 /// <summary>
 /// Init screen, set screen texture.
 /// </summary>
 /// <param name="videoMode">Video mode.</param>
 /// <param name="backgroundTexture">Screen background texture.</param>
 private void InitScreen(VideoMode.VideoModeAttributes videoMode, Texture2D backgroundTexture)
 {
     if (screen == null)
     {
         ErrorHandler.instance.presentErrorMessage("Camera component does not contain NCamera object of Screen is not assigned");
     }
     screen.renderer.material.mainTexture = backgroundTexture;
     StartCoroutine("InitBackground");
 }
Пример #4
0
        public static Vector2 visibleRect(VideoMode.VideoModeAttributes userVideoMode, Vector2 screenResolution)
        {
            float ha           = (float)userVideoMode.width / screenResolution.x;
            float va           = (float)userVideoMode.height / screenResolution.y;
            float windowAspect = screenResolution.x / screenResolution.y;

            Vector2 resolution = new Vector2();

            if (ha > va)
            {
                resolution.x = ((float)userVideoMode.height * windowAspect);
                resolution.y = (float)userVideoMode.height;
            }
            else
            {
                resolution.x = (float)userVideoMode.width;
                resolution.y = ((float)userVideoMode.width / windowAspect);
            }
            return(resolution);
        }
Пример #5
0
 /// <summary>
 /// Object major initializtion step.
 /// Build screen texture and initialize screen object.
 /// </summary>
 /// <param name="videoMode">Video mode.</param>
 /// <param name="verticalFieldOfView">Vertical FOV.</param>
 public void Init(VideoMode.VideoModeAttributes videoMode, float verticalFieldOfView)
 {
     InitTexture(mode, videoMode, ref m_backgroundTexture);
     InitScreen(videoMode, m_backgroundTexture);
     UpdateScreenTransformation(videoMode, verticalFieldOfView);
 }