Systems
ComponentSystemBase、SystemBase、ISystemBase、SystemState、Update
继承关系
- ComponentSystemBase
- SystemBase
- JobComponentSystem
- ComponentSystem
- EntityPatcherBlobAssetSystem
- RetainBlobAssetSystem
- ComponentSystemGroup
- InitializationSystemGroup
- FixedStepSimulationSystemGroup
- LateSimulationSystemGroup
- SimulationSystemGroup
- PresentationSystemGroup
- EntityCommandBufferSystem
- BeginInitializationEntityCommandBufferSystem
- EndInitializationEntityCommandBufferSystem
- BeginFixedStepSimulationEntityCommandBufferSystem
- EndFixedStepSimulationEntityCommandBufferSystem
- BeginSimulationEntityCommandBufferSystem
- EndSimulationEntityCommandBufferSystem
- BeginPresentationEntityCommandBufferSystem
生命周期
1.Create
- OnCreateForCompiler(); 被调用于CreateInstance,被调用于 World.CreateSystemInternal
- OnCreate 被调用于CreateInstance,被调用于 World.CreateSystemInternal
internal void CreateInstance(World world)
{
m_StatePtr = SystemState.Allocate();
m_StatePtr->InitManaged(world, GetType());
OnBeforeCreateInternal(world);
try
{
OnCreateForCompiler();
OnCreate();
}
catch
{
OnBeforeDestroyInternal();
OnAfterDestroyInternal();
throw;
}
}
2.OnDestroy
3. Update (主要)
- ComponentSystem.Update
public sealed override void Update()
{
var state = CheckedState();
#if ENABLE_PROFILER
using (state->m_ProfilerMarker.Auto())
#endif
{
state->BeforeUpdateResetRunTracker();
if (Enabled && ShouldRunSystem())
{
if (!state->m_PreviouslyEnabled)
{
state->m_PreviouslyEnabled = true;
OnStartRunning();
}
BeforeOnUpdate();
var oldExecutingSystem = ms_ExecutingSystem;
ms_ExecutingSystem = this;
try
{
OnUpdate();
}
finally
{
ms_ExecutingSystem = oldExecutingSystem;
AfterOnUpdate();
}
}
else if (state->m_PreviouslyEnabled)
{
state->m_PreviouslyEnabled = false;
OnStopRunningInternal();
}
}
}
- JobComponentSystem.Update
public sealed override void Update()
{
var state = CheckedState();
#if ENABLE_PROFILER
using (state->m_ProfilerMarker.Auto())
#endif
{
if (Enabled && ShouldRunSystem())
{
if (!state->m_PreviouslyEnabled)
{
state->m_PreviouslyEnabled = true;
OnStartRunning();
}
var inputJob = BeforeOnUpdate();
JobHandle outputJob = new JobHandle();
var oldExecutingSystem = ms_ExecutingSystem;
ms_ExecutingSystem = this;
try
{
outputJob = OnUpdate(inputJob);
}
catch
{
ms_ExecutingSystem = oldExecutingSystem;
AfterOnUpdate(outputJob, false);
throw;
}
ms_ExecutingSystem = oldExecutingSystem;
AfterOnUpdate(outputJob, true);
}
else if (state->m_PreviouslyEnabled)
{
state->m_PreviouslyEnabled = false;
OnStopRunning();
}
}
}
- SystemBase
public sealed override void Update()
{
var state = CheckedState();
#if ENABLE_PROFILER
using (state->m_ProfilerMarker.Auto())
#endif
{
state->BeforeUpdateResetRunTracker();
if (Enabled && ShouldRunSystem())
{
if (!state->m_PreviouslyEnabled)
{
state->m_PreviouslyEnabled = true;
OnStartRunning();
}
state->BeforeOnUpdate();
var oldExecutingSystem = ms_ExecutingSystem;
ms_ExecutingSystem = this;
try
{
OnUpdate();
}
catch
{
ms_ExecutingSystem = oldExecutingSystem;
state->AfterOnUpdate();
#if ENABLE_UNITY_COLLECTIONS_CHECKS
var hasSafetyError = false;
var details = default(SystemDependencySafetyUtility.SafetyErrorDetails);
state->CheckSafety(ref details, ref hasSafetyError);
#endif
throw;
}
ms_ExecutingSystem = oldExecutingSystem;
state->AfterOnUpdate();
#if ENABLE_UNITY_COLLECTIONS_CHECKS
{
var hasSafetyError = false;
var details = default(SystemDependencySafetyUtility.SafetyErrorDetails);
state->CheckSafety(ref details, ref hasSafetyError);
if (hasSafetyError)
{
throw new InvalidOperationException(details.FormatToString(GetType()));
}
}
#endif
}
else if (state->m_PreviouslyEnabled)
{
state->m_PreviouslyEnabled = false;
OnStopRunning();
}
}
}
包含重要对象
- SystemState