Esempio n. 1
0
 private void DrawImmutable(object target, IMemberInspectionInfo memberToInspect, Dictionary <string, bool> folderPathToIsExpanded, Stack <string> pathStack)
 {
     if (ShouldDrawTypeAsList(memberToInspect.RealType))
     {
         // Lists are only readonly on their surface.
         DrawIEnumerable(target, memberToInspect, true, folderPathToIsExpanded, pathStack);
     }
     else
     {
         // Create a readonly field.
         string text = memberToInspect.GetValue(target).ToString();
         EditorGUILayout.LabelField(memberToInspect.Info.Name, text);
     }
 }
Esempio n. 2
0
 private void DrawImmutableSelectable(object target, IMemberInspectionInfo memberToInspect, Dictionary <string, bool> folderPathToIsExpanded, Stack <string> pathStack)
 {
     if (ShouldDrawTypeAsList(memberToInspect.RealType))
     {
         Warn($"It doesn't make sense to draw an instance of {memberToInspect.Info.ReflectedType.Name} as {InspectionKind.ImmutableSelectable}. It will be drawn as {InspectionKind.Immutable} instead.");
         DrawIEnumerable(target, memberToInspect, true, folderPathToIsExpanded, pathStack);
     }
     else
     {
         // TODO Really draw references as selectable?
         EditorGUILayout.BeginHorizontal();
         EditorGUILayout.PrefixLabel(memberToInspect.Info.Name);
         string text = memberToInspect.GetValue(target).ToString();
         EditorGUILayout.SelectableLabel(text);
         EditorGUILayout.EndHorizontal();
     }
 }
Esempio n. 3
0
        private void DrawMutable(object target, IMemberInspectionInfo memberToInspect, Dictionary <string, bool> folderPathToIsExpanded, Stack <string> pathStack)
        {
            var    obj = memberToInspect.GetValue(target);
            object newObj;

            if (memberToInspect.RealType.IsEnum)
            {
                newObj = new EnumDrawer().Draw(memberToInspect, obj);
            }
            else
            {
                if (_drawers.TryGetValue(memberToInspect.RealType, out var drawer))
                {
                    //TODO better null checking (string)
                    if (obj != null /*|| memberToInspect.RealType == typeof(string)*/)
                    {
                        newObj = drawer.Draw(memberToInspect, obj);
                    }
                    else
                    {
                        DrawNone(memberToInspect.Info.Name);
                        newObj = null;
                    }
                }
                else
                {
                    if (obj != null && memberToInspect.RealType.IsValueType)
                    {
                        Warn($"The following value-type has no registered drawer: {memberToInspect.RealType}");
                        newObj = obj;
                    }
                    else
                    {
                        newObj = DrawMutableReference(memberToInspect, obj, folderPathToIsExpanded, pathStack);
                    }
                }
            }

            if (obj != newObj)
            {
                memberToInspect.SetValue(target, newObj);
            }
        }