Пример #1
0
        public static Point ConvertMobile2Unity(Point pt)
        {
            if (pt == null)
            {
                return(null);
            }
            float num   = 0f;
            float num2  = 0f;
            Point point = new Point(CoordinateType.UnityScreen);

            if (CoordinateTool.GetCurrenScreenScale(ref num, ref num2))
            {
                point.X = pt.X / num;
                point.Y = (float)Screen.height - pt.Y / num2;
                u.c(string.Concat(new object[]
                {
                    "point(",
                    pt.X,
                    ",",
                    pt.Y,
                    ") => (",
                    point.X,
                    ",",
                    point.Y,
                    ")"
                }));
            }
            return(point);
        }
Пример #2
0
        public static Point ConvertUnity2Mobile(Vector2 pt)
        {
            Point point = new Point();
            float num   = (float)Screen.height - pt.y;
            float num2  = 0f;
            float num3  = 0f;

            if (CoordinateTool.GetCurrenScreenScale(ref num2, ref num3))
            {
                point.X = pt.x * num2;
                point.Y = num * num3;
                u.d(string.Concat(new object[]
                {
                    "ConvertUnity2Mobile from point =(",
                    pt.x,
                    ", ",
                    pt.y,
                    ") ==> ( ",
                    point.X,
                    ", ",
                    point.Y,
                    ")"
                }));
            }
            else
            {
                point.X = pt.x;
                point.Y = num;
            }
            return(point);
        }
Пример #3
0
        public Rectangle GetBound(GameObject obj)
        {
            if (obj == null)
            {
                return(null);
            }
            Rectangle rc = null;
            Camera    cm = FindBestCamera(obj);

            if (cm == null)
            {
                return(null);
            }

            rc = GetBoundByCollider(cm, obj);//主要是boxcolider2d物体的时候

            if (rc == null)
            {
                rc = NGUITools.GetNGUIBound(cm, obj);
            }

            if (rc == null)
            {
                rc = GetGUIBound(cm, obj);
            }

            if (rc == null)
            {
                return(null);
            }

            Logger.v("GetBound gameobject =" + obj.name + "  rc.x=" + rc.x + ", rc.y=" + rc.y + ", wight = " + rc.width + ", height=" + rc.height);

            //坐标缩放
            float scalex = 0, scaley = 0;

            if (RuntimePlatform.IPhonePlayer == Application.platform)//ios默认返回归一化的值
            {
                rc.x      = rc.x / Screen.width;
                rc.y      = rc.y / Screen.height;
                rc.width  = rc.width / Screen.width;
                rc.height = rc.height / Screen.height;
            }
            else if (CoordinateTool.GetCurrenScreenScale(ref scalex, ref scaley))
            {
                rc.x = rc.x * scalex;
                rc.y = rc.y * scaley;

                rc.width  = rc.width * scalex;
                rc.height = rc.height * scaley;
            }
            Logger.v("GetBound() after scale : rc.x=" + rc.x + ", rc.y=" + rc.y + ", wight = " + rc.width + ", height=" + rc.height);

            return(rc);
        }
Пример #4
0
        public static Rectangle ConvertUnity2Mobile(Rectangle rect)
        {
            Rectangle rectangle = new Rectangle();
            float     num       = (float)Screen.height - rect.y;
            float     num2      = 0f;
            float     num3      = 0f;

            if (CoordinateTool.GetCurrenScreenScale(ref num2, ref num3))
            {
                rectangle.x      = rect.x * num2;
                rectangle.y      = num * num3;
                rectangle.width  = rect.width * num2;
                rectangle.height = rect.height * num3;
            }
            else
            {
                rectangle = rect;
            }
            return(rectangle);
        }