public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label) { var sizer = property.GetValue <ScreenDependentSize <T> >(); GUILayout.Space(-20); // cheat to draw over allocated rect EditorGUILayout.BeginVertical(GUI.skin.box); //"RegionBg");// GUI.skin.box); //GUILayout.Space(-20); // cheat again because "RegionBg" adds additional space //EditorGUILayout.LabelField(property.displayName, EditorStyles.boldLabel); EditorGUILayout.LabelField("CurrentValue", GetValueString(sizer.LastCalculatedSize), EditorStyles.boldLabel); ShowField(property, "OptimizedSize", "Optimized Size", ref sizer.OptimizedSize); EditorGUI.indentLevel += 1; foldout = EditorGUILayout.Foldout(foldout, "Size Modification"); if (foldout) { EditorGUILayout.BeginHorizontal(); Vector2 optimizedRes = ResolutionMonitor.GetOptimizedResolution(sizer.ScreenConfigName); float optimizedDpi = ResolutionMonitor.GetOptimizedDpi(sizer.ScreenConfigName); string opt = string.Format("{0} x {1} @ {2} DPI", optimizedRes.x, optimizedRes.y, optimizedDpi); EditorGUILayout.LabelField(opt, EditorStyles.boldLabel); if (GUILayout.Button("Change")) { Selection.activeObject = ResolutionMonitor.Instance; } EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel += 1; ShowField(property, "MinSize", "Min Size", ref sizer.MinSize); ShowField(property, "MaxSize", "Max Size", ref sizer.MaxSize); property.serializedObject.ApplyModifiedPropertiesWithoutUndo(); EditorGUILayout.Space(); DrawModifiers(property); EditorGUI.indentLevel -= 1; } EditorGUI.indentLevel -= 1; EditorGUILayout.EndVertical(); }
void SetResolution(GameViewSize size) { var type = gameView.GetType(); selectedIndex.SetValue(gameView, size.index, null); if (ResolutionMonitor.IsZoomPossible()) { var method = type.GetMethod("UpdateZoomAreaAndParent", BindingFlags.Instance | BindingFlags.NonPublic); method.Invoke(gameView, null); } }
void OnGUI() { if (gameSizeType == null) { RefreshSizes(); } Begin(mainSection: false); // Resolutions Begin(mainSection: true); DrawToolStrip(); // settings EditorGUILayout.Separator(); var style = (useBigButtons) ? GUI.skin.button : EditorStyles.toolbarButton; var prevAlign = style.alignment; style.alignment = TextAnchor.MiddleLeft; style.fontSize = 10; int currentIndex = (int)selectedIndex.GetValue(gameView, null); for (int i = 0; i < sizes.Count; i++) { if ((displayFree && i == 1) || (displayBuiltin && i == builtinCount)) { EditorGUILayout.Separator(); } var size = sizes[i]; if (!(AllowedToShow(size))) { continue; } bool isOptimizedRes = (ResolutionMonitor.IsOptimizedResolution(size.width, size.height)); bool isSelected = currentIndex == size.index; style.fontStyle = (isOptimizedRes) ? ((isSelected) ? FontStyle.BoldAndItalic : FontStyle.Italic) : ((isSelected) ? FontStyle.Bold : FontStyle.Normal); if (GUILayout.Button(GetText(size), style)) { SetResolution(size); } } GUILayout.FlexibleSpace(); style.fontStyle = FontStyle.Normal; End(mainSection: true); // Screen Configs if (this.displayScreenConfigs) { Begin(mainSection: true); Action <ScreenTypeConditions, int, int> applyScreenConfig = (config, width, height) => { if (config != null && ResolutionMonitor.SimulatedScreenConfig == config) { ResolutionMonitor.SimulatedScreenConfig = null; } else { ResolutionMonitor.SimulatedScreenConfig = config; if (this.applyScreenConfigResolution) { RefreshSizes(); GameViewSize gvs = sizes.FirstOrDefault((o) => o.width == width && o.height == height); if (gvs == null) { string name = (config != null) ? config.Name : ResolutionMonitor.Instance.FallbackName; AddSizeToUnity(name, width, height); gvs = sizes.FirstOrDefault((o) => o.width == width && o.height == height); } if (gvs != null) { SetResolution(gvs); } } } }; if (GUILayout.Button(ResolutionMonitor.Instance.FallbackName + " (Fallback)", style)) { var resolution = ResolutionMonitor.OptimizedResolutionFallback; applyScreenConfig(null, (int)resolution.x, (int)resolution.y); } EditorGUILayout.Space(); foreach (var config in ResolutionMonitor.Instance.OptimizedScreens) { if (GUILayout.Button(ResolutionMonitorEditor.GetButtonText(config), style)) { applyScreenConfig(config, config.OptimizedWidth, config.OptimizedHeight); } } GUILayout.FlexibleSpace(); End(mainSection: true); } End(mainSection: false); style.alignment = prevAlign; }
public override void OnInspectorGUI() { ResolutionMonitor monitor = (ResolutionMonitor)target; EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("Screen Configurations", EditorStyles.boldLabel); for (int i = 0; i < monitor.OptimizedScreens.Count; i++) { var config = monitor.OptimizedScreens[i]; EditorGUILayout.BeginVertical("box"); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(GetButtonText(config), EditorStyles.largeLabel, GUILayout.Height(20), GUILayout.Width(150))) { ResolutionMonitor.SimulatedScreenConfig = (ResolutionMonitor.SimulatedScreenConfig == config) ? null : config; } GUILayout.FlexibleSpace(); if (GUILayout.Button("¶x")) { SetNameOrDeleteOptimizedScreen popup = new SetNameOrDeleteOptimizedScreen(config, () => PopupWindow.focusedWindow.Close()); PopupWindow.Show(new Rect(0, 0, 400, 300), popup); } EditorGUI.BeginDisabledGroup(i == 0); if (GUILayout.Button("▲")) { MoveToIndex(config, i - 1); } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(i == monitor.OptimizedScreens.Count - 1); if (GUILayout.Button("▼")) { MoveToIndex(config, i + 1); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginVertical("box"); EditorGUILayout.LabelField("Optimized Screen Size", EditorStyles.boldLabel); config.OptimizedScreenInfo.Resolution = EditorGUILayout.Vector2Field("Optimized Resolution", config.OptimizedScreenInfo.Resolution); config.OptimizedScreenInfo.Dpi = EditorGUILayout.FloatField("Optimized DPI", config.OptimizedScreenInfo.Dpi); EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical("box"); DrawConfigPart("Check Screen Orientation", config.CheckOrientation, (o) => { o.ExpectedOrientation = (IsCertainScreenOrientation.Orientation)EditorGUILayout.EnumPopup("Orientation", o.ExpectedOrientation); }); DrawConfigPart("Check Screen Size", config.CheckScreenSize, (o) => { EditorGUILayout.BeginHorizontal(); o.MeasureType = (IsScreenOfCertainSize.ScreenMeasure)EditorGUILayout.EnumPopup(o.MeasureType, GUILayout.MinWidth(95)); o.Units = (IsScreenOfCertainSize.UnitType)EditorGUILayout.EnumPopup(o.Units, GUILayout.MinWidth(100)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(">=", GUILayout.Width(50)); o.MinSize = EditorGUILayout.FloatField(o.MinSize); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("<", GUILayout.Width(50)); o.MaxSize = EditorGUILayout.FloatField(o.MaxSize); EditorGUILayout.EndHorizontal(); if (o.MinSize >= o.MaxSize) { EditorGUILayout.HelpBox("First Value must be smaller than second value.", MessageType.Error); } }); DrawConfigPart("Check Aspect Ratio", config.CheckAspectRatio, (o) => { int selector = -1; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(">=", GUILayout.Width(50)); o.MinAspect = EditorGUILayout.FloatField(o.MinAspect, GUILayout.Width(70)); selector = EditorGUILayout.Popup(selector, aspectRatioNames); if (selector != -1) { o.MinAspect = ((AspectRatio)selector).GetRatioValue(); selector = -1; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("<=", GUILayout.Width(50)); o.MaxAspect = EditorGUILayout.FloatField(o.MaxAspect, GUILayout.Width(70)); selector = EditorGUILayout.Popup(selector, aspectRatioNames); if (selector != -1) { o.MaxAspect = ((AspectRatio)selector).GetRatioValue(); selector = -1; } EditorGUILayout.EndHorizontal(); o.Inverse = EditorGUILayout.ToggleLeft(" Inverse (ratio is not in given range)", o.Inverse); if (o.MinAspect >= o.MaxAspect) { EditorGUILayout.HelpBox("First Value must be smaller than second value.", MessageType.Error); } }); DrawConfigPart("Check Device", config.CheckDeviceType, (o) => { o.ExpectedDeviceInfo = (IsScreenOfCertainDeviceInfo.DeviceInfo)EditorGUILayout.EnumPopup("Device Info", o.ExpectedDeviceInfo); }); EditorGUILayout.EndVertical(); Rect bgRect = EditorGUILayout.BeginVertical("box"); EditorGUILayout.LabelField("Fallback Order", EditorStyles.boldLabel); // ADD FALLBACK string[] options = ResolutionMonitor.Instance.OptimizedScreens .Where(o => (config != o) && !(config.Fallbacks.Contains(o.Name))) .Select(o => o.Name) .ToArray(); if (options.Length > 0) { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); Rect r = new Rect(bgRect.x + bgRect.width - 20, bgRect.y + 3, 20, 20); int idx = EditorGUI.Popup(r, -1, options, "OL Plus"); if (idx != -1) { string name = options[idx]; idx = -1; config.Fallbacks.Insert(0, name); } EditorGUILayout.EndHorizontal(); } EditorGUI.indentLevel++; for (int k = 0; k < config.Fallbacks.Count; k++) { string name = config.Fallbacks[k]; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(string.Format("{0}. {1}", k + 1, name)); GUILayout.FlexibleSpace(); EditorGUI.BeginDisabledGroup(k == 0); if (GUILayout.Button("↑")) { config.Fallbacks.RemoveAt(k); config.Fallbacks.Insert(k - 1, name); } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(k == config.Fallbacks.Count - 1); if (GUILayout.Button("↓")) { config.Fallbacks.RemoveAt(k); config.Fallbacks.Insert(k + 1, name); } EditorGUI.EndDisabledGroup(); if (GUILayout.Button("x")) { config.Fallbacks.RemoveAt(k); } EditorGUILayout.EndHorizontal(); } EditorGUI.indentLevel--; EditorGUILayout.EndVertical(); EditorGUILayout.EndVertical(); } if (GUILayout.Button("+")) { SetNameOrDeleteOptimizedScreen popup = new SetNameOrDeleteOptimizedScreen(null, () => PopupWindow.focusedWindow.Close()); PopupWindow.Show(new Rect(0, 0, 400, 175), popup); } EditorGUILayout.EndVertical(); // Screen Configuration Global Fallback EditorGUILayout.Separator(); EditorGUILayout.BeginVertical("box"); EditorGUILayout.LabelField("Fallback", EditorStyles.boldLabel); EditorGUILayout.PropertyField(fallbackName, new GUIContent("Fallback Name")); EditorGUILayout.BeginVertical("box"); EditorGUILayout.LabelField("Optimized Screen Size", EditorStyles.boldLabel); EditorGUILayout.PropertyField(curOptRes, new GUIContent("Optimized Resolution")); EditorGUILayout.PropertyField(curOptDpi, new GUIContent("Optimized Dpi")); EditorGUILayout.EndVertical(); serializedObject.ApplyModifiedProperties(); EditorGUILayout.EndVertical(); if (GUILayout.Button("Save", GUILayout.Height(50))) { EditorUtility.SetDirty(monitor); AssetDatabase.SaveAssets(); } // DPI OVERRIDES GUILayout.FlexibleSpace(); showDpiManager = EditorGUILayout.Foldout(showDpiManager, "DPI Overwrites"); if (showDpiManager) { EditorGUILayout.HelpBox( "Some devices have no or wrong DPI values assigned by the manufacturer. " + "Here these devices can be specified to assign the correct DPI value to them.", MessageType.Info); dpiList.DoLayoutList(); } }