少年修仙传客户端基础资源
dabaoji
2023-11-13 0a23e1b83f8fda8ab9f9e32fe71c26c431faf63a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System;
 
namespace Movinarc
{
    public class PUSelection : EditorWindow
    {
      
        TreeView fileTree = null;
        Texture2D fold1 = null;
        Texture2D filepic = null;
        Texture2D line = null;
        GUIStyle boldStyle = null;
        Rect rectScroll;
        Vector2 scrollPos = Vector2.zero;
        public List<PUManager.AssetPath> fileList;
        public List<string> foundList;
        public List<string> directories;
        public string tempPath;
        public string packageName = "";
        public string packagePath;
 
        public static List<string> DirectoriesPathList(List<PUManager.AssetPath> paths)
        {
            List<string> possibleDirs = new List<string>();
            List<TreeView.NodePath> files = new List<TreeView.NodePath>();
            paths.ForEach(
                (p) =>
                {
                    var ph = TreeView.PathHierarchy(p.filePath);
                    foreach (var item in ph)
                    {
                        if (!possibleDirs.Exists((d) => d.Equals(item.path, System.StringComparison.OrdinalIgnoreCase)) &&
                            !item.path.Equals(p.filePath, System.StringComparison.OrdinalIgnoreCase))
                        {
                            possibleDirs.Add(item.path);
                        }
                    }
                    files.Add(new TreeView.NodePath(){ name = p.name, isDirectory = false, path = p.filePath });
                }
            );
            return possibleDirs;
        }
 
        void Awake()
        {
            boldStyle = new GUIStyle(GUI.skin.button);
            boldStyle.fontStyle = FontStyle.Bold;
 
        }
 
        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);
                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);
            }
        }
 
        void OnInspectorUpdate()
        {
            Repaint();
        }
 
        void Uninstall(string customPackage)
        {
            ClearWarnings();
            var fileName = System.IO.Path.GetFileNameWithoutExtension(customPackage);
            if (EditorUtility.DisplayDialog("Delete Imported Unitypackage", string.Format("You're about to uninstall the '{0}'. Are you sure you want to delete all the files related to this package?", fileName),
                    "Yes", "No"))
            {
                try
                {
                    if (EditorUtility.DisplayDialog("Delete Imported Unitypackage", string.Format("The operation can not be undone! Are you sure?"), "Yes. Do It!", "No"))
                    {
                        int delCnt = RemoveFiles(fileTree.selectedNodes);
                        
                        EditorUtility.DisplayProgressBar("Uninstalling Package", "Finalizing...", 1f);
                        if (Directory.Exists(this.tempPath))
                            RemoveMess(this.tempPath);
                        
                        EditorUtility.ClearProgressBar();
                        string msg = string.Format("{0} files/folders related to '{1}' deleted from project.", delCnt, fileName);
                        if (EditorUtility.DisplayDialog("Package Uninstaller", msg, "Ok"))
                        {
                            Debug.Log(msg);
                            EditorWindow.GetWindow(typeof(PUSelection)).Close();
                        }
                    }
                }
                catch (Exception ex)
                {
                    EditorUtility.ClearProgressBar();
                    Debug.LogError(ex.Message);
                }
            }
        }
 
        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"));
 
            GC.Collect();
            GC.WaitForPendingFinalizers();
            foreach (var f in filelist)
            {
 
                EditorUtility.DisplayProgressBar("Uninstalling Package", string.Format("Removing {0}", f.name), 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);
                        GC.Collect();
                        GC.WaitForPendingFinalizers();
                    }
                    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;
        }
 
        public static void RemoveMess(string tempPath)
        {
            try
            {
                var tempPathInfo = new DirectoryInfo(tempPath);
 
                foreach (FileInfo file in tempPathInfo.GetFiles())
                {
                    file.Delete();
                }
                foreach (DirectoryInfo dir in tempPathInfo.GetDirectories())
                {
                    dir.Delete(true);
                }
                if (Directory.GetFiles(tempPath).Length <= 0)
                    Directory.Delete(tempPath);
            }
            catch
            {
            }
        }
 
        private void GetDirectoryNames(string path, List<string> list)
        {
            var parent = Path.GetDirectoryName(path);
            if (!string.IsNullOrEmpty(parent) && !list.Contains(parent.ToLower()) && string.Compare(parent, "assets", true) != 0)
            {
                list.Add(parent.ToLower());
                if (path.Contains("/"))
                {
                    GetDirectoryNames(parent, list);
                }
            }
        }
 
        public static void ClearWarnings()
        {
            var logs = System.Type.GetType("UnityEditor.LogEntries, UnityEditor.dll");
            var clear = logs.GetMethod("Clear", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
            clear.Invoke(null, null);
        }
    }
}