@@ -23,6 +23,7 @@ public abstract class Tree
23
23
[ SerializeField ] public string PathIgnoreRoot ;
24
24
[ SerializeField ] public string PathSeparator = "/" ;
25
25
[ SerializeField ] public bool DisplayRootNode = true ;
26
+ [ SerializeField ] public bool Selectable = false ;
26
27
[ SerializeField ] public GUIStyle FolderStyle ;
27
28
[ SerializeField ] public GUIStyle TreeNodeStyle ;
28
29
[ SerializeField ] public GUIStyle ActiveTreeNodeStyle ;
@@ -69,7 +70,8 @@ public void Load(IEnumerable<ITreeData> data, string title)
69
70
Name = title ,
70
71
Label = title ,
71
72
Level = - 1 + displayRootLevel ,
72
- IsFolder = true
73
+ IsFolder = true ,
74
+ Selectable = Selectable
73
75
} ;
74
76
SetNodeIcon ( titleNode ) ;
75
77
nodes . Add ( titleNode ) ;
@@ -105,7 +107,8 @@ public void Load(IEnumerable<ITreeData> data, string title)
105
107
IsActive = d . IsActive ,
106
108
Label = label ,
107
109
Level = i + displayRootLevel ,
108
- IsFolder = isFolder
110
+ IsFolder = isFolder ,
111
+ Selectable = Selectable
109
112
} ;
110
113
111
114
if ( node . IsActive )
@@ -162,7 +165,7 @@ public Rect Render(Rect rect, Vector2 scroll, Action<TreeNode> singleClick = nul
162
165
if ( DisplayRootNode )
163
166
{
164
167
var titleNode = nodes [ 0 ] ;
165
- var selectionChanged = titleNode . Render ( rect , 0f , selectedNode == titleNode , FolderStyle , TreeNodeStyle , ActiveTreeNodeStyle ) ;
168
+ var selectionChanged = titleNode . Render ( rect , Styles . TreeIndentation , selectedNode == titleNode , FolderStyle , TreeNodeStyle , ActiveTreeNodeStyle ) ;
166
169
167
170
if ( selectionChanged )
168
171
{
@@ -428,53 +431,85 @@ public class TreeNode
428
431
public bool IsActive ;
429
432
public GUIContent content ;
430
433
[ NonSerialized ] public Texture2D Icon ;
434
+ public bool Selectable ;
431
435
432
436
public void Load ( )
433
437
{
434
438
content = new GUIContent ( Label , Icon ) ;
435
439
}
436
440
437
- public bool Render ( Rect rect , float indentation , bool isSelected , GUIStyle folderStyle , GUIStyle nodeStyle , GUIStyle activeNodeStyle )
441
+ public bool Render ( Rect rect , float indentation , bool isSelected , GUIStyle toggleStyle , GUIStyle nodeStyle , GUIStyle activeNodeStyle )
438
442
{
439
443
if ( IsHidden )
440
444
return false ;
441
445
442
- GUIStyle style ;
443
- if ( IsFolder )
444
- {
445
- style = folderStyle ;
446
- }
447
- else
446
+ var changed = false ;
447
+ var fillRect = rect ;
448
+ var nodeStartX = Level * indentation * ( Selectable ? 2 : 1 ) ;
449
+
450
+ if ( Selectable && Level > 0 )
448
451
{
449
- style = IsActive ? activeNodeStyle : nodeStyle ;
452
+ nodeStartX += 2 * Level ;
450
453
}
451
454
452
- bool changed = false ;
453
- var fillRect = rect ;
454
- var nodeRect = new Rect ( Level * indentation , rect . y , rect . width , rect . height ) ;
455
+ var nodeRect = new Rect ( nodeStartX , rect . y , rect . width , rect . height ) ;
456
+
457
+ var data = string . Format ( "Label: {0} " , Label ) ;
458
+ data += string . Format ( "Start: {0} " , nodeStartX ) ;
455
459
456
460
if ( Event . current . type == EventType . repaint )
457
461
{
458
462
nodeStyle . Draw ( fillRect , GUIContent . none , false , false , false , isSelected ) ;
459
- if ( IsFolder )
463
+ }
464
+
465
+ var styleOn = false ;
466
+ if ( IsFolder )
467
+ {
468
+ data += string . Format ( "FolderStart: {0} " , nodeStartX ) ;
469
+
470
+ var toggleRect = new Rect ( nodeStartX , nodeRect . y , indentation , nodeRect . height ) ;
471
+ nodeStartX += toggleRect . width ;
472
+
473
+ styleOn = ! IsCollapsed ;
474
+
475
+ if ( Event . current . type == EventType . repaint )
460
476
{
461
- style . Draw ( nodeRect , content , false , false , ! IsCollapsed , isSelected ) ;
477
+ toggleStyle . Draw ( toggleRect , GUIContent . none , false , false , styleOn , isSelected ) ;
462
478
}
463
- else
479
+
480
+ EditorGUI . BeginChangeCheck ( ) ;
464
481
{
465
- style . Draw ( nodeRect , content , false , false , false , isSelected ) ;
482
+ GUI . Toggle ( toggleRect , ! IsCollapsed , GUIContent . none , GUIStyle . none ) ;
466
483
}
484
+ changed = EditorGUI . EndChangeCheck ( ) ;
467
485
}
468
486
469
- if ( IsFolder )
487
+ if ( Selectable )
470
488
{
471
- var toggleRect = new Rect ( nodeRect . x , nodeRect . y , style . border . horizontal , nodeRect . height ) ;
489
+ data += string . Format ( "SelectStart: {0} " , nodeStartX ) ;
490
+
491
+ var selectRect = new Rect ( nodeStartX , nodeRect . y , indentation , nodeRect . height ) ;
492
+
493
+ nodeStartX += selectRect . width + 2 ;
472
494
473
495
EditorGUI . BeginChangeCheck ( ) ;
474
- GUI . Toggle ( toggleRect , ! IsCollapsed , GUIContent . none , GUIStyle . none ) ;
475
- changed = EditorGUI . EndChangeCheck ( ) ;
496
+ {
497
+ GUI . Toggle ( selectRect , false , GUIContent . none , Styles . ToggleMixedStyle ) ;
498
+ }
499
+ EditorGUI . EndChangeCheck ( ) ;
476
500
}
477
501
502
+ data += string . Format ( "ContentStart: {0} " , nodeStartX ) ;
503
+ var contentStyle = IsActive ? activeNodeStyle : nodeStyle ;
504
+
505
+ var contentRect = new Rect ( nodeStartX , rect . y , rect . width , rect . height ) ;
506
+ if ( Event . current . type == EventType . repaint )
507
+ {
508
+ contentStyle . Draw ( contentRect , content , false , false , styleOn , isSelected ) ;
509
+ }
510
+
511
+ Debug . Log ( data ) ;
512
+
478
513
return changed ;
479
514
}
480
515
0 commit comments