void updateScreens() { // convert the old screen data in retinaProDevice into the new retinaProScreen object foreach (retinaProDevice rd in deviceList) { if (rd.isDeviceValid() && rd.screens.Count == 0) { retinaProScreen rps = new retinaProScreen(); rps.width = rd.screenWidth; rps.height = rd.screenHeight; rps.useForBothLandscapePortrait = rd.useForBothLandscapePortrait; rd.screens.Add(rps); } } }
void showDeviceUI() { bool save = false; EditorGUI.BeginDisabledGroup(retinaProState.state != retinaProState.rpState.kWaiting); EditorGUILayout.Space(); GUILayout.Label("Devices", EditorStyles.boldLabel); EditorGUILayout.Space(); EditorGUI.EndDisabledGroup(); // begin scrolling section which contains all of our device list items GUILayout.BeginVertical(); Vector2 deviceScrollPos = Vector2.zero; deviceScrollPos.x = EditorPrefs.GetFloat("deviceScrollPosX", 0.0f); deviceScrollPos.y = EditorPrefs.GetFloat("deviceScrollPosY", 0.0f); deviceScrollPos = GUILayout.BeginScrollView(deviceScrollPos, false, false); EditorPrefs.SetFloat("deviceScrollPosX", deviceScrollPos.x); EditorPrefs.SetFloat("deviceScrollPosY", deviceScrollPos.y); EditorGUI.BeginDisabledGroup(retinaProState.state != retinaProState.rpState.kWaiting); // show each device and it's configuration if (retinaProDataSerialize.sharedInstance.deviceList != null) { for (int i = 0; i < retinaProDataSerialize.sharedInstance.deviceList.Count; i++) { retinaProDevice rpd = retinaProDataSerialize.sharedInstance.deviceList[i]; GUILayout.BeginHorizontal(); GUILayout.Label("Name:", GUILayout.Width(60f)); if (rpd != null) { string n = GUILayout.TextField(rpd.name, GUILayout.MaxWidth(150f)); if (n.CompareTo(rpd.name) != 0) { rpd.name = n; save = true; } } // EditorGUILayout.Space(); bool removeDevice = GUILayout.Button("Remove", GUILayout.Width(60f)); if (removeDevice) { retinaProDataSerialize.sharedInstance.deviceList.RemoveAt(i); save = true; break; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Pixel Size:", GUILayout.Width(60f)); if (rpd != null) { float p = EditorGUILayout.FloatField(rpd.pixelSize, GUILayout.Width(60f)); if (p != rpd.pixelSize) { rpd.pixelSize = p; save = true; } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("UIRoot:", GUILayout.Width(60f)); if (rpd != null) { if (!rpd.rootAuto) { { int rw = EditorGUILayout.IntField(rpd.rootWidth, GUILayout.Width(60f)); if (rw != rpd.rootWidth) { rpd.rootWidth = rw; save = true; } } GUILayout.Label("X", GUILayout.Width(15f)); { int rh = EditorGUILayout.IntField(rpd.rootHeight, GUILayout.Width(60f)); if (rh != rpd.rootHeight) { rpd.rootHeight = rh; save = true; } } { bool useForBothLandscapePortrait = GUILayout.Toggle(rpd.rootUseBothPortLand, "Port & Land", GUILayout.Width(80f)); if (useForBothLandscapePortrait != rpd.rootUseBothPortLand) { rpd.rootUseBothPortLand = useForBothLandscapePortrait; save = true; } } } bool autoRoot = false; if (rpd.rootAuto) { autoRoot = GUILayout.Toggle(rpd.rootAuto, "Auto (sets UIRoot manual height based on screen size)", GUILayout.Width(330f)); } else { autoRoot = GUILayout.Toggle(rpd.rootAuto, "Auto", GUILayout.Width(50f)); } if (autoRoot != rpd.rootAuto) { rpd.rootAuto = autoRoot; save = true; } } GUILayout.EndHorizontal(); if (rpd.screens != null) { for (int rsi = 0; rsi < rpd.screens.Count; rsi++) { retinaProScreen rps = rpd.screens[rsi]; if (rps != null) { GUILayout.BeginHorizontal(); GUILayout.Label("Screen:", GUILayout.Width(60f)); { int w = EditorGUILayout.IntField(rps.width, GUILayout.Width(60f)); if (w != rps.width) { rps.width = w; save = true; } } GUILayout.Label("X", GUILayout.Width(15f)); { int h = EditorGUILayout.IntField(rps.height, GUILayout.Width(60f)); if (h != rps.height) { rps.height = h; save = true; } } { bool useForBothLandscapePortrait = GUILayout.Toggle(rps.useForBothLandscapePortrait, "Port & Land", GUILayout.Width(80f)); if (useForBothLandscapePortrait != rps.useForBothLandscapePortrait) { rps.useForBothLandscapePortrait = useForBothLandscapePortrait; save = true; } } { bool pressed = GUILayout.Button("X", GUILayout.Width(20f)); if (pressed) { rpd.screens.RemoveAt(rsi); save = true; break; } } GUILayout.EndHorizontal(); } } } { GUILayout.BeginHorizontal(); GUILayout.Label("", GUILayout.Width(60f)); bool pressed = GUILayout.Button("Add Screen", GUILayout.Width(85f)); if (pressed) { retinaProScreen newScreen = new retinaProScreen(); rpd.screens.Add(newScreen); save = true; } GUILayout.EndHorizontal(); } EditorGUILayout.Space(); EditorGUILayout.Space(); } } { GUILayout.BeginHorizontal(); GUILayout.Label("", GUILayout.Width(60f)); bool pressed = GUILayout.Button("Add Device", GUILayout.Width(100f)); if (pressed) { retinaProDevice newItem = new retinaProDevice(); retinaProDataSerialize.sharedInstance.deviceList.Add(newItem); save = true; } GUILayout.EndHorizontal(); } EditorGUI.EndDisabledGroup(); GUILayout.EndScrollView(); GUILayout.EndVertical(); if (save) { retinaProDataSerialize.sharedInstance.saveSettings(); } }
// gameViewOrientation, 0 = portrait, 1 = landscape (only used if the device is used for both landscape / portrait) // this is a work around because Screen.width / Screen.height returns bogus values // screenIndex is an index into the device screen list public static void refreshReferencesForDevice(retinaProDevice deviceItem, int screenIndex, int gameViewOrientation) { if (deviceItem == null) { return; } if (!deviceItem.isDeviceValid()) { return; } if (screenIndex < 0 || screenIndex >= deviceItem.screens.Count) { return; } int manualHeight = 0; float width; float height; bool useBothPortLand; if (deviceItem.rootAuto) { retinaProScreen rps = deviceItem.screens[screenIndex]; width = (float)rps.width; height = (float)rps.height; useBothPortLand = rps.useForBothLandscapePortrait; } else { width = (float)deviceItem.rootWidth; height = (float)deviceItem.rootHeight; useBothPortLand = deviceItem.rootUseBothPortLand; } if (useBothPortLand) { if (width >= height) // landscape { if (gameViewOrientation == 1) { // screen game view is also landscape manualHeight = (int)(height * deviceItem.pixelSize); } else { // screen game view is opposite (portrait) manualHeight = (int)(width * deviceItem.pixelSize); } } else // portrait { if (gameViewOrientation == 1) { // screen game view is opposite (landscape) manualHeight = (int)(width * deviceItem.pixelSize); } else { // screen game view is also portrait manualHeight = (int)(height * deviceItem.pixelSize); } } } else { manualHeight = (int)(height * deviceItem.pixelSize); } retinaProNGTools.setRootManualHeight(manualHeight); { DirectoryInfo dinfo = new DirectoryInfo(retinaProFileLock.baseDataPath + retinaProConfig.atlasResourceFolder); if (dinfo != null && dinfo.Exists) { FileInfo [] fis = dinfo.GetFiles("*.prefab"); foreach (FileInfo fi in fis) { GameObject prefab = (GameObject)AssetDatabase.LoadAssetAtPath("Assets" + retinaProConfig.atlasResourceFolder + fi.Name, typeof(GameObject)); if (prefab == null) { continue; } UIAtlas atlas = prefab.GetComponent <UIAtlas>(); if (atlas != null) { string newAR = "Assets" + retinaProConfig.atlasResourceFolder + deviceItem.name + "/" + Path.GetFileNameWithoutExtension(fi.Name) + "~" + deviceItem.name + ".prefab"; UIAtlas ar = (UIAtlas)AssetDatabase.LoadAssetAtPath(newAR, typeof(UIAtlas)); atlas.replacement = ar; } UIFont font = prefab.GetComponent <UIFont>(); if (font != null) { string newFR = "Assets" + retinaProConfig.atlasResourceFolder + deviceItem.name + "/" + Path.GetFileNameWithoutExtension(fi.Name) + "~" + deviceItem.name + ".prefab"; UIFont fr = (UIFont)AssetDatabase.LoadAssetAtPath(newFR, typeof(UIFont)); font.replacement = fr; } } } } }
void showEditorPreviewUI() { bool save = false; bool refresh = false; EditorGUI.BeginDisabledGroup(retinaProState.state != retinaProState.rpState.kWaiting); EditorGUILayout.Space(); GUILayout.Label("Editor Preview", EditorStyles.boldLabel); EditorGUILayout.Space(); string [] availableDevices = new string[retinaProDataSerialize.sharedInstance.deviceList.Count]; for (int i = 0; i < retinaProDataSerialize.sharedInstance.deviceList.Count; i++) { if (retinaProDataSerialize.sharedInstance.deviceList[i].isDeviceValid()) { availableDevices[i] = retinaProDataSerialize.sharedInstance.deviceList[i].name; } else { availableDevices[i] = ""; } } bool showRefreshButton = true; if (availableDevices.Length == 0) { retinaProConfig.showValidDeviceNeededUI(); showRefreshButton = false; } else if (retinaProDataSerialize.sharedInstance.atlasList.Count == 0) { GUILayout.Label("Add at least one atlas"); showRefreshButton = false; } else if (retinaProDataSerialize.sharedInstance.getPreviewDeviceIdx() >= availableDevices.Length) { int idx = retinaProDataSerialize.sharedInstance.getPreviewDeviceIdx(); idx %= availableDevices.Length; retinaProDataSerialize.sharedInstance.setPreviewDeviceIdx(idx); // refresh the atlas references refresh = true; save = true; } else { int currentDeviceIdx = retinaProDataSerialize.sharedInstance.getPreviewDeviceIdx(); int newDeviceIdx = EditorGUILayout.Popup(currentDeviceIdx, availableDevices, GUILayout.Width(150f)); if (currentDeviceIdx != newDeviceIdx) { retinaProDataSerialize.sharedInstance.setPreviewDeviceIdx(newDeviceIdx); // refresh the atlas references refresh = true; save = true; } retinaProDevice di = retinaProDataSerialize.sharedInstance.deviceList[retinaProDataSerialize.sharedInstance.getPreviewDeviceIdx()]; if (di.isDeviceValid()) { if (di.screens != null && di.screens.Count > 0) { string [] screens = new string [di.screens.Count]; for (int rsi = 0; rsi < di.screens.Count; rsi++) { retinaProScreen rps = di.screens[rsi]; screens[rsi] = "" + rps.width + " x " + rps.height; } int currentScreenViewIdx = retinaProDataSerialize.sharedInstance.getPreviewScreenIdx(); int newScreenViewIdx = EditorGUILayout.Popup(currentScreenViewIdx, screens, GUILayout.Width(150f)); if (newScreenViewIdx != currentScreenViewIdx) { retinaProDataSerialize.sharedInstance.setPreviewScreenIdx(newScreenViewIdx); // refresh the atlas references refresh = true; save = true; } { retinaProScreen rps = di.screens[retinaProDataSerialize.sharedInstance.getPreviewScreenIdx()]; if (rps.useForBothLandscapePortrait) { string [] gameViews = { "Portrait", "Landscape" }; int currentGameViewIdx = retinaProDataSerialize.sharedInstance.getPreviewGameViewIdx(); int newGameViewIdx = EditorGUILayout.Popup(currentGameViewIdx, gameViews, GUILayout.Width(150f)); if (currentGameViewIdx != newGameViewIdx) { retinaProDataSerialize.sharedInstance.setPreviewGameViewIdx(newGameViewIdx); // refresh the atlas references refresh = true; save = true; } } } } } } if (showRefreshButton) { bool pressed = GUILayout.Button("Refresh Atlas References", GUILayout.Width(150f)); if (pressed) { refresh = true; } } EditorGUI.EndDisabledGroup(); if (save) { retinaProDataSerialize.sharedInstance.saveSettings(); } if (refresh) { int idx = retinaProDataSerialize.sharedInstance.getPreviewDeviceIdx(); retinaProDevice di = retinaProDataSerialize.sharedInstance.deviceList[idx]; if (di.isDeviceValid()) { retinaProNGTools.refreshReferencesForDevice(di, retinaProDataSerialize.sharedInstance.getPreviewScreenIdx(), retinaProDataSerialize.sharedInstance.getPreviewGameViewIdx()); retinaProNGTools.refresh(); } } }