Skip to content

Commit 85937c4

Browse files
committed
Possibility to force drawing default ReorderableLists
1 parent ad8836f commit 85937c4

7 files changed

Lines changed: 94 additions & 4 deletions

File tree

Assets/Editor Toolbox/Editor/ToolboxDrawerModule.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ internal static void UpdateDrawers(IToolboxInspectorSettings settings)
244244
//create all type-only-related drawers
245245
PrepareTargetTypeDrawers(settings);
246246

247+
ForceDefaultLists(settings.ForceDefaultLists);
247248
//log errors into console only once
248249
validationEnabled = false;
249250
}
@@ -268,6 +269,19 @@ internal static bool HasTargetTypeDrawer(Type type)
268269
return targetTypeDrawers.ContainsKey(type.IsGenericType ? type.GetGenericTypeDefinition() : type);
269270
}
270271

272+
internal static void ForceDefaultLists(bool value)
273+
{
274+
const string targetDefine = "TOOLBOX_FORCE_DEFAULT_LISTS";
275+
if (value)
276+
{
277+
ScriptingUtility.AppendDefine(targetDefine);
278+
}
279+
else
280+
{
281+
ScriptingUtility.RemoveDefine(targetDefine);
282+
}
283+
}
284+
271285
internal static ToolboxDecoratorDrawerBase GetDecoratorDrawer<T>(T attribute) where T : ToolboxDecoratorAttribute
272286
{
273287
return GetDecoratorDrawer(attribute.GetType());

Assets/Editor Toolbox/Editor/ToolboxEditorSettings.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ internal interface IToolboxInspectorSettings
4343
void SetAllPossibleTargetTypeDrawers();
4444

4545
bool UseToolboxDrawers { get; }
46+
bool ForceDefaultLists { get; }
4647

4748
List<SerializedType> DecoratorDrawerHandlers { get; }
4849
List<SerializedType> ConditionDrawerHandlers { get; }
@@ -83,6 +84,8 @@ internal class ToolboxEditorSettings : ScriptableObject, IToolboxGeneralSettings
8384

8485
[SerializeField]
8586
private bool useToolboxDrawers = true;
87+
[SerializeField, Tooltip("Inspectors will use the default ReorderableList instead of a simple hierarchy.")]
88+
private bool forceDefaultLists;
8689

8790
[SerializeField, ReorderableList(ListStyle.Boxed), ClassExtends(typeof(ToolboxDecoratorDrawer<>))]
8891
private List<SerializedType> decoratorDrawerHandlers = new List<SerializedType>();
@@ -327,6 +330,12 @@ public bool UseToolboxDrawers
327330
set => useToolboxDrawers = value;
328331
}
329332

333+
public bool ForceDefaultLists
334+
{
335+
get => forceDefaultLists;
336+
set => forceDefaultLists = value;
337+
}
338+
330339
public List<SerializedType> DecoratorDrawerHandlers
331340
{
332341
get => decoratorDrawerHandlers;
@@ -357,7 +366,6 @@ public List<SerializedType> TargetTypeDrawerHandlers
357366
set => targetTypeDrawerHandlers = value;
358367
}
359368

360-
361369
private static class Defaults
362370
{
363371
internal const float largeFolderIconScaleDefault = 0.8f;

Assets/Editor Toolbox/Editor/ToolboxEditorSettingsEditor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ internal class ToolboxEditorSettingsEditor : ToolboxEditor
2626
private SerializedProperty showSelectionsCountProperty;
2727
private SerializedProperty useToolboxFoldersProperty;
2828
private SerializedProperty useToolboxDrawersProperty;
29+
private SerializedProperty forceDefaultListsProperty;
2930
private SerializedProperty largeIconScaleProperty;
3031
private SerializedProperty smallIconScaleProperty;
3132
private SerializedProperty largeIconPaddingProperty;
@@ -86,6 +87,7 @@ private void OnEnable()
8687
#endif
8788
//inspector-related properties
8889
useToolboxDrawersProperty = serializedObject.FindProperty("useToolboxDrawers");
90+
forceDefaultListsProperty = serializedObject.FindProperty("forceDefaultLists");
8991

9092
drawerHandlersLists = new ReorderableListBase[5];
9193
#if UNITY_2019_3_OR_NEWER
@@ -260,6 +262,7 @@ private void DrawInspectorSettings()
260262
EditorGUI.BeginChangeCheck();
261263
EditorGUILayout.Space();
262264
EditorGUILayout.PropertyField(useToolboxDrawersProperty);
265+
EditorGUILayout.PropertyField(forceDefaultListsProperty);
263266
EditorGUILayout.Space();
264267

265268
var validateInspector = false;

Assets/Editor Toolbox/Editor/ToolboxPropertyHandler.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,15 +444,23 @@ public void OnGuiDefault(SerializedProperty property)
444444
/// </summary>
445445
public void OnGuiDefault(SerializedProperty property, GUIContent label)
446446
{
447+
#if TOOLBOX_FORCE_DEFAULT_LISTS
448+
if (isArray)
449+
{
450+
EditorGUILayout.PropertyField(property, label, true);
451+
return;
452+
}
453+
#endif
447454
//all "single" properties and native drawers should be drawn in the native way
448455
if (hasBuiltInPropertyDrawer)
449456
{
450457
ToolboxEditorGui.DrawNativeProperty(property, label);
451-
return;
452458
}
453-
454459
//handles property in default native way but supports ToolboxDrawers in children
455-
ToolboxEditorGui.DrawDefaultProperty(property, label);
460+
else
461+
{
462+
ToolboxEditorGui.DrawDefaultProperty(property, label);
463+
}
456464
}
457465
}
458466
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
4+
using UnityEditor;
5+
6+
namespace Toolbox.Editor
7+
{
8+
public static class ScriptingUtility
9+
{
10+
public static List<string> GetDefines()
11+
{
12+
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
13+
return defines.Split(';').ToList();
14+
}
15+
16+
public static void SetDefines(List<string> definesList)
17+
{
18+
var defines = string.Join(";", definesList.ToArray());
19+
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, defines);
20+
}
21+
22+
public static void AppendDefine(string define)
23+
{
24+
var definesList = GetDefines();
25+
if (definesList.Contains(define))
26+
{
27+
return;
28+
}
29+
30+
definesList.Add(define);
31+
SetDefines(definesList);
32+
}
33+
34+
public static void RemoveDefine(string define)
35+
{
36+
var definesList = GetDefines();
37+
if (definesList.RemoveAll(s => s == define) == 0)
38+
{
39+
return;
40+
}
41+
42+
SetDefines(definesList);
43+
}
44+
}
45+
}

Assets/Editor Toolbox/Editor/Utilities/ScriptingUtility.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Editor Toolbox/EditorSettings.asset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ MonoBehaviour:
4747
smallIcon: {fileID: 2800000, guid: e99d63b63394eba4aaf10385704d0ef3, type: 3}
4848
iconName:
4949
useToolboxDrawers: 1
50+
forceDefaultLists: 0
5051
decoratorDrawerHandlers:
5152
- typeReference: Toolbox.Editor.Drawers.BeginGroupAttributeDrawer, Toolbox.Editor
5253
- typeReference: Toolbox.Editor.Drawers.BeginHorizontalAttributeDrawer, Toolbox.Editor

0 commit comments

Comments
 (0)