@@ -160,12 +160,16 @@ public Rect Render(Rect rect, Vector2 scroll, Action<TreeNode> singleClick = nul
160
160
if ( DisplayRootNode )
161
161
{
162
162
var titleNode = nodes [ 0 ] ;
163
- var selectionChanged = titleNode . Render ( rect , Styles . TreeIndentation , selectedNode == titleNode , FolderStyle , TreeNodeStyle , ActiveTreeNodeStyle ) ;
163
+ var renderResult = titleNode . Render ( rect , Styles . TreeIndentation , selectedNode == titleNode , FolderStyle , TreeNodeStyle , ActiveTreeNodeStyle ) ;
164
164
165
- if ( selectionChanged )
165
+ if ( renderResult == TreeNodeRenderResult . VisibilityChange )
166
166
{
167
167
ToggleNodeVisibility ( 0 , titleNode ) ;
168
168
}
169
+ else if ( renderResult == TreeNodeRenderResult . SelectionChange )
170
+ {
171
+ ToggleNodeSelection ( 0 , titleNode ) ;
172
+ }
169
173
170
174
RequiresRepaint = HandleInput ( rect , titleNode , 0 ) ;
171
175
rect . y += ItemHeight + ItemSpacing ;
@@ -182,13 +186,16 @@ public Rect Render(Rect rect, Vector2 scroll, Action<TreeNode> singleClick = nul
182
186
{
183
187
Indent ( ) ;
184
188
}
185
- var changed = node . Render ( rect , Styles . TreeIndentation , selectedNode == node , FolderStyle , TreeNodeStyle , ActiveTreeNodeStyle ) ;
189
+ var renderResult = node . Render ( rect , Styles . TreeIndentation , selectedNode == node , FolderStyle , TreeNodeStyle , ActiveTreeNodeStyle ) ;
186
190
187
- if ( node . IsFolder && changed )
191
+ if ( renderResult == TreeNodeRenderResult . VisibilityChange )
188
192
{
189
- // toggle visibility for all the nodes under this one
190
193
ToggleNodeVisibility ( i , node ) ;
191
194
}
195
+ else if ( renderResult == TreeNodeRenderResult . SelectionChange )
196
+ {
197
+ ToggleNodeSelection ( i , node ) ;
198
+ }
192
199
193
200
if ( node . Level < level )
194
201
{
@@ -241,7 +248,28 @@ public void Blur()
241
248
RequiresRepaint = true ;
242
249
}
243
250
244
- private int ToggleNodeVisibility ( int idx , TreeNode rootNode )
251
+ private void ToggleNodeSelection ( int idx , TreeNode node )
252
+ {
253
+ if ( node . IsFolder )
254
+ {
255
+
256
+ }
257
+ else
258
+ {
259
+ switch ( node . SelectionState )
260
+ {
261
+ case SelectionState . Unselected :
262
+ node . SelectionState = SelectionState . Selected ;
263
+ break ;
264
+
265
+ case SelectionState . Selected :
266
+ node . SelectionState = SelectionState . Unselected ;
267
+ break ;
268
+ }
269
+ }
270
+ }
271
+
272
+ private void ToggleNodeVisibility ( int idx , TreeNode node )
245
273
{
246
274
var nodeLevel = node . Level ;
247
275
node . IsCollapsed = ! node . IsCollapsed ;
@@ -260,7 +288,6 @@ private int ToggleNodeVisibility(int idx, TreeNode rootNode)
260
288
{
261
289
SelectedNode = node ;
262
290
}
263
- return idx ;
264
291
}
265
292
266
293
private bool HandleInput ( Rect rect , TreeNode currentNode , int index , Action < TreeNode > singleClick = null , Action < TreeNode > doubleClick = null , Action < TreeNode > rightClick = null )
@@ -417,20 +444,23 @@ public class TreeNode
417
444
public bool IsHidden ;
418
445
public bool IsActive ;
419
446
public GUIContent content ;
420
- [ NonSerialized ] public Texture2D Icon ;
421
447
public bool Selectable ;
448
+ public SelectionState SelectionState ;
449
+
450
+ [ NonSerialized ] public Texture2D Icon ;
422
451
423
452
public void Load ( )
424
453
{
425
454
content = new GUIContent ( Label , Icon ) ;
426
455
}
427
456
428
- public bool Render ( Rect rect , float indentation , bool isSelected , GUIStyle toggleStyle , GUIStyle nodeStyle , GUIStyle activeNodeStyle )
457
+ public TreeNodeRenderResult Render ( Rect rect , float indentation , bool isSelected , GUIStyle toggleStyle , GUIStyle nodeStyle , GUIStyle activeNodeStyle )
429
458
{
459
+ var renderResult = TreeNodeRenderResult . None ;
460
+
430
461
if ( IsHidden )
431
- return false ;
462
+ return renderResult ;
432
463
433
- var changed = false ;
434
464
var fillRect = rect ;
435
465
var nodeStartX = Level * indentation * ( Selectable ? 2 : 1 ) ;
436
466
@@ -468,7 +498,10 @@ public bool Render(Rect rect, float indentation, bool isSelected, GUIStyle toggl
468
498
{
469
499
GUI . Toggle ( toggleRect , ! IsCollapsed , GUIContent . none , GUIStyle . none ) ;
470
500
}
471
- changed = EditorGUI . EndChangeCheck ( ) ;
501
+ if ( EditorGUI . EndChangeCheck ( ) )
502
+ {
503
+ renderResult = TreeNodeRenderResult . VisibilityChange ;
504
+ }
472
505
}
473
506
474
507
if ( Selectable )
@@ -479,11 +512,26 @@ public bool Render(Rect rect, float indentation, bool isSelected, GUIStyle toggl
479
512
480
513
nodeStartX += selectRect . width + 2 ;
481
514
515
+ var selectionStyle = GUI . skin . toggle ;
516
+ var selectionValue = false ;
517
+
518
+ if ( SelectionState == SelectionState . Selected )
519
+ {
520
+ selectionValue = true ;
521
+ }
522
+ else if ( SelectionState == SelectionState . Mixed )
523
+ {
524
+ selectionStyle = Styles . ToggleMixedStyle ;
525
+ }
526
+
482
527
EditorGUI . BeginChangeCheck ( ) ;
483
528
{
484
- GUI . Toggle ( selectRect , false , GUIContent . none , Styles . ToggleMixedStyle ) ;
529
+ GUI . Toggle ( selectRect , selectionValue , GUIContent . none , selectionStyle ) ;
530
+ }
531
+ if ( EditorGUI . EndChangeCheck ( ) )
532
+ {
533
+ renderResult = TreeNodeRenderResult . SelectionChange ;
485
534
}
486
- EditorGUI . EndChangeCheck ( ) ;
487
535
}
488
536
489
537
data += string . Format ( "ContentStart: {0} " , nodeStartX ) ;
@@ -497,7 +545,7 @@ public bool Render(Rect rect, float indentation, bool isSelected, GUIStyle toggl
497
545
498
546
Debug . Log ( data ) ;
499
547
500
- return changed ;
548
+ return renderResult ;
501
549
}
502
550
503
551
public override string ToString ( )
@@ -552,4 +600,18 @@ public void UpdateIcons(Texture2D activeBranchIcon, Texture2D branchIcon, Textur
552
600
}
553
601
}
554
602
}
603
+
604
+ public enum TreeNodeRenderResult
605
+ {
606
+ None ,
607
+ VisibilityChange ,
608
+ SelectionChange
609
+ }
610
+
611
+ public enum SelectionState
612
+ {
613
+ Unselected ,
614
+ Selected ,
615
+ Mixed
616
+ }
555
617
}
0 commit comments