Class ExperimentalDelayUpdates2
FlexBuilder normally guarantees that the layout tree is 'always correct' (unlike Unity, which frequently has a corrupt layout tree, and in many cases it CANNOT be uncorrupted). This works great, but causes a loss of performance in cases where you are making a large number of changes all in the same frame, and want FlexBuilder to temporarily stop doing relayouts until you finish the last change.
It is impossible for FlexBuilder to ignore your early changes because it has no way of knowing which change in your script was the 'last' one (earlier versions attempted to watch the tree and insert a last-minuted 'emergency relayout' during LateUpdate, but there were edge-cases where flaws in Unity's MonoBehaviour lifecycle allowed some layouts to miss this emergency layout, or to flicker due to Unity displaying incomplete renders).
This class offers a solution: it allows you to programmatically declare a section of code that FlexBuilder will watch your changes but do nothing until the section ends, at which point it will do the minimum number of relayout operations possible to bring the layout back to correct state.
Usage
This class can only be used with a C#
using( .. ) { ... }
statement. You create an instance of this
class in the '( )' brackets, and put all your own code in the '{ }' brackets.
e.g.
using( new ExperimentalDelayUpdates2() )
{
/// normally these three lines would cause 3 relayouts
/// ... but the 'using' causes only 1 relayout to be executed
myFlexItem.flexGrow = 1;
myFlexItem.flexShrink = 0;
myFlexItem.cssWidth = 50f;
}
Implementation/design
Whenever you change any field/property/setting of any FlexItem or FlexContainer, it will trigger a relayout of all affected items and UI elements - for many algorithms, that forces a ripple-effect of relayouts all the way up to the top of the tree.
When this class is active (see 'Usage' above) those triggers are all saved but not executed, until the class instance is disposed by C#, at which point all triggers execute in a single step.
Namespace: NinjaTools.FlexBuilder.LayoutAlgorithms
Assembly: cs.temp.dll.dll
Syntax
public class ExperimentalDelayUpdates2 : UsingImplementer
Constructors
- (void) ExperimentalDelayUpdates2()
- (void) ExperimentalDelayUpdates2(Boolean)
Fake, required by C# compiler because Microsoft chose to ban structs from having zero-arg constructors, instead of implementing something sane in their language
Parameters
Boolean | fakeVarCSharpSucks |
Fields
- (Boolean) add2FrameDelay
This is a workaround for a shameful bug in core Unity - some incompetent employee at Unity broke ALL object creation in 2021, and all current versions of Unity now corrupt the scene when objects are created or resized, because they introduced a 1 frame delay, after which UNITY OVERWRITES YOUR SCENE with stale data.
This flag lets you attempt to workaround Unity's bad code, but if you are doing layouts EVERY frame this could cause layouts in one frame to overlap with auto-delayed layouts from a previous frame, with unpredictable results
- (ExperimentalDelayUpdates2) currentDelayer
- (Boolean) debugShowDelayAdditions
- (Boolean) debugShowExecution
- (Boolean) debugShowStatistics
- (Boolean) discardUpdatesForDestroyedContainers
When the delay ends and resolves, any FlexContainer / GameObject that was destroyed (probably by a different part of the delayed calls somewhere else), but has an outstanding 'delayed layout request' will silently be dropped/ignored
- (Boolean) discardUpdatesForOrphanedContainers
When the delay ends and resolves, any FlexContainer / GameObject that has no RootFlexContainer, probably as side-effect of the other delayed calls somewhere else), but has an outstanding 'delayed layout request' will silently be dropped/ignored
Properties
Methods
- (void) CloseScope()
Processes all updates that should/could have happened during the delay phase
- (void)
DelayRelayout(FlexContainer, Func, Action, String, ITreeUpdateAlgorithmV4)
Parameters
FlexContainer | fc | |
Func<FlexContainer, Boolean> | stillRequiresRelayout | |
Action<FlexContainer> | layoutAction | |
String | reason | |
ITreeUpdateAlgorithmV4 | sourceTreeAlg |
- (void)
DelayRelayout_Instance(FlexContainer, Func, Action, String, ITreeUpdateAlgorithmV4)
Parameters
FlexContainer | fc | |
Func<FlexContainer, Boolean> | stillRequiresRelayout | |
Action<FlexContainer> | layoutAction | |
String | reason | |
ITreeUpdateAlgorithmV4 | sourceTreeAlg |
- (Boolean) isValid(ExperimentalDelayUpdates2)
- (IEnumerator)
OnDelayedCompleter(Dictionary>, String)
Parameters
Dictionary<FlexContainer, List<ExperimentalDelayUpdates2.DelayedCall>> | local_delayedCallsForContainers | |
String | local_rng |
Returns
IEnumerator |