public void CreateLink(Entity entity, Guid guid) { if (k_References.TryGetValue(guid, out var reference)) { return; } var go = new GameObject(m_WorldManager.GetEntityName(entity)); reference = go.AddComponent <EntityReference>(); reference.Guid = guid; reference.OnDestroyed += OnEntityReferenceDestroyed; go.hideFlags |= HideFlags.DontSaveInEditor; k_References.Add(guid, reference); }
protected override ISceneGraphNode CreateNode(ISceneGraphNode source, ISceneGraphNode parent) { if (source is EntityNode sourceNode) { var targetEntity = m_EntityManager.CreateEntity(m_EntityManager.GetChunk(sourceNode.Entity).Archetype); var sourceEntity = sourceNode.Entity; var visitor = new CopyVisitor(m_EntityManager, sourceEntity, targetEntity); PropertyContainer.Visit(new EntityContainer(m_EntityManager, sourceEntity), visitor); m_WorldManager.SetEntityGuid(targetEntity, Guid.NewGuid()); var entityNode = new EntityNode(this, m_Session, targetEntity); var newEntityName = EntityNameHelper.GetUniqueEntityName(m_WorldManager.GetEntityName(targetEntity), m_WorldManager, parent?.Children ?? Roots); m_WorldManager.SetEntityName(targetEntity, newEntityName); Add(entityNode, parent); return(entityNode); } return(null); }
internal static string GetUniqueEntityName(string name, IWorldManager worldManager, List <ISceneGraphNode> siblings) { if (siblings?.Count == 0) { return(name); } using (var pooledList = ListPool <string> .GetDisposable()) { foreach (var sibling in siblings) { if (sibling is EntityNode entityNode) { pooledList.List.Add(worldManager.GetEntityName(entityNode.Entity)); } } return(GetUniqueEntityName(name, pooledList.List)); } }
public void BuildFromInspector <TProperty, TContainer>(IPropertyVisitor visitor, TProperty property, ref TContainer container, ref Entity value, InspectorContext context) where TProperty : IProperty <TContainer, Entity> { var configEntity = WorldManager.GetConfigEntity(); if (value == configEntity) { return; } context.GetParent(out var parent); var headerRoot = this; parent.contentContainer.Add(headerRoot); var headerTemplate = StyleSheets.EntityHeader; headerTemplate.Template.CloneTree(headerRoot); headerRoot.AddStyleSheetSkinVariant(headerTemplate.StyleSheet); m_EnabledField = headerRoot.Q <Toggle>(k_EnabledToggle); m_EnabledField.value = !EntityManager.HasComponent <Disabled>(value); m_EnabledField.RegisterValueChangedCallback(evt => { var enabled = evt.newValue; for (var i = 0; i < Targets.Length; ++i) { var entity = Targets[i]; if (EntityManager.HasComponent <Disabled>(entity)) { if (enabled) { EntityManager.RemoveComponent <Disabled>(entity); } } else { if (!enabled) { EntityManager.AddComponentData <Disabled>(entity, default); } } } }); m_NameField = headerRoot.Q <TextField>(k_EntityNameLabel); name = WorldManager.GetEntityName(value); m_NameField.value = name; m_NameField.RegisterValueChangedCallback(evt => { if (string.IsNullOrEmpty(evt.newValue)) { m_NameField.SetValueWithoutNotify(evt.previousValue); return; } for (var i = 0; i < Targets.Length; ++i) { WorldManager.SetEntityName(Targets[i], evt.newValue); } }); }