示例#1
0
        public static void ExposeObject(Rect rect, object value)
        {
            if (value == null)
            {
                EditorGUI.HelpBox(rect, "Object is null", MessageType.None);
                return;
            }

            Type valueType = value.GetType();

            PropertyInfo[] properties = valueType.GetProperties();

            const float lineHeight = 20.0f;

            StackPanelUtility.Begin(rect, Axis.Vertical);

            foreach (PropertyInfo propInfo in properties)
            {
                Rect propertArea = StackPanelUtility.Reserve(lineHeight, rect);

                GUI.enabled = propInfo.CanWrite;

                object currentValue = propInfo.GetValue(value, null);

                object newValue = EditorGUIEx.ExposeGenericObject(propertArea, currentValue,
                                                                  propInfo.PropertyType, new GUIContent(propInfo.Name));

                if (propInfo.CanWrite)
                {
                    propInfo.SetValue(value, newValue, null);
                }
            }

            GUI.enabled = true;

            StackPanelUtility.End();
        }
示例#2
0
        public static object ExposeGenericObject(object value, Type type, GUIContent label, params GUILayoutOption[] options)
        {
            Rect position = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight, EditorStyles.numberField, options);

            return(EditorGUIEx.ExposeGenericObject(position, value, type, label));
        }