Beispiel #1
0
        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);
        }
        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);
                }
            });
        }