Exemplo n.º 1
0
        /// <summary>
        /// 从指定的XML中读取并填充<see cref="Component"/>属性。
        /// </summary>
        /// <param name="component">目标组件</param>
        /// <param name="reader">读取器</param>
        /// <param name="context">反序列化上下文</param>
        public override void Deserialize(Component component, XmlReader reader, DeserializationContext context)
        {
            base.Deserialize(component, reader.ReadSubtree(), context);

            var inputField      = (InputField)component;
            var textComponentId = reader.GetIntAttribute(AttributeTextComponent);

            if (textComponentId != 0)
            {
                context.AddReference <Text>(textComponentId, text => { inputField.textComponent = text; });
            }

            inputField.characterLimit      = reader.GetIntAttribute(AttributeCharacterLimit);
            inputField.contentType         = (InputField.ContentType)reader.GetIntAttribute(AttributeContentType);
            inputField.lineType            = (InputField.LineType)reader.GetIntAttribute(AttributeLineType);
            inputField.inputType           = (InputField.InputType)reader.GetIntAttribute(AttributeInputType);
            inputField.keyboardType        = (TouchScreenKeyboardType)reader.GetIntAttribute(AttributeKeyboardType);
            inputField.characterValidation = (InputField.CharacterValidation)reader.GetIntAttribute(AttributeCharacterValidation);

            var placeholderId = reader.GetIntAttribute(AttributePlaceholder);

            if (placeholderId != 0)
            {
                context.AddReference <Text>(textComponentId, placeholder => { inputField.placeholder = placeholder; });
            }
            inputField.caretBlinkRate        = reader.GetFloatAttribute(AttributeCaretBlinkRate);
            inputField.selectionColor        = reader.GetColor32Attribute(AttributeSelectionColor);
            inputField.shouldHideMobileInput = reader.GetBoolAttribute(AttributeHideMobileInput);

            if (reader.ReadToDescendant(ElementText))
            {
                inputField.text = reader.ReadElementString();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 从指定的XML中读取并填充<see cref="Component"/>属性。
        /// </summary>
        /// <param name="component">目标组件</param>
        /// <param name="reader">读取器</param>
        /// <param name="context">反序列化上下文</param>
        public override void Deserialize(Component component, XmlReader reader, DeserializationContext context)
        {
            var selectable = (Selectable)component;

            selectable.interactable = reader.GetBoolAttribute(AttributeInteractable);
            selectable.transition   = (Selectable.Transition)reader.GetIntAttribute(AttributeTransition);

            switch (selectable.transition)
            {
            case Selectable.Transition.None:
                break;

            case Selectable.Transition.ColorTint:
                var graphicInstanceId = reader.GetIntAttribute(AttributeTargetGraphic);
                context.AddReference <Graphic>(graphicInstanceId, graphic => { selectable.targetGraphic = graphic; });
                var subReader = reader.ReadSubtree();
                subReader.Read();
                if (subReader.Read())
                {
                    selectable.colors = subReader.GetColorBlockElement(ElementColors);
                }
                break;

            case Selectable.Transition.SpriteSwap:
                var graphicInstanceId2 = reader.GetIntAttribute(AttributeTargetGraphic);
                context.AddReference <Graphic>(graphicInstanceId2, graphic => { selectable.targetGraphic = graphic; });
                var subReader2 = reader.ReadSubtree();
                subReader2.Read();
                if (subReader2.Read())
                {
                    reader.GetSpriteStateElement(ElementSpriteState, spriteState => { selectable.spriteState = spriteState; }, context);
                    reader.Skip();
                }
                break;

            case Selectable.Transition.Animation:
                var subReader3 = reader.ReadSubtree();
                subReader3.Read();
                if (subReader3.Read())
                {
                    selectable.animationTriggers = reader.GetAnimationTriggers(ElementAnimationTriggers);
                    reader.Skip();
                }
                break;

            default:
                Debug.LogWarning("Unsupported transition mode " + selectable.transition);
                break;
            }
            reader.GetNavigationElement(ElementNavigation, navigation => { selectable.navigation = navigation; }, context);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 从指定的XML中读取并填充<see cref="Component"/>属性。
        /// </summary>
        /// <param name="component">目标组件</param>
        /// <param name="reader">读取器</param>
        /// <param name="context">反序列化上下文</param>
        public override void Deserialize(Component component, XmlReader reader, DeserializationContext context)
        {
            base.Deserialize(component, reader, context);
            var toggle = (Toggle)component;

            toggle.isOn             = reader.GetBoolAttribute(AttributeIsOn);
            toggle.toggleTransition = (Toggle.ToggleTransition)reader.GetIntAttribute(AttributeToggleTransition);

            var graphicId     = reader.GetIntAttribute(AttributeGraphic);
            var toggleGroupId = reader.GetIntAttribute(AttributeToggleGroup);

            if (graphicId != 0)
            {
                context.AddReference <Graphic>(graphicId, graphic => { toggle.graphic = graphic; });
            }
            if (toggleGroupId != 0)
            {
                context.AddReference <ToggleGroup>(toggleGroupId, toggleGroup => { toggle.group = toggleGroup; });
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 从指定的XML中读取并填充<see cref="Component"/>属性。
        /// </summary>
        /// <param name="component">目标组件</param>
        /// <param name="reader">读取器</param>
        /// <param name="context">反序列化上下文</param>
        public override void Deserialize(Component component, XmlReader reader, DeserializationContext context)
        {
            base.Deserialize(component, reader, context);
            var slider       = (Slider)component;
            var fillRectId   = reader.GetIntAttribute(AttributeFillRect);
            var handleRectId = reader.GetIntAttribute(AttributeHandleRect);

            if (fillRectId != 0)
            {
                context.AddReference <RectTransform>(fillRectId, rect => { slider.fillRect = rect; });
            }
            if (handleRectId != 0)
            {
                context.AddReference <RectTransform>(handleRectId, rect => { slider.handleRect = rect; });
            }
            slider.direction    = (Slider.Direction)reader.GetIntAttribute(AttributeDirection);
            slider.minValue     = reader.GetFloatAttribute(AttributeMinValue);
            slider.maxValue     = reader.GetFloatAttribute(AttributeMaxValue);
            slider.wholeNumbers = reader.GetBoolAttribute(AttributeWholeNumbers);
            slider.value        = reader.GetFloatAttribute(AttributeValue);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 从指定的XML中读取并填充<see cref="Component"/>属性。
        /// </summary>
        /// <param name="component">目标组件</param>
        /// <param name="reader">读取器</param>
        /// <param name="context">反序列化上下文</param>
        public override void Deserialize(Component component, XmlReader reader, DeserializationContext context)
        {
            base.Deserialize(component, reader, context);
            var scrollbar    = (Scrollbar)component;
            var handleRectId = reader.GetIntAttribute(AttributeHandleRect);

            if (handleRectId != 0)
            {
                context.AddReference <RectTransform>(handleRectId, rect => { scrollbar.handleRect = rect; });
            }
            scrollbar.direction     = (Scrollbar.Direction)reader.GetIntAttribute(AttributeDirection);
            scrollbar.value         = reader.GetFloatAttribute(AttributeValue);
            scrollbar.size          = reader.GetFloatAttribute(AttrbuteSize);
            scrollbar.numberOfSteps = reader.GetIntAttribute(AttributeNumberOfSteps);
        }