1
- using System . Collections . Generic ;
1
+ using System ;
2
+ using System . Collections . Generic ;
2
3
using System . Linq ;
3
4
using UnityEditor ;
4
5
using UnityEngine ;
@@ -52,6 +53,7 @@ public void UpdateTab(ModularShader shader)
52
53
53
54
foreach ( var template in shader . BaseModules . Concat ( shader . AdditionalModules ) . SelectMany ( x => x . Templates ) . OrderBy ( x => x . Queue ) )
54
55
{
56
+ if ( template . Template == null ) continue ;
55
57
var module = moduleByTemplate [ template ] ;
56
58
_pairs . AddRange ( _column . AddTemplate ( module . Id , template ) ) ;
57
59
}
@@ -78,6 +80,7 @@ private void CreateGUI()
78
80
79
81
public class TemplateItemElement : VisualElement
80
82
{
83
+ public float Height => Math . Max ( _asset . Keywords . Length , 1 ) * 15 + 59 ;
81
84
private ModuleTemplate _template ;
82
85
public TemplateAsset _asset ;
83
86
public string ModuleId ;
@@ -360,22 +363,40 @@ public void AddItemsToElementsHierarchy(List<TemplatePair> pairs)
360
363
{
361
364
foreach ( var item in _items )
362
365
{
363
- int i = 0 ;
364
- float counter = 0 ;
365
- foreach ( TemplatePair pair in pairs . Where ( x => x . Left == item ) )
366
- {
367
- _bezierContainer . Add ( new BezierElement ( pair ) ) ;
368
- counter += _child ? . GetTotalStackHeight ( i ) ?? 1 ;
369
- i ++ ;
370
- }
366
+ AddChildrenToHierarchy ( item , pairs ) ;
367
+ }
368
+ }
369
+
370
+ public void AddChildrenToHierarchy ( TemplateItemElement item , List < TemplatePair > pairs )
371
+ {
372
+ if ( ! _items . Contains ( item ) ) return ;
373
+ int i = 0 ;
374
+ float counter = 0 ;
375
+ var relevantPairs = pairs . Where ( x => x . Left == item ) . ToList ( ) ;
376
+ foreach ( TemplatePair pair in relevantPairs )
377
+ {
378
+ _bezierContainer . Add ( new BezierElement ( pair ) ) ;
379
+ counter += _child ? . GetTotalStackHeight ( pair . Right ) ?? 0 ;
380
+ _child ? . AddChildrenToHierarchy ( pair . Right , pairs ) ;
381
+ i ++ ;
382
+ }
371
383
372
- if ( _child == null )
373
- {
374
- _container . Add ( item ) ;
375
- continue ;
376
- }
384
+ if ( _child == null )
385
+ {
386
+ _container . Add ( item ) ;
387
+ return ;
388
+ }
377
389
378
- float height = ( counter - ( ( item . _asset . Keywords . Length - 1 ) * 15 + 89 ) ) / 2 ;
390
+ if ( relevantPairs . Count == 0 )
391
+ {
392
+ var space = new VisualElement ( ) ;
393
+ space . style . height = item . Height ;
394
+ _child . _container . Add ( space ) ;
395
+ _container . Add ( item ) ;
396
+ }
397
+ else
398
+ {
399
+ float height = ( counter - ( item . Height ) ) / 2 ;
379
400
var space = new VisualElement ( ) ;
380
401
space . style . height = height ;
381
402
_container . Add ( space ) ;
@@ -384,18 +405,19 @@ public void AddItemsToElementsHierarchy(List<TemplatePair> pairs)
384
405
space . style . height = height ;
385
406
_container . Add ( space ) ;
386
407
}
387
-
388
- _child ? . AddItemsToElementsHierarchy ( pairs ) ;
408
+
389
409
}
390
410
391
- public float GetTotalStackHeight ( int c )
411
+ public float GetTotalStackHeight ( TemplateItemElement c )
392
412
{
393
- if ( _child == null ) return ( _items [ c ] . _asset . Keywords . Length - 1 ) * 15 + 89 ;
394
-
413
+ if ( _child == null ) return c . Height ;
414
+
415
+ int index = _items . IndexOf ( c ) ;
416
+ if ( _itemsChildren [ index ] . Length == 0 ) return c . Height ;
395
417
float counter = 0 ;
396
- for ( int i = 0 ; i < _itemsChildren [ c ] . Length ; i ++ )
418
+ for ( int i = 0 ; i < _itemsChildren [ index ] . Length ; i ++ )
397
419
{
398
- counter += _child . GetTotalStackHeight ( i ) ;
420
+ counter += _child . GetTotalStackHeight ( _itemsChildren [ index ] [ i ] ) ;
399
421
}
400
422
401
423
return counter ;
0 commit comments