Exemplo n.º 1
0
        public StyleField(string label) : base(label)
        {
            AddToClassList(s_UssClassName);

            styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(s_UssPath));

            var template = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(s_UxmlPath);

            template.CloneTree(this);

            visualInput           = this.Q(s_VisualInputName);
            m_TextField           = this.Q <TextField>(s_TextFieldName);
            m_TextField.isDelayed = true;

            var popupContainer = this.Q(s_OptionsPopupContainerName);

            m_StyleKeywords            = StyleFieldConstants.KLDefault;
            m_CachedRegularOptionsList = GenerateAdditionalOptions(string.Empty);
            m_AllOptionsList           = new List <string>();
            m_AllOptionsList.AddRange(m_CachedRegularOptionsList);
            m_AllOptionsList.AddRange(m_StyleKeywords);
            m_OptionsPopup = new PopupField <string>(m_AllOptionsList, 0, OnFormatSelectedValue);
            m_OptionsPopup.AddToClassList(s_OptionsPopupUssClassName);
            popupContainer.Add(m_OptionsPopup);

            m_TextField.RegisterValueChangedCallback(OnTextFieldValueChange);
            m_OptionsPopup.RegisterValueChangedCallback(OnPopupFieldValueChange);
        }
Exemplo n.º 2
0
        internal override void Apply(VisualElement container)
        {
            /// <sample>
            // Note: PopupField has no UXML support because it is a generic type.

            var choices = new List <string> {
                "First", "Second", "Third"
            };

            // Create a new field and assign it its value.
            var normalField = new PopupField <string>("Normal Field", choices, 0);

            normalField.value = "Second";
            container.Add(normalField);

            // Create a new field, disable it, and give it a style class.
            var styledField = new PopupField <string>("Styled Field", choices, 0);

            styledField.SetEnabled(false);
            styledField.AddToClassList("some-styled-field");
            styledField.value = normalField.value;
            container.Add(styledField);

            // Mirror value of uxml field into the C# field.
            normalField.RegisterCallback <ChangeEvent <string> >((evt) =>
            {
                styledField.value = evt.newValue;
            });
            /// </sample>
        }
Exemplo n.º 3
0
//----------------------------------------------------------------------------------------------------------------------
        private PopupField <T> AddPlayerConfigPopupField <T>(VisualTreeAsset template, VisualElement parent, GUIContent content,
                                                             List <T> options, Action <MeshSyncPlayerConfig, int> onValueChanged)
        {
            TemplateContainer templateInstance = template.CloneTree();
            VisualElement     fieldContainer   = templateInstance.Query <VisualElement>("FieldContainer").First();
            PopupField <T>    popupField       = new PopupField <T>(options, options[0]);

            popupField.AddToClassList("general-settings-field");

            Label label = templateInstance.Query <Label>().First();

            label.text    = content.text;
            label.tooltip = content.tooltip;
            popupField.RegisterValueChangedCallback((ChangeEvent <T> changeEvent) => {
                MeshSyncPlayerConfig config = popupField.userData as MeshSyncPlayerConfig;
                if (null == config)
                {
                    Debug.LogError("[MeshSync] Toggle doesn't have the correct user data");
                    return;
                }

                onValueChanged(config, popupField.index);
                MeshSyncRuntimeSettings.GetOrCreateSettings().SaveSettings();
            });

            fieldContainer.Add(popupField);
            parent.Add(templateInstance);
            m_playerConfigUIElements.Add(popupField);
            return(popupField);
        }
//----------------------------------------------------------------------------------------------------------------------
        private PopupField <T> AddPlayerConfigPopupField <T>(VisualElement parent, GUIContent content,
                                                             List <T> options, T initialValue, Action <int> onValueChanged,
                                                             string containerClass = null)
        {
            PopupField <T> popupField = UIElementsEditorUtility.AddPopupField <T>(parent, content, options, initialValue,
                                                                                  (ChangeEvent <T> changeEvent) => {
                PopupField <T> targetField = (changeEvent.target) as PopupField <T>;
                if (null == targetField)
                {
                    return;
                }

                onValueChanged(targetField.index);
                MeshSyncProjectSettings.GetOrCreateInstance().SaveInEditor();
            }
                                                                                  );

            popupField.AddToClassList("general-settings-field");
            if (!string.IsNullOrEmpty(containerClass))
            {
                popupField.parent.AddToClassList(containerClass);
            }
            return(popupField);
        }
Exemplo n.º 5
0
    void CreateVisualTree()
    {
        var visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Editor/EditorComponents/LevelEditor.uxml");
        var styleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/Editor/LevelEditorWindow.uss");

        levelEditor = visualTree.CloneTree();

        addLevelContainer  = levelEditor.Q <Box>("addLevelContainer");
        levelListContainer = new IMGUIContainer(DrawAnimationList);
        levelListContainer.onGUIHandler = DrawAnimationList;
        levelList = new ReorderableList(allLevels, typeof(Level));
        levelList.drawElementCallback = DrawList;
        levelList.drawHeaderCallback  = WriteHeader;
        levelList.onReorderCallback   = ChangeListOrder;
        levelList.onSelectCallback    = SelectListItem;
        levelList.onAddCallback       = AddToList;
        levelList.onRemoveCallback    = RemoveFromList;
        addLevelContainer.Add(levelListContainer);

        MapLayer map = new MapLayer();

        map.name      = "Environment";
        map.drawRects = new Dictionary <Vector2Int, Drawable>();
        MapLayer objects = new MapLayer();

        objects.name      = "StaticObjects";
        objects.drawRects = new Dictionary <Vector2Int, Drawable>();
        MapLayer enemies = new MapLayer();

        enemies.name      = "Enemies";
        enemies.drawRects = new Dictionary <Vector2Int, Drawable>();
        MapLayer player = new MapLayer();

        player.name      = "Players";
        player.drawRects = new Dictionary <Vector2Int, Drawable>();

        layersToDraw.Add(map);
        layersToDraw.Add(objects);
        layersToDraw.Add(enemies);
        layersToDraw.Add(player);

        VisualElement stampToolLayout = levelEditor.Q <Box>("levelManagerContainer");

        levelEditor.Add(stampToolLayout);

        VisualElement levelPropertyContainer = levelEditor.Q <Box>("PropertiesBarRow1");

        // Create a new field and assign it its value.
        layersPopupField       = new PopupField <string>("Select Layer to Paint", layers, 0);
        layersPopupField.value = "Environment";
        layersPopupField.AddToClassList("height-width-slider");
        levelPropertyContainer.Add(layersPopupField);

        //Label selectTileMapLabel = new Label("Choose TileMap(64x64)");
        //levelPropertyContainer.Add(selectTileMapLabel);

        //textureObjectField = new ObjectField { objectType = typeof(UnityEngine.Texture) };
        ////textureObjectField.StretchToParentSize();
        //textureObjectField.AddToClassList("height-width-slider");
        //levelPropertyContainer.Add(textureObjectField);
        //// Mirror value of uxml field into the C# field.
        //layersPopupField.RegisterCallback<ChangeEvent<string>>((evt) =>
        //{
        //    styledField.value = evt.newValue;
        //});

        VisualElement levelMapContainer = levelEditor.Q <Box>("LevelMapContainer");

        mapElement = new IMGUIContainer(mapOnGUI);

        mapElement.AddToClassList("level-map-sub-container");
        mapElement.RegisterCallback <MouseMoveEvent>(OnMapMouseMove);
        mapElement.RegisterCallback <MouseDownEvent>(OnMapMouseDown);
        mapElement.RegisterCallback <MouseUpEvent>(OnMapMouseUp);
        mapElement.RegisterCallback <MouseOutEvent>(OnMapMouseExit);

        levelMapContainer.Add(mapElement);

        VisualElement levelTileContainer = levelEditor.Q <Box>("TileMapContainer");

        tileElement = new IMGUIContainer(tileOnGUI);

        tileElement.AddToClassList("tile-map-container");
        tileElement.RegisterCallback <MouseUpEvent>(OnTileMouseup);

        levelTileContainer.Add(tileElement);

        InitializeLists();
    }