public override void OnEnable(SeanLibManager drawer)
        {
            base.OnEnable(drawer);
            var           docAssetDir = PathTools.RelativeAssetPath(this.GetType(), RelativePath);
            var           subAssets   = AssetDatabase.FindAssets("", new string[] { docAssetDir });
            List <string> docPath     = new List <string>();

            foreach (var item in subAssets)
            {
                var assetPath = AssetDatabase.GUIDToAssetPath(item);
                if (Path.GetExtension(assetPath) == ".md")
                {
                    docPath.Add(assetPath);
                }
            }
            foreach (var aPath in docPath)
            {
                var rawDoc  = AssetDatabase.LoadAssetAtPath(aPath, typeof(TextAsset)) as TextAsset;
                var docName = aPath.Replace(docAssetDir + "/", "").Replace(".md", "");
                //需要手动加载
                var doc = new MarkDownDoc(aPath.Substring(0, aPath.LastIndexOf('/')), rawDoc, false);
                if (this.window is SeanLibDocHub)
                {
                    doc.ColorSetting = ColorSettings;
                }
                Docs[docName] = doc;
            }
            if (SearchField)
            {
                Search.downOrUpArrowKeyPressed += () => { SearchNext(); };
            }
        }
        private string GetRelocatePageName(string pageName)
        {
            var         docAssetRoot = PathTools.RelativeAssetPath(this.GetType(), RelativePath);
            MarkDownDoc current      = Docs[CurrentDocName];

            return((current.AssetDir + "/" + pageName).Replace(docAssetRoot + "/", ""));
        }
示例#3
0
 public override void OnDisable()
 {
     if (packageExtends != null)
     {
         foreach (var item in packageExtends)
         {
             item.valueChanged.RemoveListener(window.Repaint);
         }
     }
     if (pluginExtends != null)
     {
         foreach (var item in pluginExtends)
         {
             item.valueChanged.RemoveListener(window.Repaint);
         }
     }
     if (RemotepluginExtends != null)
     {
         foreach (var item in RemotepluginExtends)
         {
             item.valueChanged.RemoveListener(window.Repaint);
         }
     }
     if (doc != null)
     {
         doc.Release();
         doc = null;
     }
     base.OnDisable();
 }
示例#4
0
 public static void DrawDoc(MarkDownDoc doc, Action <string> PageChange = null, Action <string> DocChange = null, Action Repaint = null)
 {
     foreach (var data in doc.datas)
     {
         DrawData(data, PageChange, DocChange, Repaint);
         if (Event.current.type == EventType.Repaint)
         {
             data.drawRect = GUILayoutUtility.GetLastRect();
         }
     }
 }
        /// <summary>
        /// 按照文档名换页
        /// </summary>
        /// <param name="DocName"></param>
        public void changeDoc(string DocName)
        {
            if (DocName.IsNullOrEmpty() || DocName == CurrentDocName)
            {
                return;
            }
            MarkDownDoc doc = null;

            if (Docs.TryGetValue(DocName, out doc))
            {
                if (!string.IsNullOrEmpty(CurrentDocName))
                {
                    DocPages.Push(CurrentDocName);
                }
                CurrentDocName = DocName;
            }
        }
示例#6
0
        public override void OnEnable(SeanLibManager drawer)
        {
            base.OnEnable(drawer);
            //Load Doc
            var docAsset = AssetDatabase.LoadAssetAtPath <TextAsset>(PathTools.RelativeAssetPath(this.GetType(), DocDir + "/Index.md"));

            if (docAsset)
            {
                doc = new MarkDownDoc(DocDir, docAsset.text, true);
            }
            PackStorageDir = EditorUserSettings.GetConfigValue(packageKey);
            LocalLibDir    = EditorUserSettings.GetConfigValue(localKey);
            ReadRemotePluginsFile();
            ReadPackageFold();
            ReadLocalPlugin();

            RemotePlistEditor.OnEnable((info, index) =>
            {
                OnGUIUtility.Vision.BeginBackGroundColor(index % 2 == 0 ? OnGUIUtility.Colors.dark : OnGUIUtility.Colors.light);
                {
                    EditorGUILayout.BeginVertical();
                    if (OnGUIUtility.Foldout(info.Name, Styles.PackageTitle, GUILayout.ExpandWidth(true)))
                    {
                        info.Name    = EditorGUILayout.DelayedTextField("Name", info.Name);
                        info.URL     = EditorGUILayout.TextField("URL", info.URL);
                        info.version = (PluginVersion)EditorGUILayout.EnumPopup("Version", info.version);
                    }
                    EditorGUILayout.EndVertical();
                }
                OnGUIUtility.Vision.EndBackGroundColor();
                return(info);
            },
                                       () =>
            {
                return(new PluginInfo());
            }, 1, "+Plugin");
        }
        public override void OnGUI()
        {
            base.OnGUI();
            //CheckDoc
            MarkDownDoc doc = null;

            if (string.IsNullOrEmpty(CurrentDocName))
            {
                if (Docs.TryGetValue("Index", out doc))
                {
                    CurrentDocName = "Index";
                }
            }
            else
            {
                doc = Docs[CurrentDocName];
                if (Event.current.type == EventType.Layout)
                {
                    if (DocPages.Count > 0)
                    {
                        var oldDoc = Docs[DocPages.Peek()];
                        if (oldDoc.datas.Count > 0)
                        {
                            oldDoc.Release();
                        }
                    }
                    if (doc.datas.Count == 0)
                    {
                        doc.Load();
                    }
                    else
                    {
                        if (AutoRefresh && doc.RawDoc.text != doc.rawDoc)
                        {
                            doc.Release();
                            doc.rawDoc = doc.RawDoc.text;
                            doc.Load();
                        }
                    }
                }
            }
            //DrawDoc
            if (doc != null)
            {
                //ToolBar
                ToolBar();
                //DocContent
                EditorGUI.DrawRect(DrawRect, ColorPalette.Get(ColorSettings, "BackGround", Color.white));
                v = GUILayout.BeginScrollView(v);
                {
                    if (searched != null)
                    {
                        if (Event.current.type == EventType.Repaint)
                        {
                            EditorGUI.DrawRect(searched.drawRect, ColorPalette.Get(ColorSettings, "HightLight", Color.white));
                        }
                        if (Search.Current.IsNullOrEmpty())
                        {
                            searched = null;
                        }
                    }
                    EditorMarkDownDrawer.DrawDoc(doc, changePage, changeDoc, window.Repaint);
                }
                GUILayout.EndScrollView();
                if (Event.current.type == EventType.Repaint)
                {
                    DrawRect = GUILayoutUtility.GetLastRect();
                }
            }
            else
            {
                EditorGUILayout.SelectableLabel("Can't find Index.md Document at :" + PathTools.RelativeAssetPath(this.GetType(), RelativePath));
                EditorGUILayout.SelectableLabel("First you should create default page");
                if (GUILayout.Button("CreateReadMe"))
                {
                    if (EditorUtility.DisplayDialog("CreateIndex.md", "After create .md file,you have to reopen this editorwindow.", "OK", "Cancel"))
                    {
                        //Template
                        string[]  assets = AssetDatabase.FindAssets("TMP_ReadMe");
                        TextAsset text   = AssetDatabase.LoadAssetAtPath <TextAsset>(AssetDatabase.GUIDToAssetPath(assets[0]));
                        //
                        var DirRoot     = PathTools.RelativeAssetPath(this.GetType(), RelativePath);
                        var FileDirRoot = Directory.GetParent(DirRoot).FullName + @"\" + Path.GetFileName(DirRoot);
                        if (!Directory.Exists(FileDirRoot))
                        {
                            Directory.CreateDirectory(FileDirRoot);
                        }
                        FileTools.WriteAllText(FileDirRoot + "/Index.md", text.text);

                        AssetDatabase.Refresh();
                        window.Close();
                    }
                }
            }
            //PingDocScript
            if (EditScript)
            {
                GUILayout.BeginHorizontal();
                {
                    AutoRefresh = GUILayout.Toggle(AutoRefresh, "自动刷新");
                    OnGUIUtility.ScriptField("Editor Script", this.GetType());
                }
                GUILayout.EndHorizontal();
            }
        }
示例#8
0
 public void Load(string RawString, MarkDownDoc doc)
 {
     this.doc = doc;
     if (RawString.IsNullOrEmpty())
     {
         return;
     }
     if (RawString.Replace(Environment.NewLine, "") == "***")
     {
         this.type = KeyType.separator;
     }
     else if (RawString[0] == '*')
     {
         this.type = KeyType.font;
         if (RawString.IndexOf("***") == 0)
         {
             //斜体加粗
             keyValue = "BI";
             Data     = RawString.Substring(3, RawString.Length - 6);
         }
         else if (RawString.IndexOf("**") == 0)
         {
             //加粗
             keyValue = "B";
             Data     = RawString.Substring(2, RawString.Length - 4);
         }
         else if (RawString.IndexOf("*") == 0)
         {
             //斜体
             keyValue = "I";
             Data     = RawString.Substring(1, RawString.Length - 2);
         }
     }
     else if (RawString[0] == '#')
     {
         this.type = KeyType.title;
         if (RawString.IndexOf("###") == 0)
         {
             //1号标题
             keyValue = "1";
             Data     = RawString.Substring(3, RawString.Length - 3);
         }
         else if (RawString.IndexOf("##") == 0)
         {
             //3级标题
             keyValue = "2";
             Data     = RawString.Substring(2, RawString.Length - 2);
         }
         else if (RawString.IndexOf("#") == 0)
         {
             //3级标题
             keyValue = "3";
             Data     = RawString.Substring(1, RawString.Length - 1);
         }
     }
     else if (RawString[0] == '!')
     {
         this.type = KeyType.image;
         int start = RawString.IndexOf("(") + 1;
         int end   = RawString.LastIndexOf(")");
         Data = RawString.Substring(start, RawString.Length - start - (RawString.Length - end));
         var ImgAssetPath = doc.AssetDir + "/" + Data;
         if (Path.GetExtension(ImgAssetPath) == ".gif")
         {
             gifDrawer = new GUIGifDrawer();
             gifDrawer.LoadGIF(PathTools.Asset2File(ImgAssetPath));
             if (EditorUserSettings.GetConfigValue("DocAutoPlayGif") != "true")
             {
                 gifDrawer.Controller = true;
             }
             gifDrawer.Play();
         }
         else
         {
             if (PathTools.IsAssetPath(ImgAssetPath))
             {
                 this.texture = AssetDatabase.LoadAssetAtPath(ImgAssetPath, typeof(Texture2D)) as Texture2D;
             }
             else if (File.Exists(ImgAssetPath))
             {
                 byte[] img = File.ReadAllBytes(ImgAssetPath);
                 this.texture = new Texture2D(1024, 1024);
                 texture.LoadImage(img);
             }
         }
     }
     else if (RawString[0] == '(')
     {
         this.type = KeyType.link;
         int start = RawString.IndexOf("(") + 1;
         int end   = RawString.LastIndexOf(")");
         Data = RawString.Substring(start, RawString.Length - start - (RawString.Length - end));
     }
     else if (RawString.IndexOf(">>") == 0)
     {
         this.type = KeyType.doc;
         Data      = RawString.Remove(0, 2);
     }
     else if (RawString[0] == '>')
     {
         this.type = KeyType.page;
         Data      = RawString.Remove(0, 1);
     }
     else if (RawString[0] == '|')
     {
         this.type = KeyType.table;
         string[] datas = RawString.Split('|');
         for (int i = 1; i < datas.Length; i++)
         {
             if (datas[i] == "--:")
             {
                 this.type = KeyType.separator;
                 break;
             }
             MarkDownData subdata = new MarkDownData();
             subdata.Load(datas[i], this.doc);
             this.subdatas.Add(subdata);
         }
     }
     else if (RawString.IndexOf("```") == 0)
     {
         this.type = KeyType.code;
         keyValue  = RawString.Substring(3, RawString.Length - 3);
     }
     else if (RawString.IndexOf("QA") == 0)
     {
         this.type = KeyType.qa;
         keyValue  = RawString.Substring(2, RawString.Length - 2);
     }
     else if (RawString.IndexOf("/{") == 0)
     {
         this.type = KeyType.foldin;
         keyValue  = RawString.Substring(2, RawString.Length - 2);
     }
     else if (RawString.IndexOf("/}") == 0)
     {
         this.type = KeyType.foldout;
         keyValue  = RawString.Substring(2, RawString.Length - 2);
     }
     else
     {
         Data = RawString;
     }
 }