|
9 | 9 | namespace GitHub.Unity
|
10 | 10 | {
|
11 | 11 | [Serializable]
|
12 |
| - public class Tree |
| 12 | + public class BranchesTree: Tree |
| 13 | + { |
| 14 | + [NonSerialized] public Texture2D ActiveNodeIcon; |
| 15 | + [NonSerialized] public Texture2D NodeIcon; |
| 16 | + [NonSerialized] public Texture2D FolderIcon; |
| 17 | + [NonSerialized] public Texture2D RootFolderIcon; |
| 18 | + |
| 19 | + protected override Texture2D GetNodeIcon(TreeNode node) |
| 20 | + { |
| 21 | + Texture2D nodeIcon; |
| 22 | + if (node.IsActive) |
| 23 | + { |
| 24 | + nodeIcon = ActiveNodeIcon; |
| 25 | + } |
| 26 | + else if (node.IsFolder) |
| 27 | + { |
| 28 | + if (node.Level == 1) |
| 29 | + nodeIcon = RootFolderIcon; |
| 30 | + else |
| 31 | + nodeIcon = FolderIcon; |
| 32 | + } |
| 33 | + else |
| 34 | + { |
| 35 | + nodeIcon = NodeIcon; |
| 36 | + } |
| 37 | + return nodeIcon; |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + [Serializable] |
| 42 | + public abstract class Tree |
13 | 43 | {
|
14 | 44 | public static float ItemHeight { get { return EditorGUIUtility.singleLineHeight; } }
|
15 | 45 | public static float ItemSpacing { get { return EditorGUIUtility.standardVerticalSpacing; } }
|
16 | 46 |
|
17 | 47 | [SerializeField] public Rect Margin = new Rect();
|
18 | 48 | [SerializeField] public Rect Padding = new Rect();
|
19 | 49 |
|
20 |
| - [NonSerialized] public Texture2D ActiveNodeIcon; |
21 |
| - [NonSerialized] public Texture2D NodeIcon; |
22 |
| - [NonSerialized] public Texture2D FolderIcon; |
23 |
| - [NonSerialized] public Texture2D RootFolderIcon; |
24 |
| - |
25 | 50 | [SerializeField] public GUIStyle FolderStyle;
|
26 | 51 | [SerializeField] public GUIStyle TreeNodeStyle;
|
27 | 52 | [SerializeField] public GUIStyle ActiveTreeNodeStyle;
|
@@ -82,7 +107,7 @@ public void Load(IEnumerable<ITreeData> data, string title)
|
82 | 107 | Level = 0,
|
83 | 108 | IsFolder = true
|
84 | 109 | };
|
85 |
| - SetNodeIcons(titleNode); |
| 110 | + SetNodeIcon(titleNode); |
86 | 111 | nodes.Add(titleNode);
|
87 | 112 |
|
88 | 113 | foreach (var d in data)
|
@@ -110,7 +135,7 @@ public void Load(IEnumerable<ITreeData> data, string title)
|
110 | 135 | activeNode = node;
|
111 | 136 | }
|
112 | 137 |
|
113 |
| - SetNodeIcons(node); |
| 138 | + SetNodeIcon(node); |
114 | 139 |
|
115 | 140 | nodes.Add(node);
|
116 | 141 | if (isFolder)
|
@@ -369,32 +394,19 @@ private void Unindent()
|
369 | 394 | indents.Pop();
|
370 | 395 | }
|
371 | 396 |
|
372 |
| - private void SetNodeIcons(TreeNode node) |
| 397 | + private void SetNodeIcon(TreeNode node) |
373 | 398 | {
|
374 |
| - if (node.IsActive) |
375 |
| - { |
376 |
| - node.Icon = ActiveNodeIcon; |
377 |
| - } |
378 |
| - else if (node.IsFolder) |
379 |
| - { |
380 |
| - if (node.Level == 1) |
381 |
| - node.Icon = RootFolderIcon; |
382 |
| - else |
383 |
| - node.Icon = FolderIcon; |
384 |
| - } |
385 |
| - else |
386 |
| - { |
387 |
| - node.Icon = NodeIcon; |
388 |
| - } |
389 |
| - |
| 399 | + node.Icon = GetNodeIcon(node); |
390 | 400 | node.Load();
|
391 | 401 | }
|
392 | 402 |
|
| 403 | + protected abstract Texture2D GetNodeIcon(TreeNode node); |
| 404 | + |
393 | 405 | public void LoadNodeIcons()
|
394 | 406 | {
|
395 | 407 | foreach (var treeNode in nodes)
|
396 | 408 | {
|
397 |
| - SetNodeIcons(treeNode); |
| 409 | + SetNodeIcon(treeNode); |
398 | 410 | }
|
399 | 411 | }
|
400 | 412 | }
|
|
0 commit comments