public static Vector <int, int> GetAspectRatioCoeff(AspectRatioOptions aspecRatio)
        {
            if (aspecRatio == AspectRatioOptions.Default)
            {
                throw new CameraViewException("Cannot get coefficients for 'Default' aspect ratio");
            }

            var coeff = aspecRatio.ToString().Remove(0, 6).Split('_');

            return(new Vector <int, int>(int.Parse(coeff[0]), int.Parse(coeff[1])));
        }
Exemple #2
0
    void ChoseResolution()
    {
        //Get current screen resolution
        Resolution myRes = Screen.currentResolution;
        //we calculate Aspect Ratio coeficient:
        float myAR;

#if UNITY_EDITOR
        Vector2 size = GetMainGameViewSize();
        myAR = size.x / size.y;
#else
        myAR = (float)myRes.width / (float)myRes.height;
#endif



        //We find our Aspect Ratio "Option"!
        AspectRatioOptions myARO = null;
        myARO = ResolutionDictionary.Find(x => Mathf.Approximately(x.aspectRatio, myAR));

        if (myARO == null)
        {
            //if not found, we save the default AspectRatio as current
            //and return;
            GameConfig.s.currentAspectRatio = ResolutionDictionary[0];
            return;
        }
        else
        {
            //We save the AspectRatio we are playing with on the GameConfig Instance
            //and continue
            GameConfig.s.currentAspectRatio = myARO;
        }


        //If the current resolution exceeds the maximum resolution of out Option
        //we change resolution
        if (myRes.height > myARO.height)
        {
            Screen.SetResolution(myARO.width, myARO.height, true, myARO.refreshRate);
        }
    }