-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor refactor changes; possibility to use EditorButtonAttribute and …
…DynamicHelpAttribute in nested types; implement AnimationCurveSettingsAttribute & Drawer
- Loading branch information
Showing
46 changed files
with
361 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
Assets/Editor Toolbox/Editor/Drawers/ISerializedPropertyContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...oolbox/Editor/ToolboxDrawerModule.cs.meta → ...rawers/ISerializedPropertyContext.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
Assets/Editor Toolbox/Editor/Drawers/Regular/AnimationCurveSettingsAttributeDrawer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Editor Toolbox/Editor/Drawers/Regular/AnimationCurveSettingsAttributeDrawer.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ | |
/// </summary> | ||
public abstract class ToolboxAttributeDrawer : ToolboxDrawer | ||
{ } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 32 additions & 2 deletions
34
Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxDecoratorDrawerBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,41 @@ | ||
using UnityEngine; | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace Toolbox.Editor.Drawers | ||
{ | ||
public abstract class ToolboxDecoratorDrawerBase : ToolboxAttributeDrawer | ||
{ | ||
public abstract void OnGuiBegin(ToolboxAttribute attribute); | ||
protected object[] GetDeclaringObjects() | ||
{ | ||
if (PropertyContext == null) | ||
{ | ||
return Array.Empty<object>(); | ||
} | ||
|
||
var property = PropertyContext.Property; | ||
return property.GetDeclaringObjects(); | ||
} | ||
|
||
internal virtual void OnGuiBegin(ToolboxAttribute attribute, ISerializedPropertyContext propertyContext) | ||
{ | ||
PropertyContext = propertyContext; | ||
OnGuiBegin(attribute); | ||
PropertyContext = null; | ||
} | ||
|
||
internal virtual void OnGuiClose(ToolboxAttribute attribute, ISerializedPropertyContext propertyContext) | ||
{ | ||
PropertyContext = propertyContext; | ||
OnGuiClose(attribute); | ||
PropertyContext = null; | ||
} | ||
|
||
public abstract void OnGuiBegin(ToolboxAttribute attribute); | ||
public abstract void OnGuiClose(ToolboxAttribute attribute); | ||
|
||
/// <summary> | ||
/// Context associated with <see cref="UnityEditor.SerializedProperty"/> that is currently handled. | ||
/// </summary> | ||
protected ISerializedPropertyContext PropertyContext { get; private set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.