Пример #1
0
        public IconButton AddFooterButton(Texture icon, string tooltip, string ussClassName, Action action)
        {
            var button = new IconButton(icon, tooltip, action);

            button.AddToClassList(FooterButtonUssClassName);

            if (!string.IsNullOrEmpty(ussClassName))
            {
                button.AddToClassList(ussClassName);
            }

            FooterButtons?.Add(button);
            return(button);
        }
Пример #2
0
        private void CreateItem(int index)
        {
            var item = new VisualElement();

            item.AddToClassList(ItemUssClassName);
            item.AddToClassList(index % 2 == 0 ? ItemEvenUssClassName : ItemOddUssClassName);
            _itemsContainer.Add(item);

            var dragHandle = new Image {
                image = _dragIcon.Texture, tooltip = Proxy.ReorderTooltip
            };

            dragHandle.AddToClassList(DragHandleUssClassName);
            dragHandle.RegisterCallback((MouseDownEvent e) => StartDrag(e, GetItemIndex(item)));
            item.Add(dragHandle);

            var content = Proxy.CreateField(index);

            content.AddToClassList(ItemContentUssClassName);
            item.Add(content);

            var remove = new IconButton(_removeIcon.Texture, Proxy.RemoveTooltip, () => RemoveItem(index));

            remove.AddToClassList(RemoveButtonUssClassName);
            item.Add(remove);
        }
Пример #3
0
        public ScenePickerControl(AssetReference value, Action onCreate)
        {
            _load = new IconButton(Icon.Load.Texture, "Load this scene", Load)
            {
                tintColor = Color.black
            };
            _load.AddToClassList(LoadUssClassName);

            _create = new IconButton(Icon.Add.Texture, "Create a new scene", () => Create(onCreate));
            _create.AddToClassList(CreateUssClassName);

            _buildWarning = new MessageBox(MessageBoxType.Info, "This scene is not in the build settings. Add it now?");
            _buildWarning.Add(new Button(AddToBuild)
            {
                text = "Add"
            });

            var assets   = AssetHelper.GetAssetList(typeof(SceneAsset));
            var provider = ScriptableObject.CreateInstance <SceneProvider>();

            provider.Setup(assets.Type.Name, assets.Paths.Prepend("None").ToList(), assets.Assets.Prepend(null).Cast <SceneAsset>().ToList(), GetIcon, OnSelected);

            Setup(provider, value);

            Add(_load);
            Add(_create);
            Add(_buildWarning);

            this.MakeDragReceiver();
            this.AddStyleSheet(Configuration.ElementsPath, Stylesheet);
            AddToClassList(UssClassName);
        }
        public ObjectPickerControl(Object value, Object owner, Type type)
        {
            if (type == null || !(typeof(Object).IsAssignableFrom(type)))
            {
                Debug.LogWarningFormat(_invalidTypeWarning, type);
                return;
            }

            Type = type;

            _inspect = new IconButton(Icon.Inspect.Texture, "View this object in the inspector", Inspect);
            _inspect.AddToClassList(InspectUssClassName);

            var provider = ScriptableObject.CreateInstance <ObjectProvider>();

            if (typeof(Component).IsAssignableFrom(type) || typeof(GameObject) == type)
            {
                var objects = ObjectHelper.GetObjectList(type, true);
                provider.Setup(type.Name, objects.Paths.Prepend("None").ToList(), objects.Objects.Prepend(null).ToList(), GetIcon, OnSelected);
            }
            else
            {
                var databaseAssets = AssetHelper.GetAssetList(type);

                var paths  = databaseAssets.Paths.Prepend("None");
                var assets = databaseAssets.Assets.Prepend(null);

                if (owner)
                {
                    var sceneObject = owner.GetAsGameObject();
                    if (sceneObject)
                    {
                        var sceneAssets = ObjectHelper.GetObjectList(type, false);                         // Don't include disabled because this will look at all resources
                        paths  = paths.Concat(sceneAssets.Paths);
                        assets = assets.Concat(sceneAssets.Objects);
                    }
                }

                provider.Setup(type.Name, paths.ToList(), assets.ToList(), GetIcon, OnSelected);
            }

            Setup(provider, value);
            Add(_inspect);

            this.MakeDragReceiver();
            this.AddStyleSheet(Configuration.ElementsPath, Stylesheet);
            AddToClassList(UssClassName);
        }