public void Refresh()
        {
            if (currentVisualElement == null)
            {
                return;
            }

            m_Header.style.display = DisplayStyle.Flex;

            m_TextField.UnregisterValueChangedCallback(m_SelectorNameChangeCallback);
            m_TextField.UnregisterCallback(m_SelectorEnterKeyDownCallback);
            m_TextField.UnregisterValueChangedCallback(m_ElementNameChangeCallback);
            m_TextField.RemoveManipulator(m_RightClickManipulator);

            if (m_Selection.selectionType == BuilderSelectionType.StyleSelector ||
                m_Selection.selectionType == BuilderSelectionType.ParentStyleSelector)
            {
                m_TextField.RegisterValueChangedCallback(m_SelectorNameChangeCallback);
                m_TextField.RegisterCallback(m_SelectorEnterKeyDownCallback);

                ToggleNameOverrideBox(false);

                m_StatusIndicator.style.visibility = Visibility.Hidden;

                (m_TextField.labelElement as INotifyValueChanged <string>).SetValueWithoutNotify(BuilderConstants.BuilderInspectorSelector);

                m_TextField.SetValueWithoutNotify(BuilderSharedStyles.GetSelectorString(currentVisualElement));

                m_Icon.style.backgroundImage = EditorGUIUtility.Load("StyleSheet Icon") as Texture2D;
            }
            else
            {
                ToggleNameOverrideBox(!string.IsNullOrEmpty(currentVisualElement.name));
                m_StatusIndicator.style.visibility = Visibility.Visible;
                m_TextField.SetValueWithoutNotify(currentVisualElement.name);
                SetTypeAndIcon();

                if (m_Selection.selectionType == BuilderSelectionType.Element)
                {
                    m_TextField.RegisterValueChangedCallback(m_ElementNameChangeCallback);
                    m_TextField.AddManipulator(m_RightClickManipulator);
                }
            }

            var currentElementType  = currentVisualElement.GetType();
            var isEditorOnlyElement = false;

            if (currentElementType.Namespace != null)
            {
                isEditorOnlyElement = currentElementType.Namespace.Contains("UnityEditor");
            }

            m_Pill.style.display = isEditorOnlyElement ? DisplayStyle.Flex : DisplayStyle.None;
            AdjustBottomPadding(isEditorOnlyElement && !m_Inspector.document.fileSettings.editorExtensionMode);
        }
Exemple #2
0
    void AddDescGroup(
        List <CodeGenDescription> descList,
        VisualElement elementAddTo,
        string groupLabel,
        bool open,
        VisualElement targetElement)
    {
        var group      = new Foldout();
        var savedColor = GUI.backgroundColor;

        group.style.backgroundColor = Color.gray;
        group.value = open;
        group.text  = groupLabel;

        var eventFields = new VisualElement();

        foreach (var type in descList)
        {
            var field = new TextField(type.DisplayEventTypeName);
            field.style.backgroundColor = savedColor;
            field.isReadOnly            = true;
            field.value = editorWindowCodeBuilder.ContainsCallback(type.CallbackMethodName) ?
                          type.CallbackMethodName : string.Empty;

            var doubleClickManipulator = new MouseDoubleClickManipulator()
                                         .RegisterDoubleClick(() =>
            {
                field.value = type.CallbackMethodName;
                GenerateCode(type);
            });
            field.AddManipulator(doubleClickManipulator);
            eventFields.Add(field);
        }
        group.Add(eventFields);
        var warnLabel = new Label("Set the VisualElement name.");

        warnLabel.visible = false;
        group.Add(warnLabel);

        group.schedule.Execute(_ =>
        {
            var isEnabled = !string.IsNullOrEmpty(targetElement.name);
            scrollView.SetEnabled(isEnabled);
            eventFields.visible = isEnabled;
            warnLabel.visible   = !isEnabled;
        }).Every(100);

        elementAddTo.Add(group);
    }