public static IEnumerable <FieldAndComment> GetCommentsForClass(Type classType) { string className = classType.ToString().Split('.').Last(); string path = GetClassPath(className); if (string.IsNullOrEmpty(path)) { yield break; } var reader = new StreamReader(path); string currentLine; while ((currentLine = reader.ReadLine()) != null) { if (string.IsNullOrEmpty(currentLine)) { continue; } currentLine = currentLine.Trim(); FieldAndComment fieldAndComment = null; if (currentLine.StartsWith(tripleSlash) && currentLine.Contains(xmlOpenTag)) { fieldAndComment = ReadXmlComment(reader); if (!Preferences.useXml) { fieldAndComment = null; } } else if (currentLine.StartsWith(doubleSlash)) { fieldAndComment = ReadDoubleSlashComment(reader, currentLine); if (!Preferences.useDoubleSlash) { fieldAndComment = null; } } if (fieldAndComment != null) { yield return(fieldAndComment); } } reader.Dispose(); if (classType.BaseType != null && classType.BaseType != typeof(Behaviour)) { foreach (FieldAndComment fieldAndComment in GetCommentsForClass(classType.BaseType)) { yield return(fieldAndComment); } } }
public static void DrawInspector(SerializedObject serializedObject, FieldAndComment[] comments) { EditorGUI.BeginChangeCheck(); serializedObject.Update(); foreach (FieldAndComment fieldAndComment in comments.Where(comment => string.IsNullOrEmpty(comment.field)).Reverse()) { GUILayout.TextArea(fieldAndComment.comment, "Box", GUILayout.ExpandWidth(true)); } SerializedProperty iterator = serializedObject.GetIterator(); for (var enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false) { string comment = null; FieldAndComment field = comments.FirstOrDefault(f => f.field == iterator.name); if (field != null) { comment = field.comment; } bool disableScope = iterator.propertyPath == "m_Script"; EditorGUI.BeginDisabledGroup(disableScope); if (string.IsNullOrEmpty(comment)) { EditorGUILayout.PropertyField(iterator, true); } else { EditorGUILayout.PropertyField(iterator, new GUIContent(Preferences.fieldPrefix + iterator.displayName, comment), true); } EditorGUI.EndDisabledGroup(); } serializedObject.ApplyModifiedProperties(); EditorGUI.EndChangeCheck(); }