Comments (4)
Actually, I stand corrected, Full Inspector does not recognize a custom editor for a specific enum type.
Code Example:
[System.Flags]
public enum Direction
{
UP = 1,
DOWN = 2,
LEFT = 4,
RIGHT = 8,
}
using UnityEngine;
using UnityEditor;
using FullInspector;
[CustomPropertyEditor(typeof(Direction))]
public class DirectionEditor : PropertyEditor<Direction>
{
public override Direction Edit(Rect region, GUIContent label, Direction element)
{
return (Direction)EditorGUI.EnumMaskField(region, label, element);
}
public override float GetElementHeight(GUIContent label, Direction element)
{
return EditorStyles.numberField.CalcHeight(label, 1000);
}
}
from fullinspector.
I'll update the default enum property editor to correctly handle [Flags]
.
I've additionally adjusted the property editor resolution order to allow for enums to be overriden.
If you want this fix now, then please update PropertyEditor.GetCachedEditors
to
private static List<IPropertyEditor> GetCachedEditors(Type propertyType) {
List<IPropertyEditor> editors;
if (_cachedPropertyEditors.TryGetValue(propertyType, out editors) == false) {
editors = new List<IPropertyEditor>();
_cachedPropertyEditors[propertyType] = editors;
IPropertyEditor editor;
// arrays always need special handling; we don't support overriding them
if ((editor = ArrayPropertyEditor.TryCreate(propertyType)) != null) editors.Add(editor);
// try to add a user-defined editor
if (UserDefinedNonGenericPropertyEditors.Value.ContainsKey(propertyType)) {
editors.Add(UserDefinedNonGenericPropertyEditors.Value[propertyType].Value);
}
// try and create an editor from one of the user-defined generic property editors
if ((editor = TryCreateFromGenericPropertyEditor(propertyType)) != null) editors.Add(editor);
// try to create an inherited property editor
if ((editor = TryCreateInheritedPropertyEditor(propertyType)) != null) editors.Add(editor);
// enums come after generic & inherited to allow them to be overridden
if ((editor = EnumPropertyEditor.TryCreate(propertyType)) != null) editors.Add(editor);
// try and create an editor for abstract/interface type
if ((editor = AbstractTypePropertyEditor.TryCreate(propertyType)) != null) editors.Add(editor);
// try and create a reflected editor; will only fail for arrays or collections,
// which should be covered by the array editor
if ((editor = ReflectedPropertyEditor.TryCreate(propertyType)) != null) editors.Add(editor);
}
return editors;
}
Thanks.
from fullinspector.
I love you sir!
from fullinspector.
Additionally, EnumPropertyEditor
will be changed to this in 1.2:
/// <summary>
/// Provides a property editor for enums.
/// </summary>
internal class EnumPropertyEditor : IPropertyEditor {
public object Edit(Rect region, GUIContent label, object element) {
Enum selected = (Enum)element;
if (Attribute.IsDefined(selected.GetType(), typeof(FlagsAttribute))) {
return EditorGUI.EnumMaskField(region, label, selected);
}
return EditorGUI.EnumPopup(region, label, selected);
}
public float GetElementHeight(GUIContent label, object element) {
return EditorStyles.popup.CalcHeight(label, 100);
}
public static IPropertyEditor TryCreate(Type dataType) {
if (dataType.IsEnum == false) {
return null;
}
return new EnumPropertyEditor();
}
}
from fullinspector.
Related Issues (20)
- Toolkit's DefaultInspector not working inside groups
- Inspector GUI very slow when showing lots of SharedInstances HOT 4
- Editor callbacks can't get unregistered, so some methods that re-add themselves accumulate callbacks
- Add MinMaxSlider to the toolkit
- "Proxy editor for Gradient" leaking HOT 1
- Property editors breaking tk.Slider (and tk.IntSlider) HOT 2
- Error with Unity 5.5 HOT 1
- Dictionary, Property (Unity 5.5) - InvalidCastException: Cannot cast from source type to destination type HOT 1
- Visual Studio CPU usage spikes when working on a GetEditor() method for the Toolkit HOT 2
- Delegate serialization causing prefab checkout HOT 1
- Unity Editor crashes when reloading the assemblies. HOT 2
- No activity anymore? HOT 6
- nvm HOT 1
- database browsing Feature request.
- Multi Selecting prefabs and changing color field causes exception HOT 2
- Animation Curves not serialized (?) in Unity 2017 HOT 10
- warnings when reseting metadata HOT 2
- FullInspector with Json.NET as the default serializer : empty data with Resources.Load() HOT 3
- BaseScriptableObject that implements IList<T> breaks inspector HOT 2
- fiGUI PushLabelWidth & PopLabelWidth not balanced - Memory leak & UI Issues
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fullinspector.