Skip to content

Commit

Permalink
Merge pull request #107 from arimger/develop
Browse files Browse the repository at this point in the history
Develop - 0.12.11
  • Loading branch information
arimger authored Apr 5, 2024
2 parents 8eb47f9 + db1b172 commit 4985b2f
Show file tree
Hide file tree
Showing 27 changed files with 224 additions and 96 deletions.
9 changes: 8 additions & 1 deletion Assets/Editor Toolbox/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
## 0.12.0 [28.03.2024]
## 0.12.11 [05.04.2024]

### Changed:
- Fix handling the HasNativeTypeDrawer method in Unity 2022.3.23
- Ignore `m_SerializedDataModeController` in Toolbox wizards
- Change [Begin/EndHorizontal] behaviour (more customization options to handle available space)

## 0.12.10 [28.03.2024]

### Changed:
- Fix fetching and initializing Toolbox features when assets are updating
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,25 @@ namespace Toolbox.Editor.Drawers
{
public class BeginHorizontalAttributeDrawer : ToolboxDecoratorDrawer<BeginHorizontalAttribute>
{
private static float lastFetchedWidth = 0.0f;

protected override void OnGuiBeginSafe(BeginHorizontalAttribute attribute)
{
var width = EditorGUIUtility.currentViewWidth;
//set a new width value for label/field controls
EditorGUIUtility.labelWidth = width * attribute.LabelToWidthRatio;
EditorGUIUtility.fieldWidth = width * attribute.FieldToWidthRatio;
if (GuiLayoutUtility.TryGetLayoutWidth(out var layoutWidth))
{
lastFetchedWidth = layoutWidth;
}

EditorGUIUtility.labelWidth = attribute.LabelWidth;
if (attribute.ControlFieldWidth && attribute.ElementsInLayout > 0)
{
var width = lastFetchedWidth;
width -= attribute.WidthOffset;
width -= (attribute.LabelWidth + attribute.WidthOffsetPerElement + EditorGUIUtility.standardVerticalSpacing * 4) * attribute.ElementsInLayout;
width /= attribute.ElementsInLayout;
EditorGUIUtility.fieldWidth = width;
}

//begin horizontal group using internal utility
ToolboxLayoutHandler.BeginHorizontal();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static BeginHorizontalGroupAttributeDrawer()
/// </summary>
private static readonly ControlDataStorage<Vector2> storage;

private static float lastFetchedWidth = 0.0f;

private void HandleScrollView(float fixedHeight)
{
Expand All @@ -29,25 +30,33 @@ private void HandleScrollView(float fixedHeight)
storage.AppendItem(controlId, newScroll);
}


protected override void OnGuiBeginSafe(BeginHorizontalGroupAttribute attribute)
{
var fixedWidth = EditorGUIUtility.currentViewWidth;
var fixedHeight = attribute.Height;
EditorGUIUtility.labelWidth = fixedWidth * attribute.LabelToWidthRatio;
EditorGUIUtility.fieldWidth = fixedWidth * attribute.FieldToWidthRatio;
if (GuiLayoutUtility.TryGetLayoutWidth(out var layoutWidth))
{
lastFetchedWidth = layoutWidth;
}

ToolboxLayoutHandler.BeginVertical(Style.groupBackgroundStyle);
if (attribute.HasLabel)
{
GUILayout.Label(attribute.Label, EditorStyles.boldLabel);
}

HandleScrollView(fixedHeight);
EditorGUIUtility.labelWidth = attribute.LabelWidth;
if (attribute.ControlFieldWidth && attribute.ElementsInLayout > 0)
{
var width = lastFetchedWidth;
width -= attribute.WidthOffset;
width -= (attribute.LabelWidth + attribute.WidthOffsetPerElement + EditorGUIUtility.standardVerticalSpacing * 4) * attribute.ElementsInLayout;
width /= attribute.ElementsInLayout;
EditorGUIUtility.fieldWidth = width;
}

HandleScrollView(attribute.Height);
ToolboxLayoutHandler.BeginHorizontal();
}


private static class Style
{
internal static readonly GUIStyle groupBackgroundStyle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ static ReorderableListExposedAttributeDrawer()

private static readonly PropertyDataStorage<ReorderableListBase, ReorderableListExposedAttribute> storage;


private static void ConnectCallbacks(ReorderableListBase list, ReorderableListExposedAttribute attribute)
{
var listTarget = list.SerializedObject;
Expand Down Expand Up @@ -80,7 +79,6 @@ private static MethodInfo FindMethod(SerializedObject target, string methodName,
return methodInfo;
}


protected override void OnGuiSafe(SerializedProperty property, GUIContent label, ReorderableListExposedAttribute attribute)
{
storage.ReturnItem(property, attribute).DoList(label);
Expand Down
3 changes: 0 additions & 3 deletions Assets/Editor Toolbox/Editor/Internal/PropertyScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public PropertyScope(SerializedProperty property, GUIContent label, bool closeMa
TryDrawLabel(rect, label);
}


private void HandleEvents(Rect rect)
{
if (property.isArray)
Expand All @@ -56,7 +55,6 @@ private void TryDrawLabel(Rect rect, GUIContent label)
}
}


public void Close()
{
ToolboxEditorGui.CloseProperty();
Expand All @@ -73,7 +71,6 @@ public void Dispose()
Close();
}


public bool IsVisible => property.isExpanded;
public Rect LabelRect { get; private set; }
public Rect InputRect { get; private set; }
Expand Down
25 changes: 19 additions & 6 deletions Assets/Editor Toolbox/Editor/ToolboxDrawerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ internal static void InitializeModule()
ToolboxEditorHandler.OnEditorReload += ReloadDrawers;
}


private static readonly Type decoratorDrawerBase = typeof(ToolboxDecoratorDrawer<>);
private static readonly Type conditionDrawerBase = typeof(ToolboxConditionDrawer<>);
private static readonly Type selfPropertyDrawerBase = typeof(ToolboxSelfPropertyDrawer<>);
Expand Down Expand Up @@ -261,11 +260,25 @@ internal static void UpdateDrawers(IToolboxInspectorSettings settings)
/// </summary>
internal static bool HasNativeTypeDrawer(Type type)
{
#if UNITY_2023_3_OR_NEWER
var parameters = new object[] { type, null, false };
#else
var parameters = new object[] { type };
#endif
object[] parameters;
var parameterInfos = getDrawerTypeForTypeMethod.GetParameters();
var parametersCount = parameterInfos.Length;
switch (parametersCount)
{
default:
case 1:
parameters = new object[] { type };
break;
//NOTE: Unity 2022.3.23 or above
case 2:
parameters = new object[] { type, false };
break;
//NOTE: Unity 2023.3.x or above
case 3:
parameters = new object[] { type, null, false };
break;
}

var result = getDrawerTypeForTypeMethod.Invoke(null, parameters) as Type;
return result != null && typeof(PropertyDrawer).IsAssignableFrom(result);
}
Expand Down
3 changes: 0 additions & 3 deletions Assets/Editor Toolbox/Editor/ToolboxEditorGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ private static Rect GetLineRect(Rect rect, float thickness, float padding, bool
: new Rect(rect.x + padding / 2, rect.y, thickness, rect.height);
}


/// <summary>
/// Draws horizontal line.
/// Uses built-in layouting system.
Expand Down Expand Up @@ -248,7 +247,6 @@ public static partial class ToolboxEditorGui
{
private static EditorWindow lastTargetedWindow;


/// <summary>
/// Checks if user is still focusing the proper (searchable) window.
/// </summary>
Expand Down Expand Up @@ -276,7 +274,6 @@ private static void OnPopupWindowUpdated()
}
}


public static void DrawSearchablePopup(Rect rect, GUIContent label, int currentIndex, string[] options, Action<int> onSelect)
{
DrawSearchablePopup(rect, label, currentIndex, options, onSelect, EditorStyles.miniPullDown);
Expand Down
1 change: 0 additions & 1 deletion Assets/Editor Toolbox/Editor/ToolboxPropertyHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ private void ProcessLabel(SerializedProperty property, GUIContent label)
}
}


/// <summary>
/// Draw property using built-in layout system and cached <see cref="ToolboxAttributeDrawer"/>s.
/// </summary>
Expand Down
2 changes: 0 additions & 2 deletions Assets/Editor Toolbox/Editor/Utilities/DraggingUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ static DraggingUtility()
BindingFlags.NonPublic | BindingFlags.Instance);
}


private static readonly MethodInfo validateAssignmentMethod;
private static readonly MethodInfo appendFoldoutValueMethod;

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


public static Object ValidateAssignment(Object[] references, SerializedProperty property, Type type, bool exactType)
{
#if UNITY_2017_1_OR_NEWER
Expand Down
2 changes: 0 additions & 2 deletions Assets/Editor Toolbox/Editor/Utilities/EditorGuiUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ internal static class EditorGuiUtility

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


public static Texture2D CreateColorTexture()
{
return CreateColorTexture(Color.clear);
Expand Down Expand Up @@ -100,7 +99,6 @@ public static Texture GetHelpIcon(MessageType messageType)
return null;
}


public static float FoldoutSize { get; internal set; } = 15.0f;
public static float SpacingSize => EditorGUIUtility.standardVerticalSpacing;
public static float HeightSize => EditorGUIUtility.singleLineHeight;
Expand Down
23 changes: 21 additions & 2 deletions Assets/Editor Toolbox/Editor/Utilities/GuiLayoutUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public static class GuiLayoutUtility
/// </summary>
public static readonly float layoutPadding = -2 * EditorGUIUtility.standardVerticalSpacing;


public static void BeginStrechedVertical()
{
BeginFixedVertical(GUIStyle.none);
Expand Down Expand Up @@ -54,6 +53,26 @@ public static void CreateSpace(float space)
GUILayout.Space(space);
}

//TODO: add more helper methods
/// <summary>
/// A bit hacky way to retrieve the width of currently active layout.
/// Width is properly calculated only when the <see cref="Event.type"/> equals to <see cref="EventType.Repaint"/>.
/// </summary>
public static bool TryGetLayoutWidth(out float width)
{
using (var scope = new EditorGUILayout.HorizontalScope())
{
if (Event.current.type == EventType.Repaint)
{
var scopeRect = scope.rect;
width = scopeRect.width;
return true;
}
else
{
width = 0.0f;
return false;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,37 +88,36 @@ internal static void Initialize()

private void DrawSettingsPanel()
{
EditorGUILayout.LabelField("Settings", EditorStyles.boldLabel);

var rect = EditorGUILayout.GetControlRect(true);
rect = EditorGUI.PrefixLabel(rect, Style.typeContent);
typeField.OnGui(rect, true, OnTypeSelected, data.InstanceType);
if (data.InstanceType == null)
{
return;
}

ToolboxEditorGui.DrawLine();

EditorGUI.BeginChangeCheck();
data.InstanceName = EditorGUILayout.TextField(Style.nameContent, data.InstanceName);
data.InstancesCount = EditorGUILayout.IntField(Style.countContent, data.InstancesCount);

EditorGUI.BeginChangeCheck();
var assignedInstance = EditorGUILayout.ObjectField(Style.objectContent, data.BlueprintObject, data.InstanceType, false);
data.BlueprintObject = assignedInstance;
if (EditorGUI.EndChangeCheck())
using (new EditorGUILayout.HorizontalScope())
{
UpdateBlueprintObjectEditor();
}
EditorGUI.BeginChangeCheck();
var assignedInstance = EditorGUILayout.ObjectField(Style.objectContent, data.BlueprintObject, data.InstanceType, false);
data.BlueprintObject = assignedInstance;
if (EditorGUI.EndChangeCheck())
{
UpdateBlueprintObjectEditor();
}

if (assignedInstance != null)
{
inspectDefaultObject = GUILayout.Toggle(inspectDefaultObject,
Style.foldoutContent, Style.foldoutStyle, Style.foldoutOptions);
}
else
{
inspectDefaultObject = false;
if (assignedInstance != null)
{
inspectDefaultObject = GUILayout.Toggle(inspectDefaultObject,
Style.foldoutContent, Style.foldoutStyle, Style.foldoutOptions);
}
else
{
inspectDefaultObject = false;
}
}

if (inspectDefaultObject)
Expand All @@ -129,7 +128,6 @@ private void DrawSettingsPanel()
}
}


if (EditorGUI.EndChangeCheck())
{
OnWizardUpdate();
Expand Down Expand Up @@ -237,7 +235,7 @@ protected override void OnWizardUpdate()
protected override void OnWizardGui()
{
base.OnWizardGui();
using (new EditorGUILayout.VerticalScope(Style.backgroundStyle))
using (new EditorGUILayout.VerticalScope())
{
DrawSettingsPanel();
}
Expand All @@ -250,6 +248,7 @@ private static class Style
internal static readonly GUIStyle backgroundStyle;
internal static readonly GUIStyle foldoutStyle;

internal static readonly GUIContent typeContent = new GUIContent("Instance Type");
internal static readonly GUIContent nameContent = new GUIContent("Instance Name");
internal static readonly GUIContent countContent = new GUIContent("Instances Count", "Indicates how many instances will be created.");
internal static readonly GUIContent objectContent = new GUIContent("Blueprint Object", "Will be used as a blueprint for all created ScriptableObjects.");
Expand Down
11 changes: 10 additions & 1 deletion Assets/Editor Toolbox/Editor/Wizards/ToolboxWizard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ namespace Toolbox.Editor.Wizards

public class ToolboxWizard : EditorWindow
{
private static readonly string[] propertiesToIgnore = new string[]
{
PropertyUtility.Defaults.scriptPropertyName,
"m_SerializedDataModeController"
};

private Editor targetEditor;

private Vector2 scrollPosition;
Expand Down Expand Up @@ -84,7 +90,10 @@ private void ReinitEditor(Editor editor)
editor.hideFlags = HideFlags.HideAndDontSave;
if (editor is ToolboxEditor toolboxEditor)
{
toolboxEditor.IgnoreProperty(PropertyUtility.Defaults.scriptPropertyName);
foreach (var property in propertiesToIgnore)
{
toolboxEditor.IgnoreProperty(property);
}
}
}

Expand Down
Loading

0 comments on commit 4985b2f

Please sign in to comment.