Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 23 additions & 30 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,39 @@ on:

env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}

jobs:
testRunner:
name: Test all modes 📝
testAllModes:
name: Test in '${{ matrix.testMode }}' 📝
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
testMode:
- playmode
- editmode
- standalone
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Create LFS file list
run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id

- name: Restore LFS cache
uses: actions/cache@v2
id: lfs-cache
- uses: actions/checkout@v4
with:
path: .git/lfs
key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}

- name: Git LFS Pull
run: |
git lfs pull
git add .
git reset --hard

- name: Restore Library cache
uses: actions/cache@v2
lfs: true
- uses: actions/cache@v3
with:
path: Library
key: Library-test-project
restore-keys: |
Library-test-project-
Library-

- uses: game-ci/unity-test-runner@v2
id: testRunner
- uses: game-ci/unity-test-runner@v4
id: tests
with:
testMode: all

- uses: actions/upload-artifact@v2
testMode: ${{ matrix.testMode }}
artifactsPath: ${{ matrix.testMode }}-artifacts
checkName: ${{ matrix.testMode }} Test Results
- uses: actions/upload-artifact@v3
if: always()
with:
name: Test results (all modes)
path: ${{ steps.testRunner.outputs.artifactsPath }}
name: Test results for ${{ matrix.testMode }}
path: ${{ steps.tests.outputs.artifactsPath }}
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.13.2 [29.11.2024]

### Added:
- AnimationCurveSettingsAttribute

### Changed:
- Possibility to use [EditorButton] and [DynamicHelp] in nested types
- For now SerializeReference properties without children will always be folded
- Fix exception while building labels for generic types without arguments
- Fix drawing SerializedDictionary if value or key types cannot be serialized

## 0.13.1 [30.08.2024]

### Changed:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;

using UnityEditor;

namespace Toolbox.Editor.Drawers
Expand Down Expand Up @@ -68,14 +67,8 @@ public static bool TryGetValue(string source, SerializedProperty causer, out obj

public static bool TryGetValue(string source, SerializedProperty causer, out object value, out bool hasMixedValues, Func<object, object, bool> nextValuesComparer)
{
var targetObjects = causer.serializedObject.targetObjects;
var parentObjects = new object[targetObjects.Length];
for (var i = 0; i < targetObjects.Length; i++)
{
var targetObject = targetObjects[i];
parentObjects[i] = causer.GetDeclaringObject(targetObject);
}

//NOTE: consider using NonAlloc implementation
var parentObjects = causer.GetDeclaringObjects();
return TryGetValue(source, parentObjects, out value, out hasMixedValues, nextValuesComparer);
}
}
Expand Down
13 changes: 13 additions & 0 deletions Assets/Editor Toolbox/Editor/Drawers/ISerializedPropertyContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Reflection;
using UnityEditor;

namespace Toolbox.Editor.Drawers
{
public interface ISerializedPropertyContext
{
SerializedProperty Property { get; }
FieldInfo FieldInfo { get; }
Type Type { get; }
}
}

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
@@ -0,0 +1,32 @@
using UnityEditor;
using UnityEngine;

namespace Toolbox.Editor.Drawers
{
[CustomPropertyDrawer(typeof(AnimationCurveSettingsAttribute))]
public class AnimationCurveSettingsAttributeDrawer : PropertyDrawerBase
{
protected override void OnGUISafe(Rect position, SerializedProperty property, GUIContent label)
{
var attribute = Attribute;
var curveRanges = new Rect(
attribute.Min.x,
attribute.Min.y,
attribute.Max.x - attribute.Min.x,
attribute.Max.y - attribute.Min.y);

var color = attribute.Color;

EditorGUI.BeginProperty(position, label, property);
EditorGUI.CurveField(position, property, color, curveRanges, label);
EditorGUI.EndProperty();
}

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

private AnimationCurveSettingsAttribute Attribute => attribute as AnimationCurveSettingsAttribute;
}
}

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 @@ -99,16 +99,13 @@ protected override void OnGUISafe(Rect position, SerializedProperty property, GU
}
}


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


private AssetPreviewAttribute Attribute => attribute as AssetPreviewAttribute;


private static class Style
{
internal static readonly float offset = 6.0f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ protected virtual void OnGUISafe(Rect position, SerializedProperty property, GUI
EditorGUI.PropertyField(position, property, label);
}


/// <summary>
/// Native call to return the expected height.
/// </summary>
public override sealed float GetPropertyHeight(SerializedProperty property, GUIContent label)
public sealed override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return IsPropertyValid(property)
? GetPropertyHeightSafe(property, label)
Expand All @@ -40,22 +39,20 @@ public override sealed float GetPropertyHeight(SerializedProperty property, GUIC
/// <summary>
/// Native call to draw the provided property.
/// </summary>
public override sealed void OnGUI(Rect position, SerializedProperty property, GUIContent label)
public sealed override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (IsPropertyValid(property))
{
OnGUISafe(position, property, label);
return;
}

var warningContent = new GUIContent(property.displayName + " has invalid property drawer");
//create additional warning log to the console window
ToolboxEditorLog.WrongAttributeUsageWarning(attribute, property);
//create additional warning label based on the property name
var warningContent = new GUIContent(property.displayName + " has invalid property drawer");
ToolboxEditorGui.DrawEmptyProperty(position, property, warningContent);
}


/// <summary>
/// Checks if provided property can be properly handled by this drawer.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class DynamicHelpAttributeDrawer : ToolboxDecoratorDrawer<DynamicHelpAttr
protected override void OnGuiBeginSafe(DynamicHelpAttribute attribute)
{
var sourceHandle = attribute.SourceHandle;
var targetObjects = ToolboxEditorHandler.CurrentTargetObjects;
var targetObjects = GetDeclaringObjects();
if (ValueExtractionHelper.TryGetValue(sourceHandle, targetObjects, out var value, out var hasMixedValues))
{
var messageText = hasMixedValues ? "-" : value?.ToString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections;
using System.Reflection;

using Unity.EditorCoroutines.Editor;
using UnityEditor;
using UnityEngine;
Expand All @@ -9,7 +8,7 @@ namespace Toolbox.Editor.Drawers
{
public class EditorButtonAttributeDrawer : ToolboxDecoratorDrawer<EditorButtonAttribute>
{
private MethodInfo GetMethod(EditorButtonAttribute attribute, Object[] targetObjects, string methodName)
private MethodInfo GetMethod(EditorButtonAttribute attribute, object[] targetObjects, string methodName)
{
var methodInfo = ReflectionUtility.GetObjectMethod(methodName, targetObjects);
if (methodInfo == null)
Expand Down Expand Up @@ -50,7 +49,7 @@ private bool IsClickable(ButtonActivityType activityType)
return true;
}

private bool IsClickable(EditorButtonAttribute attribute, Object[] targetObjects)
private bool IsClickable(EditorButtonAttribute attribute, object[] targetObjects)
{
if (!IsClickable(attribute.ActivityType))
{
Expand Down Expand Up @@ -93,7 +92,7 @@ private bool IsClickable(EditorButtonAttribute attribute, Object[] targetObjects
return true;
}

private void CallMethods(EditorButtonAttribute attribute, Object[] targetObjects)
private void CallMethods(EditorButtonAttribute attribute, object[] targetObjects)
{
var methodInfo = GetMethod(attribute, targetObjects, attribute.MethodName);
if (methodInfo == null)
Expand All @@ -120,17 +119,16 @@ private void CallMethods(EditorButtonAttribute attribute, Object[] targetObjects
}
}


protected override void OnGuiCloseSafe(EditorButtonAttribute attribute)
{
var targetObjects = ToolboxEditorHandler.CurrentTargetObjects;
if (targetObjects == null || targetObjects.Length == 0)
var declaringObjects = GetDeclaringObjects();
if (declaringObjects == null || declaringObjects.Length == 0)
{
//NOTE: something went really wrong, internal bug or OnGuiBeginSafe was called out of the Toolbox scope
return;
}

var disable = !IsClickable(attribute, targetObjects);
var disable = !IsClickable(attribute, declaringObjects);
using (new EditorGUI.DisabledScope(disable))
{
var label = string.IsNullOrEmpty(attribute.ExtraLabel)
Expand All @@ -141,12 +139,11 @@ protected override void OnGuiCloseSafe(EditorButtonAttribute attribute)

if (GUILayout.Button(content, Style.buttonStyle))
{
CallMethods(attribute, targetObjects);
CallMethods(attribute, declaringObjects);
}
}
}


private static class Style
{
internal static readonly GUIStyle buttonStyle = new GUIStyle(GUI.skin.button)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ static ScrollableItemsAttributeDrawer()

private static readonly PropertyDataStorage<Vector2, ScrollableItemsAttribute> storage;


private void DrawSettingsBody(SerializedProperty property, ScrollableItemsAttribute attribute, out int size, out Vector2 indexRange)
{
EditorGUILayout.PropertyField(property.GetSize());
Expand Down Expand Up @@ -53,7 +52,6 @@ private void DrawElementsBody(SerializedProperty property, ScrollableItemsAttrib
}
}


protected override void OnGuiSafe(SerializedProperty property, GUIContent label, ScrollableItemsAttribute attribute)
{
using (var propertyScope = new PropertyScope(property, label))
Expand All @@ -70,7 +68,6 @@ protected override void OnGuiSafe(SerializedProperty property, GUIContent label,
}
}


private static class Style
{
//TODO: apply custom styling for the drawer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,19 @@ static SerializedDictionaryDrawer()
var content = list.GetElementContent(element, index);
using (new EditorGUILayout.HorizontalScope())
{
var kOption = GUILayout.Width(Style.kGroupWidth);
DrawDictionaryProperty(kProperty, Style.kLabel, Style.kLabelWidth, kOption);

var vLabel = vProperty.hasVisibleChildren
? Style.vLabel
: GUIContent.none;
DrawDictionaryProperty(vProperty, vLabel, Style.vLabelWidth);
if (kProperty != null)
{
var kOption = GUILayout.Width(Style.kGroupWidth);
DrawDictionaryProperty(kProperty, Style.kLabel, Style.kLabelWidth, kOption);
}

if (vProperty != null)
{
var vLabel = vProperty.hasVisibleChildren
? Style.vLabel
: GUIContent.none;
DrawDictionaryProperty(vProperty, vLabel, Style.vLabelWidth);
}
}
};
return list;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
/// </summary>
public abstract class ToolboxAttributeDrawer : ToolboxDrawer
{ }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ protected virtual PropertyCondition OnGuiValidateSafe(SerializedProperty propert
return PropertyCondition.Valid;
}


public sealed override PropertyCondition OnGuiValidate(SerializedProperty property)
{
return OnGuiValidate(property, PropertyUtility.GetAttribute<T>(property));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;

using UnityEngine;

namespace Toolbox.Editor.Drawers
Expand All @@ -16,7 +15,6 @@ protected virtual void OnGuiCloseSafe(T attribute)
protected virtual void OnGuiEndSafe(T attribute)
{ }


public sealed override void OnGuiBegin(ToolboxAttribute attribute)
{
OnGuiBegin(attribute as T);
Expand Down
Loading