/// <summary>
        /// Draws the object.
        /// </summary>
        public static void DrawObject(object obj, bool drawHeader, bool friendlyNamespacePrefix, UnityEngine.Object target, bool drawNoFieldsNotice, Action changeCallback)
        {
            if (obj == null)
            {
                return;
            }

            if (drawHeader)
            {
                EditorGUILayout.LabelField(DisplayTypeName(obj.GetType(), friendlyNamespacePrefix), EditorStyles.boldLabel);
            }

            EditorGUI.BeginChangeCheck();
            var inspectorDrawer = InspectorDrawerUtility.InspectorDrawerForType(obj.GetType());

            if (inspectorDrawer != null)
            {
                inspectorDrawer.OnInspectorGUI(obj, target);
            }
            else
            {
                ObjectInspector.DrawFields(obj, drawNoFieldsNotice);
            }

            if (EditorGUI.EndChangeCheck())
            {
                InspectorUtility.RecordUndoDirtyObject(target, "Change Value");
                if (changeCallback != null)
                {
                    changeCallback();
                }
            }
        }
        /// <summary>
        /// Draws a field belonging to the object with the specified field name.
        /// </summary>
        /// <param name="obj">The object being drawn.</param>
        /// <param name="name">The name of the field.</param>
        public static void DrawField(object obj, string name)
        {
            var field = GetField(obj, name);

            if (field != null)
            {
                var prevValue = field.GetValue(obj);
                var value     = ObjectInspector.DrawObject(new GUIContent(SplitCamelCase(name), GetFieldTooltip(field)), field.FieldType, prevValue, name, 0, null, null, field, true);
                if (prevValue != value && GUI.changed)
                {
                    field.SetValue(obj, value);
                }
            }
            else
            {
                Debug.LogError("Error: Unable to find a field with name " + name + " on object " + obj);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Draws a field belonging to the object with the specified field name.
        /// </summary>
        /// <param name="obj">The object being drawn.</param>
        /// <param name="name">The name of the field.</param>
        public static void DrawField(object obj, string name)
        {
            var field = GetField(obj, name);

            if (field != null)
            {
                try {
                    var prevValue = field.GetValue(obj);
                    var value     = ObjectInspector.DrawObject(new GUIContent(Shared.Editor.Utility.EditorUtility.SplitCamelCase(name), GetFieldTooltip(field)), field.FieldType, obj, prevValue, name, 0, null, null, field, true);
                    if (prevValue != value && GUI.changed)
                    {
                        field.SetValue(obj, value);
                    }
                } catch (Exception /*e*/) { }
            }
            else
            {
                Debug.LogError($"Error: Unable to find a field with name {name} on object {obj}.");
            }
        }