-
Notifications
You must be signed in to change notification settings - Fork 3
App
DucNV_2000 edited this page Jul 11, 2024
·
2 revisions
App is the struct helper reference to MonoGlobal. It provides the following support methods
-
SubTick,SubFixedTick,SubLateTick: Register to update onMonoGlobal
Example
private void Awake()
{
App.SubTick(CustomUpdate);
App.SubFixedTick(CustomFixedUpdate);
App.SubLateTick(CustomLateUpdate);
}
private void CustomUpdate()
{
Debug.Log("Update");
}
private void CustomFixedUpdate()
{
Debug.Log("Fixed Update");
}
private void CustomLateUpdate()
{
Debug.Log("Late Update");
}-
UnSubTick,UnSubFixedTick,UnSubLateTick: Cancel registration to perform updates on MonoGlobal
Example
private void OnDisable()
{
App.UnSubTick(CustomUpdate);
App.UnSubFixedTick(CustomFixedUpdate);
App.UnSubLateTick(CustomLateUpdate);
}
private void CustomUpdate()
{
Debug.Log("Update");
}
private void CustomFixedUpdate()
{
Debug.Log("Fixed Update");
}
private void CustomLateUpdate()
{
Debug.Log("Late Update");
}-
AddPauseCallback: insert callback inside OnApplicationPause -
RemovePauseCallback:remove callback inside OnApplicationPause if it exits -
AddFocusCallback: insert callback inside OnApplicationFocus -
RemoveFocusCallback: remove callback inside OnApplicationFocus if it exits -
AddQuitCallback: insert callback inside OnApplicationQuit -
RemoveQuitCallback:remove callback inside OnApplicationQuit if it exits -
StartCoroutine: start coroutine by MonoGlobal -
StopCoroutine: stop coroutine by MonoGlobal -
StopAllCoroutine: stop all coroutine by MonoGlobal -
ToMainThread: Converts the specified action to one that runs on the main thread. The converted action will be invoked upon the next Unity Update event. -
RunOnMainThread: Schedules the specifies action to be run on the main thread (game thread). The action will be invoked upon the next Unity Update event. -
Delay: Handle delay
Example
private void A()
{
App.Delay(1.5f, () => { Debug.Log("OnCompleted"); });
}-
CancelDelay:
Example
private void A()
{
var handleDelay = App.Delay(1.5f, () => { Debug.Log("OnCompleted"); });
App.CancelDelay(handleDelay);
}-
PauseDelay:
Example
private void A()
{
var handleDelay = App.Delay(1.5f, () => { Debug.Log("OnCompleted"); });
App.PauseDelay(handleDelay);
}-
ResumeDelay:
Example
private void A()
{
var handleDelay = App.Delay(1.5f, () => { Debug.Log("OnCompleted"); });
App.ResumeDelay(handleDelay);
}-
CancelAllDelay,PauseAllDelay,ResumeAllDelay:
Example
private void A()
{
App.CancelAllDelay();
App.PauseAllDelay();
App.ResumeAllDelay();
}- Note: Safe Delay call when it had target, progress delay will be cancel when target was destroyed (The target is MonoBehaviour)
private void A()
{
App.Delay(this, 1.5f, () => { Debug.Log("OnCompleted"); }); // the target is `this`
}