Esempio n. 1
0
        private void ReparentLinks(NativeArray <Guid> guids)
        {
            foreach (var guid in guids)
            {
                var entity = m_WorldManager.GetEntityFromGuid(guid);
                if (!m_EntityManager.Exists(entity))
                {
                    continue;
                }
                var reference = GetEntityReference(guid);
                if (!reference || null == reference)
                {
                    continue;
                }

                if (m_EntityManager.HasComponent <Parent>(entity))
                {
                    var parent          = m_EntityManager.GetComponentData <Parent>(entity).Value;
                    var parentReference = GetEntityReference(parent);
                    if (parentReference && null != parentReference)
                    {
                        reference.transform.SetParent(parentReference.transform, true);
                    }
                    else
                    {
                        reference.transform.SetParent(null, true);
                    }
                }
                else
                {
                    reference.transform.SetParent(null, true);
                }
            }
        }
        private void HandleChanges(Changes changes)
        {
            if (m_IsUndoing)
            {
                return;
            }

            foreach (var guid in changes.CreatedEntities())
            {
                var entity = m_WorldManager.GetEntityFromGuid(guid);
                PopulateInitialComponentList(entity);
            }

            foreach (var diff in changes.WorldDiff.AddComponents)
            {
                var hash      = changes.WorldDiff.TypeHashes[diff.TypeHashIndex];
                var typeIndex = TypeManager.GetTypeIndexFromStableTypeHash(hash);
                var type      = TypeManager.GetType(typeIndex);
                if (hash == ComponentOrderHash || type.GetCustomAttributes(typeof(HideInInspectorAttribute)).Any())
                {
                    continue;
                }
                var guid   = changes.WorldDiff.Entities[diff.EntityIndex].ToGuid();
                var entity = m_WorldManager.GetEntityFromGuid(guid);
                AddTypeToBuffer(entity, hash);
            }

            foreach (var diff in changes.WorldDiff.RemoveComponents)
            {
                var hash      = changes.WorldDiff.TypeHashes[diff.TypeHashIndex];
                var typeIndex = TypeManager.GetTypeIndexFromStableTypeHash(hash);
                var type      = TypeManager.GetType(typeIndex);
                if (hash == ComponentOrderHash || type.GetCustomAttributes(typeof(HideInInspectorAttribute)).Any())
                {
                    continue;
                }
                var guid   = changes.WorldDiff.Entities[diff.EntityIndex].ToGuid();
                var entity = m_WorldManager.GetEntityFromGuid(guid);
                RemoveTypeFromBuffer(entity, hash);
            }
        }
        private void ValueChanged(InspectorDataProxy <Entity> proxy, ChangeEvent <Object> evt)
        {
            if (m_SimpleMode)
            {
                if (evt.newValue && null != evt.newValue)
                {
                    EntityReference entityRef = null;
                    switch (evt.newValue)
                    {
                    case EntityReference reference:
                        entityRef = reference;
                        break;

                    case Component component:
                        entityRef = component.GetComponent <EntityReference>();
                        break;

                    case GameObject gameObject:
                        entityRef = gameObject.GetComponent <EntityReference>();
                        break;
                    }

                    if (entityRef && null != entityRef)
                    {
                        proxy.Data = m_WorldManager.GetEntityFromGuid(entityRef.Guid);
                    }
                    else
                    {
                        proxy.Data = Entity.Null;
                    }
                }
                else
                {
                    proxy.Data = Entity.Null;
                }
            }
            else
            {
                if (evt.newValue && null != evt.newValue)
                {
                    proxy.Data = m_AssetManager.GetEntity(evt.newValue);
                }
                else
                {
                    proxy.Data = Entity.Null;
                }
            }
        }
Esempio n. 4
0
 public Entity GetEntityFromUnityComponent(Component component)
 {
     return(m_WorldManager.GetEntityFromGuid(component.GetComponent <EntityReference>().Guid));
 }
Esempio n. 5
0
        private void HandleChanges(Changes changes)
        {
            if (m_EditorUndoManager.IsUndoRedoing || DomainReload.IsDomainReloading)
            {
                return;
            }

            var workspaceScenes = GetWorkspaceScenesRW();

            using (var pooled = HashSetPool <Scene> .GetDisposable())
            {
                var sceneSet = pooled.Set;

                foreach (var entityGuid in changes.AllChangedEntities())
                {
                    var entity = m_WorldManager.GetEntityFromGuid(entityGuid);

                    if (m_WorldManager.EntityManager.HasComponent <SceneGuid>(entity) &&
                        m_WorldManager.EntityManager.HasComponent <SceneInstanceId>(entity))
                    {
                        var sceneGuid       = m_WorldManager.EntityManager.GetSharedComponentData <SceneGuid>(entity);
                        var sceneInstanceId = m_WorldManager.EntityManager.GetSharedComponentData <SceneInstanceId>(entity);

                        if (ConfigurationScene.Guid == sceneGuid.Guid)
                        {
                            continue;
                        }

                        sceneSet.Add(new Scene(sceneGuid, sceneInstanceId));
                    }
                }

                if (sceneSet.Count > 0)
                {
                    foreach (var scene in sceneSet)
                    {
                        if (m_ChangedScenes.Add(scene))
                        {
                            var index          = IndexOf(workspaceScenes, scene);
                            var workspaceScene = workspaceScenes[index];
                            workspaceScene.ChangeVersion++;
                            workspaceScenes[index] = workspaceScene;
                        }
                    }
                }
            }

            if (changes.EntitiesWereDeleted)
            {
                // Use the created inverse entities. Since we have component data for them.
                foreach (var scene in GetScenesForCreatedEntities(changes.InverseDiff))
                {
                    m_RebuildScenes.Add(scene);

                    if (m_ChangedScenes.Add(scene))
                    {
                        var index = IndexOf(workspaceScenes, scene);
                        if (index != -1)
                        {
                            var workspaceScene = workspaceScenes[index];
                            workspaceScene.ChangeVersion++;
                            workspaceScenes[index] = workspaceScene;
                        }
                        else
                        {
                            m_Graphs.Remove(scene.SceneGuid.Guid);
                        }
                    }
                }
            }

            using (var pooledGuids = ListPool <Guid> .GetDisposable())
            {
                var guids = pooledGuids.List;
                guids.AddRange(changes.ChangedEntitiesWithSetComponent <SiblingIndex>());
                guids.AddRange(changes.ChangedEntitiesWithSetComponent <Parent>());

                if (guids.Count > 0)
                {
                    var entityManager = m_WorldManager.EntityManager;

                    for (var i = 0; i < guids.Count; ++i)
                    {
                        var entityGuid = guids[i];
                        var entity     = m_WorldManager.GetEntityFromGuid(entityGuid);
                        if (entityManager.HasComponent <SceneGuid>(entity) &&
                            entityManager.HasComponent <SceneInstanceId>(entity))
                        {
                            var sceneGuid       = entityManager.GetSharedComponentData <SceneGuid>(entity);
                            var sceneInstanceId = entityManager.GetSharedComponentData <SceneInstanceId>(entity);

                            m_RebuildScenes.Add(new Scene(sceneGuid, sceneInstanceId));
                        }
                    }
                }
            }
        }