Пример #1
0
            public VariableDictionaryWatchControl(string name, IVariableDictionary variables, bool allowClose)
            {
                var proxy = new WatchProxy(variables);
                var list  = new ListField
                {
                    Label        = name,
                    AllowAdd     = false,
                    AllowRemove  = false,
                    AllowReorder = false,
                    Tooltip      = "The variables in this map",
                    EmptyLabel   = "This variable map is empty",
                    EmptyTooltip = "There are no variables in this map",
                };

                list.SetProxy(proxy, null, false);

                if (allowClose)
                {
                    list.Header.Add(new IconButton(RemoveFromHierarchy)
                    {
                        image = Icon.Close.Texture, tooltip = "Close this watch"
                    });
                }

                Add(list);
            }
Пример #2
0
        public override void Create(VisualElement root)
        {
            var asset             = ScriptableObject.CreateInstance <SampleAsset>();
            var obj               = new SerializedObject(asset);
            var typedPrimitives   = new List <int>();
            var typedClasses      = new List <SampleItemBool>();
            var typedReferences   = new List <ISampleItem>();
            var genericPrimitives = new List <int>();
            var genericClasses    = new List <SampleItemBool>();
            var genericReferences = new List <ISampleItem>();

            var proxies = new List <ProxySelect>
            {
                new ProxySelect("Typed Primitive", new ListProxy <int>(typedPrimitives, CreateInt), null, false, typedPrimitives),
                new ProxySelect("Typed Class", new ListProxy <SampleItemBool>(typedClasses, CreateSampleItemBool), typeof(SampleItemBool), false, typedClasses),
                new ProxySelect("Typed Reference", new ListProxy <ISampleItem>(typedReferences, CreateSampleItem), typeof(ISampleItem), true, typedReferences),
                new ProxySelect("Generic Primitive", new ListProxy(genericPrimitives, CreateInt), typeof(int), false, genericPrimitives),
                new ProxySelect("Generic Class", new ListProxy(genericClasses, CreateSampleItemBool), typeof(SampleItemBool), false, genericClasses),
                new ProxySelect("Generic Reference", new ListProxy(genericReferences, CreateSampleItem), typeof(ISampleItem), true, genericReferences),
                new ProxySelect("Property Primitive", CreatePropertyProxy(obj, nameof(SampleAsset.Primitives)), null, false, asset.Primitives),
                new ProxySelect("Property Class", CreatePropertyProxy(obj, nameof(SampleAsset.Classes)), null, false, asset.Classes),
                new ProxySelect("Property Reference", CreatePropertyProxy(obj, nameof(SampleAsset.References)), typeof(ISampleItem), true, asset.References),
                new ProxySelect("None", null, null, false, null)
            };

            var startingProxy = 0;
            var list          = new ListField();

            list.Label = "Sample List";
            list.SetProxy(proxies[startingProxy].Proxy, proxies[startingProxy].ItemType, proxies[startingProxy].AllowDerived);
            root.Add(list);

            var proxyPopup = new UnityEditor.UIElements.PopupField <ProxySelect>("Item Type", proxies, startingProxy, proxy => proxy.Name, proxy => proxy.Name);

            proxyPopup.RegisterValueChangedCallback(e => list.SetProxy(e.newValue.Proxy, e.newValue.ItemType, e.newValue.AllowDerived));
            root.Add(proxyPopup);

            var allowAddToggle = new Toggle("Allow Add");

            allowAddToggle.value = list.AllowAdd;
            allowAddToggle.RegisterValueChangedCallback(e => list.AllowAdd = e.newValue);
            root.Add(allowAddToggle);

            var allowRemoveToggle = new Toggle("Allow Remove");

            allowRemoveToggle.value = list.AllowRemove;
            allowRemoveToggle.RegisterValueChangedCallback(e => list.AllowRemove = e.newValue);
            root.Add(allowRemoveToggle);

            var allowReorderToggle = new Toggle("Allow Reorder");

            allowReorderToggle.value = list.AllowReorder;
            allowReorderToggle.RegisterValueChangedCallback(e => list.AllowReorder = e.newValue);
            root.Add(allowReorderToggle);

            var emptyLabelText = new TextField("Empty Label");

            emptyLabelText.value = list.EmptyLabel;
            emptyLabelText.RegisterValueChangedCallback(e => list.EmptyLabel = e.newValue);
            root.Add(emptyLabelText);

            var emptyTooltipText = new TextField("Empty Tooltip");

            emptyTooltipText.value = list.EmptyTooltip;
            emptyTooltipText.RegisterValueChangedCallback(e => list.EmptyTooltip = e.newValue);
            root.Add(emptyTooltipText);

            var addTooltipText = new TextField("Add Tooltip");

            addTooltipText.value = list.AddTooltip;
            addTooltipText.RegisterValueChangedCallback(e => list.AddTooltip = e.newValue);
            root.Add(addTooltipText);

            var removeTooltipText = new TextField("Remove Tooltip");

            removeTooltipText.value = list.RemoveTooltip;
            removeTooltipText.RegisterValueChangedCallback(e => list.RemoveTooltip = e.newValue);
            root.Add(removeTooltipText);

            var reorderTooltipText = new TextField("Reorder Tooltip");

            reorderTooltipText.value = list.ReorderTooltip;
            reorderTooltipText.RegisterValueChangedCallback(e => list.ReorderTooltip = e.newValue);
            root.Add(reorderTooltipText);

            var printButton = new Button(() => Print(proxies[proxyPopup.index].List));

            printButton.text = "Log List Contents";
            root.Add(printButton);
        }