Exemplo n.º 1
0
 protected InspectorAdapter(InspectorVisitor <T> visitor)
 {
     Visitor = visitor;
     Context = visitor.Context;
     Targets = visitor.Targets;
     Session = visitor.Session;
 }
Exemplo n.º 2
0
        public static TElement Construct <TProperty, TElement, TFieldType, TContainer, TValue>(
            TProperty property,
            ref TContainer container,
            ref TValue value,
            InspectorContext context
            )
            where TProperty : IProperty <TContainer, TValue>
            where TElement : BaseField <TFieldType>, new()
            where TValue : struct
        {
            var element = ConstructBase <TProperty, TContainer, TElement, TFieldType, TValue>(property);

            if (TranslatorFactory <TValue> .TryGetUpdater(element, out var t))
            {
                var offset = context.GetOffsetOfField(property.GetName());
                var index  = context.GetCurrentIndex();
                var setter = context.DataProvider;
                t.SetUpdaters(element, setter, offset, index);
            }
            else
            {
                UnityEngine.Debug.Log($"No data translator registered between {typeof(TValue).Name} and {typeof(TFieldType).Name}");
            }

            if (context.GetParent(out var parent))
            {
                parent.contentContainer.Add(element);
            }

            if (property.IsContainer)
            {
                context.PushParent(element);
            }
            return(element);
        }
Exemplo n.º 3
0
 public static TElement Construct <TProperty, TElement, TContainer, TValue>(
     TProperty property,
     ref TContainer container,
     ref TValue value,
     InspectorContext context
     )
     where TProperty : IProperty <TContainer, TValue>
     where TElement : BaseField <TValue>, new()
     where TValue : struct
 {
     return(Construct <TProperty, TElement, TValue, TContainer, TValue>(property, ref container, ref value, context));
 }
Exemplo n.º 4
0
        public static Label Label <TProperty, TContainer, TValue>(TProperty property, ref TContainer container,
                                                                  ref TValue value, InspectorContext context)
            where TProperty : IProperty <TContainer, TValue>
        {
            var name  = property.GetName();
            var label = new Label {
                text = name
            };

            if (context.GetParent(out var parent))
            {
                parent.Add(label);
            }

            if (property.IsContainer)
            {
                context.PushParent(label);
            }
            return(label);
        }
Exemplo n.º 5
0
 public static IntegerField ShortField <TProperty, TContainer>(TProperty property, ref TContainer container, ref short value, InspectorContext context)
     where TProperty : IProperty <TContainer, short>
 => GuiConstructFactory.Construct <TProperty, IntegerField, int, TContainer, short>(property, ref container, ref value, context);
Exemplo n.º 6
0
 public static Toggle Toggle <TProperty, TContainer>(TProperty property, ref TContainer container, ref bool value, InspectorContext context)
     where TProperty : IProperty <TContainer, bool>
 {
     return(GuiConstructFactory.Construct <TProperty, Toggle, TContainer, bool>(property, ref container, ref value, context));
 }
Exemplo n.º 7
0
        public static EnumField EnumField <TProperty, TContainer, TValue>(TProperty property, ref TContainer container,
                                                                          ref TValue value, InspectorContext context) where TProperty : IProperty <TContainer, TValue>
        {
            if (typeof(TValue).IsEnum)
            {
                var name    = property.GetName();
                var element = new EnumField(value as Enum);
                GuiConstructFactory.SetNames(property, element);
                if (context.GetParent(out var parent))
                {
                    parent.contentContainer.Add(element);
                }
                GuiConstructFactory.SetDataUpdater <TProperty, TContainer, TValue>(property, element, context, name);

                return(element);
            }

            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);
                }
            });
        }
Exemplo n.º 9
0
 public StructInspectorFactoryScope(InspectorContext context, IComponentDataElement root, CustomInspectorManager customInspectors)
 {
     Context = context;
     Context.StructElementFactory = new StructDataElementFactory <T>(root, customInspectors);
 }
Exemplo n.º 10
0
 public static LongField LongField <TProperty, TContainer>(TProperty property, ref TContainer container, ref long value, InspectorContext context)
     where TProperty : IProperty <TContainer, long>
 {
     return(GuiConstructFactory.Construct <TProperty, LongField, TContainer, long>(property, ref container, ref value, context));
 }
Exemplo n.º 11
0
        public static Foldout Foldout <TProperty, TContainer, TValue>(TProperty property, ref TContainer container, ref TValue value, InspectorContext context, string name = null)
            where TProperty : IProperty <TContainer, TValue>
        {
            var hasTooltip   = property.Attributes?.HasAttribute <TooltipAttribute>() ?? false;
            var propertyName = property.GetName();
            var foldout      = new Foldout
            {
                name        = propertyName,
                text        = name ?? propertyName,
                bindingPath = propertyName,
                tooltip     = hasTooltip ? property.Attributes.GetAttribute <TooltipAttribute>().Tooltip : string.Empty,
            };

            GuiConstructFactory.SetTooltip(property, foldout);

            if (!context.GetParent(out var parent))
            {
                return(foldout);
            }

            if (property.IsContainer)
            {
                parent.Add(foldout);
                context.PushParent(foldout);
            }

            return(foldout);
        }
Exemplo n.º 12
0
        internal static void SetDataUpdater <TProperty, TContainer, TValue>(TProperty property, EnumField element, InspectorContext context, string name)
            where TProperty : IProperty <TContainer, TValue>
        {
            var type = Enum.GetUnderlyingType(typeof(TValue));

            if (type == typeof(byte))
            {
                SetDataUpdater <TValue, byte>(element, name, context);
            }
            else if (type == typeof(sbyte))
            {
                SetDataUpdater <TValue, sbyte>(element, name, context);
            }
            else if (type == typeof(short))
            {
                SetDataUpdater <TValue, short>(element, name, context);
            }
            else if (type == typeof(ushort))
            {
                SetDataUpdater <TValue, ushort>(element, name, context);
            }
            else if (type == typeof(int))
            {
                SetDataUpdater <TValue, int>(element, name, context);
            }
            else if (type == typeof(uint))
            {
                SetDataUpdater <TValue, uint>(element, name, context);
            }
            else if (type == typeof(long))
            {
                SetDataUpdater <TValue, long>(element, name, context);
            }
            else if (type == typeof(ulong))
            {
                SetDataUpdater <TValue, ulong>(element, name, context);
            }
        }
Exemplo n.º 13
0
        private static void SetDataUpdater <TEnumType, TValue>(EnumField element, string name, InspectorContext context)
            where TValue : struct
        {
            var offset = context.GetOffsetOfField(name);
            var setter = context.DataProvider;

            if (null == setter)
            {
                element.SetEnabled(false);
            }
            else
            {
                element.RegisterValueChangedCallback(evt =>
                {
                    setter.SetDataAtOffset((TValue)(object)evt.newValue, offset);
                });

                element.userData = new GuiUpdaters.EnumFieldUpdater <TEnumType, TValue>(
                    setter,
                    offset,
                    element,
                    new Translator <Enum, TValue>
                {
                    ToField = v => (Enum)Enum.ToObject(typeof(TEnumType), v),
                    ToValue = v => (TValue)(v as IConvertible).ToType(typeof(TValue), null)
                });
            }
        }
Exemplo n.º 14
0
 public InspectorVisitor(Session session, NativeArray <T> targets)
 {
     Context = new InspectorContext();
     Targets = targets;
     Session = session;
 }
Exemplo n.º 15
0
 public static IntegerField IntField <TProperty, TContainer>(TProperty property, ref TContainer container, ref int value, InspectorContext context)
     where TProperty : IProperty <TContainer, int>
 {
     return(GuiConstructFactory.Construct <TProperty, IntegerField, TContainer, int>(property, ref container, ref value, context));
 }
Exemplo n.º 16
0
 public static FloatField FloatField <TProperty, TContainer>(TProperty property, ref TContainer container,
                                                             ref float value, InspectorContext context)
     where TProperty : IProperty <TContainer, float>
 => GuiConstructFactory.Construct <TProperty, FloatField, TContainer, float>(property, ref container,
                                                                             ref value, context);
Exemplo n.º 17
0
 public static LongField UIntField <TProperty, TContainer>(TProperty property, ref TContainer container, ref uint value, InspectorContext context)
     where TProperty : IProperty <TContainer, uint>
 => GuiConstructFactory.Construct <TProperty, LongField, long, TContainer, uint>(property, ref container, ref value, context);
Exemplo n.º 18
0
 public static DoubleField DoubleField <TProperty, TContainer>(TProperty property, ref TContainer container, ref double value, InspectorContext context)
     where TProperty : IProperty <TContainer, double>
 {
     return(GuiConstructFactory.Construct <TProperty, DoubleField, TContainer, double>(property, ref container, ref value, context));
 }
Exemplo n.º 19
0
 public static TextField ULongField <TProperty, TContainer>(TProperty property, ref TContainer container, ref ulong value, InspectorContext context)
     where TProperty : IProperty <TContainer, ulong>
 => GuiConstructFactory.Construct <TProperty, TextField, string, TContainer, ulong>(property, ref container, ref value, context);
Exemplo n.º 20
0
 public static TextField CharField <TProperty, TContainer>(TProperty property, ref TContainer container, ref char value, InspectorContext context)
     where TProperty : IProperty <TContainer, char>
 {
     return(GuiConstructFactory.Construct <TProperty, TextField, string, TContainer, char>(property, ref container, ref value, context));
 }
Exemplo n.º 21
0
 public DataProviderScope(InspectorContext context, IComponentDataElement componentElement)
 {
     Context = context;
     Context.DataProvider = new ComponentOffsetDataProvider(componentElement);
 }
Exemplo n.º 22
0
        public override void BuildFromVisitor <TProperty, TContainer, TValue>(IPropertyVisitor visitor, TProperty property,
                                                                              ref TContainer container, ref TValue value, InspectorContext context)
        {
            base.BuildFromVisitor(visitor, property, ref container, ref value, context);

            if (null == Inspector)
            {
                var addNewItemButton = new Button(AddNewItem)
                {
                    text = "Add New Item"
                };
                addNewItemButton.AddToClassList("unity-ecs-add-buffer-item");
                Add(addNewItemButton);
            }
        }