public static void Draw(Rect position, InstructionVariable variable, GUIContent label) { var typeNames = GetTypeNames(); var typeWidth = position.width * 0.5f; var typeRect = new Rect(position.x, position.y, typeWidth, position.height); var valueRect = new Rect(typeRect.xMax + 5, position.y, position.width - typeWidth - 5, position.height); var index = GetTypeIndex(variable); using (var changes = new EditorGUI.ChangeCheckScope()) { index = EditorGUI.Popup(typeRect, index, typeNames); if (changes.changed) { SetTypeIndex(variable, index); } } if (variable.IsReference) { VariableReferenceDrawer.DrawName(valueRect, variable.Reference); } else { VariableValueDrawer.DrawValue(valueRect, variable.Value, null, null); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var typeNames = GetTypeNames(); var nameProperty = property.FindPropertyRelative("Name"); var isReferenceProperty = property.FindPropertyRelative("IsReference"); var nameWidth = position.width * 0.3f; var typeWidth = position.width * 0.3f; var nameRect = new Rect(position.x, position.y, nameWidth, position.height); var typeRect = new Rect(nameRect.xMax + 5, position.y, typeWidth, position.height); var valueRect = new Rect(typeRect.xMax + 5, position.y, position.width - nameWidth - typeWidth - 10, position.height); var index = GetTypeIndex(property); EditorGUI.PropertyField(nameRect, nameProperty, GUIContent.none); using (var changes = new EditorGUI.ChangeCheckScope()) { index = EditorGUI.Popup(typeRect, index, typeNames); if (changes.changed) { SetTypeIndex(property, index); } } if (isReferenceProperty.boolValue) { var referenceProperty = property.FindPropertyRelative("Reference"); VariableReferenceDrawer.DrawName(valueRect, referenceProperty); } else { var valueProperty = property.FindPropertyRelative("Value"); VariableValueDrawer.DrawValue(valueRect, valueProperty); } }