public static MobileScreen getAndroidMScreen() { Logger.v("getAndroidMScreen, begin"); if (mscreen != null) { return(mscreen); } int width = -1; int height = -1; bool bMScreen = false; try { width = u3dautomation.CallStatic <int>("GetWidth"); height = u3dautomation.CallStatic <int>("GetHeight"); bMScreen = true; } catch (System.Exception ex) { Logger.e(ex.ToString()); } if (bMScreen) { mscreen = new MobileScreen(width, height); } Logger.d("getAndroidMScreen: width=" + width + ", height=" + height); return(mscreen); }
public static bool GetCurrenScreenParam(ref float offsetx, ref float offsety, ref float scalex, ref float scaley) { //Logger.d("getCurrenScreenScale"); if (physicalscreen == null) { physicalscreen = AndroidRobot.getAndroidMScreen(); //为了查问题用 Logger.d("Screen.width=" + Screen.width + ", Screen.height=" + Screen.height); if (physicalscreen != null) { Logger.d("physicalscreen.width=" + physicalscreen.width + " , physicalscreen.height=" + physicalscreen.height + "physicalscreen.x=" + physicalscreen.x + " , physicalscreen.y=" + physicalscreen.y); } } if (physicalscreen == null) { Logger.d("get physical screen failed."); return(false); } int realphysicalwidth = physicalscreen.width; int realphysicalheight = physicalscreen.height; //做下面校验,是为了防止有些游戏登录时是竖屏、游戏里面是横屏 //横屏的情况下 if (Screen.width > Screen.height) { if (realphysicalwidth < realphysicalheight) { realphysicalwidth = physicalscreen.height; realphysicalheight = physicalscreen.width; } } //竖屏的情况下 else if (Screen.width < Screen.height) { if (realphysicalwidth > realphysicalheight) { realphysicalwidth = physicalscreen.height; realphysicalheight = physicalscreen.width; } } float sx = (float)(realphysicalwidth / (Screen.width * 1.0)); float sy = (float)(realphysicalheight / (Screen.height * 1.0)); Logger.v("realphysicalwidth=" + realphysicalwidth + ", realphysicalheight=" + realphysicalheight); Logger.v("Screen.width=" + Screen.width + ", Screen.height=" + Screen.height); Logger.v("sx=" + sx + ", sy=" + sy); scalex = sx; scaley = sy; offsetx = physicalscreen.x; offsety = physicalscreen.y; return(true); }