Ejemplo n.º 1
0
        protected override void Refresh()
        {
            var path  = GetPath();
            var asset = AssetDatabase.LoadAssetAtPath <SceneAsset>(path);
            var text  = asset ? asset.name : "None (Scene)";
            var icon  = GetIcon(asset);

            SetLabel(icon, text);

            if (asset)
            {
                var scene      = SceneManager.GetSceneByPath(path);
                var buildIndex = SceneUtility.GetBuildIndexByScenePath(path);

                _load.SetEnabled(!scene.isLoaded || SceneManager.sceneCount > 1);
                _load.image = scene.isLoaded ? Icon.Unload.Texture : Icon.Load.Texture;

                _buildWarning.SetDisplayed(buildIndex < 0);
            }
            else
            {
                _load.image = Icon.Load.Texture;
                _load.SetEnabled(false);

                _buildWarning.SetDisplayed(false);
            }
        }
Ejemplo n.º 2
0
        private void CreateFrame()
        {
            SetLabel(Proxy.Label, Proxy.Tooltip);

            _addButton = AddHeaderButton(_addIcon.Texture, Proxy.AddTooltip, AddButtonUssClassName, AddItem);
            _addButton.SetEnabled(false);
            _removeButtons = Content.Query <IconButton>(className: RemoveButtonUssClassName).Build();

            _keyField = new TextField();
            _keyField.AddToClassList(HeaderKeyTextUssClassName);
            _keyField.RegisterValueChangedCallback(evt => AddKeyChanged(evt.newValue));
            _keyField.Q(TextField.textInputUssName).RegisterCallback <KeyDownEvent>(evt => KeyPressed(evt));

            var keyPlaceholder = new PlaceholderControl(Proxy.AddPlaceholder);

            keyPlaceholder.AddToField(_keyField);

            Header.Add(_keyField);
            _keyField.PlaceInFront(Label);

            var empty = new TextElement {
                text = Proxy.EmptyLabel, tooltip = Proxy.EmptyTooltip
            };

            empty.AddToClassList(EmptyLabelUssClassName);

            Content.Add(empty);

            _itemsContainer = new VisualElement();
            _itemsContainer.AddToClassList(ItemsUssClassName);

            Content.Add(_itemsContainer);
        }
Ejemplo n.º 3
0
        public void Refresh()
        {
            while (_itemsContainer.childCount > Proxy.ItemCount)
            {
                _itemsContainer.RemoveAt(_itemsContainer.childCount - 1);
            }

            for (var i = 0; i < _itemsContainer.childCount; i++)
            {
                UpdateItem(i);
            }

            for (var i = _itemsContainer.childCount; i < Proxy.ItemCount; i++)
            {
                CreateItem(i);
            }

            EnableInClassList(EmptyUssClassName, Proxy.ItemCount == 0);
            EnableInClassList(AddDisabledUssClassName, !Proxy.AllowAdd);
            EnableInClassList(RemoveDisabledUssClassName, !Proxy.AllowRemove);
            EnableInClassList(MoveDisabledUssClassName, !Proxy.AllowReorder);

            _addButton.SetEnabled(Proxy.CanAdd());

            _removeButtons.ForEach(button =>
            {
                var index     = GetItemIndex(button.parent);
                var removable = Proxy.CanRemove(index);

                button.SetEnabled(removable);
            });
        }
Ejemplo n.º 4
0
        private void AddKeyChanged(string newValue)
        {
            // Separately check for empty because we don't want empty to be addable but we also don't want it be show as invalid
            var valid = IsKeyValid(newValue) || string.IsNullOrEmpty(newValue);

            EnableInClassList(AddKeyInvalidUssClassName, !valid);
            _addButton.SetEnabled(valid && !string.IsNullOrEmpty(newValue));
        }
Ejemplo n.º 5
0
        protected override void Refresh()
        {
            var text = Value == null ? $"None ({Type.Name})" : Value.name;
            var icon = GetIcon(Value);

            SetLabel(icon, text);

            _inspect.SetEnabled(Value);
        }