protected ComponentElementBase(IComponentProperty property, EntityInspectorContext context)
 {
     Type        = property.Type;
     Path        = property.Name;
     DisplayName = GetDisplayName(property.Name);
     Context     = context;
     Container   = Context.EntityContainer;
 }
        public static bool TryGetComponentData <T>(this EntityInspectorContext context, out T component)
            where T : class, IComponentData
        {
            if (!context.TargetExists() || !context.EntityManager.HasComponent <T>(context.Entity))
            {
                component = default;
                return(false);
            }

            component = context.EntityManager.GetComponentData <T>(context.Entity);
            return(true);
        }
Exemplo n.º 3
0
        public TagComponentContainer(EntityInspectorContext context)
        {
            Context = context;
            Resources.Templates.CommonResources.AddStyles(this);
            AddToClassList(UssClasses.Resources.Inspector);
            AddToClassList(UssClasses.Resources.ComponentIcons);

            InspectorUtility.CreateComponentHeader(this, ComponentPropertyType.Tag, "Tags");
            var foldout = this.Q <Foldout>(className: UssClasses.Inspector.Component.Header);

            contentContainer = foldout.contentContainer;
            binding          = this;
            binding.Update();

            contentContainer.SetEnabled(!Context.IsReadOnly);
        }
 public BufferElement(IComponentProperty property, EntityInspectorContext context, ref InspectedBuffer <TList, TElement> value) : base(property, context)
 {
     m_Content = CreateContent(property, ref value);
 }
        static void OnClicked(ClickEvent evt, EntityInspectorContext context, VisualElement current)
        {
            switch (current)
            {
            case Foldout foldout:
                if (!foldout.Q <Toggle>().worldBound.Contains(evt.position))
                {
                    break;
                }
                foldout.value = !foldout.value;
                break;

            case ObjectField objectField:
                var display = objectField.Q(className: UssClasses.UIToolkit.ObjectField.Display);
                if (null == display)
                {
                    break;
                }
                if (!display.worldBound.Contains(evt.position))
                {
                    break;
                }

                if (evt.clickCount == 1)
                {
                    EditorGUIUtility.PingObject(objectField.value);
                }
                else
                {
                    var value = objectField.value;
                    if (null != value && value)
                    {
                        Selection.activeObject = value;
                    }
                }
                break;

            case EntityField entityField:
                var input = entityField.Q(className: "unity-entity-field__input");
                if (null == input)
                {
                    break;
                }
                if (!input.worldBound.Contains(evt.position))
                {
                    break;
                }

                if (evt.clickCount > 1)
                {
                    var world = context.World;
                    if (null == world || !world.IsCreated)
                    {
                        break;
                    }
                    if (!context.EntityManager.Exists(entityField.value))
                    {
                        break;
                    }

                    EntitySelectionProxy.SelectEntity(context.World, entityField.value);
                }
                break;
            }

            for (var i = 0; i < current.childCount; ++i)
            {
                OnClicked(evt, context, current[i]);
            }
        }
        static void OnClicked(ClickEvent evt, EntityInspectorContext context)
        {
            var element = (VisualElement)evt.target;

            OnClicked(evt, context, element);
        }
 public ComponentElement(IComponentProperty property, EntityInspectorContext context, ref TComponent value)
     : base(property, context)
 {
     binding   = this;
     m_Content = CreateContent(property, ref value);
 }
Exemplo n.º 8
0
 public EntityInspectorVisitor(VisualElement componentRoot, VisualElement tagRoot, EntityInspectorContext context)
 {
     m_ComponentRoot     = componentRoot;
     m_TagsComponentRoot = tagRoot;
     m_Context           = context;
 }
 public TagElement(IComponentProperty property, EntityInspectorContext context) : base(property, context)
 {
     Resources.Templates.Inspector.TagComponentElement.Clone(this);
     this.Q <Label>().text = DisplayName;
     this.Q <VisualElement>(className: UssClasses.Inspector.Component.Icon).AddToClassList(UssClasses.Inspector.ComponentTypes.Tag);
 }
 public EntityHeader(EntityInspectorContext context)
 {
     m_Context = context;
 }