-
Notifications
You must be signed in to change notification settings - Fork 27
Added InspectorCurveAttribute #191
base: master
Are you sure you want to change the base?
Conversation
…ssignment (for example, assemly reload of non-serialized fields).
Already stumbled on something. How can I make this work on collections? Currently, it will error out:
|
I read some of the code and thought I had figured a solution, but failed. What I tried to do was adding a public interface fiICollectionAttributeProvider {
IEnumerable<object> GetAttributes(params object[] attributeArgs);
} Then, in public InspectorCollectionItemAttributesAttribute(Type attributes, params object[] attributeArgs) {
if (typeof(fiICollectionAttributeProvider).Resolve().IsAssignableFrom(attributes.Resolve()) == false) {
throw new ArgumentException("Must be an instance of FullInspector.fiICollectionAttributeProvider", "attributes");
}
var instance = (fiICollectionAttributeProvider)Activator.CreateInstance(attributes);
AttributeProvider = fiAttributeProvider.Create(instance.GetAttributes(attributeArgs).ToArray());
} But it didn't work. public class InspectorMovementCurvesCollection: fiICollectionAttributeProvider {
public IEnumerable<object> GetAttributes(params object[] attributeArgs) {
yield return new InspectorCurveAttribute(0, 0, 10, 10);
}
} Meaning, it would actually use the But, if I instead used Could you shed some light on this, @jacobdufault ? What I ended up doing was to just have a default that matches my current needs public class InspectorMovementCurvesDefault: fiICollectionAttributeProvider {
public IEnumerable<object> GetAttributes() {
yield return new InspectorCurveAttribute();
}
} I'll update the PR with this. |
Any idea why the constructor forwarding approach did not work? I would expect that Is this the usage you were trying to go for? [InspectorCollectionProxy(typeof(InspectorCurveAttribute), 0, 0, 1, 1)]
public LIst<AnimationCurve> entries; |
|
||
namespace FullInspector.Modules { | ||
[CustomAttributePropertyEditor(typeof(InspectorCurveAttribute), ReplaceOthers = true)] | ||
public class InspectorCurveAttributeEditor<TElement> : AttributePropertyEditor<TElement, InspectorCurveAttribute> { |
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. So
public class InspectorCurveAttributeEditor : AttributePropertyEditor<AnimationCurve, InspectorCurveAttribute> {
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed when the class is not generic.
|
||
|
||
/// <summary> | ||
/// Uses the default constructor from <see cref="InspectorCurveAttribute" /><br /> |
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.
nit: No indentation after ///
(applies to every comment)
Needed something like this to restrict curves to a certain range and just whipped this a few minutes ago.
Always impressed with how easy we can do things in FullInspector.
Placed in the
Modules
folder, sinceInspectorRange
is already there.Would appreciate a quick review before merging.