Author Topic: Modular UIs and Init Issues  (Read 1408 times)

Jodon

  • Guest
Modular UIs and Init Issues
« on: November 21, 2013, 11:11:22 PM »
Hello,

My product requires a lot of UI work where we stretch and anchor stuff.  I've noticed in 3.0.5 and earlier, that this doesn't quite work properly when anchoring and stretching to a 'container' because of initialization order issues.  For instance, I have a deep hierarchy of anchoring/stretching but it could so happen that a child would get their UIAnchor.Start() before its parent gets a UIStretch.Start() etc. etc.  I've fixed it for the two cases I've run into.  I'm sure you can fix it more eloquently.  Here is the code I use.

UIAnchor.cs:

  1.         bool CheckContainerDoneResizing()
  2.         {
  3.                 // Wait until the parent has done stretching...
  4.                 if ( !runOnlyOnce || !container || !Application.isPlaying )
  5.                         return true;
  6.                
  7.                 UIStretch parentStretch = NGUITools.FindInParents<UIStretch>( container );
  8.                 if ( parentStretch && parentStretch.runOnlyOnce )
  9.                 {
  10.                         Invoke( "Update", float.Epsilon );
  11.                         return false;
  12.                 }
  13.  
  14.                 UIAnchor parentAnchor = NGUITools.FindInParents<UIAnchor>( container );
  15.                 if ( parentAnchor && parentAnchor.runOnlyOnce )
  16.                 {
  17.                         Invoke ( "Update", float.Epsilon );
  18.                         return false;
  19.                 }
  20.                
  21.                 return true;
  22.         }
  23.  
  24.         void Update()
  25.         {
  26.                 if ( !CheckContainerDoneResizing() )
  27.                         return;
  28.            ...
  29.          }
  30.  

Similarly for UIStretch:

  1.         bool CheckContainerDoneStretching()
  2.         {
  3.                 // Wait until the parent has done stretching...
  4.                 if ( !runOnlyOnce || !container || !Application.isPlaying )
  5.                         return true;
  6.  
  7.                 UIStretch parentStretch = NGUITools.FindInParents<UIStretch>( container );
  8.                 if ( parentStretch && parentStretch.runOnlyOnce )
  9.                 {
  10.                         Invoke( "Update", float.Epsilon );
  11.                         return false;
  12.                 }
  13.  
  14.                 return true;
  15.         }
  16.  
  17.         void Update ()
  18.         {
  19.                 if ( !CheckContainerDoneStretching() )
  20.                         return;
  21.            ...
  22.          }
  23.  

Unrelated, I also do a lot of work with UITable.  It seems UITable should have more "direction" options.  For instance I anchor to the top-right of the screen but then have no way of listing items going left-wards.  I again wrote my own code to solve this issue but I think that should be standard.

Cheers.

Jodon

  • Guest
Re: Modular UIs and Init Issues
« Reply #1 on: November 28, 2013, 07:15:38 PM »
I've updated to 3.0.6f6 and these issues still exist, so we had to re-apply this code.