Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

Initialization

UniTaskLoopRunnerYieldInitialization
UniTaskLoopRunnerInitialization
PlayerUpdateTime
DirectorSampleTime
AsyncUploadTimeSlicedUpdate
SynchronizeInputs
SynchronizeState
XREarlyUpdate
UniTaskLoopRunnerLastYieldInitialization
UniTaskLoopRunnerLastInitialization

EarlyUpdate

UniTaskLoopRunnerYieldEarlyUpdate
UniTaskLoopRunnerEarlyUpdate
PollPlayerConnection
ProfilerStartFrame
GpuTimestamp
AnalyticsCoreStatsUpdate
UnityWebRequestUpdate
ExecuteMainThreadJobs
ProcessMouseInWindow
ClearIntermediateRenderers
ClearLines
PresentBeforeUpdate
ResetFrameStatsAfterPresent
UpdateAsyncReadbackManager
UpdateStreamingManager
UpdateTextureStreamingManager
UpdatePreloading
RendererNotifyInvisible
PlayerCleanupCachedData
UpdateMainGameViewRect
UpdateCanvasRectTransform
XRUpdate
UpdateInputManager
ProcessRemoteInput
ScriptRunDelayedStartupFrame
UpdateKinect
DeliverIosPlatformEvents
TangoUpdate
DispatchEventQueueEvents
PhysicsResetInterpolatedTransformPosition
SpriteAtlasManagerUpdate
PerformanceAnalyticsUpdate
UniTaskLoopRunnerLastYieldEarlyUpdate
UniTaskLoopRunnerLastEarlyUpdate

FixedUpdate

UniTaskLoopRunnerYieldFixedUpdate
UniTaskLoopRunnerFixedUpdate
ClearLines
NewInputFixedUpdate
DirectorFixedSampleTime
AudioFixedUpdate
ScriptRunBehaviourFixedUpdate
DirectorFixedUpdate
LegacyFixedAnimationUpdate
XRFixedUpdate
PhysicsFixedUpdate
Physics2DFixedUpdate
DirectorFixedUpdatePostPhysics
ScriptRunDelayedFixedFrameRate
UniTaskLoopRunnerLastYieldFixedUpdate
UniTaskLoopRunnerLastFixedUpdate

PreUpdate

UniTaskLoopRunnerYieldPreUpdate
UniTaskLoopRunnerPreUpdate
PhysicsUpdate
Physics2DUpdate
CheckTexFieldInput
IMGUISendQueuedEvents
NewInputUpdate
SendMouseEvents
AIUpdate
WindUpdate
UpdateVideo
UniTaskLoopRunnerLastYieldPreUpdate
UniTaskLoopRunnerLastPreUpdate

Update

UniTaskLoopRunnerYieldUpdate
UniTaskLoopRunnerUpdate
ScriptRunBehaviourUpdate
ScriptRunDelayedDynamicFrameRate
ScriptRunDelayedTasks
DirectorUpdate
UniTaskLoopRunnerLastYieldUpdate
UniTaskLoopRunnerLastUpdate

PreLateUpdate

UniTaskLoopRunnerYieldPreLateUpdate
UniTaskLoopRunnerPreLateUpdate
AIUpdatePostScript
DirectorUpdateAnimationBegin
LegacyAnimationUpdate
DirectorUpdateAnimationEnd
DirectorDeferredEvaluate
EndGraphicsJobsAfterScriptUpdate
ParticleSystemBeginUpdateAll
ConstraintManagerUpdate
ScriptRunBehaviourLateUpdate
UniTaskLoopRunnerLastYieldPreLateUpdate
UniTaskLoopRunnerLastPreLateUpdate

PostLateUpdate

UniTaskLoopRunnerYieldPostLateUpdate
UniTaskLoopRunnerPostLateUpdate
PlayerSendFrameStarted
DirectorLateUpdate
ScriptRunDelayedDynamicFrameRate
PhysicsSkinnedClothBeginUpdate
UpdateRectTransform
UpdateCanvasRectTransform
PlayerUpdateCanvases
UpdateAudio
VFXUpdate
ParticleSystemEndUpdateAll
EndGraphicsJobsAfterScriptLateUpdate
UpdateCustomRenderTextures
UpdateAllRenderers
EnlightenRuntimeUpdate
UpdateAllSkinnedMeshes
ProcessWebSendMessages
SortingGroupsUpdate
UpdateVideoTextures
UpdateVideo
DirectorRenderImage
PlayerEmitCanvasGeometry
PhysicsSkinnedClothFinishUpdate
FinishFrameRendering
BatchModeUpdate
PlayerSendFrameComplete
UpdateCaptureScreenshot
PresentAfterDraw
ClearImmediateRenderers
PlayerSendFramePostPresent
UpdateResolution
InputEndFrame
TriggerEndOfFrameCallbacks
GUIClearEvents
ShaderHandleErrors
ResetInputAxis
ThreadedLoadingDebug
ProfilerSynchronizeStats
MemoryFrameMaintenance
ExecuteGameCenterCallbacks
ProfilerEndFrame
UniTaskLoopRunnerLastYieldPostLateUpdate
UniTaskLoopRunnerLastPostLateUpdate

@neuecc

This comment has been minimized.

Copy link
Owner Author

@neuecc neuecc commented May 6, 2020

// ---Script Loop
PlayerLoopTiming.Initialization
PlayerLoopTiming.LastInitialization
PlayerLoopTiming.EarlyUpdate
PlayerLoopTiming.LastEarlyUpdate
PlayerLoopTiming.PreUpdate
PlayerLoopTiming.LastPreUpdate
PlayerLoopTiming.Update
Update
yield null
yield WaitForSeconds
yield WWW
yield StartCoroutine
PlayerLoopTiming.LastUpdate
PlayerLoopTiming.PreLateUpdate
LateUpdate
PlayerLoopTiming.LastPreLateUpdate
PlayerLoopTiming.PostLateUpdate
PlayerLoopTiming.LastPostLateUpdate
yield WaitForEndOfFrame

// --- Physics Loop
PlayerLoopTiming.FixedUpdate
FixedUpdate
yield WaitForFixedUpdate
PlayerLoopTiming.LastFixedUpdate
@neuecc

This comment has been minimized.

Copy link
Owner Author

@neuecc neuecc commented Jun 7, 2020

Helper method, inject at first (PlayerLoopInfo.Inject()).
After, you can see current playerloop by Debug.Log("Loop:" + PlayerLoopInfo.CurrentLoopType).

public class PlayerLoopInfo
{
    // [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
    static void Init()
    {
        var playerLoop = UnityEngine.LowLevel.PlayerLoop.GetDefaultPlayerLoop();
        DumpPlayerLoop("Default", playerLoop);
    }

    public static void DumpPlayerLoop(string which, UnityEngine.LowLevel.PlayerLoopSystem playerLoop)
    {
        var sb = new StringBuilder();
        sb.AppendLine($"{which} PlayerLoop List");
        foreach (var header in playerLoop.subSystemList)
        {
            sb.AppendFormat("------{0}------", header.type.Name);
            sb.AppendLine();
            foreach (var subSystem in header.subSystemList)
            {
                sb.AppendFormat("{0}.{1}", header.type.Name, subSystem.type.Name);
                sb.AppendLine();

                if (subSystem.subSystemList != null)
                {
                    UnityEngine.Debug.LogWarning("More Subsystem:" + subSystem.subSystemList.Length);
                }
            }
        }

        UnityEngine.Debug.Log(sb.ToString());
    }

    public static Type CurrentLoopType { get; private set; }

    public static void Inject()
    {
        var system = PlayerLoop.GetCurrentPlayerLoop();

        for (int i = 0; i < system.subSystemList.Length; i++)
        {
            var loop = system.subSystemList[i].subSystemList.SelectMany(x =>
            {
                var t = typeof(WrapLoop<>).MakeGenericType(x.type);
                var instance = (ILoopRunner)Activator.CreateInstance(t, x.type);
                return new[] { new PlayerLoopSystem { type = t, updateDelegate = instance.Run }, x };
            }).ToArray();

            system.subSystemList[i].subSystemList = loop;
        }

        PlayerLoop.SetPlayerLoop(system);
    }

    interface ILoopRunner
    {
        void Run();
    }

    class WrapLoop<T> : ILoopRunner
    {
        readonly Type type;

        public WrapLoop(Type type)
        {
            this.type = type;
        }

        public void Run()
        {
            CurrentLoopType = type;
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment