Exemple #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)
        {
            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);
        }