Skip to content

Commit 4985b2f

Browse files
authored
Merge pull request #107 from arimger/develop
Develop - 0.12.11
2 parents 8eb47f9 + db1b172 commit 4985b2f

27 files changed

+224
-96
lines changed

Assets/Editor Toolbox/CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
## 0.12.0 [28.03.2024]
1+
## 0.12.11 [05.04.2024]
2+
3+
### Changed:
4+
- Fix handling the HasNativeTypeDrawer method in Unity 2022.3.23
5+
- Ignore `m_SerializedDataModeController` in Toolbox wizards
6+
- Change [Begin/EndHorizontal] behaviour (more customization options to handle available space)
7+
8+
## 0.12.10 [28.03.2024]
29

310
### Changed:
411
- Fix fetching and initializing Toolbox features when assets are updating

Assets/Editor Toolbox/Editor/Drawers/Toolbox/Decorator/BeginHorizontalAttributeDrawer.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,25 @@ namespace Toolbox.Editor.Drawers
55
{
66
public class BeginHorizontalAttributeDrawer : ToolboxDecoratorDrawer<BeginHorizontalAttribute>
77
{
8+
private static float lastFetchedWidth = 0.0f;
9+
810
protected override void OnGuiBeginSafe(BeginHorizontalAttribute attribute)
911
{
10-
var width = EditorGUIUtility.currentViewWidth;
11-
//set a new width value for label/field controls
12-
EditorGUIUtility.labelWidth = width * attribute.LabelToWidthRatio;
13-
EditorGUIUtility.fieldWidth = width * attribute.FieldToWidthRatio;
12+
if (GuiLayoutUtility.TryGetLayoutWidth(out var layoutWidth))
13+
{
14+
lastFetchedWidth = layoutWidth;
15+
}
16+
17+
EditorGUIUtility.labelWidth = attribute.LabelWidth;
18+
if (attribute.ControlFieldWidth && attribute.ElementsInLayout > 0)
19+
{
20+
var width = lastFetchedWidth;
21+
width -= attribute.WidthOffset;
22+
width -= (attribute.LabelWidth + attribute.WidthOffsetPerElement + EditorGUIUtility.standardVerticalSpacing * 4) * attribute.ElementsInLayout;
23+
width /= attribute.ElementsInLayout;
24+
EditorGUIUtility.fieldWidth = width;
25+
}
1426

15-
//begin horizontal group using internal utility
1627
ToolboxLayoutHandler.BeginHorizontal();
1728
}
1829
}

Assets/Editor Toolbox/Editor/Drawers/Toolbox/Decorator/BeginHorizontalGroupAttributeDrawer.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ static BeginHorizontalGroupAttributeDrawer()
1818
/// </summary>
1919
private static readonly ControlDataStorage<Vector2> storage;
2020

21+
private static float lastFetchedWidth = 0.0f;
2122

2223
private void HandleScrollView(float fixedHeight)
2324
{
@@ -29,25 +30,33 @@ private void HandleScrollView(float fixedHeight)
2930
storage.AppendItem(controlId, newScroll);
3031
}
3132

32-
3333
protected override void OnGuiBeginSafe(BeginHorizontalGroupAttribute attribute)
3434
{
35-
var fixedWidth = EditorGUIUtility.currentViewWidth;
36-
var fixedHeight = attribute.Height;
37-
EditorGUIUtility.labelWidth = fixedWidth * attribute.LabelToWidthRatio;
38-
EditorGUIUtility.fieldWidth = fixedWidth * attribute.FieldToWidthRatio;
35+
if (GuiLayoutUtility.TryGetLayoutWidth(out var layoutWidth))
36+
{
37+
lastFetchedWidth = layoutWidth;
38+
}
3939

4040
ToolboxLayoutHandler.BeginVertical(Style.groupBackgroundStyle);
4141
if (attribute.HasLabel)
4242
{
4343
GUILayout.Label(attribute.Label, EditorStyles.boldLabel);
4444
}
4545

46-
HandleScrollView(fixedHeight);
46+
EditorGUIUtility.labelWidth = attribute.LabelWidth;
47+
if (attribute.ControlFieldWidth && attribute.ElementsInLayout > 0)
48+
{
49+
var width = lastFetchedWidth;
50+
width -= attribute.WidthOffset;
51+
width -= (attribute.LabelWidth + attribute.WidthOffsetPerElement + EditorGUIUtility.standardVerticalSpacing * 4) * attribute.ElementsInLayout;
52+
width /= attribute.ElementsInLayout;
53+
EditorGUIUtility.fieldWidth = width;
54+
}
55+
56+
HandleScrollView(attribute.Height);
4757
ToolboxLayoutHandler.BeginHorizontal();
4858
}
4959

50-
5160
private static class Style
5261
{
5362
internal static readonly GUIStyle groupBackgroundStyle;

Assets/Editor Toolbox/Editor/Drawers/Toolbox/PropertyList/ReorderableListExposedAttributeDrawer.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ static ReorderableListExposedAttributeDrawer()
3131

3232
private static readonly PropertyDataStorage<ReorderableListBase, ReorderableListExposedAttribute> storage;
3333

34-
3534
private static void ConnectCallbacks(ReorderableListBase list, ReorderableListExposedAttribute attribute)
3635
{
3736
var listTarget = list.SerializedObject;
@@ -80,7 +79,6 @@ private static MethodInfo FindMethod(SerializedObject target, string methodName,
8079
return methodInfo;
8180
}
8281

83-
8482
protected override void OnGuiSafe(SerializedProperty property, GUIContent label, ReorderableListExposedAttribute attribute)
8583
{
8684
storage.ReturnItem(property, attribute).DoList(label);

Assets/Editor Toolbox/Editor/Internal/PropertyScope.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public PropertyScope(SerializedProperty property, GUIContent label, bool closeMa
2929
TryDrawLabel(rect, label);
3030
}
3131

32-
3332
private void HandleEvents(Rect rect)
3433
{
3534
if (property.isArray)
@@ -56,7 +55,6 @@ private void TryDrawLabel(Rect rect, GUIContent label)
5655
}
5756
}
5857

59-
6058
public void Close()
6159
{
6260
ToolboxEditorGui.CloseProperty();
@@ -73,7 +71,6 @@ public void Dispose()
7371
Close();
7472
}
7573

76-
7774
public bool IsVisible => property.isExpanded;
7875
public Rect LabelRect { get; private set; }
7976
public Rect InputRect { get; private set; }

Assets/Editor Toolbox/Editor/ToolboxDrawerModule.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ internal static void InitializeModule()
2323
ToolboxEditorHandler.OnEditorReload += ReloadDrawers;
2424
}
2525

26-
2726
private static readonly Type decoratorDrawerBase = typeof(ToolboxDecoratorDrawer<>);
2827
private static readonly Type conditionDrawerBase = typeof(ToolboxConditionDrawer<>);
2928
private static readonly Type selfPropertyDrawerBase = typeof(ToolboxSelfPropertyDrawer<>);
@@ -261,11 +260,25 @@ internal static void UpdateDrawers(IToolboxInspectorSettings settings)
261260
/// </summary>
262261
internal static bool HasNativeTypeDrawer(Type type)
263262
{
264-
#if UNITY_2023_3_OR_NEWER
265-
var parameters = new object[] { type, null, false };
266-
#else
267-
var parameters = new object[] { type };
268-
#endif
263+
object[] parameters;
264+
var parameterInfos = getDrawerTypeForTypeMethod.GetParameters();
265+
var parametersCount = parameterInfos.Length;
266+
switch (parametersCount)
267+
{
268+
default:
269+
case 1:
270+
parameters = new object[] { type };
271+
break;
272+
//NOTE: Unity 2022.3.23 or above
273+
case 2:
274+
parameters = new object[] { type, false };
275+
break;
276+
//NOTE: Unity 2023.3.x or above
277+
case 3:
278+
parameters = new object[] { type, null, false };
279+
break;
280+
}
281+
269282
var result = getDrawerTypeForTypeMethod.Invoke(null, parameters) as Type;
270283
return result != null && typeof(PropertyDrawer).IsAssignableFrom(result);
271284
}

Assets/Editor Toolbox/Editor/ToolboxEditorGui.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ private static Rect GetLineRect(Rect rect, float thickness, float padding, bool
2020
: new Rect(rect.x + padding / 2, rect.y, thickness, rect.height);
2121
}
2222

23-
2423
/// <summary>
2524
/// Draws horizontal line.
2625
/// Uses built-in layouting system.
@@ -248,7 +247,6 @@ public static partial class ToolboxEditorGui
248247
{
249248
private static EditorWindow lastTargetedWindow;
250249

251-
252250
/// <summary>
253251
/// Checks if user is still focusing the proper (searchable) window.
254252
/// </summary>
@@ -276,7 +274,6 @@ private static void OnPopupWindowUpdated()
276274
}
277275
}
278276

279-
280277
public static void DrawSearchablePopup(Rect rect, GUIContent label, int currentIndex, string[] options, Action<int> onSelect)
281278
{
282279
DrawSearchablePopup(rect, label, currentIndex, options, onSelect, EditorStyles.miniPullDown);

Assets/Editor Toolbox/Editor/ToolboxPropertyHandler.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ private void ProcessLabel(SerializedProperty property, GUIContent label)
397397
}
398398
}
399399

400-
401400
/// <summary>
402401
/// Draw property using built-in layout system and cached <see cref="ToolboxAttributeDrawer"/>s.
403402
/// </summary>

Assets/Editor Toolbox/Editor/Utilities/DraggingUtility.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ static DraggingUtility()
1818
BindingFlags.NonPublic | BindingFlags.Instance);
1919
}
2020

21-
2221
private static readonly MethodInfo validateAssignmentMethod;
2322
private static readonly MethodInfo appendFoldoutValueMethod;
2423

2524
private static readonly int dragAndDropHash = "customDragAndDrop".GetHashCode();
2625

27-
2826
public static Object ValidateAssignment(Object[] references, SerializedProperty property, Type type, bool exactType)
2927
{
3028
#if UNITY_2017_1_OR_NEWER

Assets/Editor Toolbox/Editor/Utilities/EditorGuiUtility.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ internal static class EditorGuiUtility
1616

1717
private static readonly Dictionary<string, Texture2D> loadedTextures = new Dictionary<string, Texture2D>();
1818

19-
2019
public static Texture2D CreateColorTexture()
2120
{
2221
return CreateColorTexture(Color.clear);
@@ -100,7 +99,6 @@ public static Texture GetHelpIcon(MessageType messageType)
10099
return null;
101100
}
102101

103-
104102
public static float FoldoutSize { get; internal set; } = 15.0f;
105103
public static float SpacingSize => EditorGUIUtility.standardVerticalSpacing;
106104
public static float HeightSize => EditorGUIUtility.singleLineHeight;

0 commit comments

Comments
 (0)