public bool TryActivateObjectByPhase(ref PhaseEnabler phaseEnabler, ref ActivatableObject activatableObject) { int phase = phaseConfig.phase; bool enabled = phase == phaseEnabler.enabledPhase; if (activatableObject.linkedObjectActive == enabled) { return(false); } activatableObject.linkedObjectActive = enabled; activatableObject.synchronized = false; return(true); }
public void ExecuteEach(EntityManager entityManager, ComponentGroup phaseEnablerGroup) { NativeArray <Entity> entities = phaseEnablerGroup.ToEntityArray(Allocator.TempJob); for (int entityIndex = 0, numEntities = entities.Length; entityIndex < numEntities; ++entityIndex) { Entity entity = entities[entityIndex]; PhaseEnabler phaseEnabler = entityManager.GetComponentData <PhaseEnabler>(entity); ActivatableObject activatableObject = entityManager.GetSharedComponentData <ActivatableObject>(entity); if (!TryActivateObjectByPhase(ref phaseEnabler, ref activatableObject)) { continue; } entityManager.SetSharedComponentData <ActivatableObject>(entity, activatableObject); } entities.Dispose(); }