/// <summary>
        /// Generates documentation for all classes that implement or extend a type.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="assembly"></param>
        private void Generate(Type type, Assembly assembly, StreamWriter readmeWriter)
        {
            var incRegex = new Regex(includeRegex, RegexOptions.IgnoreCase);
            var excRegex = new Regex(excludeRegex, RegexOptions.IgnoreCase);

            fields.Clear();

            IEnumerable <Type> types = assembly.GetTypes().Where(t => !t.IsAbstract && type.IsAssignableFrom(t));

            foreach (Type t in types)
            {
                if (incRegex.IsMatch(t.FullName) && !excRegex.IsMatch(t.FullName))
                {
                    ExtractAllEditorAccessibleFields(t);
                }
            }

            foreach (KeyValuePair <Type, List <FieldRecord> > entries in fields)
            {
                string dirPath = GetDirPath(entries.Key);
                Directory.CreateDirectory(dirPath);

                readmeWriter.WriteLine("  * [" + entries.Key + "](./" + GetRelativePath(entries.Key) + ")");

                StreamWriter typeWriter = new StreamWriter(GetFullPath(entries.Key));
                typeWriter.Write("# " + entries.Key + "\n");

                Attribute[] attrs = Attribute.GetCustomAttributes(entries.Key, typeof(Attribute));
                for (int i = 0; i < attrs.Length; i++)
                {
                    switch (attrs[i].GetType().Name)
                    {
                    case "DocGenAttribute":
                        DocGenAttribute docgen = (DocGenAttribute)attrs[i];
                        typeWriter.Write(docgen.Description + "\n\n");
                        break;

                    default:
                        break;
                    }
                }

                foreach (FieldRecord entry in entries.Value)
                {
                    typeWriter.WriteLine(entry.ToMarkdown());
                }

                typeWriter.Close();

                AssetDatabase.ImportAsset(GetFullPath(entries.Key));
            }
        }
            internal FieldRecord(FieldInfo info, GameObject defaultsGo)
            {
                this.info = info;

                if (info.ReflectedType == typeof(MonoBehaviour))
                {
                    MonoBehaviour obj = defaultsGo.AddComponent(info.ReflectedType) as MonoBehaviour;
                    defaultValue = info.GetValue(obj);
                    this.script  = MonoScript.FromMonoBehaviour(obj);
                }
                else
                {
                    ScriptableObject instance = ScriptableObject.CreateInstance(info.ReflectedType);
                    this.defaultValue = info.GetValue(instance);
                    this.script       = MonoScript.FromScriptableObject(instance);
                    ScriptableObject.DestroyImmediate(instance);
                }

                object[] attributes = info.GetCustomAttributes(true);
                foreach (object attr in attributes)
                {
                    if (attr is SerializeField)
                    {
                        // we don't need to record that it is serialized as we are only processing serialized fields.
                        continue;
                    }

                    if (attr is TooltipAttribute)
                    {
                        tooltip = attr as TooltipAttribute;
                        continue;
                    }

                    if (attr is RangeAttribute)
                    {
                        range = attr as RangeAttribute;
                        continue;
                    }

                    if (attr is DocGenAttribute)
                    {
                        docGenAttr = attr as DocGenAttribute;
                        continue;
                    }

                    Debug.LogWarning("Unable to document attribute type " + attr.GetType());
                }
            }
示例#3
0
        public static void DrawDocGenAttributes(this UnityEditor.Editor editor)
        {
            Attribute[] attributes = Attribute.GetCustomAttributes(editor.target.GetType(), typeof(Attribute));

            for (int i = 0; i < attributes.Length; i++)
            {
                switch (attributes[i].GetType().Name)
                {
                case "DocGenAttribute":
                    DocGenAttribute docgen = (DocGenAttribute)attributes[i];
                    EditorGUILayout.HelpBox(docgen.Description, MessageType.Info);
                    break;

                default:
                    break;
                }
            }
        }
示例#4
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            DocGenAttribute docgen    = attribute as DocGenAttribute;
            Rect            fieldRect = new Rect(position);

            EditorGUI.BeginProperty(position, label, property);
            EditorGUI.PropertyField(fieldRect, property, label, true);
            property.isExpanded = EditorGUI.Foldout(fieldRect, property.isExpanded, GUIContent.none, true);

            if (property.isExpanded)
            {
                Rect helpRect = fieldRect;
                helpRect.y      = fieldRect.y + EditorGUIUtility.singleLineHeight;
                helpRect.height = helpHeight;

                GUIStyle helpStyle = GUI.skin.GetStyle("HelpBox");
                helpStyle.richText = true;
                EditorGUI.TextArea(helpRect, docgen.Description, helpStyle);
                helpHeight = helpStyle.CalcHeight(new GUIContent(docgen.Description), EditorGUIUtility.currentViewWidth);
            }

            EditorGUI.EndProperty();
        }