少年修仙传客户端基础资源
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
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
 
namespace UnityEngine.AssetBundles
{
    [System.Serializable]
    public class AssetBundleInspectTab
    {
        Rect m_Position;
        [SerializeField]
        private Vector2 m_ScrollPosition;
 
        [SerializeField]
        private InspectTabData m_Data;
        
 
        private List<string> m_BundleList = new List<string>();
        private InspectBundleTree m_BundleTreeView;
        [SerializeField]
        private TreeViewState m_BundleTreeState;
 
        public Editor m_Editor = null;
 
        //[SerializeField] 
        private List<AssetBundle> m_LoadedBundles;
 
        private SingleBundleInspector m_SingleInspector;
 
 
        public AssetBundleInspectTab()
        {
            m_LoadedBundles = new List<AssetBundle>();
            m_SingleInspector = new SingleBundleInspector();
        }
 
        public void SaveBundle(AssetBundle b)
        { 
            m_LoadedBundles.Add(b);
        }
 
        public void OnEnable(Rect pos, EditorWindow parent)
        {
            m_Position = pos;
            if (m_Data == null)
                m_Data = new InspectTabData();
 
            //LoadData...
            var dataPath = System.IO.Path.GetFullPath(".");
            dataPath = dataPath.Replace("\\", "/");
            dataPath += "/Library/AssetBundleBrowserInspect.dat";
 
            if (File.Exists(dataPath))
            {
                BinaryFormatter bf = new BinaryFormatter();
                FileStream file = File.Open(dataPath, FileMode.Open);
                var data = bf.Deserialize(file) as InspectTabData;
                if (data != null)
                    m_Data = data;
                file.Close();
            }
 
 
            if (m_BundleList == null)
                m_BundleList = new List<string>(); 
 
            if (m_BundleTreeState == null)
                m_BundleTreeState = new TreeViewState();
            m_BundleTreeView = new InspectBundleTree(m_BundleTreeState, this);
            m_BundleTreeView.Reload();
 
 
            RefreshBundles();
            
        }
 
        public void OnDisable()
        {
            ClearData();
 
            var dataPath = System.IO.Path.GetFullPath(".");
            dataPath = dataPath.Replace("\\", "/");
            dataPath += "/Library/AssetBundleBrowserInspect.dat";
 
            BinaryFormatter bf = new BinaryFormatter();
            FileStream file = File.Create(dataPath);
 
            bf.Serialize(file, m_Data);
            file.Close();
        }
 
        public void OnGUI(Rect pos)
        {
            m_Position = pos;
 
            if (Application.isPlaying)
            {
                var style = GUI.skin.label;
                style.alignment = TextAnchor.MiddleCenter;
                style.wordWrap = true;
                GUI.Label(
                    new Rect(m_Position.x + 1f, m_Position.y + 1f, m_Position.width - 2f, m_Position.height - 2f),
                    new GUIContent("Inspector unavailable while in PLAY mode"),
                    style);
            }
            else
            {
                OnGUIEditor();
            }
        }
 
        private void OnGUIEditor()
        {
            //////input path
            EditorGUILayout.Space();
            GUILayout.BeginHorizontal();
            var originalPath = m_Data.m_BundlePath;
            m_Data.m_BundlePath = EditorGUILayout.TextField("Bundle Path", m_Data.m_BundlePath);
            
            if (GUILayout.Button("Browse", GUILayout.MaxWidth(75f)))
                BrowseForFolder();
            GUILayout.EndHorizontal();
            EditorGUILayout.Space();
 
            if (originalPath != m_Data.m_BundlePath)
            {
                RefreshBundles();
            }
 
            if (m_BundleList.Count > 0)
            {
                m_BundleTreeView.OnGUI(new Rect(m_Position.x, m_Position.y + 30, m_Position.width / 2.0f, m_Position.height - 30));
                m_SingleInspector.OnGUI(new Rect(m_Position.x + m_Position.width / 2.0f, m_Position.y + 30, m_Position.width / 2.0f, m_Position.height - 30));
            }
        }
 
        //TODO - this is largely copied from BuildTab, should maybe be shared code.
        private void BrowseForFolder()
        {
            var newPath = EditorUtility.OpenFolderPanel("Bundle Folder", m_Data.m_BundlePath, string.Empty);
            if (!string.IsNullOrEmpty(newPath))
            {
                var gamePath = System.IO.Path.GetFullPath(".");//TODO - FileUtil.GetProjectRelativePath??
                gamePath = gamePath.Replace("\\", "/");
                if (newPath.StartsWith(gamePath))
                    newPath = newPath.Remove(0, gamePath.Length + 1);
                m_Data.m_BundlePath = newPath;
            }
        }
        public void RefreshBundles()
        {
            ClearData();
 
            //DesignDebug.Log("Did someone say refresh?");
            //do some loading
            LoadBundles();
        }
        private void ClearData()
        {
            m_SingleInspector.SetBundle(null);
 
            foreach (var bundle in m_LoadedBundles)
            {
                if (bundle != null) //get into this situation on a rare restart weirdness.
                    bundle.Unload(true);
            }
            m_LoadedBundles.Clear();
        }
        private void AddFilePathToList(string path)
        {
            //////////////////////////////////////
            /// code to handle appended hash things
            //var files = Directory.GetFiles(path);
            //Array.Sort(files);
            //int size = files.Length;
            //for (int i = 0; i < size; i++)
            //{
            //    ... do something...
            //}
            //////////////////////////////////////
 
 
            foreach (var file in Directory.GetFiles(path))
            {
                if (Path.GetExtension(file) == ".manifest")
                {
                    var f = file.Substring(0, file.LastIndexOf('.')).Replace('\\', '/');
                    if (File.Exists(f))
                        m_BundleList.Add(f);
                    else
                        DebugEx.Log("Expected bundle not found: " + f + ". Note: Browser does not yet support inspecting bundles with hash appended.");
                }
            }
 
            foreach (var dir in Directory.GetDirectories(path))
            {
                AddFilePathToList(dir);
            }
        }
        private void LoadBundles()
        {
            if (m_Data.m_BundlePath == string.Empty)
                return;
            
            //find assets
            if (m_BundleList == null)
                m_BundleList = new List<string>();
 
            m_BundleList.Clear();
            if (Directory.Exists(m_Data.m_BundlePath))
            {
                AddFilePathToList(m_Data.m_BundlePath);
            }
            m_BundleTreeView.Reload();
        }
 
        public List<string> BundleList
        { get { return m_BundleList; } }
 
 
        public void SetBundleItem(InspectTreeItem selected)
        {
            if (selected == null)
                m_SingleInspector.SetBundle(null);
            else
                m_SingleInspector.SetBundle(selected.bundle, selected.bundlePath);
        }
 
        [System.Serializable]
        public class InspectTabData
        {
            public string m_BundlePath = string.Empty;
        }
    }
}