FairyGUI.UIContentScaler.ApplyChange C# (CSharp) Method

ApplyChange() public method

public ApplyChange ( ) : void
return void
        public void ApplyChange()
        {
            if (scaleMode == ScaleMode.ScaleWithScreenSize)
            {
                if (designResolutionX == 0 || designResolutionY == 0)
                    return;

                int dx = designResolutionX;
                int dy = designResolutionY;
                if (Screen.width > Screen.height && dx < dy || Screen.width < Screen.height && dx > dy)
                {
                    //scale should not change when orientation change
                    int tmp = dx;
                    dx = dy;
                    dy = tmp;
                }

                if (screenMatchMode == ScreenMatchMode.MatchWidthOrHeight)
                {
                    float s1 = (float)Screen.width / dx;
                    float s2 = (float)Screen.height / dy;
                    scaleFactor = Mathf.Min(s1, s2);
                }
                else if (screenMatchMode == ScreenMatchMode.MatchWidth)
                    scaleFactor = (float)Screen.width / dx;
                else
                    scaleFactor = (float)Screen.height / dy;
            }
            else if (scaleMode == ScaleMode.ConstantPhysicalSize)
            {
                float dpi = Screen.dpi;
                if (dpi == 0)
                    dpi = fallbackScreenDPI;
                if (dpi == 0)
                    dpi = 96;
                scaleFactor = dpi / (defaultSpriteDPI == 0 ? 96 : defaultSpriteDPI);
            }
            else
                scaleFactor = constantScaleFactor;

            StageCamera.screenSizeVer++;
        }

Usage Example

Example #1
0
 void OnEnable()
 {
     if (Application.isPlaying)
     {
         //播放模式下都是通过Stage自带的UIContentScaler实现调整的,所以这里只是把参数传过去
         UIContentScaler scaler = Stage.inst.gameObject.GetComponent <UIContentScaler>();
         if (scaler != this)
         {
             scaler.scaleMode = scaleMode;
             if (scaleMode == ScaleMode.ScaleWithScreenSize)
             {
                 scaler.designResolutionX = designResolutionX;
                 scaler.designResolutionY = designResolutionY;
                 scaler.screenMatchMode   = screenMatchMode;
                 scaler.ignoreOrientation = ignoreOrientation;
             }
             else if (scaleMode == ScaleMode.ConstantPhysicalSize)
             {
                 scaler.fallbackScreenDPI = fallbackScreenDPI;
                 scaler.defaultSpriteDPI  = defaultSpriteDPI;
             }
             else
             {
                 scaler.constantScaleFactor = constantScaleFactor;
             }
             scaler.ApplyChange();
             GRoot.inst.ApplyContentScaleFactor();
         }
     }
     else //Screen width/height is not reliable in OnEnable in editmode
     {
         _changed = true;
     }
 }
All Usage Examples Of FairyGUI.UIContentScaler::ApplyChange