public Differs(IEntityHierarchy hierarchy) { foreach (var componentType in hierarchy.Strategy.ComponentsToWatch) { if (!ComponentDataDiffer.CanWatch(componentType) && !SharedComponentDataDiffer.CanWatch(componentType)) { throw new NotSupportedException($" The component {componentType} requested by strategy of type {hierarchy.Strategy.GetType()} cannot be watched. No suitable differ available."); } } m_Hierarchy = hierarchy; m_EntityDiffer = new EntityDiffer(hierarchy.World); foreach (var componentToWatch in hierarchy.Strategy.ComponentsToWatch) { var typeInfo = TypeManager.GetTypeInfo(componentToWatch.TypeIndex); switch (typeInfo.Category) { case TypeManager.TypeCategory.ComponentData when UnsafeUtility.IsUnmanaged(componentToWatch.GetManagedType()): m_ComponentDataDiffers.Add((new ComponentDataDiffer(componentToWatch))); break; case TypeManager.TypeCategory.ISharedComponentData: m_SharedComponentDataDiffers.Add((new SharedComponentDataDiffer(componentToWatch))); break; } } m_ComponentDataDifferResults = new ComponentDataDiffer.ComponentChanges[m_ComponentDataDiffers.Count]; m_SharedComponentDataDifferResults = new SharedComponentDataDiffer.ComponentChanges[m_SharedComponentDataDiffers.Count]; }
public EntityHierarchyDiffer(IEntityHierarchy hierarchy, int cooldownDurationInMs = 0) { m_Hierarchy = hierarchy; m_Cooldown = new Cooldown(TimeSpan.FromMilliseconds(cooldownDurationInMs)); m_SceneMapper = new SceneMapper(); foreach (var componentType in hierarchy.GroupingStrategy.ComponentsToWatch) { if (!ComponentDataDiffer.CanWatch(componentType) && !SharedComponentDataDiffer.CanWatch(componentType)) { throw new NotSupportedException($" The component {componentType} requested by strategy of type {hierarchy.GroupingStrategy.GetType()} cannot be watched. No suitable differ available."); } } m_Hierarchy = hierarchy; m_EntityDiffer = new EntityDiffer(hierarchy.World); foreach (var componentToWatch in hierarchy.GroupingStrategy.ComponentsToWatch) { var typeInfo = TypeManager.GetTypeInfo(componentToWatch.TypeIndex); switch (typeInfo.Category) { case TypeManager.TypeCategory.ComponentData when UnsafeUtility.IsUnmanaged(componentToWatch.GetManagedType()): m_ComponentDataDiffers.Add((new ComponentDataDiffer(componentToWatch))); break; case TypeManager.TypeCategory.ISharedComponentData: m_SharedComponentDataDiffers.Add((new SharedComponentDataDiffer(componentToWatch))); break; } } m_ComponentDataDifferResults = new ComponentDataDiffer.ComponentChanges[m_ComponentDataDiffers.Count]; m_SharedComponentDataDifferResults = new SharedComponentDataDiffer.ComponentChanges[m_SharedComponentDataDiffers.Count]; m_NewEntities = new NativeList <Entity>(1024, Allocator.Persistent); m_RemovedEntities = new NativeList <Entity>(1024, Allocator.Persistent); m_DifferHandles = new NativeArray <JobHandle>(m_ComponentDataDiffers.Count + 1, Allocator.Persistent); }