Inheritance: UnityEngine.MonoBehaviour
Example #1
0
        void OnScreenSizeChanged()
        {
            screenWidth  = Screen.width;
            screenHeight = Screen.height;
            if (screenWidth == 0 || screenHeight == 0)
            {
                return;
            }

            cachedCamera.orthographicSize = screenHeight / 2 * UnitsPerPixel;
            cachedCamera.aspect           = (float)screenWidth / screenHeight;
            cachedTransform.localPosition = new Vector3(cachedCamera.orthographicSize * cachedCamera.aspect, -cachedCamera.orthographicSize);

            if (isMain)
            {
                screenSizeVer++;
                if (Application.isPlaying)
                {
                    Stage.inst.HandleScreenSizeChanged();
                }
                else
                {
                    UIContentScaler scaler = GameObject.FindObjectOfType <UIContentScaler>();
                    if (scaler != null)
                    {
                        scaler.ApplyChange();
                    }
                    else
                    {
                        UIContentScaler.scaleFactor = 1;
                    }
                }
            }
        }
Example #2
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;
     }
 }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="constantScaleFactor"></param>
        public void SetContentScaleFactor(float constantScaleFactor)
        {
            UIContentScaler scaler = Stage.inst.gameObject.GetComponent <UIContentScaler>();

            scaler.scaleMode           = UIContentScaler.ScaleMode.ConstantPixelSize;
            scaler.constantScaleFactor = constantScaleFactor;
            scaler.ApplyChange();
            ApplyContentScaleFactor();
        }
Example #4
0
        /// <summary>
        /// Set content scale factor.
        /// </summary>
        /// <param name="designResolutionX">Design resolution of x axis.</param>
        /// <param name="designResolutionY">Design resolution of y axis.</param>
        /// <param name="screenMatchMode">Math mode.</param>
        public void SetContentScaleFactor(int designResolutionX, int designResolutionY, UIContentScaler.ScreenMatchMode screenMatchMode)
        {
            UIContentScaler scaler = Stage.inst.gameObject.GetComponent <UIContentScaler>();

            scaler.designResolutionX = designResolutionX;
            scaler.designResolutionY = designResolutionY;
            scaler.scaleMode         = UIContentScaler.ScaleMode.ScaleWithScreenSize;
            scaler.ApplyChange();
            ApplyContentScaleFactor();
        }
Example #5
0
        void OnResolutionChanged(int lw, int lh)
        {
            SetSize(Renderer.ScreenWidth, Renderer.ScreenHeight);
#if CE_5_5
            NGraphics.viewportReverseScale = new Vector2(1, 1);
#else
            NGraphics.viewportReverseScale = new Vector2(800.0f / this.width, 600.0f / this.height);
#endif

            UIContentScaler.ApplyChange();
        }
Example #6
0
        /// <summary>
        /// Set content scale factor.
        /// </summary>
        /// <param name="designResolutionX">Design resolution of x axis.</param>
        /// <param name="designResolutionY">Design resolution of y axis.</param>
        /// <param name="screenMatchMode">Match mode.</param>
        public void SetContentScaleFactor(int designResolutionX, int designResolutionY, UIContentScaler.ScreenMatchMode screenMatchMode)
        {
            UIContentScaler scaler = CentorPivot.This.GetComponent <UIContentScaler>();

            scaler.designResolutionX = designResolutionX;
            scaler.designResolutionY = designResolutionY;
            scaler.scaleMode         = UIContentScaler.ScaleMode.ScaleWithScreenSize;
            scaler.screenMatchMode   = screenMatchMode;
            scaler.ApplyChange();
            ApplyContentScaleFactor();
        }
 static public int get_designResolutionX(IntPtr l)
 {
     try {
         FairyGUI.UIContentScaler self = (FairyGUI.UIContentScaler)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.designResolutionX);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int get_screenMatchMode(IntPtr l)
 {
     try {
         FairyGUI.UIContentScaler self = (FairyGUI.UIContentScaler)checkSelf(l);
         pushValue(l, true);
         pushEnum(l, (int)self.screenMatchMode);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #9
0
        internal void HandleScreenSizeChanged()
        {
            stageWidth  = Screen.width;
            stageHeight = Screen.height;

            UIContentScaler scaler = this.gameObject.GetComponent <UIContentScaler>();

            scaler.ApplyChange();
            GRoot.inst.ApplyContentScaleFactor();

            onStageResized.Call();
        }
 static public int ApplyModifiedProperties(IntPtr l)
 {
     try {
         FairyGUI.UIContentScaler self = (FairyGUI.UIContentScaler)checkSelf(l);
         self.ApplyModifiedProperties();
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #11
0
        internal void HandleScreenSizeChanged()
        {
            stageWidth  = Screen.width;
            stageHeight = Screen.height;

            this.cachedTransform.localScale = new Vector3(StageCamera.UnitsPerPixel, StageCamera.UnitsPerPixel, StageCamera.UnitsPerPixel);

            UIContentScaler scaler = this.gameObject.GetComponent <UIContentScaler>();

            scaler.ApplyChange();
            GRoot.inst.ApplyContentScaleFactor();

            onStageResized.Call();
        }
Example #12
0
        internal void HandleScreenSizeChanged()
        {
            stageWidth  = Screen.width;
            stageHeight = Screen.height;

            this.cachedTransform.localScale = new Vector3(CameraComponent.UnitsPerPixel, CameraComponent.UnitsPerPixel, CameraComponent.UnitsPerPixel);

            UIContentScaler scaler = CentorPivot.This.GetComponent <UIContentScaler>();

            scaler.ApplyChange();
            GRoot.inst.ApplyContentScaleFactor();

            DispatchEvent("onStageResized", null);
        }
Example #13
0
 static int ApplyModifiedProperties(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         FairyGUI.UIContentScaler obj = (FairyGUI.UIContentScaler)ToLua.CheckObject <FairyGUI.UIContentScaler>(L, 1);
         obj.ApplyModifiedProperties();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #14
0
 static int ApplyChange(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         FairyGUI.UIContentScaler obj = (FairyGUI.UIContentScaler)ToLua.CheckObject(L, 1, typeof(FairyGUI.UIContentScaler));
         obj.ApplyChange();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static public int set_screenMatchMode(IntPtr l)
 {
     try {
         FairyGUI.UIContentScaler self = (FairyGUI.UIContentScaler)checkSelf(l);
         FairyGUI.UIContentScaler.ScreenMatchMode v;
         checkEnum(l, 2, out v);
         self.screenMatchMode = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int set_designResolutionY(IntPtr l)
 {
     try {
         FairyGUI.UIContentScaler self = (FairyGUI.UIContentScaler)checkSelf(l);
         System.Int32             v;
         checkType(l, 2, out v);
         self.designResolutionY = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #17
0
    static int get_ignoreOrientation(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FairyGUI.UIContentScaler obj = (FairyGUI.UIContentScaler)o;
            bool ret = obj.ignoreOrientation;
            LuaDLL.lua_pushboolean(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index ignoreOrientation on a nil value"));
        }
    }
Example #18
0
    static int set_defaultSpriteDPI(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FairyGUI.UIContentScaler obj = (FairyGUI.UIContentScaler)o;
            int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
            obj.defaultSpriteDPI = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index defaultSpriteDPI on a nil value"));
        }
    }
Example #19
0
    static int get_screenMatchMode(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FairyGUI.UIContentScaler obj = (FairyGUI.UIContentScaler)o;
            FairyGUI.UIContentScaler.ScreenMatchMode ret = obj.screenMatchMode;
            ToLua.Push(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index screenMatchMode on a nil value" : e.Message));
        }
    }
Example #20
0
    static int get_defaultSpriteDPI(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FairyGUI.UIContentScaler obj = (FairyGUI.UIContentScaler)o;
            int ret = obj.defaultSpriteDPI;
            LuaDLL.lua_pushinteger(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index defaultSpriteDPI on a nil value"));
        }
    }
Example #21
0
    static int set_screenMatchMode(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FairyGUI.UIContentScaler obj = (FairyGUI.UIContentScaler)o;
            FairyGUI.UIContentScaler.ScreenMatchMode arg0 = (FairyGUI.UIContentScaler.ScreenMatchMode)ToLua.CheckObject(L, 2, typeof(FairyGUI.UIContentScaler.ScreenMatchMode));
            obj.screenMatchMode = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index screenMatchMode on a nil value" : e.Message));
        }
    }
Example #22
0
    static int get_constantScaleFactor(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FairyGUI.UIContentScaler obj = (FairyGUI.UIContentScaler)o;
            int ret = obj.constantScaleFactor;
            LuaDLL.lua_pushinteger(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index constantScaleFactor on a nil value" : e.Message));
        }
    }
Example #23
0
    static int set_ignoreOrientation(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FairyGUI.UIContentScaler obj = (FairyGUI.UIContentScaler)o;
            bool arg0 = LuaDLL.luaL_checkboolean(L, 2);
            obj.ignoreOrientation = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index ignoreOrientation on a nil value"));
        }
    }
Example #24
0
    static int set_constantScaleFactor(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FairyGUI.UIContentScaler obj = (FairyGUI.UIContentScaler)o;
            int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
            obj.constantScaleFactor = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index constantScaleFactor on a nil value" : e.Message));
        }
    }
Example #25
0
    static int set_scaler(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            LayersMgr obj = (LayersMgr)o;
            FairyGUI.UIContentScaler arg0 = (FairyGUI.UIContentScaler)ToLua.CheckUnityObject(L, 2, typeof(FairyGUI.UIContentScaler));
            obj.scaler = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index scaler on a nil value" : e.Message));
        }
    }
        void OnScreenSizeChanged(int newWidth, int newHeight)
        {
            if (newWidth == 0 || newHeight == 0)
            {
                return;
            }

            screenWidth  = newWidth;
            screenHeight = newHeight;

            float upp;

            if (constantSize)
            {
                cachedCamera.orthographicSize = DefaultCameraSize;
                upp = cachedCamera.orthographicSize * 2 / screenHeight;
            }
            else
            {
                upp = 0.02f;
                cachedCamera.orthographicSize = screenHeight / 2 * UnitsPerPixel;
            }
            cachedTransform.localPosition = new Vector3(cachedCamera.orthographicSize * screenWidth / screenHeight, -cachedCamera.orthographicSize);

            if (isMain)
            {
                UnitsPerPixel = upp;
                screenSizeVer++;
                if (Application.isPlaying)
                {
                    Stage.inst.HandleScreenSizeChanged();
                }
                else
                {
                    UIContentScaler scaler = GameObject.FindObjectOfType <UIContentScaler>();
                    if (scaler != null)
                    {
                        scaler.ApplyChange();
                    }
                    else
                    {
                        UIContentScaler.scaleFactor = 1;
                    }
                }
            }
        }
Example #27
0
 /// <summary>
 /// Set content scale factor.
 /// </summary>
 /// <param name="designResolutionX">Design resolution of x axis.</param>
 /// <param name="designResolutionY">Design resolution of y axis.</param>
 /// <param name="screenMatchMode">Math mode.</param>
 public void SetContentScaleFactor(int designResolutionX, int designResolutionY, UIContentScaler.ScreenMatchMode screenMatchMode)
 {
     UIContentScaler scaler = Stage.inst.gameObject.GetComponent<UIContentScaler>();
     scaler.designResolutionX = designResolutionX;
     scaler.designResolutionY = designResolutionY;
     scaler.scaleMode = UIContentScaler.ScaleMode.ScaleWithScreenSize;
     scaler.screenMatchMode = screenMatchMode;
     scaler.ApplyChange();
     ApplyContentScaleFactor();
 }
Example #28
0
        void OnResolutionChanged(object sender, EventArgs args)
        {
            SetSize(game.GraphicsDevice.PresentationParameters.BackBufferWidth, game.GraphicsDevice.PresentationParameters.BackBufferHeight);

            UIContentScaler.ApplyChange();
        }