public BuilderCodePreview(BuilderPaneWindow paneWindow)
        {
            m_PaneWindow = paneWindow;

            m_ScrollView = new ScrollView(ScrollViewMode.VerticalAndHorizontal);
            m_ScrollView.AddToClassList(s_CodeScrollViewClassName);
            Add(m_ScrollView);

            AddToClassList(s_UssClassName);

            m_Container = new VisualElement();
            m_Container.AddToClassList(s_CodeContainerClassName);

            m_LineNumbers = new Label();
            m_LineNumbers.RemoveFromClassList(TextField.ussClassName);
            m_LineNumbers.AddToClassList(s_CodeClassName);
            m_LineNumbers.AddToClassList(s_CodeLineNumbersClassName);
            m_LineNumbers.AddToClassList(s_CodeInputClassName);

            m_Code            = new TextField(TextField.kMaxLengthNone, true, false, char.MinValue);
            m_Code.isReadOnly = true;
            m_Code.name       = s_CodeName;
            m_Code.RemoveFromClassList(TextField.ussClassName);
            m_Code.AddToClassList(s_CodeClassName);
            m_Code.AddToClassList(s_CodeTextClassName);
            var codeInput = m_Code.Q(className: TextField.inputUssClassName);

            codeInput.AddToClassList(s_CodeInputClassName);

            m_CodeOuterContainer = new VisualElement();
            m_CodeOuterContainer.AddToClassList(s_CodeCodeOuterContainerClassName);
            m_Container.Add(m_CodeOuterContainer);

            m_CodeContainer = new VisualElement();
            m_CodeContainer.AddToClassList(s_CodeCodeContainerClassName);
            m_CodeOuterContainer.Add(m_CodeContainer);

            m_CodeContainer.Add(m_LineNumbers);
            m_CodeContainer.Add(m_Code);

            m_ScrollView.Add(m_Container);

            // Make sure the Hierarchy View gets focus when the pane gets focused.
            primaryFocusable = m_Code;

            // Make sure no key events get through to the code field.
            m_Code.Q(TextInputBaseField <string> .textInputUssName).RegisterCallback <KeyDownEvent>(BlockEvent);
            m_Code.Q(TextInputBaseField <string> .textInputUssName).RegisterCallback <KeyUpEvent>(BlockEvent);

            SetText(string.Empty);
        }
Пример #2
0
        private void Setup()
        {
            TextField = new TextField();
            TextField.AddToClassList(TextUssClassName);
            TextField.RegisterValueChangedCallback(evt => Value = evt.newValue);

            var enabled = Options.Count > 0;

            _dropdownButton = new VisualElement {
                tooltip = enabled ? "Show the combo box options" : "No preset options available"
            };
            _dropdownButton.AddToClassList(BasePopupField <string, string> .inputUssClassName);
            _dropdownButton.AddToClassList(ButtonUssClassName);
            _dropdownButton.AddManipulator(new Clickable(OpenDropdown));
            _dropdownButton.SetEnabled(enabled);

            _menu = new GenericMenu();

            foreach (var option in Options)
            {
                _menu.AddItem(new GUIContent(option), false, () => SelectItem(option));
            }

            Add(TextField);
            Add(_dropdownButton);
        }
Пример #3
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);
        }
Пример #4
0
        // Made its own method for now as we have issues auto-converting between string and char in a TextField
        // TODO: refactor SetupField so we can do just the field.value part separately to combine with this
        private VisualElement SetupCharField()
        {
            TextField field = new TextField();

            field.AddToClassList("portField");
            if (TryGetValueObject(out object result))
            {
                field.value = UdonGraphExtensions.UnescapeLikeALiteral((char)result);
            }

            field.isDelayed = true;

            // Special handling for escaping char value
            field.OnValueChanged((e) =>
            {
                if (e.newValue[0] == '\\' && e.newValue.Length > 1)
                {
                    SetNewValue(UdonGraphExtensions.EscapeLikeALiteral(e.newValue.Substring(0, 2)));
                }
                else
                {
                    SetNewValue(e.newValue[0]);
                }
            });
            _inputField = field;

            // Add label, shown when input is connected. Not shown by default
            var friendlyName = UdonGraphExtensions.FriendlyTypeName(typeof(char)).FriendlyNameify();
            var label        = new EngineUI.Label(friendlyName);

            _inputFieldTypeLabel = label;

            return(_inputField);
        }
Пример #5
0
 void CreateTextField()
 {
     m_TextField = new TextField(-1, false, false, '*');
     m_TextField.AddToClassList("textfield");
     m_TextField.RegisterCallback <ChangeEvent <string> >(OnTextChanged);
     m_TextField.value = "";
 }
Пример #6
0
        public BTGraphNode CreateBTNode(BTGraphNodeData nodeData)
        {
            BTGraphNode node = new BTGraphNode(nodeData.isRootNode)
            {
                title = nodeData.title
            };

            if (!nodeData.isRootNode)
            {
                Port inputPort = node.InstantiatePort(Orientation.Horizontal, Direction.Input, Port.Capacity.Multi, typeof(bool));
                inputPort.portName = "Input";
                node.inputContainer.Add(inputPort);
            }
            else
            {
                if (RootNode != null)
                {
                    RemoveElement(RootNode);
                }
                node.title = "Root";
                RootNode   = node;
                AddElement(RootNode);
            }

            Port outputPort = node.InstantiatePort(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, typeof(bool));

            outputPort.portName = "Output";
            node.outputContainer.Add(outputPort);

            if (!nodeData.isRootNode)
            {
                TextField txtNodeType = new TextField("Type");
                txtNodeType.value = nodeData.nodeType;
                txtNodeType.AddToClassList("nodetype-input");
                txtNodeType.RegisterValueChangedCallback(evt =>
                {
                    node.NodeType = evt.newValue;
                });
                node.extensionContainer.Add(txtNodeType);

                TextField txtNodeTitle = new TextField();
                txtNodeTitle.AddToClassList("title-input");
                txtNodeTitle.RegisterValueChangedCallback(evt =>
                {
                    node.title = evt.newValue;
                });
                txtNodeTitle.SetValueWithoutNotify(node.title);
                node.titleContainer.RemoveAt(0);
                node.titleContainer.Insert(0, txtNodeTitle);
            }

            node.RefreshExpandedState();
            node.RefreshPorts();

            node.SetPosition(new Rect(nodeData.position, MIN_NODE_SIZE));

            AddElement(node);

            return(node);
        }
Пример #7
0
        public ToolbarSearchField()
        {
            Toolbar.SetToolbarStyleSheet(this);
            m_CurrentText = String.Empty;

            AddToClassList(ussClassName);

            m_TextField = new TextField();
            m_TextField.AddToClassList(textUssClassName);
            hierarchy.Add(m_TextField);
            m_TextField.RegisterValueChangedCallback(OnTextChanged);
            m_TextField.Q(TextField.textInputUssName).RegisterCallback <KeyDownEvent>(OnTextFieldKeyDown);

            m_SearchButton = new Button(() => {})
            {
                name = "unity-search"
            };
            m_SearchButton.AddToClassList(searchButtonUssClassName);
            m_TextField.hierarchy.Add(m_SearchButton);


            m_CancelButton = new Button(() => {})
            {
                name = "unity-cancel"
            };
            m_CancelButton.AddToClassList(cancelButtonUssClassName);
            m_CancelButton.AddToClassList(cancelButtonOffVariantUssClassName);
            m_TextField.hierarchy.Add(m_CancelButton);
        }
        public override void CreateSettingsUI(VisualElement rootElement)
        {
            var settingsobject     = GetOrCreateSettings <ThunderstoreSettings>();
            var serializedSettings = new SerializedObject(settingsobject);
            var container          = new VisualElement();
            var label = new Label(ObjectNames.NicifyVariableName(nameof(ThunderstoreUrl)));
            var field = new TextField {
                bindingPath = nameof(ThunderstoreUrl)
            };

            field.RegisterCallback <ChangeEvent <string> >(ce =>
            {
                if (ce.newValue != ce.previousValue)
                {
                    OnThunderstoreUrlChanged?.Invoke(field, new StringValueChangeArgs {
                        newValue = ce.newValue, previousValue = ce.previousValue
                    });
                }
            });
            container.Add(label);
            container.Add(field);
            container.AddToClassList("thunderkit-field");
            field.AddToClassList("thunderkit-field-input");
            label.AddToClassList("thunderkit-field-label");
            rootElement.Add(container);

            container.Bind(serializedSettings);
        }
Пример #9
0
        private TextField AddTextField(string text, VisualElement container, EventCallback <ChangeEvent <string> > e,
                                       int lines = 1)
        {
            var row = new Box();

            row.AddToClassList("properties-item");

            var label = new Label(text);

            var field = new TextField();

            if (lines > 1)
            {
                field.multiline = true;
                field.AddToClassList("multiline");
            }

            field.RegisterCallback(e);

            row.Add(label);
            row.Add(field);

            container.Add(row);

            return(field);
        }
Пример #10
0
 public IntegerElememt()
 {
     this.AddToClassList("integer-element");
     input = new TextField();
     input.AddToClassList("input");
     this.Add(input);
     input.RegisterValueChangedCallback(OnValueChanged);
 }
Пример #11
0
 public StringElement()
 {
     this.AddToClassList("string-element");
     input = new TextField();
     input.AddToClassList("input");
     this.Add(input);
     input.RegisterValueChangedCallback(OnValueChanged);
 }
Пример #12
0
 public DecimalElement()
 {
     this.AddToClassList("decimal-element");
     input = new TextField();
     input.AddToClassList("input");
     this.Add(input);
     input.RegisterValueChangedCallback(OnValueChanged);
 }
Пример #13
0
        /// <summary>
        /// Builds the node UI.
        /// </summary>
        private void BuildNodeControls()
        {
            // An UIElements.Button that adds new DialogueNodePorts to the output container.
            Button addChoiceButton = new Button(() => AddDialogueNodePorts())
            {
                text = "Add Choice"
            };

            titleButtonContainer.Add(addChoiceButton);

            // The UIElements.Foldout that contains the main controls.
            Foldout contentFoldout = new Foldout
            {
                text = "Dialogue Properties"
            };

            contentContainer.Add(contentFoldout);

            // The UIElements.TextField that sets the speaker's name.
            TextField speakerNameField = new TextField("Speaker Name")
            {
                value = SpeakerName
            };

            speakerNameField.RegisterValueChangedCallback(evt =>
            {
                SpeakerName = evt.newValue;
                UpdateTitle();
            });
            contentFoldout.contentContainer.Add(speakerNameField);

            contentFoldout.contentContainer.Add(new VisualElement {
                name = "divider"
            });

            // The UIElements.TextField that contains the speaker's dialogue
            TextField dialogueTextField = new TextField("Dialogue Text")
            {
                value = DialogueText
            };

            dialogueTextField.RegisterValueChangedCallback(evt =>
            {
                DialogueText = evt.newValue;
                UpdateTitle();
            });
            dialogueTextField.multiline = true;
            dialogueTextField.AddToClassList("dialogueTextField");
            contentFoldout.contentContainer.Add(dialogueTextField);

            contentFoldout.contentContainer.Add(new VisualElement {
                name = "divider"
            });

            RefreshExpandedState();
            RefreshPorts();
            SetPosition(new Rect(Vector2.zero, DefaultNodeSize));
        }
Пример #14
0
        private static TextField BuildTextField(string text, string clazz)
        {
            var textfield = new TextField();

            textfield.SetValueWithoutNotify(text);
            textfield.AddToClassList(clazz);
            textfield.tooltip = text;
            return(textfield);
        }
        public void OnEnable()
        {
            targetPlatform   = EditorUserBuildSettings.activeBuildTarget;
            assetBundleNames = AssetDatabase.GetAllAssetBundleNames();
            SetBuildFolder(targetPlatform);
            LoadConfig(assetBundleNames);

            LoadTemplates();
            LoadStyles();

            rootVisualElement.name = "body";

            VisualElement window = windowTemplate.CloneTree();

            rootVisualElement.Add(window);

            VisualElement assetBundlesTable = rootVisualElement.Query <VisualElement>("assetBundlesTable").First();

            if (assetBundlesTable != null)
            {
                foreach (string assetBundleName in assetBundleNames)
                {
                    VisualElement row = new VisualElement();
                    row.AddToClassList("row");
                    row.AddToClassList("listItem");

                    Label assetBundleLabel = new Label(assetBundleName);
                    assetBundleLabel.AddToClassList("column200");
                    row.Add(assetBundleLabel);

                    TextField assetBundleVersion = new TextField();
                    assetBundleVersion.AddToClassList("column100");
                    assetBundleVersion.name  = assetBundleName + "Version";
                    assetBundleVersion.value = config.AssetBundleInfos
                                               .FirstOrDefault(info => info.Name == assetBundleName)?.Version.ToString();
                    row.Add(assetBundleVersion);

                    assetBundlesTable.Add(row);
                }
            }

            EnumField platform = rootVisualElement.Query <EnumField>("platform");

            if (platform != null)
            {
                platform.value = EditorUserBuildSettings.activeBuildTarget;
                platform.RegisterValueChangedCallback(OnTargetPlatformChanged);
            }

            Button buildButton = new Button(OnBuildClicked)
            {
                name = "buildButton", text = "Build"
            };

            rootVisualElement.Add(buildButton);
        }
Пример #16
0
        public TextField CreateRenamingTextField(VisualElement documentElement, Label nameLabel, BuilderSelection selection)
        {
            var renameTextfield = new TextField()
            {
                name      = BuilderConstants.ExplorerItemRenameTextfieldName,
                isDelayed = true
            };

            renameTextfield.AddToClassList(BuilderConstants.ExplorerItemRenameTextfieldClassName);

            if (BuilderSharedStyles.IsSelectorElement(documentElement))
            {
                renameTextfield.SetValueWithoutNotify(BuilderSharedStyles.GetSelectorString(documentElement));
            }
            else
            {
                renameTextfield.SetValueWithoutNotify(
                    string.IsNullOrEmpty(documentElement.name)
                        ? documentElement.typeName
                        : documentElement.name);
            }
            renameTextfield.AddToClassList(BuilderConstants.HiddenStyleClassName);

            renameTextfield.RegisterCallback <KeyUpEvent>((e) =>
            {
#if !UNITY_2019_4 && !UNITY_2020_1 && !UNITY_2020_2 && !UNITY_2020_3
                if (e.keyCode == KeyCode.Return || e.keyCode == KeyCode.KeypadEnter || e.keyCode == KeyCode.Escape)
                {
                    (e.currentTarget as VisualElement).Blur();
                    return;
                }
#endif

                e.StopImmediatePropagation();
            });

            renameTextfield.RegisterCallback <FocusOutEvent>(e =>
            {
                OnEditTextFinished(documentElement, renameTextfield, nameLabel, selection);
            });

            return(renameTextfield);
        }
Пример #17
0
    public static SettingsProvider CreateBulletTeamSettingsProvider()
    {
        // First parameter is the path in the Settings window.
        // Second parameter is the scope of this setting: it only appears in the Settings window for the Project scope.
        var provider = new SettingsProvider("Project/BulletTeamSettings", SettingsScope.Project)
        {
            label = "Bullet Team Layers",
            // activateHandler is called when the user clicks on the Settings item in the Settings window.
            activateHandler = (searchContext, rootElement) => {
                var settings = BulletTeamSettings.GetSerializedSettings();
                settings.Update();

                // rootElement is a VisualElement. If you add any children to it, the OnGUI function
                // isn't called because the SettingsProvider uses the UIElements drawing framework.
                //rootElement.styleSheets.Add (AssetDatabase.LoadAssetAtPath<StyleSheet> ("Assets/Editor/settings_ui.uss"));
                var title = new Label()
                {
                    text = "Bullet Team Layers"
                };
                title.AddToClassList("title");
                rootElement.Add(title);

                var properties = new ScrollView()
                {
                    style =
                    {
                        flexDirection = FlexDirection.Column
                    }
                };
                properties.AddToClassList("property-list");
                rootElement.Add(properties);

                SerializedProperty layerNamesProp = settings.FindProperty("layerNames");

                for (int i = 0; i < layerNamesProp.arraySize; i++)
                {
                    SerializedProperty property = layerNamesProp.GetArrayElementAtIndex(i);
                    TextField          prop     = new TextField()
                    {
                        label = string.Format("Layer {0}", i),
                        value = property.stringValue
                    };
                    prop.BindProperty(property);
                    prop.AddToClassList("property-value");
                    properties.Add(prop);
                }
                settings.ApplyModifiedProperties();
            },

            // Populate the search keywords to enable smart search filtering and label highlighting:
            keywords = new HashSet <string>(new [] { "Bullet Team Layers" })
        };

        return(provider);
    }
Пример #18
0
        public ArrayElement()
        {
            sizeInput = new TextField();

            title.Add(sizeInput);

            sizeInput.RegisterValueChangedCallback(OnSizeChange);

            this.AddToClassList("array-element");
            sizeInput.AddToClassList("input");
        }
        public SimpleStackNode(MathStackNode node)
        {
            var visualTree = Resources.Load("SimpleStackNodeHeader") as VisualTreeAsset;

            m_Header = visualTree.Instantiate();

            m_TitleItem = m_Header.Q <Label>(name: "titleLabel");
            m_TitleItem.AddToClassList("label");

            m_TitleEditor = m_Header.Q(name: "titleField") as TextField;

            m_TitleEditor.AddToClassList("textfield");
            m_TitleEditor.visible = false;

            m_TitleEditor.RegisterCallback <FocusOutEvent>(e => { OnEditTitleFinished(); });
            m_TitleEditor.Q("unity-text-input").RegisterCallback <KeyDownEvent>(OnKeyPressed);


            headerContainer.Add(m_Header);

            m_OperationControl = m_Header.Q <EnumField>(name: "operationField");
            m_OperationControl.Init(MathStackNode.Operation.Addition);
            m_OperationControl.value = node.currentOperation;
            m_OperationControl.RegisterCallback <ChangeEvent <Enum> >(v =>
            {
                node.currentOperation = (MathStackNode.Operation)v.newValue;

                MathNode mathNode = userData as MathNode;

                if (mathNode != null && mathNode.mathBook != null)
                {
                    mathNode.mathBook.inputOutputs.ComputeOutputs();
                }
            });

            var inputPort  = InstantiatePort(Orientation.Vertical, Direction.Input, Port.Capacity.Single, typeof(float));
            var outputPort = InstantiatePort(Orientation.Vertical, Direction.Output, Port.Capacity.Single, typeof(float));

            inputPort.portName  = "";
            outputPort.portName = "";

            inputContainer.Add(inputPort);
            outputContainer.Add(outputPort);

            RegisterCallback <MouseDownEvent>(OnMouseUpEvent);

            userData            = node;
            viewDataKey         = node.nodeID.ToString();
            title               = node.name;
            inputPort.userData  = node;
            outputPort.userData = node;
        }
Пример #20
0
        public GroupNode()
        {
            m_ContentItem = new GroupNodeDropArea();
            m_ContentItem.ClearClassList();
            m_ContentItem.AddToClassList("content");

            var visualTree = EditorGUIUtility.Load("UXML/GraphView/GroupNode.uxml") as VisualTreeAsset;

            m_MainContainer = visualTree.CloneTree(null);
            m_MainContainer.AddToClassList("mainContainer");

            m_HeaderItem = m_MainContainer.Q(name: "header");
            m_HeaderItem.AddToClassList("header");

            m_TitleItem = m_MainContainer.Q <Label>(name: "titleLabel");
            m_TitleItem.AddToClassList("label");

            m_TitleEditor = m_MainContainer.Q(name: "titleField") as TextField;

            m_TitleEditor.AddToClassList("textfield");
            m_TitleEditor.visible = false;

            m_TitleEditor.RegisterCallback <FocusOutEvent>(e => { OnEditTitleFinished(); });
            m_TitleEditor.RegisterCallback <KeyDownEvent>(OnKeyPressed);

            VisualElement contentPlaceholder = m_MainContainer.Q(name: "contentPlaceholder");

            contentPlaceholder.Add(m_ContentItem);

            Add(m_MainContainer);

            ClearClassList();
            AddToClassList("groupNode");

            clippingOptions = ClippingOptions.ClipAndCacheContents;
            capabilities   |= Capabilities.Selectable | Capabilities.Movable | Capabilities.Deletable;

            m_HeaderItem.RegisterCallback <PostLayoutEvent>(OnHeaderSizeChanged);
            RegisterCallback <PostLayoutEvent>(e => { MoveElements(); });
            RegisterCallback <MouseDownEvent>(OnMouseUpEvent);

            this.schedule.Execute(e => {
                if (visible && (m_Initialized == false))
                {
                    m_Initialized = true;

                    UpdateGeometryFromContent();
                }
            });
        }
Пример #21
0
 void UpdateValidation()
 {
     m_IsValid = m_Validator == null || m_Validator(m_TextField.value);
     if (m_IsValid)
     {
         m_SubmitButton.SetEnabled(true);
         m_TextField.RemoveFromClassList("invalid");
     }
     else
     {
         m_SubmitButton.SetEnabled(false);
         m_TextField.AddToClassList("invalid");
     }
 }
Пример #22
0
        private VisualElement CreateFooter()
        {
            var expressionText = new TextField {
                tooltip = "Type an expression to execute"
            };

            expressionText.AddToClassList(UssExpressionClassName);

            void execute()
            {
                if (string.IsNullOrWhiteSpace(expressionText.text))
                {
                    var valid = ExecuteExpression(expressionText.text);
                    if (valid)
                    {
                        expressionText.SetValueWithoutNotify(string.Empty);
                    }

                    EnableInClassList(UssExpressionInvalidClassName, !valid);
                }
            };

            expressionText.RegisterCallback <KeyDownEvent>(evt =>
            {
                if (evt.keyCode == KeyCode.KeypadEnter || evt.keyCode == KeyCode.Return)
                {
                    execute();
                }
            });

            var executeButton = new IconButton(execute)
            {
                image = _executeIcon.Texture, tooltip = "Execute this expression"
            };

            executeButton.AddToClassList(UssExecuteButtonClassName);

            var placeholder = new Placeholder("Execute Expression");

            placeholder.AddToField(expressionText);

            var footer = new Toolbar();

            footer.AddToClassList(UssFooterClassName);
            footer.Add(expressionText);
            footer.Add(executeButton);

            return(footer);
        }
Пример #23
0
        protected static VisualElement CreateStandardField(string gamePath)
        {
            var container = new VisualElement();
            var label     = new Label(ObjectNames.NicifyVariableName(gamePath));
            var field     = new TextField {
                bindingPath = gamePath,
            };

            container.Add(label);
            container.Add(field);
            container.AddToClassList("thunderkit-field");
            field.AddToClassList("thunderkit-field-input");
            label.AddToClassList("thunderkit-field-label");
            return(container);
        }
Пример #24
0
        private void RecordingRenameView(string recordingFilePath)
        {
            string fileName = recordingFilePath.Substring($"{AutomatedQARuntimeSettings.RecordingFolderNameWithAssetPath}".Length + 1);

            VisualElement renameContainer = new VisualElement();

            renameContainer.AddToClassList("item-block");

            TextField newName = new TextField();

            newName.value = fileName.Replace(".json", string.Empty);
            newName.AddToClassList("edit-field");

            // Schedule focus event to highlight input's text (Required for successful focus).
            rootVisualElement.schedule.Execute(() => {
                newName.ElementAt(0).Focus();
            });

            Button saveButton = new Button()
            {
                text = "✓"
            };

            saveButton.clickable.clicked += () => {
                var renamePath = Path.Combine("Assets", AutomatedQARuntimeSettings.RecordingFolderName, $"{newName.value}.json");
                AssetDatabase.MoveAsset(recordingFilePath, renamePath);
                recordingPaths = GetAllRecordingAssetPaths();
                recordingPaths.Sort();
                SetUpView();
            };
            saveButton.AddToClassList("small-button");
            renameContainer.Add(saveButton);

            Button cancelButton = new Button()
            {
                text = "X"
            };

            cancelButton.clickable.clicked += () => {
                renameFile = string.Empty;
                SetUpView();
            };
            cancelButton.AddToClassList("small-button");
            renameContainer.Add(cancelButton);

            renameContainer.Add(newName);
            root.Add(renameContainer);
        }
Пример #25
0
        public FoldoutNumberField()
        {
            // Used for its dragger.
            var toggleInput = toggle.Q(className: "unity-toggle__input");

            m_DraggerIntegerField      = new IntegerField(" ");
            m_DraggerIntegerField.name = "dragger-integer-field";
            m_DraggerIntegerField.AddToClassList(k_DraggerFieldUssClassName);
            m_DraggerIntegerField.RegisterValueChangedCallback(OnDraggerFieldUpdate);
            toggleInput.Add(m_DraggerIntegerField);

            m_TextField           = new TextField();
            m_TextField.isDelayed = true; // only updates on Enter or lost focus
            m_TextField.AddToClassList(textUssClassName);
            header.hierarchy.Add(m_TextField);
        }
Пример #26
0
        // ------------------------------------------------------------ BaseOnEnable
        // -- BaseOnEnable ---------------------------------------------------------
        protected override void BaseOnEnable()
        {
            beforeDefaultElements = new VisualElement();

            excludedFields.Add("description");
            rootContainer = new VisualElement();

            var headerLabel = new Label("Above-Average Inspector");

            headerLabel.AddToClassList("headerLabel");
            beforeDefaultElements.Add(headerLabel);

            var descriptionText = new TextField
            {
                bindingPath = serializedObject.FindProperty("description").propertyPath
            };

            descriptionText.SetEnabled(false);
            descriptionText.AddToClassList("descriptionTextField");
            beforeDefaultElements.Add(descriptionText);

            rootContainer.AddToClassList("rootContainer");

            // --- Primary Box Container -----------------------
            var container = new Box();

            // --- Path Refresh Button -------------------------
            refreshPaths = new Button(RefreshPaths)
            {
                text = "Refresh Paths", name = "refreshPaths"
            };
            refreshPaths.AddToClassList("interfaceButton");

            // --- Get Events Button ---------------------------
            getStyleSheets = new Button(GetStyleSheets)
            {
                text = "Refresh StyleSheets", name = "getStyleSheets"
            };
            getStyleSheets.AddToClassList("interfaceButton");

            container.Add(refreshPaths);
            container.Add(getStyleSheets);
            rootContainer.Add(container);
            afterDefaultElements = new VisualElement();
            afterDefaultElements.Add(rootContainer);
        }
        public static SettingsProvider CreateMyCustomSettingsProvider()
        {
            // First parameter is the path in the Settings window.
            // Second parameter is the scope of this setting: it only appears in the Settings window for the Project scope.
            var provider = new SettingsProvider("Project/MyCustomUIElementsSettings", SettingsScope.Project)
            {
                label = "Custom UI Elements",
                // activateHandler is called when the user clicks on the Settings item in the Settings window.
                activateHandler = (searchContext, rootElement) => {
                    var settings = MyCustomSettings.GetSerializedSettings();

                    // rootElement is a VisualElement. If you add any children to it, the OnGUI function
                    // isn't called because the SettingsProvider uses the UIElements drawing framework.
                    var styleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/Unity Attributes Example/43.SettingsProvider/Editor/settings_ui.uss");
                    rootElement.styleSheets.Add(styleSheet);
                    var title = new Label()
                    {
                        text = "Custom UI Elements"
                    };
                    title.AddToClassList("title");
                    rootElement.Add(title);

                    var properties = new VisualElement()
                    {
                        style =
                        {
                            flexDirection = FlexDirection.Column
                        }
                    };
                    properties.AddToClassList("property-list");
                    rootElement.Add(properties);

                    var tf = new TextField()
                    {
                        value = settings.FindProperty("m_SomeString").stringValue
                    };
                    tf.AddToClassList("property-value");
                    properties.Add(tf);
                },

                // Populate the search keywords to enable smart search filtering and label highlighting:
                keywords = new HashSet <string>(new[] { "Number", "Some String" })
            };

            return(provider);
        }
Пример #28
0
        void BuildReferenceNameField(PropertySheet propertySheet)
        {
            if (!isSubGraph || shaderInput is ShaderKeyword)
            {
                var textPropertyDrawer = new TextPropertyDrawer();
                propertySheet.Add(textPropertyDrawer.CreateGUI(
                                      null,
                                      (string)shaderInput.referenceName,
                                      "Reference",
                                      out var propertyVisualElement));

                m_ReferenceNameField = (TextField)propertyVisualElement;
                m_ReferenceNameField.RegisterValueChangedCallback(
                    evt =>
                {
                    this._preChangeValueCallback("Change Reference Name");
                    this._referenceNameChangedCallback(evt.newValue);

                    if (string.IsNullOrEmpty(shaderInput.overrideReferenceName))
                    {
                        m_ReferenceNameField.RemoveFromClassList("modified");
                    }
                    else
                    {
                        m_ReferenceNameField.AddToClassList("modified");
                    }

                    this._postChangeValueCallback(true, ModificationScope.Graph);
                });

                _resetReferenceNameCallback = newValue =>
                {
                    m_ReferenceNameField.value = newValue;
                    m_ReferenceNameField.RemoveFromClassList("modified");
                };

                if (!string.IsNullOrEmpty(shaderInput.overrideReferenceName))
                {
                    propertyVisualElement.AddToClassList("modified");
                }
                propertyVisualElement.SetEnabled(shaderInput.isRenamable);
                propertyVisualElement.styleSheets.Add(Resources.Load <StyleSheet>("Styles/PropertyNameReferenceField"));
            }
        }
Пример #29
0
        public static TextField CreateEditableLabel(TextElement container, SerializedProperty property, bool multiline = false)
        {
            var edit = new TextField {
                multiline = multiline
            };

            edit.BindProperty(property);
            edit.AddToClassList(NodeEditableLabelUssClassName);
            edit.Q(TextField.textInputUssName).RegisterCallback <FocusOutEvent>(evt => HideEditableText(edit));

            container.BindProperty(property);
            container.RegisterCallback <MouseDownEvent>(evt => OnEditEvent(evt, edit));
            container.RegisterValueChangedCallback(e => container.text = e.newValue);
            container.Add(edit);

            HideEditableText(edit);

            return(edit);
        }
Пример #30
0
        public void AddChoicePort(DialogueNode dialogueNode, string overriddenPortName = "")
        {
            var generatedPort = GeneratePort(dialogueNode, Direction.Output);

            generatedPort.styleSheets.Add(Resources.Load <StyleSheet>("DialogueGraph"));
            generatedPort.AddToClassList("output-port");

            var oldLabel = generatedPort.contentContainer.Q <Label>("type");

            generatedPort.contentContainer.Remove(oldLabel);

            var outputPortCount = dialogueNode.outputContainer.Query("connector").ToList().Count;

            var choicePortName = string.IsNullOrEmpty(overriddenPortName)
                ? $"Choice {outputPortCount}"
                : overriddenPortName;

            var textField = new TextField
            {
                name  = string.Empty,
                value = choicePortName
            };

            textField.AddToClassList("output-field");
            textField.multiline = true;
            textField.RegisterValueChangedCallback(evt => generatedPort.portName = evt.newValue);
            generatedPort.contentContainer.Add(new Label("  "));
            generatedPort.contentContainer.Add(textField);

            var deleteButton = new Button(() => RemovePort(dialogueNode, generatedPort))
            {
                text = "X"
            };

            generatedPort.contentContainer.Add(deleteButton);

            generatedPort.portName = choicePortName;
            dialogueNode.outputContainer.Add(generatedPort);
            dialogueNode.RefreshExpandedState();
            dialogueNode.RefreshPorts();
        }