Game Development Reference
In-Depth Information
To solve this issue, we can return to the PropertyDrawer class; this time associating
the class with a specific class rather than an attribute, as shown in the following code
sample 8-10:
01 //Custom Editor class to expose global properties of a class
02 //----------------------------------------------
03 using UnityEngine;
04 using UnityEditor;
05 using System.Collections;
06 using System.Reflection;
07 //----------------------------------------------
08 [CustomPropertyDrawer(typeof(ClassWithProperties))]
09 public class PropertyLister : PropertyDrawer
10 {
11 //Height of inspector panel
12 float InspectorHeight = 0;
13
14 //Height of single row in pixels
15 float RowHeight = 15;
16
17 //Spacing between rows
18 float RowSpacing = 5;
19
20 // Draw the property inside the given rect
21 public override void OnGUI(Rect position, SerializedProperty
property, GUIContent label)
22 {
23 EditorGUI.BeginProperty(position, label, property);
24
25 //Get referenced object
26 object o = property.serializedObject.targetObject;
27 ClassWithProperties CP =
o.GetType().GetField(property.name).GetValue(o) as
ClassWithProperties;
28
29 int indent = EditorGUI.indentLevel;
30 EditorGUI.indentLevel = 0;
31
32 //Layout
33 Rect LayoutRect = new Rect(position.x, position.y,
position.width, RowHeight);
34
35 //Find all properties for object
 
Search WWH ::




Custom Search