Ejemplo n.º 1
0
 private void ShowIndexDoc()
 {
     if (doc != null)
     {
         EditorMarkDownDrawer.DrawDoc(doc);
     }
 }
Ejemplo n.º 2
0
        private void ShowLocalPlugins()
        {
            for (int i = 0; i < LocalPlugins.Plugins.Count; i++)
            {
                var package = LocalPlugins.Plugins[i];
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button(package.Name, Styles.PackageTitle, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(false)))
                {
                    bool b = !pluginExtends[i].target;
                    foreach (var extend in pluginExtends)
                    {
                        extend.target = false;
                    }
                    pluginExtends[i].target = b;
                }
                if (!string.IsNullOrEmpty(package.URL) && GUILayout.Button("Import", Styles.ImportButton, GUILayout.Width(80)))
                {
                    if (EditorUtility.DisplayDialog(@"Import LocalPlugin", @"导入本地插件时,插件不会复制到项目内,而是存储在原本的目录中,通过绝对路径引用。
因此不能将项目分享给其他用户!", "这是本地项目", "这是合作项目"))
                    {
#if UNITY_2019_2_3
                        var Internal_packageType = typeof(Client).Assembly.GetType("UnityEditor.PackageManager.UI.Package");
                        var addLocalMethod       = Internal_packageType.GetMethod("AddFromLocalDisk", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
                        addLocalMethod.Invoke(null, new object[] { package.URL });
#elif UNITY_2019_1_OR_NEWER
                        Client.Add("file:" + Directory.GetParent(package.URL));
#endif
                    }
                }
                EditorGUILayout.EndHorizontal();
                if (EditorGUILayout.BeginFadeGroup(pluginExtends[i].faded))
                {
                    EditorGUILayout.BeginVertical();
                    if (package.doc != null)
                    {
                        EditorMarkDownDrawer.DrawDoc(package.doc);
                    }
                    else
                    {
                        EditorGUILayout.LabelField("Cant find MD document", EditorStyles.boldLabel);
                    }
                    EditorGUILayout.EndVertical();
                }
                EditorGUILayout.EndFadeGroup();
            }
        }
Ejemplo n.º 3
0
 private void ShowPackages()
 {
     for (int i = 0; i < PackagePlugins.Plugins.Count; i++)
     {
         var package = PackagePlugins.Plugins[i];
         EditorGUILayout.BeginHorizontal();
         if (GUILayout.Button(package.Name, Styles.PackageTitle, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(false)))
         {
             bool b = !packageExtends[i].target;
             foreach (var extend in packageExtends)
             {
                 extend.target = false;
             }
             packageExtends[i].target = b;
         }
         if (GUILayout.Button("Import", Styles.ImportButton, GUILayout.Width(80)))
         {
             AssetDatabase.ImportPackage(package.URL, true);
             //Process.Start(package);
         }
         EditorGUILayout.EndHorizontal();
         if (EditorGUILayout.BeginFadeGroup(packageExtends[i].faded))
         {
             EditorGUILayout.BeginVertical();
             if (package.doc != null)
             {
                 EditorMarkDownDrawer.DrawDoc(package.doc);
             }
             else
             {
                 EditorGUILayout.LabelField("Cant find MD document", EditorStyles.boldLabel);
             }
             EditorGUILayout.EndVertical();
         }
         EditorGUILayout.EndFadeGroup();
     }
 }
Ejemplo n.º 4
0
        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();
            }
        }