protected override void OnCreate() { base.OnCreate(); BeginSimulationEntityCommandBufferSystem = World.GetOrCreateSystem <BeginSimulationEntityCommandBufferSystem>(); initializationSystemGroup = World.GetOrCreateSystem <InitializationSystemGroup>(); Application.targetFrameRate = 60; }
public LatiosWorld(string name) : base(name) { BootstrapTools.PopulateTypeManagerWithGenerics(typeof(ManagedComponentTag <>), typeof(IComponent)); BootstrapTools.PopulateTypeManagerWithGenerics(typeof(ManagedComponentSystemStateTag <>), typeof(IComponent)); BootstrapTools.PopulateTypeManagerWithGenerics(typeof(CollectionComponentTag <>), typeof(ICollectionComponent)); BootstrapTools.PopulateTypeManagerWithGenerics(typeof(CollectionComponentSystemStateTag <>), typeof(ICollectionComponent)); worldGlobalEntity = new ManagedEntity(EntityManager.CreateEntity(), EntityManager); sceneGlobalEntity = new ManagedEntity(EntityManager.CreateEntity(), EntityManager); worldGlobalEntity.AddComponentData(new WorldGlobalTag()); sceneGlobalEntity.AddComponentData(new SceneGlobalTag()); m_initializationSystemGroup = GetOrCreateSystem <MyInitializationSystemGroup>(); m_simulationSystemGroup = GetOrCreateSystem <SimulationSystemGroup>(); m_presentationSystemGroup = GetOrCreateSystem <PresentationSystemGroup>(); }
public LatiosWorld(string name) : base(name) { //BootstrapTools.PopulateTypeManagerWithGenerics(typeof(ManagedComponentTag<>), typeof(IManagedComponent)); BootstrapTools.PopulateTypeManagerWithGenerics(typeof(ManagedComponentSystemStateTag <>), typeof(IManagedComponent)); //BootstrapTools.PopulateTypeManagerWithGenerics(typeof(CollectionComponentTag<>), typeof(ICollectionComponent)); BootstrapTools.PopulateTypeManagerWithGenerics(typeof(CollectionComponentSystemStateTag <>), typeof(ICollectionComponent)); worldGlobalEntity = new ManagedEntity(EntityManager.CreateEntity(), EntityManager); sceneGlobalEntity = new ManagedEntity(EntityManager.CreateEntity(), EntityManager); worldGlobalEntity.AddComponentData(new WorldGlobalTag()); sceneGlobalEntity.AddComponentData(new SceneGlobalTag()); #if UNITY_EDITOR EntityManager.SetName(worldGlobalEntity, "World Global Entity"); EntityManager.SetName(sceneGlobalEntity, "Scene Global Entity"); #endif m_initializationSystemGroup = GetOrCreateSystem <LatiosWorldInitializationSystemGroup>(); m_simulationSystemGroup = GetOrCreateSystem <LatiosSimulationSystemGroup>(); m_presentationSystemGroup = GetOrCreateSystem <LatiosPresentationSystemGroup>(); }
private void CreateWorld() { mainWorld = new World("main"); World.Active = mainWorld; initializationSystemGroup = new InitializationSystemGroup(); presentationSystemGroup = new PresentationSystemGroup(); simulationSystemGroup = new SimulationSystemGroup(); mainWorld.AddSystem(initializationSystemGroup); mainWorld.AddSystem(presentationSystemGroup); mainWorld.AddSystem(simulationSystemGroup); CreateOrAddSystem <InputSystem>(1); CreateOrAddSystem <ControlSystem>(1); CreateOrAddSystem <MovementSystem>(2); CreateOrAddSystem <Unity.Transforms.CopyTransformToGameObjectSystem>(1); entity2GameObjectMapping = new Dictionary <Entity, GameObject>(); gameObject2EntityMapping = new Dictionary <GameObject, Entity>(); entity2PoolMapping = new Dictionary <Entity, ObjectPool>(); // initializationSystemGroup.AddSystemToUpdateList(mainWorld.GetOrCreateSystem<GameStateSystem>()); // stateMachine = new StateMachine(); }
public static void Initialize(string worldName, bool editorWorld) { PlayerLoopManager.RegisterDomainUnload(DomainUnloadShutdown, 10000); var world = new World(worldName); World.Active = world; var systems = GetAllSystems(WorldSystemFilterFlags.Default); if (systems == null) { world.Dispose(); if (World.Active == world) { World.Active = null; } return; } // create presentation system and simulation system InitializationSystemGroup initializationSystemGroup = world.GetOrCreateSystem <InitializationSystemGroup>(); SimulationSystemGroup simulationSystemGroup = world.GetOrCreateSystem <SimulationSystemGroup>(); PresentationSystemGroup presentationSystemGroup = world.GetOrCreateSystem <PresentationSystemGroup>(); // Add systems to their groups, based on the [UpdateInGroup] attribute. foreach (var type in systems) { // Skip the built-in root-level systems if (type == typeof(InitializationSystemGroup) || type == typeof(SimulationSystemGroup) || type == typeof(PresentationSystemGroup)) { continue; } if (editorWorld) { if (Attribute.IsDefined(type, typeof(ExecuteInEditMode))) { Debug.LogError( $"{type} is decorated with {typeof(ExecuteInEditMode)}. Support for this attribute will be deprecated. Please use {typeof(ExecuteAlways)} instead."); } if (!Attribute.IsDefined(type, typeof(ExecuteAlways))) { continue; } } var groups = type.GetCustomAttributes(typeof(UpdateInGroupAttribute), true); if (groups.Length == 0) { simulationSystemGroup.AddSystemToUpdateList(GetOrCreateManagerAndLogException(world, type) as ComponentSystemBase); } foreach (var g in groups) { var group = g as UpdateInGroupAttribute; if (group == null) { continue; } if (!(typeof(ComponentSystemGroup)).IsAssignableFrom(group.GroupType)) { Debug.LogError($"Invalid [UpdateInGroup] attribute for {type}: {group.GroupType} must be derived from ComponentSystemGroup."); continue; } var groupMgr = GetOrCreateManagerAndLogException(world, group.GroupType); if (groupMgr == null) { Debug.LogWarning( $"Skipping creation of {type} due to errors creating the group {group.GroupType}. Fix these errors before continuing."); continue; } var groupSys = groupMgr as ComponentSystemGroup; if (groupSys != null) { groupSys.AddSystemToUpdateList(GetOrCreateManagerAndLogException(world, type) as ComponentSystemBase); } } } // Update player loop initializationSystemGroup.SortSystemUpdateList(); simulationSystemGroup.SortSystemUpdateList(); presentationSystemGroup.SortSystemUpdateList(); ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world); }
protected virtual void Start() { // set up initialization group // ReSharper disable once UnusedVariable // not used by the bootstrapper but is one of Unity's root system groups InitializationSystemGroup initGroup = AddSystem(typeof(Initialization), new InitializationSystemGroup()); SetSystemSortingEnabled(initGroup, false); // set up simulation systems SimulationSystemGroup simGroup = AddSystem(typeof(FixedUpdate), new SimulationSystemGroup()); SetSystemSortingEnabled(simGroup, false); { AddSystem(simGroup, new SimulationDestroySystem()); SimulationResetSystemGroup simResetGroup = AddSystem(simGroup, new SimulationResetSystemGroup()); SetSystemSortingEnabled(simResetGroup, false); { foreach (SystemTypeReference systemTypeReference in _simulationResetSystems) { GetOrCreateSystem(simResetGroup, systemTypeReference.SystemType); } } AddSystem(simGroup, new PreSimulationEntityCommandBufferSystem()); SimulationMainSystemGroup simMainGroup = AddSystem(simGroup, new SimulationMainSystemGroup()); SetSystemSortingEnabled(simMainGroup, false); { foreach (SystemTypeReference systemTypeReference in _mainSimulationSystems) { GetOrCreateSystem(simMainGroup, systemTypeReference.SystemType); } } AddSystem(simGroup, new PostSimulationEntityCommandBufferSystem()); } // UI interactions happen before the presentation group // set up presentation systems PresentationSystemGroup presGroup = AddSystem(typeof(Update), new PresentationSystemGroup()); SetSystemSortingEnabled(presGroup, false); { AddSystem(presGroup, new PrePresentationEntityCommandBufferSystem()); PresentationPreUpdateSystemGroup presPreUpdateGroup = AddSystem(presGroup, new PresentationPreUpdateSystemGroup()); SetSystemSortingEnabled(presPreUpdateGroup, false); { foreach (SystemTypeReference systemTypeReference in _presentationPreUpdateSystems) { GetOrCreateSystem(presPreUpdateGroup, systemTypeReference.SystemType); } } AddSystem(presGroup, new PreManagedMonoBehaviourUpdateEntityCommandBufferSystem()); AddSystem(presGroup, new ManagedMonoBehaviourUpdateSystem()); AddSystem(presGroup, new PostManagedMonoBehaviourUpdateEntityCommandBufferSystem()); PresentationPostUpdateSystemGroup presPostUpdateGroup = AddSystem(presGroup, new PresentationPostUpdateSystemGroup()); SetSystemSortingEnabled(presPostUpdateGroup, false); { foreach (SystemTypeReference systemTypeReference in _presentationPostUpdateSystems) { GetOrCreateSystem(presPostUpdateGroup, systemTypeReference.SystemType); } } AddSystem(presGroup, new PostPresentationEntityCommandBufferSystem()); AddSystem(presGroup, new PresentationDestroySystem()); AddSystem(presGroup, new PrefabSpawnSystem(this)); AddSystem(presGroup, new EndOfFrameEntityCommandBufferSystem()); EndOfFrameSystemGroup endOfFrameGroup = AddSystem(presGroup, new EndOfFrameSystemGroup()); SetSystemSortingEnabled(endOfFrameGroup, false); { foreach (SystemTypeReference systemTypeReference in _endOfFrameSystems) { GetOrCreateSystem(endOfFrameGroup, systemTypeReference.SystemType); } } } // set up archetypes ArchetypeProducer[] initialArchetypeProducers = _archetypeProducers.ToArray(); _archetypeProducers.Clear(); foreach (ArchetypeProducer archetypeProducer in initialArchetypeProducers) { AddArchetypeProducer(archetypeProducer); } }