Exemple #1
0
            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];
            }
Exemple #2
0
        public static void Register(IEntityHierarchy hierarchy)
        {
            var system = World.DefaultGameObjectInjectionWorld.GetExistingSystem <EntityHierarchyDiffSystem>();

            system.DoRegister(hierarchy);

            EditorUpdateUtility.EditModeQueuePlayerLoopUpdate();
        }
Exemple #3
0
        void DoRegister(IEntityHierarchy hierarchy)
        {
            if (m_DiffersPerContainer.ContainsKey(hierarchy))
            {
                return;
            }

            m_DiffersPerContainer.Add(hierarchy, new Differs(hierarchy));
        }
Exemple #4
0
        public void Refresh(IEntityHierarchy entityHierarchy)
        {
            if (m_Hierarchy == entityHierarchy)
            {
                return;
            }

            m_Hierarchy = entityHierarchy;
            UpdateStructure();
            OnUpdate();
        }
Exemple #5
0
        void DoUnregister(IEntityHierarchy hierarchy)
        {
            if (!m_DiffersPerContainer.ContainsKey(hierarchy))
            {
                return;
            }

            var differs = m_DiffersPerContainer[hierarchy];

            differs.Dispose();
            m_DiffersPerContainer.Remove(hierarchy);
        }
Exemple #6
0
        public static void Unregister(IEntityHierarchy hierarchy)
        {
            if (!hierarchy.World.IsCreated)
            {
                return; // World was already disposed.
            }
            var system = World.DefaultGameObjectInjectionWorld.GetExistingSystem <EntityHierarchyDiffSystem>();

            system.DoUnregister(hierarchy);

            EditorUpdateUtility.EditModeQueuePlayerLoopUpdate();
        }
        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);
        }
        public static EntityHierarchyItem GetTreeViewItem(ITreeViewItem parent, EntityHierarchyNodeId nodeId, IEntityHierarchy hierarchy)
        {
            var item = Pool <EntityHierarchyItem> .GetPooled();

            item.Initialize(parent, nodeId, hierarchy);
            return(item);
        }