Skip to content

Commit b406771

Browse files
committed
Add compatibility to old version of Unity while adding new features to support newer version
1 parent f7b6d99 commit b406771

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

Editor/SceneManagerWindow.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,13 @@ private void DrawElement(Rect rect, int index, bool isActive, bool isFocused) {
178178
EditorApplication.isPlaying = false;
179179
} else if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) {
180180
playScene = true;
181-
var loadedScenes = new List<string>(EditorSceneManager.loadedSceneCount);
182-
for (int i = 0, c = EditorSceneManager.loadedSceneCount; i < c; i++) {
181+
#if UNITY_2022_2_OR_NEWER
182+
int loadedSceneCount = SceneManager.loadedSceneCount;
183+
#else
184+
int loadedSceneCount = SceneManager.sceneCount;
185+
#endif
186+
var loadedScenes = new List<string>(loadedSceneCount);
187+
for (int i = 0; i < loadedSceneCount; i++) {
183188
Scene scene = SceneManager.GetSceneAt(i);
184189
if (scene.IsValid() && !string.IsNullOrEmpty(scene.path))
185190
loadedScenes.Add(scene.path);

Editor/UInspectorPlus/ComponentMethodDrawer.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,12 @@ private void InitMethodParams() {
408408
var genericArgs = method.GetGenericArguments();
409409
if (parameters.Length > 0) {
410410
var firstParam = parameters[0].ParameterType;
411-
if (firstParam.IsGenericMethodParameter) {
411+
#if NETSTANDARD2_1_OR_GREATER
412+
bool isGenericMethodParameter = firstParam.IsGenericMethodParameter;
413+
#else
414+
bool isGenericMethodParameter = firstParam.IsGenericParameter;
415+
#endif
416+
if (isGenericMethodParameter) {
412417
genericArgs[firstParam.GenericParameterPosition] = targetType;
413418
method = method.MakeGenericMethod(genericArgs);
414419
} else if (firstParam.ContainsGenericParameters) {
@@ -466,7 +471,7 @@ private void DrawComponent() {
466471
if (GUILayout.Button(selectedMethodIndex < 0 ? GUIContent.none : methodNames[selectedMethodIndex + 1].content, EditorStyles.popup))
467472
ShowSearchPopup();
468473
if (OnClose != null) {
469-
if (GUILayout.Button(EditorGUIUtility.IconContent("Toolbar Minus"), EditorStyles.miniLabel, GUILayout.ExpandWidth(false)))
474+
if (GUILayout.Button(EditorGUIUtility.IconContent("Toolbar Minus"), Helper.IconButtonStyle, GUILayout.ExpandWidth(false)))
470475
OnClose();
471476
EditorGUILayout.EndHorizontal();
472477
}

Editor/UInspectorPlus/Helpers.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,12 @@ internal static Type GetGenericListType(this Type targetType) {
477477

478478
internal static GUIStyle GetGUIStyle(string styleName) => GUI.skin.FindStyle(styleName) ??
479479
EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).FindStyle(styleName);
480+
481+
#if UNITY_2021_2_OR_NEWER
482+
internal static GUIStyle IconButtonStyle => EditorStyles.iconButton;
483+
#else
484+
internal static GUIStyle IconButtonStyle => EditorStyles.miniButton;
485+
#endif
480486

481487
internal static T GetOrDefault<T>(object value, T defaultValue = default) {
482488
if (value == null) return defaultValue;

Editor/UInspectorPlus/InspectorDrawer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ protected virtual void Draw(bool readOnly) {
206206
if (allowMethods) {
207207
GUILayout.BeginHorizontal();
208208
GUILayout.FlexibleSpace();
209-
if (GUILayout.Button(EditorGUIUtility.IconContent("Toolbar Plus", "Add Method / Index Properties Watcher"), EditorStyles.miniLabel, GUILayout.ExpandWidth(false))) {
209+
if (GUILayout.Button(EditorGUIUtility.IconContent("Toolbar Plus", "Add Method / Index Properties Watcher"), Helper.IconButtonStyle, GUILayout.ExpandWidth(false))) {
210210
ComponentMethodDrawer newDrawer = null;
211211
newDrawer = new ComponentMethodDrawer(target, targetType) {
212212
AllowPrivateFields = allowPrivate,

Editor/UInspectorPlus/MethodPropertyDrawer.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,10 @@ public void Draw(bool readOnly, Rect? rect = null) {
335335
hasMatchMenu = DrawAssignButton(rect.HasValue ? (Rect?)Helper.ScaleRect(rect.Value, 1, 0.5F, 0, 0, -EditorGUIUtility.singleLineHeight, -7.5F, 15, 15) : null);
336336
if (!hasMatchMenu && !readOnly && referenceModeBtn) {
337337
if (rect.HasValue) {
338-
if (GUI.Button(rect.Value.ScaleRect(1, 0.5F, 0, 0, -EditorGUIUtility.singleLineHeight, -7.5F, 15, 15), EditorGUIUtility.IconContent("_Menu"), EditorStyles.miniLabel))
338+
if (GUI.Button(rect.Value.ScaleRect(1, 0.5F, 0, 0, -EditorGUIUtility.singleLineHeight, -7.5F, 15, 15), EditorGUIUtility.IconContent("_Menu"), Helper.IconButtonStyle))
339339
ShowMenu(rect.Value);
340340
} else {
341-
if (GUILayout.Button(EditorGUIUtility.IconContent("_Menu"), EditorStyles.miniLabel, GUILayout.ExpandWidth(false)))
341+
if (GUILayout.Button(EditorGUIUtility.IconContent("_Menu"), Helper.IconButtonStyle, GUILayout.ExpandWidth(false)))
342342
ShowMenu(menuButtonRect);
343343
if (Event.current.type == EventType.Repaint)
344344
menuButtonRect = GUILayoutUtility.GetLastRect();
@@ -449,8 +449,8 @@ private bool DrawAssignButton(Rect? rect) {
449449
hasButton = true;
450450
if (
451451
rect.HasValue ?
452-
GUI.Button(rect.Value, EditorGUIUtility.IconContent("Linked"), EditorStyles.miniLabel) :
453-
GUILayout.Button(EditorGUIUtility.IconContent("Linked"), EditorStyles.miniLabel, GUILayout.ExpandWidth(false))
452+
GUI.Button(rect.Value, EditorGUIUtility.IconContent("Linked"), Helper.IconButtonStyle) :
453+
GUILayout.Button(EditorGUIUtility.IconContent("Linked"), Helper.IconButtonStyle, GUILayout.ExpandWidth(false))
454454
) {
455455
drawer.TryApplyValue(rawValue);
456456
finishedDrawer = drawer;
@@ -728,9 +728,9 @@ private void DrawUnknownField(bool readOnly, object target, Rect? position = nul
728728
return;
729729
bool clicked;
730730
if (!position.HasValue)
731-
clicked = GUILayout.Button(EditorGUIUtility.IconContent("MoreOptions"), EditorStyles.miniLabel, GUILayout.ExpandWidth(false));
731+
clicked = GUILayout.Button(EditorGUIUtility.IconContent("MoreOptions"), Helper.IconButtonStyle, GUILayout.ExpandWidth(false));
732732
else
733-
clicked = GUI.Button(position.Value, EditorGUIUtility.IconContent("MoreOptions"), EditorStyles.miniLabel);
733+
clicked = GUI.Button(position.Value, EditorGUIUtility.IconContent("MoreOptions"), Helper.IconButtonStyle);
734734
if (clicked)
735735
InspectorChildWindow.Open(target, true, privateFields, obsolete, true, false, this);
736736
}

0 commit comments

Comments
 (0)