Beispiel #1
0
        void OnGUI()
        {
            if (fileTree == null)
            {
                fileTree = ScriptableObject.CreateInstance <TreeView>();
                if (fileList != null)
                {
                    fold1   = Resources.Load("pu_fold") as Texture2D;
                    filepic = Resources.Load("pu_file2") as Texture2D;
                    line    = Resources.Load("pu_line") as Texture2D;

                    fileList.ForEach((f) => fileTree.AddNodeFromPath(f.filePath, directories, foundList));
                    rectScroll = new Rect(0, 0, this.position.width, 50);
                }
                fileTree.ParentalCheck();
                fileTree.EmptyFolderCheck(directories);
            }

            GUILayout.Box(packageName, GUILayout.ExpandWidth(true));
            GUILayout.Label(line);
            GUILayout.Label("");
            var rect = GUILayoutUtility.GetLastRect();

            if (fileList != null)
            {
                rectScroll.x = rect.x;
                rectScroll.y = rect.y;
                scrollPos    = GUI.BeginScrollView(new Rect(rect.x, rect.y + rect.height, this.position.width - rect.x, this.position.height - rect.height - rect.y - 40),
                                                   scrollPos,
                                                   rectScroll);
                Debug.Log("this.position.height = " + this.position.height);
                fileTree.populateTree(fileTree.treeroot, ref rect, fold1, filepic);

                GUI.EndScrollView();
                if (rectScroll.width < rect.x)
                {
                    rectScroll.width += rect.x;
                }
                if (rectScroll.height < rect.y)
                {
                    rectScroll.height += rect.y;
                }

                var recBtn = new Rect(5, this.position.height - 30, 50, 20);
                if (GUI.Button(recBtn, "All"))
                {
                    fileTree.checkAll(fileTree.treeroot, true);
                }
                recBtn.x += 55;
                if (GUI.Button(recBtn, "None"))
                {
                    fileTree.checkNone(fileTree.treeroot);
                }
                recBtn.x = this.position.width - 130;
                if (GUI.Button(recBtn, "Cancel"))
                {
                    if (Directory.Exists(this.tempPath))
                    {
                        RemoveMess(this.tempPath);
                    }
                    this.Close();
                }
                recBtn.x     = this.position.width - 75;
                recBtn.width = 70;
                if (fileTree.selectedNodes != null && fileTree.selectedNodes.Count > 0)
                {
                    GUI.enabled = true;
                }
                else
                {
                    GUI.enabled = false;
                }
                if (GUI.Button(recBtn, "Uninstall", boldStyle))
                {
                    uninstall(this.packagePath);
                }
                if (position.width < rect.x)
                {
                    position = new Rect(position.x, position.y, rect.x + 30, position.height);
                }
            }
        }
Beispiel #2
0
        private int RemoveFiles(List <TreeNode> filelist)
        {
            float  step     = .5f / filelist.Count;
            float  progress = .5f + step;
            var    dirs     = new List <string>();
            int    deleted  = 0;
            string appPath  = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf(@"Assets"));

            foreach (var f in filelist)
            {
                EditorUtility.DisplayProgressBar("Uninstalling Package", string.Format("Removing {0}", f), progress);
                progress += step;
                try
                {
                    string fullPath = Path.Combine(appPath, f.path);

                    var phList = TreeView.PathHierarchy(f.path);
                    phList.ForEach((ph) =>
                    {
                        if (!dirs.Exists(d => d.Equals(ph.path, StringComparison.OrdinalIgnoreCase)))
                        {
                            dirs.Add(ph.path);
                        }
                    });

                    if (File.Exists(fullPath))
                    {
                        File.Delete(fullPath);
                        deleted++;
                    }
                }
                catch (Exception ex)
                {
                    Debug.LogError(ex.Message);
                }
                finally
                {
                    try
                    {
                        //deleting meta file
                        string fullPath = Path.Combine(appPath, f.path);
                        var    meta     = fullPath + ".meta";
                        if (File.Exists(meta))
                        {
                            File.Delete(meta);
                        }
                    }
                    catch
                    {
                    }
                }
            }
            dirs = dirs.OrderByDescending(i => i.Count(x => x == '/')).ToList();
            foreach (var item in dirs)
            {
                var fullpath = Path.Combine(appPath, item);
                try
                {
                    //deleted += (AssetDatabase.DeleteAsset(item) ? 1 : 0);
                    if (Directory.Exists(fullpath))
                    {
                        if (Directory.GetFiles(fullpath).Length <= 0)
                        {
                            Directory.Delete(fullpath);
                            deleted++;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.LogError(ex.Message);
                }
                finally
                {
                    try
                    {
                        var meta = fullpath + ".meta";
                        if (File.Exists(meta))
                        {
                            File.Delete(meta);
                        }
                    }
                    catch
                    {
                    }
                }
            }
            AssetDatabase.Refresh();
            return(deleted);
        }