少年修仙传客户端基础资源
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
using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
 
namespace Movinarc
{
    public class TreeView : EditorWindow
    {
        public TreeNode treenode;
        public TreeNode treeroot;
        public List<TreeNode> selectedNodes;
 
        public class NodePath
        {
            public TreeNode parent;
            public string path;
            public string name;
            public bool isDirectory;
        }
 
        public TreeView()
        {
            treenode = new TreeNode();
            selectedNodes = new List<TreeNode>();
            insertRoot();
        }
 
        public bool allCheckedByDefault = true;
        public bool allExpandedByDefault = true;
 
        /// <summary>
        /// Adds the node from path.
        /// </summary>
        /// <param name="path">Path.</param>
        /// <param name = "dirList"></param>
        public void AddNodeFromPath(string path, List<string> dirList, List<string> foundList)
        {
            var ph = PathHierarchy(path);
            for (int i = 0; i < ph.Count; i++)
            {
                var p = ph[i];
                if (!treenode.PathExists(p.path))
                {
                    TreeNode pathParent = treenode.GetParentNodeInPath(p.path, treeroot);
                    TreeNode node = new TreeNode();
                    node.parent = pathParent;
                    node.name = p.name;
                    node.path = TreeNode.iHateSlashes(p.path);
                    node.isDirectory = dirList.Exists((d) => d.Equals(node.path, StringComparison.OrdinalIgnoreCase));
                    node.isChecked = foundList.Exists(f => f.Equals(node.path, StringComparison.OrdinalIgnoreCase)) && allCheckedByDefault;
                    node.lastCheckedState = node.isChecked;
                    if (node.isChecked)
                        selectedNodes.Add(node);
                    node.isExpanded = allExpandedByDefault;
                    pathParent.AddNode(node);
                }
            }
        }
 
        public void ParentalCheck()
        {
            foreach (var node in selectedNodes)
            {
                doParentalCheck(node);
            }
        }
 
        private void doParentalCheck(TreeNode node)
        {
            if (node.isDirectory && node.children.Count == 0)
            {
                node.isChecked = true;
                node.lastCheckedState = true;
            }
            if (node.isChecked && node.parent != null)
            {
                node.parent.isChecked = true;
                node.parent.lastCheckedState = true;
                doParentalCheck(node.parent);
            }
        }
 
        public void EmptyFolderCheck(List<string> dirs)
        {
            var all = AssetDatabase.GetAllAssetPaths().ToList();
            var dirGuids = new List<string>();
            dirs.ForEach(d => dirGuids.Add(AssetDatabase.AssetPathToGUID(d)));
            foreach (var node in treeroot.children)
            {
                doEmptyFolderCheck(node, dirGuids, all);
            }
        }
 
        private void doEmptyFolderCheck(TreeNode node, List<string> dirs, List<string> all)
        {
            if (node.isDirectory)
            {
 
                //UnityEditor
                var found = AssetDatabase.FindAssets("", new[] { node.path }).ToList();
                PUSelection.ClearWarnings();
                if (!found.Except(dirs).Any() && all.Exists(a => a.Equals(node.path, StringComparison.OrdinalIgnoreCase)))
                {
                    node.isChecked = true;
                    node.lastCheckedState = true;
                }
                foreach (var child in node.children)
                {
                    doEmptyFolderCheck(child, dirs, all);
                }
            }
        }
 
        public void populateTree(TreeNode node, ref Rect position, Texture2D foldIcon = null, Texture2D fileIcon = null)
        {
            if (!node.isRoot)
            {
                var content = new GUIContent();
                content.text = node.name;
                if (node != null && node.path != null)
                    position.x = 5 + 15 * node.path.Split('/').Length;
                if (node.isChecked)
                {
 
                }
                if (node.isDirectory)
                {
                    position.width = 15;
                    node.isExpanded = EditorGUI.Foldout(position, node.isExpanded, "");
                    position.x += 15;
                    position.width = 500;
                    node.isChecked = GUI.Toggle(position, node.isChecked, foldIcon);
                    position.x += 15;
 
 
                }
                else //is file
                {
                    position.x += 15;
                    node.isChecked = GUI.Toggle(position, node.isChecked, fileIcon);
                    position.x += 15;
                }
                position.width = 500;
                position.x += 15;
                var lblStyle = EditorStyles.label;
                if (node.isChecked)
                {
                    lblStyle = EditorStyles.boldLabel;
                    if (!selectedNodes.Contains(node))
                    {
                        selectedNodes.Add(node);
                    }
                }
                else
                {
                    if (selectedNodes.Contains(node))
                    {
                        selectedNodes.Remove(node);
                    }
                }
                GUI.Label(position, node.name, lblStyle);
                if (node.lastCheckedState != node.isChecked)
                {
                    node.lastCheckedState = node.isChecked;
                    checkChildren(node);
                }
                position.y += position.height;
            }
 
            if (node.isExpanded)
                foreach (var child in node.children)
                {
                    position.x += 15;
                    populateTree(child, ref position, foldIcon, fileIcon);
                }
 
        }
 
        void checkChildren(TreeNode node)
        {
            foreach (var child in node.children)
            {
                child.isChecked = node.isChecked;
                if (child.children != null && child.children.Count > 0)
                    checkChildren(child);
            }
        }
 
        public void checkAll(TreeNode node, bool all)
        {
            foreach (var item in node.children)
            {
                item.isChecked = all;
                item.lastCheckedState = !all;
                if (item.children != null && item.children.Count > 0)
                    checkChildren(item);
            }
        }
 
        public void checkNone(TreeNode node)
        {
            checkAll(node, false);
        }
 
        /// <summary>
        /// Paths the hierarchy.
        /// in:
        /// Assets/1/2/3 
        ///
        /// out: 
        /// Assets
        /// Assets/1
        /// Assets/1/2
        /// Assets/1/2/3
        /// </summary>
        /// <param name="path">Path.</param>
        public static List<NodePath> PathHierarchy(string path)
        {
            var ph = getPathHierarchy(path, new List<NodePath>());
            ph.Reverse();
            return ph;
        }
 
        static List<NodePath> getPathHierarchy(string path, List<NodePath> lst)
        {
            List<string> pl = new List<string>(path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries));
            if (pl.Count > 0)
            {
                lst.Add(new NodePath() { path = path, name = pl[pl.Count - 1] });
                pl.RemoveAt(pl.Count - 1);
                string joined = TreeNode.listToPath(pl);
                getPathHierarchy(joined, lst);
            }
            return lst;
        }
 
        private void insertRoot()
        {
            TreeNode root = new TreeNode();
            root.name = "";
            root.parent = null;
            root.isRoot = true;
            root.root = null;
            root.isExpanded = true;
            root.isChecked = true;
            treenode.AddNode(root);
            treeroot = root;
            treenode.root = treeroot;
        }
    }
 
}