Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. //a serializable class, it should be possible write an custom property drawer for it
  2. [System.Serializable]
  3. public class SimpleClass
  4. {
  5. public int myField;
  6. }
  7.  
  8. [CustomPropertyDrawer (typeof (SimpleClass))]
  9. public class SimpleClassDrawer : PropertyDrawer{
  10.  
  11. public override void OnGUI (Rect pos, SerializedProperty prop, GUIContent label)
  12. {
  13. SerializedProperty myField= prop.FindPropertyRelative ("myField");
  14. //here's the problem: myField always null
  15. }
  16.  
  17. public class Test : MonoBehaviour {
  18. public SimpleClass s;
  19. }
  20.  
  21. using UnityEngine;
  22. using UnityEditor;
  23. using System.Collections;
  24.  
  25.  
  26. [CustomPropertyDrawer (typeof (ScaledCurve))]
  27. public class PropertyDrawerTest : PropertyDrawer {
  28. public override void OnGUI (Rect pos, SerializedProperty prop, GUIContent label) {
  29. SerializedProperty myValue = prop.FindPropertyRelative ("myValue");
  30.  
  31. int indent = EditorGUI.indentLevel;
  32. EditorGUI.indentLevel = 1;
  33. EditorGUI.PropertyField(
  34. new Rect(pos.x,pos.y,pos.width,pos.height),
  35. myValue,
  36. label
  37. );
  38. EditorGUI.indentLevel = indent;
  39. }
  40. }
  41.  
  42. using UnityEngine;
  43. using System.Collections;
  44.  
  45. [System.Serializable]
  46. public class ScaledCurve {
  47. public int myValue = 1;
  48. }
  49.  
  50. public class PropertyDrawerImpl : MonoBehaviour {
  51. public ScaledCurve Curve;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement