public void SetUp()
        {
            m_DefaultWorld    = World.DefaultGameObjectInjectionWorld;
            m_TestSystemGroup = m_DefaultWorld.GetOrCreateSystem <SystemScheduleTestGroup>();
            m_TestSystem1     = m_DefaultWorld.GetOrCreateSystem <SystemScheduleTestSystem1>();
            m_TestSystem2     = m_DefaultWorld.GetOrCreateSystem <SystemScheduleTestSystem2>();
            m_TestSystemGroup.AddSystemToUpdateList(m_TestSystem1);
            m_TestSystemGroup.AddSystemToUpdateList(m_TestSystem2);
            m_DefaultWorld.GetOrCreateSystem <SimulationSystemGroup>().AddSystemToUpdateList(m_TestSystemGroup);

            m_SystemScheduleWindow = !EditorApplication.isPlaying ? SystemScheduleTestUtilities.CreateSystemsWindow() : EditorWindow.GetWindow <SystemScheduleWindow>();

            m_SystemScheduleWindow.SelectedWorld = m_DefaultWorld;
            m_SystemScheduleWindow.BaseState.SelectedWorldName = k_SystemScheduleEditorWorld;
        }
 static void AddSystemAndLogException(World world, ComponentSystemGroup group, Type type)
 {
     try
     {
         group.AddSystemToUpdateList(world.GetOrCreateSystem(type) as ComponentSystemBase);
     }
     catch (Exception e)
     {
         Debug.LogException(e);
     }
 }
        /// <summary>
        /// Creates as system and adds it to provided component system group
        /// </summary>
        /// <param name="world"></param>
        /// <param name="systemType"></param>
        /// <param name="componentSystemGroup"></param>
        /// <exception cref="ArgumentNullException">Thrown if componentSystemGroup or systemType is null</exception>
        /// <exception cref="ArgumentException">Thrown if systemType is not a ComponentSystemBase</exception>
        public static void CreateInGroup(this World world, Type systemType, ComponentSystemGroup componentSystemGroup)
        {
            ThrowIfNotComponentSystem(systemType);

            if (componentSystemGroup is null)
            {
                throw new ArgumentNullException(nameof(componentSystemGroup));
            }
            componentSystemGroup.AddSystemToUpdateList(world.CreateSystem(systemType));
            //componentSystemGroup.SortSystemUpdateList();
        }
Exemple #4
0
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Alpha1))
     {
         this.onSpawn?.Invoke(spawnCount, spawnRadiusMinMax);
         if (moveJobSystem == null)
         {
             moveJobSystem = World.DefaultGameObjectInjectionWorld.CreateSystem <MoveJobSystem>();
             moveJobSystem.Init(new Vector3(0, 0, 0));
             systemGroup.AddSystemToUpdateList(moveJobSystem);
         }
     }
 }
        private void AddSystemToGroup(ComponentSystemGroup group, ComponentSystemBase system)
        {
            switch (group)
            {
            case IList <ComponentSystemBase> lcsg:
                lcsg.Add(system);
                return;

            default:
                group.AddSystemToUpdateList(system);
                return;
            }
        }
        //Copied and pasted from Entities package and then modified as needed.
        /// <summary>
        /// Injects the system into the world. Automatically creates parent ComponentSystemGroups if necessary.
        /// </summary>
        /// <remarks>This function does nothing for unmanaged systems.</remarks>
        /// <param name="type">The type to inject. Uses world.GetOrCreateSystem</param>
        /// <param name="world">The world to inject the system into</param>
        /// <param name="defaultGroup">If no UpdateInGroupAttributes exist on the type and this value is not null, the system is injected in this group</param>
        public static ComponentSystemBase InjectSystem(Type type, World world, ComponentSystemGroup defaultGroup = null)
        {
            if (!typeof(ComponentSystemBase).IsAssignableFrom(type))
            {
                return(null);
            }

            var groups = type.GetCustomAttributes(typeof(UpdateInGroupAttribute), true);
            ComponentSystemBase result = null;

            if (groups.Length == 0 && defaultGroup != null)
            {
                result = world.GetOrCreateSystem(type);
                defaultGroup.AddSystemToUpdateList(result);
                return(result);
            }

            foreach (var g in groups)
            {
                if (!(g is UpdateInGroupAttribute group))
                {
                    continue;
                }

                if (!(typeof(ComponentSystemGroup)).IsAssignableFrom(group.GroupType))
                {
                    Debug.LogError($"Invalid [UpdateInGroup] attribute for {type}: {group.GroupType} must be derived from ComponentSystemGroup.");
                    continue;
                }

                var groupMgr = world.GetExistingSystem(group.GroupType);
                if (groupMgr == null)
                {
                    groupMgr = InjectSystem(group.GroupType, world, defaultGroup);
                }
                var groupTarget = groupMgr as ComponentSystemGroup;
                result = world.GetOrCreateSystem(type);
                groupTarget.AddSystemToUpdateList(result);
            }
            return(result);
        }
Exemple #7
0
 void Start()
 {
     systemGroup   = World.DefaultGameObjectInjectionWorld.GetOrCreateSystem <ComponentSystemGroup>();
     spawnerSystem = World.DefaultGameObjectInjectionWorld.CreateSystem <EntitySpawnerSystem>();
     systemGroup.AddSystemToUpdateList(spawnerSystem);
 }