Skip to content

Commit 3235783

Browse files
authored
Merge pull request #51 from arimger/feature/forcing-default-lists
Feature/forcing default lists
2 parents 481c28e + 8ae429a commit 3235783

10 files changed

Lines changed: 139 additions & 7 deletions
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Toolbox.Editor
2+
{
3+
internal static class ToolboxDefines
4+
{
5+
internal const string defaultListsDefine = "TOOLBOX_FORCE_DEFAULT_LISTS";
6+
}
7+
}

Assets/Editor Toolbox/Editor/ToolboxDefines.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/Editor/ToolboxDrawerModule.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ namespace Toolbox.Editor
1010
{
1111
using Toolbox.Editor.Drawers;
1212

13+
//TODO:
14+
//1. dedicated class to initialize and hold drawer-related data
15+
//2. dedicated class used for settings initialization
16+
//3. separate logic for resettings active drawers
17+
1318
internal static class ToolboxDrawerModule
1419
{
1520
[InitializeOnLoadMethod]
@@ -244,6 +249,7 @@ internal static void UpdateDrawers(IToolboxInspectorSettings settings)
244249
//create all type-only-related drawers
245250
PrepareTargetTypeDrawers(settings);
246251

252+
ForceDefaultLists(settings.ForceDefaultLists);
247253
//log errors into console only once
248254
validationEnabled = false;
249255
}
@@ -268,6 +274,18 @@ internal static bool HasTargetTypeDrawer(Type type)
268274
return targetTypeDrawers.ContainsKey(type.IsGenericType ? type.GetGenericTypeDefinition() : type);
269275
}
270276

277+
internal static void ForceDefaultLists(bool value)
278+
{
279+
if (value)
280+
{
281+
ScriptingUtility.AppendDefine(ToolboxDefines.defaultListsDefine);
282+
}
283+
else
284+
{
285+
ScriptingUtility.RemoveDefine(ToolboxDefines.defaultListsDefine);
286+
}
287+
}
288+
271289
internal static ToolboxDecoratorDrawerBase GetDecoratorDrawer<T>(T attribute) where T : ToolboxDecoratorAttribute
272290
{
273291
return GetDecoratorDrawer(attribute.GetType());
@@ -412,7 +430,7 @@ internal static ToolboxPropertyHandler GetPropertyHandler(SerializedProperty pro
412430

413431
//TODO:
414432
//NOTE: unfortunately there is no valid, non-reflection way to check if property has a custom native drawer
415-
private readonly static MethodInfo getDrawerTypeForTypeMethod =
433+
private static readonly MethodInfo getDrawerTypeForTypeMethod =
416434
ReflectionUtility.GetEditorMethod("UnityEditor.ScriptAttributeUtility", "GetDrawerTypeForType",
417435
BindingFlags.NonPublic | BindingFlags.Static);
418436
}

Assets/Editor Toolbox/Editor/ToolboxEditorSettings.cs

Lines changed: 11 additions & 2 deletions
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; }
@@ -81,8 +82,11 @@ internal class ToolboxEditorSettings : ScriptableObject, IToolboxGeneralSettings
8182
[SerializeField, ReorderableList(ListStyle.Boxed)]
8283
private List<FolderData> customFolders = new List<FolderData>();
8384

84-
[SerializeField]
85+
[SerializeField, Tooltip("Set to false if you don't want to use Toolbox attributes and related features.")]
8586
private bool useToolboxDrawers = true;
87+
[SerializeField, Tooltip("By default, Inspectors will use the built-in version of the list instead of the Toolbox-based one. " +
88+
"Keep in mind that built-in properties don't support Toolbox attributes. \n\n Changing this property will recompile the code.")]
89+
private bool forceDefaultLists;
8690

8791
[SerializeField, ReorderableList(ListStyle.Boxed), ClassExtends(typeof(ToolboxDecoratorDrawer<>))]
8892
private List<SerializedType> decoratorDrawerHandlers = new List<SerializedType>();
@@ -327,6 +331,12 @@ public bool UseToolboxDrawers
327331
set => useToolboxDrawers = value;
328332
}
329333

334+
public bool ForceDefaultLists
335+
{
336+
get => forceDefaultLists;
337+
set => forceDefaultLists = value;
338+
}
339+
330340
public List<SerializedType> DecoratorDrawerHandlers
331341
{
332342
get => decoratorDrawerHandlers;
@@ -357,7 +367,6 @@ public List<SerializedType> TargetTypeDrawerHandlers
357367
set => targetTypeDrawerHandlers = value;
358368
}
359369

360-
361370
private static class Defaults
362371
{
363372
internal const float largeFolderIconScaleDefault = 0.8f;

Assets/Editor Toolbox/Editor/ToolboxEditorSettingsEditor.cs

Lines changed: 5 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,9 @@ private void DrawInspectorSettings()
260262
EditorGUI.BeginChangeCheck();
261263
EditorGUILayout.Space();
262264
EditorGUILayout.PropertyField(useToolboxDrawersProperty);
265+
EditorGUI.BeginDisabledGroup(!useToolboxDrawersProperty.boolValue);
266+
EditorGUILayout.PropertyField(forceDefaultListsProperty);
267+
EditorGUI.EndDisabledGroup();
263268
EditorGUILayout.Space();
264269

265270
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

ProjectSettings/ProjectSettings.asset

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ PlayerSettings:
6868
androidRenderOutsideSafeArea: 0
6969
androidUseSwappy: 0
7070
androidBlitType: 0
71+
androidResizableWindow: 0
72+
androidDefaultWindowWidth: 1920
73+
androidDefaultWindowHeight: 1080
74+
androidMinimumWindowWidth: 400
75+
androidMinimumWindowHeight: 300
76+
androidFullscreenMode: 1
7177
defaultIsNativeResolution: 1
7278
macRetinaSupport: 1
7379
runInBackground: 1
@@ -121,6 +127,7 @@ PlayerSettings:
121127
vulkanEnableSetSRGBWrite: 0
122128
vulkanEnablePreTransform: 0
123129
vulkanEnableLateAcquireNextImage: 0
130+
vulkanEnableCommandBufferRecycling: 1
124131
m_SupportedAspectRatios:
125132
4:3: 1
126133
5:4: 1
@@ -236,6 +243,7 @@ PlayerSettings:
236243
useCustomGradlePropertiesTemplate: 0
237244
useCustomProguardFile: 0
238245
AndroidTargetArchitectures: 5
246+
AndroidTargetDevices: 0
239247
AndroidSplashScreenScale: 0
240248
androidSplashScreen: {fileID: 0}
241249
AndroidKeystoreName:
@@ -252,6 +260,7 @@ PlayerSettings:
252260
height: 180
253261
banner: {fileID: 0}
254262
androidGamepadSupportLevel: 0
263+
chromeosInputEmulation: 1
255264
AndroidMinifyWithR8: 0
256265
AndroidMinifyRelease: 0
257266
AndroidMinifyDebug: 0
@@ -354,6 +363,7 @@ PlayerSettings:
354363
cameraUsageDescription:
355364
locationUsageDescription:
356365
microphoneUsageDescription:
366+
bluetoothUsageDescription:
357367
switchNMETAOverride:
358368
switchNetLibKey:
359369
switchSocketMemoryPoolSize: 6144
@@ -491,6 +501,10 @@ PlayerSettings:
491501
switchNetworkInterfaceManagerInitializeEnabled: 1
492502
switchPlayerConnectionEnabled: 1
493503
switchUseNewStyleFilepaths: 0
504+
switchUseMicroSleepForYield: 1
505+
switchEnableRamDiskSupport: 0
506+
switchMicroSleepForYieldTime: 25
507+
switchRamDiskSpaceSize: 12
494508
ps4NPAgeRating: 12
495509
ps4NPTitleSecret:
496510
ps4NPTrophyPackPath:
@@ -561,6 +575,7 @@ PlayerSettings:
561575
ps4videoRecordingFeaturesUsed: 0
562576
ps4contentSearchFeaturesUsed: 0
563577
ps4CompatibilityPS5: 0
578+
ps4AllowPS5Detection: 0
564579
ps4GPU800MHz: 1
565580
ps4attribEyeToEyeDistanceSettingVR: 0
566581
ps4IncludedModules: []
@@ -585,7 +600,8 @@ PlayerSettings:
585600
webGLLinkerTarget: 1
586601
webGLThreadsSupport: 0
587602
webGLDecompressionFallback: 0
588-
scriptingDefineSymbols: {}
603+
scriptingDefineSymbols:
604+
1:
589605
additionalCompilerArguments: {}
590606
platformArchitecture: {}
591607
scriptingBackend: {}
@@ -632,6 +648,7 @@ PlayerSettings:
632648
metroFTAName:
633649
metroFTAFileTypes: []
634650
metroProtocolName:
651+
vcxProjDefaultLanguage:
635652
XboxOneProductId:
636653
XboxOneUpdateKey:
637654
XboxOneSandboxId:

0 commit comments

Comments
 (0)