Esempio n. 1
0
        public Rectangle GetBound(GameObject obj)
        {
            Rectangle rc = null;

            if (obj == null)
            {
                return(null);
            }
            if (UGUITools.isUGUIElement(obj))
            {
                rc = UGUITools.GetUGUIBound(obj);
            }
            if (rc == null)
            {
                Camera cm = FindBestCamera(obj);
                if (cm == null)
                {
                    return(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 offsetx = 0, offsety = 0, 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.GetCurrenScreenParam(ref offsetx, ref offsety, ref scalex, ref scaley))
            {
                rc.x = rc.x * scalex + offsetx;
                rc.y = rc.y * scaley + offsety;

                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);
        }