Skip to content
This repository was archived by the owner on Jul 30, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions Assets/FullInspector2/Modules/InspectorCurve/Editor.meta

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,40 @@
using System;
using UnityEditor;
using UnityEngine;

namespace FullInspector.Modules {
[CustomAttributePropertyEditor(typeof(InspectorCurveAttribute), ReplaceOthers = true)]
public class InspectorCurveAttributeEditor<TElement> : AttributePropertyEditor<TElement, InspectorCurveAttribute> {
Copy link
Owner

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> {

private static T Cast<T>(object o) {
Copy link
Owner

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.

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);
}
}
}

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,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 />
Copy link
Owner

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)

/// Usage:<br />
/// [<see cref="InspectorCollectionItemAttributesAttribute" />(typeof(<see cref="InspectorMovementCurvesDefault" />))]
/// </summary>
public class InspectorMovementCurvesDefault: fiICollectionAttributeProvider {
public IEnumerable<object> GetAttributes() {
yield return new InspectorCurveAttribute();
}
}

}

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