Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //a serializable class, it should be possible write an custom property drawer for it
- [System.Serializable]
- public class SimpleClass
- {
- public int myField;
- }
- [CustomPropertyDrawer (typeof (SimpleClass))]
- public class SimpleClassDrawer : PropertyDrawer{
- public override void OnGUI (Rect pos, SerializedProperty prop, GUIContent label)
- {
- SerializedProperty myField= prop.FindPropertyRelative ("myField");
- //here's the problem: myField always null
- }
- public class Test : MonoBehaviour {
- public SimpleClass s;
- }
- using UnityEngine;
- using UnityEditor;
- using System.Collections;
- [CustomPropertyDrawer (typeof (ScaledCurve))]
- public class PropertyDrawerTest : PropertyDrawer {
- public override void OnGUI (Rect pos, SerializedProperty prop, GUIContent label) {
- SerializedProperty myValue = prop.FindPropertyRelative ("myValue");
- int indent = EditorGUI.indentLevel;
- EditorGUI.indentLevel = 1;
- EditorGUI.PropertyField(
- new Rect(pos.x,pos.y,pos.width,pos.height),
- myValue,
- label
- );
- EditorGUI.indentLevel = indent;
- }
- }
- using UnityEngine;
- using System.Collections;
- [System.Serializable]
- public class ScaledCurve {
- public int myValue = 1;
- }
- public class PropertyDrawerImpl : MonoBehaviour {
- public ScaledCurve Curve;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement