Skip to content

Commit

Permalink
Merge pull request #112 from arimger/develop
Browse files Browse the repository at this point in the history
Develop - 0.12.12
  • Loading branch information
arimger committed Jun 17, 2024
2 parents 4985b2f + 124f866 commit acfa0ba
Show file tree
Hide file tree
Showing 204 changed files with 454 additions and 144 deletions.
11 changes: 11 additions & 0 deletions Assets/Editor Toolbox/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## 0.12.12 [17.06.2024]

### Changed:
- LabelWidthAttribute is now part of the Toolbox decorator attributes (can be mixed with other attributes)
- Hierarchy: Script, Tag, and Layer columns are now excluded from the default settings
- Possibility to change style for groups ([BeginGroup] and [BeginHorizontalGroup] attributes)
- ScriptableObject Creation Wizard now accepts only ScriptableObjects marked with the [CreateInWizard] or [CreateAssetMenu] attributes

### Added:
- NotPrefabObjectOnlyAttribute

## 0.12.11 [05.04.2024]

### Changed:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,13 @@ protected override void OnGUISafe(Rect position, SerializedProperty property, GU
}
}


public override bool IsPropertyValid(SerializedProperty property)
{
return property.propertyType == SerializedPropertyType.ObjectReference;
}


private NotNullAttribute Attribute => attribute as NotNullAttribute;


private static class Style
{
#if UNITY_2019_3_OR_NEWER
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using UnityEditor;
using UnityEngine;

namespace Toolbox.Editor.Drawers
{
[CustomPropertyDrawer(typeof(NotPrefabObjectOnlyAttribute))]
public class NotPrefabObjectOnlyAttributeDrawer : ObjectValidationDrawer
{
protected override string GetWarningMessage()
{
return "Assigned object can't be a Prefab.";
}

protected override bool IsObjectValid(Object objectValue, SerializedProperty property)
{
if (objectValue == null)
{
return false;
}

var attribute = Attribute;
if (PrefabUtility.GetPrefabAssetType(objectValue) == PrefabAssetType.NotAPrefab)
{
return true;
}

if (PrefabUtility.GetPrefabInstanceStatus(objectValue) == PrefabInstanceStatus.Connected &&
attribute.AllowInstancedPrefabs)
{
return true;
}

return false;
}

private NotPrefabObjectOnlyAttribute Attribute => attribute as NotPrefabObjectOnlyAttribute;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ protected virtual string GetWarningMessage()

protected abstract bool IsObjectValid(Object objectValue, SerializedProperty property);


public override bool IsPropertyValid(SerializedProperty property)
{
return property.propertyType == SerializedPropertyType.ObjectReference;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ private void HandleTargetPicker(Rect position, SerializedProperty property)
}
}


protected override float GetPropertyHeightSafe(SerializedProperty property, GUIContent label)
{
return SceneExists(property.stringValue)
Expand All @@ -88,13 +87,11 @@ protected override void OnGUISafe(Rect position, SerializedProperty property, GU
HandleTargetPicker(position, property);
}


public override bool IsPropertyValid(SerializedProperty property)
{
return property.propertyType == SerializedPropertyType.String;
}


private static class Style
{
internal static readonly float rowHeight = EditorGUIUtility.singleLineHeight;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ private GameObject GetGameObject(Object reference)
return null;
}


protected override string GetWarningMessage()
{
return "Assigned object has to be instantiated in the Scene.";
Expand All @@ -28,7 +27,7 @@ protected override string GetWarningMessage()
protected override bool IsObjectValid(Object objectValue, SerializedProperty property)
{
var gameObject = GetGameObject(objectValue);
return gameObject && !string.IsNullOrEmpty(gameObject.scene.name);
return gameObject != null && !string.IsNullOrEmpty(gameObject.scene.name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ protected override void OnGUISafe(Rect position, SerializedProperty property, GU
EditorGUI.EndProperty();
}


public override bool IsPropertyValid(SerializedProperty property)
{
return property.propertyType == SerializedPropertyType.Enum;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,40 @@ namespace Toolbox.Editor.Drawers
{
public class BeginGroupAttributeDrawer : ToolboxDecoratorDrawer<BeginGroupAttribute>
{
private GUIStyle GetStyle(GroupStyle style)
{
switch (style)
{
default:
case GroupStyle.Round:
return Style.roundGroupBackgroundStyle;
case GroupStyle.Boxed:
return Style.boxedGroupBackgroundStyle;
}
}

protected override void OnGuiBeginSafe(BeginGroupAttribute attribute)
{
ToolboxLayoutHandler.BeginVertical(Style.groupBackgroundStyle);
var style = GetStyle(attribute.Style);
ToolboxLayoutHandler.BeginVertical(style);
if (attribute.HasLabel)
{
GUILayout.Label(attribute.Label, EditorStyles.boldLabel);
}
}


private static class Style
{
internal static readonly GUIStyle groupBackgroundStyle;
internal static readonly GUIStyle roundGroupBackgroundStyle;
internal static readonly GUIStyle boxedGroupBackgroundStyle;

static Style()
{
#if UNITY_2019_3_OR_NEWER
groupBackgroundStyle = new GUIStyle("helpBox")
#else
groupBackgroundStyle = new GUIStyle("box")
#endif
roundGroupBackgroundStyle = new GUIStyle("helpBox")
{
padding = new RectOffset(13, 12, 5, 5)
};
boxedGroupBackgroundStyle = new GUIStyle("box")
{
padding = new RectOffset(13, 12, 5, 5)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,27 @@ private void HandleScrollView(float fixedHeight)
storage.AppendItem(controlId, newScroll);
}

private GUIStyle GetStyle(GroupStyle style)
{
switch (style)
{
default:
case GroupStyle.Round:
return Style.roundGroupBackgroundStyle;
case GroupStyle.Boxed:
return Style.boxedGroupBackgroundStyle;
}
}

protected override void OnGuiBeginSafe(BeginHorizontalGroupAttribute attribute)
{
if (GuiLayoutUtility.TryGetLayoutWidth(out var layoutWidth))
{
lastFetchedWidth = layoutWidth;
}

ToolboxLayoutHandler.BeginVertical(Style.groupBackgroundStyle);
var style = GetStyle(attribute.Style);
ToolboxLayoutHandler.BeginVertical(style);
if (attribute.HasLabel)
{
GUILayout.Label(attribute.Label, EditorStyles.boldLabel);
Expand All @@ -59,16 +72,17 @@ protected override void OnGuiBeginSafe(BeginHorizontalGroupAttribute attribute)

private static class Style
{
internal static readonly GUIStyle groupBackgroundStyle;
internal static readonly GUIStyle roundGroupBackgroundStyle;
internal static readonly GUIStyle boxedGroupBackgroundStyle;
internal static readonly GUIStyle scrollViewGroupStyle;

static Style()
{
#if UNITY_2019_3_OR_NEWER
groupBackgroundStyle = new GUIStyle("helpBox")
#else
groupBackgroundStyle = new GUIStyle("box")
#endif
roundGroupBackgroundStyle = new GUIStyle("helpBox")
{
padding = new RectOffset(13, 12, 5, 5)
};
boxedGroupBackgroundStyle = new GUIStyle("box")
{
padding = new RectOffset(13, 12, 5, 5)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,13 @@ namespace Toolbox.Editor.Drawers
{
public class LabelAttributeDrawer : ToolboxDecoratorDrawer<LabelAttribute>
{
protected override void OnGuiBeginSafe(LabelAttribute attribute)
private static GUIStyle GetLabelStyle(FontStyle style)
{
//prepare proper styles for the scope and text
var scopeStyle = GetScopeStyle(attribute.SkinStyle);
var labelStyle = GetLabelStyle(attribute.FontStyle);

GUILayout.Space(attribute.SpaceBefore);
//create (optionally) the vertical scope group
using (CreateScopeIfNeeded(scopeStyle))
switch (style)
{
labelStyle.alignment = attribute.Alignment;
labelStyle.fontStyle = attribute.FontStyle;
EditorGUILayout.LabelField(GetContent(attribute), labelStyle);
default:
return Style.labelStyle;
}

GUILayout.Space(attribute.SpaceAfter);
}


private static GUIStyle GetLabelStyle(FontStyle style)
{
return Style.labelStyle;
}

private static GUIStyle GetScopeStyle(SkinStyle style)
Expand All @@ -41,9 +26,9 @@ private static GUIStyle GetScopeStyle(SkinStyle style)
return Style.boxedScopeStyle;
case SkinStyle.Round:
return Style.roundScopeStyle;
default:
return Style.labelScopeStyle;
}

return Style.labelScopeStyle;
}

private static GUIContent GetContent(LabelAttribute attribute)
Expand Down Expand Up @@ -72,6 +57,23 @@ private static IDisposable CreateScopeIfNeeded(GUIStyle style)
return style != null ? new EditorGUILayout.VerticalScope(style) : null;
}

protected override void OnGuiBeginSafe(LabelAttribute attribute)
{
//prepare proper styles for the scope and text
var scopeStyle = GetScopeStyle(attribute.SkinStyle);
var labelStyle = GetLabelStyle(attribute.FontStyle);

GUILayout.Space(attribute.SpaceBefore);
//create (optionally) the vertical scope group
using (CreateScopeIfNeeded(scopeStyle))
{
labelStyle.alignment = attribute.Alignment;
labelStyle.fontStyle = attribute.FontStyle;
EditorGUILayout.LabelField(GetContent(attribute), labelStyle);
}

GUILayout.Space(attribute.SpaceAfter);
}

private static class Style
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using UnityEditor;
using UnityEngine;

namespace Toolbox.Editor.Drawers
{
public class LabelWidthAttributeDrawer : ToolboxDecoratorDrawer<LabelWidthAttribute>
{
private float widthToRestore;

protected override void OnGuiBeginSafe(LabelWidthAttribute attribute)
{
base.OnGuiBeginSafe(attribute);
widthToRestore = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = attribute.Width;
}

protected override void OnGuiCloseSafe(LabelWidthAttribute attribute)
{
EditorGUIUtility.labelWidth = widthToRestore;
base.OnGuiCloseSafe(attribute);
}
}
}
4 changes: 1 addition & 3 deletions Assets/Editor Toolbox/Editor/ToolboxDrawerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ internal static void InitializeModule()
/// </summary>
private static readonly Dictionary<string, ToolboxPropertyHandler> propertyHandlers = new Dictionary<string, ToolboxPropertyHandler>();


/// <summary>
/// Settings provided to handle custom drawers.
/// </summary>
Expand All @@ -54,15 +53,14 @@ internal static void InitializeModule()
/// </summary>
private static bool validationEnabled = true;


/// <summary>
/// Creates all possible attribute-based drawers and add them to proper collections.
/// </summary>
private static void PrepareAssignableDrawers(IToolboxInspectorSettings settings)
{
void AddAttributeDrawer<T>(Type drawerType, Type attributeType, Dictionary<Type, T> drawersCollection) where T : ToolboxAttributeDrawer
{
if (drawerType == null)
if (drawerType == null || attributeType == null)
{
return;
}
Expand Down
3 changes: 1 addition & 2 deletions Assets/Editor Toolbox/Editor/ToolboxPropertyHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Toolbox.Editor
{
using Toolbox.Attributes;
using Toolbox.Attributes.Property;
using Toolbox.Editor.Drawers;

/// <summary>
Expand Down Expand Up @@ -90,7 +90,6 @@ internal class ToolboxPropertyHandler
/// </summary>
private ILabelProcessorAttribute labelProcessorAttribute;


/// <summary>
/// Constructor prepares all property-related data for custom drawing.
/// </summary>
Expand Down
Loading

0 comments on commit acfa0ba

Please sign in to comment.