public void fixFont(ref UIFont fontRef) { // determine if this is the parent reference font or it's a device specific font retinaProParent parent = fontRef.gameObject.GetComponent <retinaProParent>(); if (parent == null) { return; } // get name of prefab we want to have this parent font reference retinaProRuntimeDevice d = rt.deviceList[activeDeviceIdx]; string fontName = fontRef.name + "~" + d.name; #if RETINAPRO_ATLASCONTROLLER_DEBUGLOG Debug.Log("Required Font = " + fontName); #endif // determine whether we should load a font / replace existing font reference bool replace = false; if (fontRef.replacement == null) { // this font isn't referencing anything, fix it replace = true; } else { // this font is referencing something, is that the one we want? if (fontRef.replacement.name.CompareTo(fontName) != 0) { // this font isn't referencing the atlas we want, fix it replace = true; } } // load the required font and update the parents font reference if (replace) { #if RETINAPRO_ATLASCONTROLLER_DEBUGLOG Debug.Log("- loading"); #endif string prefabName = retinaProDataRuntime.atlasFolder + d.name + "/" + fontName; UIFont font = Resources.Load(prefabName, typeof(UIFont)) as UIFont; if (font != null) { fontRef.replacement = font; #if RETINAPRO_ATLASCONTROLLER_DEBUGLOG Debug.Log("- loaded"); #endif } else { Debug.LogWarning("Could not load the font"); } } else { #if RETINAPRO_ATLASCONTROLLER_DEBUGLOG Debug.Log("- already loaded"); #endif } }
bool loadDevices(ref XMLNode nodes) { XMLNodeList nodeList = nodes.GetNodeList("retinaProData>0>ArrayOfRetinaProDevice>0>retinaProDevice"); if (nodeList == null) { return(false); } foreach (XMLNode node in nodeList) { retinaProRuntimeDevice rd = new retinaProRuntimeDevice(); foreach (DictionaryEntry pair in node) { if (pair.Key.ToString().CompareTo("name") == 0) { XMLNodeList vs = (XMLNodeList)pair.Value; foreach (XMLNode v in vs) { foreach (DictionaryEntry dp in v) { if (dp.Key.ToString().CompareTo("_text") == 0) { rd.name = dp.Value.ToString(); } } } } else if (pair.Key.ToString().CompareTo("pixelSize") == 0) { XMLNodeList vs = (XMLNodeList)pair.Value; foreach (XMLNode v in vs) { foreach (DictionaryEntry dp in v) { if (dp.Key.ToString().CompareTo("_text") == 0) { string str = dp.Value.ToString(); Single.TryParse(str, out rd.pixelSize); } } } } else if (pair.Key.ToString().CompareTo("screens") == 0) { XMLNodeList vs = (XMLNodeList)pair.Value; foreach (XMLNode v in vs) { retinaProRuntimeScreen rs = new retinaProRuntimeScreen(); foreach (DictionaryEntry dp in v) { if (dp.Key.ToString().CompareTo("width") == 0) { XMLNodeList vs2 = (XMLNodeList)dp.Value; foreach (XMLNode v2 in vs2) { foreach (DictionaryEntry dp2 in v2) { if (dp2.Key.ToString().CompareTo("_text") == 0) { string str = dp2.Value.ToString(); Int32.TryParse(str, out rs.width); } } } } else if (dp.Key.ToString().CompareTo("height") == 0) { XMLNodeList vs2 = (XMLNodeList)dp.Value; foreach (XMLNode v2 in vs2) { foreach (DictionaryEntry dp2 in v2) { if (dp2.Key.ToString().CompareTo("_text") == 0) { string str = dp2.Value.ToString(); Int32.TryParse(str, out rs.height); } } } } else if (dp.Key.ToString().CompareTo("useForBothLandscapePortrait") == 0) { XMLNodeList vs2 = (XMLNodeList)dp.Value; foreach (XMLNode v2 in vs2) { foreach (DictionaryEntry dp2 in v2) { if (dp2.Key.ToString().CompareTo("_text") == 0) { string str = dp2.Value.ToString(); Boolean.TryParse(str, out rs.useForBothLandscapePortrait); } } } } } rd.screens.Add(rs); } } else if (pair.Key.ToString().CompareTo("rootWidth") == 0) { XMLNodeList vs = (XMLNodeList)pair.Value; foreach (XMLNode v in vs) { foreach (DictionaryEntry dp in v) { if (dp.Key.ToString().CompareTo("_text") == 0) { string str = dp.Value.ToString(); Int32.TryParse(str, out rd.rootWidth); } } } } else if (pair.Key.ToString().CompareTo("rootHeight") == 0) { XMLNodeList vs = (XMLNodeList)pair.Value; foreach (XMLNode v in vs) { foreach (DictionaryEntry dp in v) { if (dp.Key.ToString().CompareTo("_text") == 0) { string str = dp.Value.ToString(); Int32.TryParse(str, out rd.rootHeight); } } } } else if (pair.Key.ToString().CompareTo("rootAuto") == 0) { XMLNodeList vs = (XMLNodeList)pair.Value; foreach (XMLNode v in vs) { foreach (DictionaryEntry dp in v) { if (dp.Key.ToString().CompareTo("_text") == 0) { string str = dp.Value.ToString(); bool.TryParse(str, out rd.rootAuto); } } } } else if (pair.Key.ToString().CompareTo("rootUseBothPortLand") == 0) { XMLNodeList vs = (XMLNodeList)pair.Value; foreach (XMLNode v in vs) { foreach (DictionaryEntry dp in v) { if (dp.Key.ToString().CompareTo("_text") == 0) { string str = dp.Value.ToString(); bool.TryParse(str, out rd.rootUseBothPortLand); } } } } } // add one to the device list deviceList.Add(rd); #if RETINAPRO_DEBUGLOG { string debug = ""; debug += "RetinaPro Device = " + rd.name + ", "; debug += "pixelSize = " + rd.pixelSize + ", "; if (rd.rootAuto) { debug += "root = Auto, "; } else { debug += "root (" + rd.rootWidth + " x " + rd.rootHeight + "), Port & Land = " + rd.rootUseBothPortLand + ", "; } for (int si = 0; si < rd.screens.Count; si++) { debug += "screen[" + si + "] = { " + rd.screens[si].width + " X " + rd.screens[si].height + ", Port & Land = " + rd.screens[si].useForBothLandscapePortrait + " }"; if (si != rd.screens.Count - 1) { debug += ", "; } } Debug.Log(debug); } #endif } return(true); }
public void refreshActiveDevice() { activeDeviceIdx = -1; activeScreenIdx = -1; float aspect = ((float)Screen.width) / ((float)Screen.height); #if RETINAPRO_ATLASCONTROLLER_DEBUGLOG Debug.Log("Screen Size (" + Screen.width + ", " + Screen.height + ")"); Debug.Log("Screen aspect: " + aspect); #endif // what resolution are we running at // compare against our devices for (int i = 0; i < rt.deviceList.Count; i++) { retinaProRuntimeDevice dd = rt.deviceList[i]; for (int s = 0; s < dd.screens.Count; s++) { retinaProRuntimeScreen rs = dd.screens[s]; if (rs.useForBothLandscapePortrait) { if ( (rs.width == Screen.width && rs.height == Screen.height) || (rs.width == Screen.height && rs.height == Screen.width) ) { activeDeviceIdx = i; activeScreenIdx = s; break; } } else { if (rs.width == Screen.width && rs.height == Screen.height) { activeDeviceIdx = i; activeScreenIdx = s; break; } } } } if (activeDeviceIdx == -1) { // we did not find any devices that match the current screen resolution Debug.LogWarning("Did not find any devices that match the current resolution"); int bestIdx = -1; int bestScreenIdx = -1; float bestAspectDiff = 0.0f; int highestWidth = 0; // check the aspect ratio and find the closest and highest resolution that matches that aspect ratio for (int i = 0; i < rt.deviceList.Count; i++) { retinaProRuntimeDevice dd = rt.deviceList[i]; for (int s = 0; s < dd.screens.Count; s++) { retinaProRuntimeScreen rs = dd.screens[s]; float deviceAspect = ((float)rs.width) / ((float)rs.height); checkAspect(ref rs, aspect, deviceAspect, ref i, ref s, ref bestAspectDiff, ref bestIdx, ref bestScreenIdx, ref highestWidth); if (rs.useForBothLandscapePortrait) { deviceAspect = ((float)rs.height) / ((float)rs.width); checkAspect(ref rs, aspect, deviceAspect, ref i, ref s, ref bestAspectDiff, ref bestIdx, ref bestScreenIdx, ref highestWidth); } } } activeDeviceIdx = bestIdx; activeScreenIdx = bestScreenIdx; } if (activeDeviceIdx != -1) { Debug.Log("Using device: " + rt.deviceList[activeDeviceIdx].name + ", pixel size = " + rt.deviceList[activeDeviceIdx].pixelSize); if (activeScreenIdx != -1) { Debug.Log("Using screen: " + rt.deviceList[activeDeviceIdx].screens[activeScreenIdx].width + " X " + rt.deviceList[activeDeviceIdx].screens[activeScreenIdx].height + ", Port & Land = " + rt.deviceList[activeDeviceIdx].screens[activeScreenIdx].useForBothLandscapePortrait); } } }