This repository was archived by the owner on Jul 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Added InspectorCurveAttribute #191
Open
SugoiDev
wants to merge
8
commits into
jacobdufault:master
Choose a base branch
from
SugoiDev:InspectorCurveAttribute
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2b4c7a6
Added InspectorCurveAttribute
SugoiDev 22b6ca2
Better param name seamantics; fixed null ref bug with curves before a…
SugoiDev 45a70ac
xml docs; added way to use in collections (using the default construc…
SugoiDev 7ac6b6d
Moving into correct folder
SugoiDev 20734fd
xml doc format
SugoiDev 9eacd9c
debug comment with correct variable name
SugoiDev b3bd14a
less insanity
SugoiDev 8da5cc6
fixing misunderstanding mistake. The attribute's params make sense now.
SugoiDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
Assets/FullInspector2/Modules/InspectorCurve/Editor/InspectorCurveAttributeEditor.cs
This file contains hidden or 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,40 @@ | ||
using System; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace FullInspector.Modules { | ||
[CustomAttributePropertyEditor(typeof(InspectorCurveAttribute), ReplaceOthers = true)] | ||
public class InspectorCurveAttributeEditor<TElement> : AttributePropertyEditor<TElement, InspectorCurveAttribute> { | ||
private static T Cast<T>(object o) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed when the class is not generic. |
||
return (T)Convert.ChangeType(o, typeof(T)); | ||
} | ||
|
||
protected override TElement Edit(Rect region, GUIContent label, TElement element, InspectorCurveAttribute attribute, fiGraphMetadata metadata) { | ||
if (attribute.Width <= 0) { | ||
Debug.Log("Invalid width. Resetting to 1"); | ||
attribute.Width = 1; | ||
} | ||
|
||
if (attribute.Height <= 0) { | ||
Debug.Log("Invalid height. Resetting to 1"); | ||
attribute.Height = 1; | ||
} | ||
|
||
var curveRange = new Rect(attribute.X, attribute.Y, attribute.Width, attribute.Height); | ||
var curve = element == null ? | ||
AnimationCurve.Linear(0, 1, 1, 1) : | ||
Cast<AnimationCurve>(element); | ||
|
||
return Cast<TElement>(EditorGUI.CurveField(region, label, curve, Color.green, curveRange)); | ||
} | ||
|
||
|
||
protected override float GetElementHeight(GUIContent label, TElement element, InspectorCurveAttribute attribute, fiGraphMetadata metadata) { | ||
return EditorStyles.largeLabel.CalcHeight(label, 100); | ||
} | ||
|
||
public override bool CanEdit(Type type) { | ||
return type == typeof(AnimationCurve); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Assets/FullInspector2/Modules/InspectorCurve/Editor/InspectorCurveAttributeEditor.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
Assets/FullInspector2/Modules/InspectorCurve/InspectorCurveAttribute.cs
This file contains hidden or 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,49 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace FullInspector { | ||
|
||
|
||
/// <summary> | ||
/// Attribute for customized curves.<br /> | ||
/// To use on collections, add <br /> | ||
/// [<see cref="InspectorCollectionItemAttributesAttribute"/>(typeof(<see cref="InspectorMovementCurvesDefault"/>))] | ||
/// <br /> | ||
/// Or create a custom class, similar to <see cref="InspectorMovementCurvesDefault" /> | ||
/// instead. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] | ||
public sealed class InspectorCurveAttribute : Attribute { | ||
|
||
public float X; | ||
public float Y; | ||
|
||
public float Height; | ||
public float Width; | ||
|
||
|
||
/// <summary> | ||
/// Creates a curve field constrained to the rect defined by the passed parameters. | ||
/// </summary> | ||
public InspectorCurveAttribute(float x = 0, float y = 0, float width = 1, float height = 1) { | ||
X = x; | ||
Y = y; | ||
Width = width; | ||
Height = height; | ||
} | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Uses the default constructor from <see cref="InspectorCurveAttribute" /><br /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: No indentation after /// |
||
/// Usage:<br /> | ||
/// [<see cref="InspectorCollectionItemAttributesAttribute" />(typeof(<see cref="InspectorMovementCurvesDefault" />))] | ||
/// </summary> | ||
public class InspectorMovementCurvesDefault: fiICollectionAttributeProvider { | ||
public IEnumerable<object> GetAttributes() { | ||
yield return new InspectorCurveAttribute(); | ||
} | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
Assets/FullInspector2/Modules/InspectorCurve/InspectorCurveAttribute.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
AnimationCurve
is a sealed class, you don't need to make this editor generic. Sopublic class InspectorCurveAttributeEditor : AttributePropertyEditor<AnimationCurve, InspectorCurveAttribute> {