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:
bool CheckContainerDoneResizing()
{
// Wait until the parent has done stretching...
if ( !runOnlyOnce || !container || !Application.isPlaying )
return true;
UIStretch parentStretch = NGUITools.FindInParents<UIStretch>( container );
if ( parentStretch && parentStretch.runOnlyOnce )
{
Invoke( "Update", float.Epsilon );
return false;
}
UIAnchor parentAnchor = NGUITools.FindInParents<UIAnchor>( container );
if ( parentAnchor && parentAnchor.runOnlyOnce )
{
Invoke ( "Update", float.Epsilon );
return false;
}
return true;
}
void Update()
{
if ( !CheckContainerDoneResizing() )
return;
...
}
Similarly for UIStretch:
bool CheckContainerDoneStretching()
{
// Wait until the parent has done stretching...
if ( !runOnlyOnce || !container || !Application.isPlaying )
return true;
UIStretch parentStretch = NGUITools.FindInParents<UIStretch>( container );
if ( parentStretch && parentStretch.runOnlyOnce )
{
Invoke( "Update", float.Epsilon );
return false;
}
return true;
}
void Update ()
{
if ( !CheckContainerDoneStretching() )
return;
...
}
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.