少年修仙传客户端基础资源
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
//(c) 2016 Movinarc
//http://movinarc.com/unity-package-uninstaller
using UnityEngine;
using UnityEditor;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Win32;
using System.IO.Compression;
using System.Reflection;
 
//SharpCompress: https://sharpcompress.codeplex.com/
using SharpCompress;
using SharpCompress.Reader;
using SharpCompress.Common;
using System.Collections;
using System.ComponentModel;
 
namespace Movinarc
{
    public class PUManager : EditorWindow
    {
        Vector2 scrollPos = Vector2.zero;
        Texture2D putitle = null;
        Texture2D puicon = null;
        Texture2D line = null;
        Texture2D imgInfo;
        Texture2D imgQuestion;
        Texture2D openicon = null;
        string customPackage = string.Empty;
        GUIStyle horAlignStyle = null;
        GUIStyle fontStyle = null;
        GUIStyle[] searchStyles = null;
        string searchText = "";
        List<Package> packages = null;
        List<Package> assetStoreList = null;
        Rect rectScrollView;
        double lastTime = 0;
        bool blinkOn = true;
        string unityPath = "";
        string infoToShow = "";
 
        struct Package
        {
            public string fullPath;
            public string fileName;
            public string dateString;
            public DateTime date;
        }
 
        public class AssetPath
        {
            public string name = "";
            public string filePath = "";
            public bool isDirectory = false;
        }
 
        [MenuItem("Assets/Uninstall Package...")]
        static void CreateWindow()
        {
            var win = EditorWindow.GetWindow(typeof(PUManager));
            win.minSize = new Vector2(410, 450);
            win.titleContent.text = "Uninstall Package";
            win.titleContent.tooltip = "v1.3";
            win.Focus();
        }
 
        public void Update()
        {
            if (EditorApplication.timeSinceStartup - lastTime > .25)
            {
                blinkOn = !blinkOn;
                lastTime = EditorApplication.timeSinceStartup;
                Repaint();
            }
        }
 
        public void OnGUI()
        {
            #region init
            if (packages == null || packages.Count <= 0)
            {
                TreeView tv = CreateInstance<TreeView>();
                tv.allCheckedByDefault = true;
                packages = new List<Package>();
 
                #if UNITY_EDITOR_WIN
                unityPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                unityPath = Path.Combine(unityPath, "Unity");
 
                #elif UNITY_EDITOR_OSX
 
                unityPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/Library/Unity";
                #endif
                var info = new DirectoryInfo(unityPath);
                var files = info.GetFiles("*.unitypackage", SearchOption.AllDirectories);
                foreach (var file in files)
                {
                    packages.Add(new Package()
                        { fileName = Path.GetFileNameWithoutExtension(file.FullName), 
                            fullPath = file.FullName,
                            date = file.CreationTime, dateString = file.CreationTime.ToString("g")
                        });
                }
                packages = packages.OrderBy(i => i.fileName).ToList();
                assetStoreList = new List<Package>(packages);
 
 
                putitle = Resources.Load("PU_title") as Texture2D;
                puicon = Resources.Load("PU_icon") as Texture2D;
                line = Resources.Load("pu_line") as Texture2D;
                imgInfo = Resources.Load("pu_i") as Texture2D;
                imgQuestion = Resources.Load("pu_q") as Texture2D;
 
                openicon = Resources.Load("Open_icon") as Texture2D;
                horAlignStyle = new GUIStyle();
                horAlignStyle.padding = new RectOffset(0, 5, 15, 0);
 
                fontStyle = new GUIStyle();
                fontStyle.fontSize = 9;
                fontStyle.normal.textColor = new Color(.2f, .2f, .2f);
                fontStyle.padding = new RectOffset(5, 0, 5, 0);
                fontStyle.wordWrap = true;
 
 
                searchStyles = new GUIStyle[3];
                searchText = "";
            }
            #endregion
 
            GUI.skin.label.alignment = TextAnchor.MiddleLeft;
            GUILayout.Label(putitle);
            #region Search/Select
            searchStyles[0] = GUI.skin.FindStyle("Toolbar");
            searchStyles[1] = GUI.skin.FindStyle("ToolbarSeachTextField");
            searchStyles[2] = GUI.skin.FindStyle("ToolbarSeachCancelButton");
 
            GUILayout.BeginHorizontal();
            GUILayout.Box("Search / Select ", GUILayout.ExpandWidth(true));
            GUILayout.Label(imgQuestion, GUILayout.ExpandWidth(false));
            var qrect = GUILayoutUtility.GetLastRect();
            if (qrect.Contains(Event.current.mousePosition))
            {
                infoToShow = "[Search / Select] \nType the name of the package you are looking for to filter the list of packages.";
            }
 
            GUILayout.EndHorizontal();
 
            GUILayout.BeginHorizontal(searchStyles[0]);
            GUI.SetNextControlName("txtSearch");
            searchText = GUILayout.TextField(searchText, searchStyles[1]);
        
            if (GUILayout.Button("", searchStyles[2]))
            {
                searchText = "";
                GUI.FocusControl(null);
            }
 
            GUI.FocusControl("txtSearch");
            GUILayout.EndHorizontal();
 
            GUILayout.Space(15.0f);
            scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
            GUILayout.BeginVertical();
 
            if (assetStoreList != null && assetStoreList.Count > 0)
            {
                foreach (var item in assetStoreList)
                {
                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button(new GUIContent(puicon, "Uninstall"), GUILayout.ExpandWidth(false)))
                    {
                        CheckUninstall(item.fullPath);
                    }
                    var irect = GUILayoutUtility.GetLastRect();
                    irect.width = position.width;
                    if (irect.Contains(Event.current.mousePosition) && rectScrollView.Contains(Event.current.mousePosition))
                    {
                        infoToShow = String.Format("[Name] {0}\n[Path] {1}\n[Downladed] {2}", item.fileName, item.fullPath, item.dateString);
                    }
                    GUILayout.Label(item.fileName, this.horAlignStyle, GUILayout.MinWidth(230));
 
 
                    GUILayout.EndHorizontal();
                    GUILayout.Space(5.0f);
                    GUILayout.Label(line);
                }
            }
 
            GUILayout.EndVertical();
            GUILayout.EndScrollView();
            if (Event.current.type == EventType.Repaint)
            {
                rectScrollView = GUILayoutUtility.GetLastRect();
                rectScrollView.x = scrollPos.x;
                rectScrollView.y = scrollPos.y;
            }
            #endregion
 
            GUILayout.Space(10.0f);
 
            #region Browse
            GUILayout.BeginHorizontal();
            GUILayout.Box("Browse ", GUILayout.ExpandWidth(true));
            GUILayout.Label(imgQuestion, GUILayout.ExpandWidth(false));
            qrect = GUILayoutUtility.GetLastRect();
            if (qrect.Contains(Event.current.mousePosition))
            {
                infoToShow = "[Browse] \nClick Open to select a unity package file, from your computer. Then click uninstall to unimport the package.";
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
 
            if (GUILayout.Button(new GUIContent(openicon, "Open"), GUILayout.ExpandWidth(false))) // Custom Open Button
            {
                var f = EditorUtility.OpenFilePanel("Select the .unitypackage file you are going to remove from project", "", "unitypackage");
                if (System.IO.File.Exists(f))
                {
                    this.customPackage = f;
                }
            }
            if (string.IsNullOrEmpty(customPackage))
                GUI.enabled = false;
            else
                GUI.enabled = true;
            if (GUILayout.Button(new GUIContent(puicon, "Uninstall"), GUILayout.ExpandWidth(false))) // Custom Uninstall Button
            {
                CheckUninstall(this.customPackage);
            }
            GUI.enabled = true;
            GUILayout.BeginVertical();
            if (string.IsNullOrEmpty(customPackage))
                GUILayout.Label("---", horAlignStyle);
            else
            {
                FileInfo fi = new FileInfo(customPackage);
                var pkgName = Path.GetFileNameWithoutExtension(fi.FullName);
                GUILayout.BeginHorizontal();
                GUILayout.Label(pkgName, this.horAlignStyle, GUILayout.ExpandWidth(true));
                GUILayout.EndHorizontal();
                var irect = GUILayoutUtility.GetLastRect();
                if (irect.Contains(Event.current.mousePosition))
                {
                    infoToShow = String.Format("[Name] {0}\n[Path] {1}\n[Downladed] {2}", pkgName, fi.FullName, fi.CreationTime.ToString("g"));
                }
            }
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            #endregion
 
            GUILayout.Space(10.0f);
            GUILayout.Label(line, GUILayout.ExpandWidth(true));
 
            if (GUI.changed)
            {
                FilterAssetStoreList(searchText);
            }
            GUILayout.BeginHorizontal();
            GUILayout.Label(imgInfo);
 
            if (!String.IsNullOrEmpty(infoToShow))
            {
                GUILayout.Label(infoToShow, fontStyle, GUILayout.Height(70), GUILayout.ExpandWidth(true));
            }
            else
            {
                GUILayout.Label("", fontStyle, GUILayout.Height(70), GUILayout.ExpandWidth(true));
            }
            GUILayout.EndHorizontal();
 
        }
 
        void FilterAssetStoreList(string what)
        {
            if (packages != null)
                assetStoreList = packages.FindAll(x => x.fileName.ToLowerInvariant().Contains(what.ToLowerInvariant()));
        }
 
        public void PrepareForUnimport(string file2import, string tempPath)
        {
            // test absolute
            if (!File.Exists(file2import))
            {
                // test relative
                file2import = Path.Combine(Environment.CurrentDirectory, file2import);
                if (!File.Exists(file2import))
                    throw new FileNotFoundException(file2import);
            }
 
            if (!file2import.ToLower().EndsWith(".unitypackage"))
                throw new Exception("You must select *.unitypackage files.");
 
            if (!Directory.Exists(tempPath))
                Directory.CreateDirectory(tempPath);
 
            EditorUtility.DisplayProgressBar("Uninstalling Package", "Initializing...", .25f);
            HolyGZip(file2import, tempPath);
 
            EditorUtility.DisplayProgressBar("Uninstalling Package", "Fetching Package Structure...", .5f);
            List<AssetPath> fileList = GenerateAssetList(tempPath);
 
 
            var assetList = AssetDatabase.GetAllAssetPaths().ToList();
            var foundList = new List<string>();
            foreach (var item in assetList)
            {
                if (fileList.Exists((f) => f.filePath.Equals(item, StringComparison.OrdinalIgnoreCase)))
                {
                    foundList.Add(item);
                }
            }
            var dirs = PUSelection.DirectoriesPathList(fileList);
 
            EditorUtility.ClearProgressBar();
            bool goOn = true;
            if (foundList.Count <= 0)
            {
                if (!EditorUtility.DisplayDialog("No files found.", "It seems that '" + Path.GetFileNameWithoutExtension(file2import) + "' doesn't exist in your project. Do you want to continue anyway?", "Continue Anyway", "No"))
                {
                    goOn = false;
                    PUSelection.RemoveMess(tempPath);
                }
            }
            if (goOn)
            {
                PUSelection pus = ScriptableObject.CreateInstance<PUSelection>();
                pus.fileList = fileList;
                pus.directories = dirs;
                pus.foundList = foundList;
                pus.packageName = Path.GetFileNameWithoutExtension(file2import);
                pus.packagePath = file2import;
                pus.tempPath = tempPath;
                pus.titleContent = new GUIContent("");
                pus.minSize = new Vector2(300, 200);
 
                pus.ShowUtility();
            }
        }
 
        void CheckUninstall(string customPackage)
        {
            try
            {
 
                UninstallPackage(customPackage);
 
            }
            catch (Exception ex)
            {
                EditorUtility.ClearProgressBar();
                Debug.LogError(ex.Message);
            }
        }
 
        public void UninstallPackage(string path)
        {
            string tempPath = Path.Combine(Path.GetTempPath(), "PU" + DateTime.Now.Ticks.ToString());
 
            PrepareForUnimport(path, tempPath);
        }
 
        public void HolyGZip(string gzipFileName, string targetDir)
        {
            using (Stream stream = File.OpenRead(gzipFileName))
            {
                var reader = ReaderFactory.Open(stream);
                var progress = .25f;
 
                while (reader.MoveToNextEntry())
                {
                    if (!reader.Entry.IsDirectory)
                    {
                        reader.WriteEntryToDirectory(targetDir, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite);
                        progress += .75f * reader.Entry.Size / stream.Length;
                        EditorUtility.DisplayProgressBar("Uninstalling Package", "Analysing... ", progress);
 
                    }
                }
            }
        }
 
        private List<AssetPath> GenerateAssetList(string contentPath)
        {
            string appPath = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf(@"Assets"));
            var lst = new List<AssetPath>();
            var directoryInfo = new DirectoryInfo(contentPath).GetDirectories();
            foreach (var item in directoryInfo)
            {
                string pathnameFromFile = File.ReadAllLines(Path.Combine(item.FullName, "pathname")).ToList().First();
                //ensure path correction
                pathnameFromFile = pathnameFromFile.Replace(@"\\", "/");
                pathnameFromFile = pathnameFromFile.Replace(@"\", "/");
 
                var asset = new AssetPath();
                if (Directory.Exists(Path.Combine(appPath, pathnameFromFile)))
                {
                    asset.name = Path.GetDirectoryName(pathnameFromFile);
 
                    if (!pathnameFromFile.EndsWith("/"))
                    {
                        pathnameFromFile += "/";
                    }
                }
                else
                {
                    asset.name = Path.GetFileName(pathnameFromFile);
                }
                asset.filePath = pathnameFromFile;
 
                lst.Add(asset);
            }
            var ordered = lst.OrderByDescending(i => i.filePath.Count(x => x == '/'));
 
            return ordered.ToList();
        }
    }
}