public interface IWorldUser
Represents a user that wishes to be notified when certain events occur on a World. You can register this user via World.Register
Name | Type | Description |
---|---|---|
UseFastOnOriginCellChangedMethod | bool |
Gets a value indicating whether this users OnOriginCellChanged_Fast method should
be called rather
than its OnOriginCellChanged_Slow method. If you need to perform some work over multiple
frames
after the world has its Origin Cell changed, you should implement this property to
return false, otherwise
have it return true so OnOriginCellChanged_Fast is called.
|
UserID | int |
The ID assigned to the user at time of registration with the World. |
bool IsReadyForOriginCellChange()
Called when the World the user is registered to is about to perform an Origin Cell
Change. The World will
query all users using this method to make sure they are ready. You can return false
to tell the World your user is
not ready. The world will exit the Current frame if at least one user is not ready,
and then query
all users again in a subsequent frame. Once all users are ready, the world will call
OnOriginCellChanging before starting the Origin Cell change.
If you need to block execution of certain operations while the Origin Cell Change
is running, or run certain code to prepare your user for the change,
you should place such code within OnOriginCellChanging rather than IsReadyForOriginCellChange.
This is because some other World User may return false for IsReadyForOriginCellChange,
in which case there is no
reason for you to initiate the blocking code or run the preparation code yet. OnOriginCellChanging,
on ther other hand, is only called after all users are ready,
right before the Origin Cell Change begins, which is where you will need to initiate
the blocking code and prepare for the Origin Cell change.
An Origin Cell change can be initiated in four ways. Via the Active Grid when the
player crosses a World Reset boundary, via the Active
Grid when its TryChangeOriginCellOfWorld is called, via the World when its ChangeOriginCell
is called, or via the World when its
LoadWorldRegion method is called with setOriginCellToWorldRegionOriginCell set to
true. No matter how the Origin Cell update is initiated,
this method will be queried.
bool
Return true if the user is ready for the Origin Cell Change, false otherwise. The
Origin Cell change will not occur until all World users are
ready for it.
void OnOriginCellChanged_Fast(OriginCellChangeInfo originCellChangeInfo)
Called when the World the user is registered to has completed its Origin Cell change.
There are two methods
similarly named, OnOriginCellChanged_Fast and OnOriginCellChangeCompletedSlow.
OnOriginCellChanged_Fast is executed in a single frame and will be called when
UseFastOnOriginCellChangedMethod is implemented to return true.
This is ideal when your code is lightweight and/or doesn't need to be run over multiple
frames.
OnOriginCellChanged_Slow is executed (usually) over multiple frames by introducing
yield statements in
your method implementation, and is called when UseFastOnOriginCellChangedMethod
is implemented to return false.
Also note that if you are using a World Shifter component with its Perform Shift In
Single Frame option enabled, the
OnOriginCellChanged_Slow method will be run in a single frame, which is a waste. In
this situation, it is better to set
your UseFastOnOriginCellChangedMethod to return true and put your code in OnOriginCellChanged_Fast.
An Origin Cell change can be initiated in four ways. Via the Active Grid when the
player crosses a World Reset boundary, via the Active
Grid when its TryChangeOriginCellOfWorld is called, via the World when its ChangeOriginCell
is called, or via the World when its
LoadWorldRegion method is called with setOriginCellToWorldRegionOriginCell set to
true. No matter how the Origin Cell is initiated,
this or OnOriginCellChangeCompletedSlow will be used.
Name | Type | Description |
---|---|---|
originCellChangeInfo | OriginCellChangeInfo |
Information pertaining to the Origin Cell Change. See the OriginCellChangeInfo page for more information. |
IEnumerator<YieldInstruction> OnOriginCellChanged_Slow(OriginCellChangeInfo originCellChangeInfo)
Called when the World the user is registered to has completed its Origin Cell change.
There are two methods
similarly named, OnOriginCellChangeCompletedFast and OnOriginCellChanged_Slow.
OnOriginCellChanged_Fast is executed in a single frame and will be called when
UseFastOnOriginCellChangedMethod is implemented to return true.
This is ideal when your code is lightweight and/or doesn't need to be run over multiple
frames.
OnOriginCellChanged_Slow is executed (usually) over multiple frames by introducing
yield statements in
your method implementation, and is called when UseFastOnOriginCellChangedMethod
is implemented to return false.
Also note that if you are using a World Shift component with its Perform Shift In
Single Frame option enabled, the
OnOriginCellChanged_Slow method will be run in a single frame, which is a waste. In
this situation, it is better to set
your UseFastOnOriginCellChangedMethod to return true and put your code in OnOriginCellChanged_Fast.
An Origin Cell change can be initiated in four ways. Via the Active Grid when the
player crosses a World Reset boundary, via the Active
Grid when its TryChangeOriginCellOfWorld is called, via the World when its ChangeOriginCell
is called, or via the World when its
LoadWorldRegion method is called with setOriginCellToWorldRegionOriginCell set to
true. No matter how the Origin Cell is initiated,
this or OnOriginCellChangeCompletedFast will be used.
Name | Type | Description |
---|---|---|
originCellChangeInfo | OriginCellChangeInfo |
Information pertaining to the Origin Cell Change. See the OriginCellChangeInfo page for more information. |
IEnumerator<YieldInstruction>
An IEnumerator<YieldInstruction> that can be iterated over or used as a coroutine.
See the
YieldInstruction page for more info.
void OnOriginCellChanging()
Called before an Origin Cell Change has started, after all World Users have returned
true for
IsReadyForOriginCellChange.
You can place code that prepares for the update or blocks other code from executing
(that would interfere or cause issues if it ran at the same time as the change) here.
Such code should not
be placed inside of the IsReadyForOriginCellChange, as even if one user returns true for this
method, one or more other users may return false, in which case the change will not
proceed.
An Origin Cell change can be initiated in four ways. Via the Active Grid when the
player crosses a World Reset boundary, via the Active
Grid when its TryChangeOriginCellOfWorld is called, via the World when its ChangeOriginCell
is called, or via the World when its
LoadWorldRegion method is called with setOriginCellToWorldRegionOriginCell set to
true. No matter how the Origin Cell is initiated,
this method will be queried.
void OnOriginCellsClamped(ClampingOperationInfo operationInfo)
Called when a World's Origin Cell and its Zone Groupings' Origin Cells are clamped. See the ClampOriginCell method for more information.
Name | Type | Description |
---|---|---|
operationInfo | ClampingOperationInfo |
Information about the Clamping Operation. See the ClampingOperationInfo page for more information. |
bool TryDesyncFromWorld(bool failureWillDelayDestruction)
Called when the World the user is registered to is about to be destroyed. There are
two scenarios where this can occur:
1) The World is being destroyed via the Component Manager. In this case {BoldTagOpen}failureWillDelayDestruction{BoldTagClose}
will be true and
the destruction of the World can be delayed by the World User, by returning false
in the method body.
This can be used if an operation is being performed that would fail if the World were
destroyed, or result in cascading errors.
Each user has the method queried and if one of them returns false for this method,
a frame is yielded and the users are queried again afterwards.
The cycle repeats until all users desync correctly. Please note, however, that once
a user desyncs (and returns true), they will not be queried
again (this differs from the way
IsReadyForOriginCellChange works). Only users that fail to desync are queried again.
2) The World is being destroyed via a Destroy method call or the application quitting
(which could be exiting play mode if in the editor).
In this scenario the destruction cannot be delayed, so failureWillDelayDestruction
will be false. Your users must perform as much cleanup as
they can and should generally return true. If they return false, an error message
is printed giving you details about the user that failed to desync and the World that
was destroyed.
Name | Type | Description |
---|---|---|
failureWillDelayDestruction | bool |
For option 1 above, failureWillDelayDestruction will be true to indicate that a failed desync will cause a delay, and that the TryDesyncFromWorld will be re-queried again in the future if you return false. For option 2, failureWillDelayDestruction will be false to indicate that the user cannot delay the destruction and this will be there one and only chance to desync (the method will not be called again). |
bool
True if the user was able to sucessfully desync from the world, false otherwise. It's
recommended to always return true when failureWillDelayDestruction is false, as returning
false
will only cause an error to print (but will accomplish nothing else).