public T GetOrCreateSystem <T>(ComponentSystemGroup group) where T : ComponentSystemBase { T system = _world.GetOrCreateSystem <T>(); AddSystemToGroup(group, system); return(system); }
public ComponentSystemBase AddSystem(ComponentSystemGroup group, ComponentSystemBase system) { _world.AddSystem(system); AddSystemToGroup(group, system); return(system); }
protected override void OnCreate() { base.OnCreate(); simGroup = World.GetOrCreateSystem <SimulationSystemGroup>(); //FixedRateUtils.EnableFixedRateWithCatchUp(simGroup, UnityEngine.Time.fixedDeltaTime); FixedRateUtils.EnableFixedRateSimple(simGroup, UnityEngine.Time.fixedDeltaTime); }
public ComponentSystemBase GetOrCreateSystem(ComponentSystemGroup group, Type systemType) { ComponentSystemBase system = _world.GetOrCreateSystem(systemType); AddSystemToGroup(group, system); return(system); }
/// <summary> /// Injects all RootSuperSystems in the systems list into the world. /// Automatically creates parent ComponentSystemGroups if necessary. /// </summary> /// <param name="systems">List of systems containing the RootSuperSystems to inject using world.GetOrCreateSystem</param> /// <param name="world">The world to inject the systems 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 void InjectRootSuperSystems(List <Type> systems, World world, ComponentSystemGroup defaultGroup = null) { foreach (var type in systems) { if (typeof(RootSuperSystem).IsAssignableFrom(type)) { InjectSystem(type, world, defaultGroup); } } }
/// <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(); }
static void AddSystemAndLogException(World world, ComponentSystemGroup group, Type type) { try { group.AddSystemToUpdateList(world.GetOrCreateSystem(type) as ComponentSystemBase); } catch (Exception e) { Debug.LogException(e); } }
protected Match(MatchConfig config, World world = null) { Config = config; World = world ?? Unity.Entities.World.DefaultGameObjectInjectionWorld; Simulation = World.GetOrCreateSystem <SimulationSystemGroup>(); Simulation.Enabled = false; Simulation.SortSystems(); _blobAssetStore = new BlobAssetStore(); }
private static void PrintGroup(string groupName, ComponentSystemGroup systemGroup, ref int index, StringBuilder sb) { sb.AppendLine(groupName); sb.AppendLine("----------------------"); foreach (var system in systemGroup.Systems) { sb.AppendLine(" " + index + ".: " + system.GetType().FullName); index++; } sb.AppendLine(); }
protected override void OnCreate() { base.OnCreate(); _ = this; #if !UNITY_CLIENT m_ServerComponentGroup = World.GetExistingSystem <ServerSimulationSystemGroup>(); #endif #if !UNITY_SERVER m_ClientPresentationGroup = World.GetExistingSystem <ClientPresentationSystemGroup>(); m_ClientComponentGroup = World.GetExistingSystem <ClientSimulationSystemGroup>(); #endif }
private void AddSystemToGroup(ComponentSystemGroup group, ComponentSystemBase system) { switch (group) { case IList <ComponentSystemBase> lcsg: lcsg.Add(system); return; default: group.AddSystemToUpdateList(system); return; } }
public bool ShouldGroupUpdate(ComponentSystemGroup group) { // if this is true, means we're being called a second or later time in a loop if (m_UpdatedThisFrame) { m_UpdatedThisFrame = false; return(false); } m_UpdatedThisFrame = true; UpdateCount += 1; return(true); }
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; }
/// <summary> /// This reflection helper needed because the setter on <see cref="ComponentSystemGroup.EnableSystemSorting"/> is /// protected. /// </summary> private static void SetSystemSortingEnabled(ComponentSystemGroup group, bool enabled) { const string propertyName = "EnableSystemSorting"; PropertyInfo enableSystemSortingPropertyInfo = group.GetType() .GetProperty(propertyName) ! .DeclaringType ! .GetProperty(propertyName); enableSystemSortingPropertyInfo !.SetValue( group, enabled, BindingFlags.Instance | BindingFlags.NonPublic, null, null, CultureInfo.CurrentCulture); }
//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); }
/// <summary> /// Injects all systems made by Unity (or systems that use "Unity" in their namespace or assembly). /// Automatically creates parent ComponentSystemGroups if necessary. /// Use this instead of InjectSystemsFromNamespace because Unity sometimes forgets to put namespaces on things. /// </summary> /// <param name="systems"></param> /// <param name="world"></param> /// <param name="defaultGroup"></param> public static void InjectUnitySystems(List <Type> systems, World world, ComponentSystemGroup defaultGroup = null, bool silenceWarnings = true) { foreach (var type in systems) { if (type.Namespace == null) { if (type.Assembly.FullName.Contains("Unity") && !silenceWarnings) { Debug.LogWarning("Hey Unity Devs! You forget a namespace for " + type.ToString()); } else { continue; } } else if (!type.Namespace.Contains("Unity")) { continue; } InjectSystem(type, world, defaultGroup); } }
public ComponentSystemBase GetOrCreateSystem(ComponentSystemGroup group, Type systemType) { return(_world.GetOrCreateSystem(group, systemType)); }
/// <summary> /// Injects all systems in which contain 'namespaceSubstring within their namespaces. /// Automatically creates parent ComponentSystemGroups if necessary. /// Use this for libraries which use traditional injection to inject into the default world. /// </summary> /// <param name="systems">List of systems containing the namespaced systems to inject using world.GetOrCreateSystem</param> /// <param name="namespaceSubstring">The namespace substring to query the systems' namespace against</param> /// <param name="world">The world to inject the systems 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 void InjectSystemsFromNamespace(List <Type> systems, string namespaceSubstring, World world, ComponentSystemGroup defaultGroup = null) { foreach (var type in systems) { if (type.Namespace == null) { Debug.LogWarning("No namespace for " + type.ToString()); continue; } else if (!type.Namespace.Contains(namespaceSubstring)) { continue; } InjectSystem(type, world, defaultGroup); } }
void Start() { systemGroup = World.DefaultGameObjectInjectionWorld.GetOrCreateSystem <ComponentSystemGroup>(); spawnerSystem = World.DefaultGameObjectInjectionWorld.CreateSystem <EntitySpawnerSystem>(); systemGroup.AddSystemToUpdateList(spawnerSystem); }
public ComponentSystemBase AddSystem(ComponentSystemGroup group, ComponentSystemBase system) { return(_world.AddSystem(group, system)); }
public T GetOrCreateSystem <T>(ComponentSystemGroup group) where T : ComponentSystemBase { return(_world.GetOrCreateSystem <T>(group)); }
public T AddSystem <T>(ComponentSystemGroup group, T system) where T : ComponentSystemBase { return((T)AddSystem(group, (ComponentSystemBase)system)); }
public T AddSystem <T>(ComponentSystemGroup group, T system) where T : ComponentSystemBase { return(_world.AddSystem(group, system)); }
private void Awake() { world = World.DefaultGameObjectInjectionWorld; simGroup = world.GetExistingSystem <SimulationSystemGroup>(); simGroup.Enabled = false; }