@@ -486,39 +486,103 @@ public T ReplaceOrPush<T>(MonoView instance) where T : MonoView
486486 /// Moves the specified instance to the top of the stack. If the instance is not in the stack, does nothing.
487487 /// </summary>
488488 /// <param name="instance"></param>
489- public void MoveToTop ( MonoView instance )
489+ public bool MoveToTop ( MonoView instance )
490490 {
491491 int idx = _stack . IndexOf ( instance ) ;
492492 if ( idx == - 1 )
493493 {
494494 Debug . LogError ( "[WindowStack] The provided window instance is not in the stack." , this ) ;
495- return ;
495+ return false ;
496496 }
497497
498498 if ( idx == _stack . Count - 1 )
499- return ;
499+ return false ;
500+
501+ _stack . RemoveAt ( idx ) ;
502+ _stack . Add ( instance ) ;
503+ instance . transform . SetAsLastSibling ( ) ;
504+ UpdateOrder ( idx ) ;
505+ UpdateVisibility ( ) ;
506+ return true ;
507+ }
508+
509+ public bool TryMoveToTop ( MonoView instance )
510+ {
511+ int idx = _stack . IndexOf ( instance ) ;
512+ if ( idx == - 1 )
513+ return false ;
514+
515+ if ( idx == _stack . Count - 1 )
516+ return false ;
500517
501518 _stack . RemoveAt ( idx ) ;
502519 _stack . Add ( instance ) ;
503520 instance . transform . SetAsLastSibling ( ) ;
504521 UpdateOrder ( idx ) ;
505522 UpdateVisibility ( ) ;
523+ return true ;
524+ }
525+
526+ /// <summary>
527+ /// Moves the first instance of the specified type to the top of the stack. If no instance of that type is found, does nothing.
528+ /// </summary>
529+ /// <typeparam name="T"></typeparam>
530+ public bool MoveToTop < T > ( ) where T : MonoView
531+ {
532+ for ( int i = 0 ; i < _stack . Count ; i ++ )
533+ {
534+ if ( _stack [ i ] is T instance )
535+ return MoveToTop ( instance ) ;
536+ }
537+
538+ return false ;
506539 }
507540
508541 /// <summary>
509542 /// Moves the first instance of the specified type to the top of the stack. If no instance of that type is found, does nothing.
510543 /// </summary>
511544 /// <typeparam name="T"></typeparam>
512- public void MoveToTop < T > ( ) where T : MonoView
545+ public bool TryMoveToTop < T > ( ) where T : MonoView
513546 {
514547 for ( int i = 0 ; i < _stack . Count ; i ++ )
515548 {
516549 if ( _stack [ i ] is T instance )
550+ return TryMoveToTop ( instance ) ;
551+ }
552+
553+ return false ;
554+ }
555+
556+ /// <summary>
557+ /// Returns true if the stack contains at least one instance of the specified type, false otherwise.
558+ /// </summary>
559+ public bool Contains < T > ( ) where T : MonoView
560+ {
561+ for ( int i = 0 ; i < _stack . Count ; i ++ )
562+ {
563+ if ( _stack [ i ] is T )
517564 {
518- MoveToTop ( instance ) ;
519- return ;
565+ return true ;
520566 }
521567 }
568+
569+ return false ;
570+ }
571+
572+ /// <summary>
573+ /// Returns the first instance of the specified type in the stack, or null if no instance of that type is found.
574+ /// </summary>
575+ public T GetFirstView < T > ( ) where T : MonoView
576+ {
577+ for ( int i = 0 ; i < _stack . Count ; i ++ )
578+ {
579+ if ( _stack [ i ] is T view )
580+ {
581+ return view ;
582+ }
583+ }
584+
585+ return null ;
522586 }
523587
524588 private void RemoveTop ( )
0 commit comments