/// <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 image = (RawImage)component; var imageId = reader.GetAttribute(AttributeTexture); context.AddDependency <Texture2D>(imageId, texture => { image.texture = texture; }); image.color = reader.GetColor32Attribute(AttributeColor); image.material = reader.GetMaterialElement(ElementMaterial); image.uvRect = reader.GetRectAttribute(AttributeRect); }
/// <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 image = (Image)component; var spriteId = reader.GetAttribute(AttributeSourceImage); context.AddDependency <Sprite>(spriteId, sprite => { image.sprite = sprite; }); image.color = reader.GetColor32Attribute(AttributeColor); image.material = reader.GetMaterialElement(ElementMaterial); image.type = (Image.Type)reader.GetIntAttribute(AttributeImageType); switch (image.type) { case Image.Type.Simple: reader.GetBoolAttribute(AttributePreserveAspect, image.preserveAspect); break; case Image.Type.Sliced: reader.GetBoolAttribute(AttributeFillCenter, image.fillCenter); break; case Image.Type.Tiled: reader.GetBoolAttribute(AttributeFillCenter, image.fillCenter); break; case Image.Type.Filled: image.fillMethod = (Image.FillMethod)reader.GetIntAttribute(AttributeFillCenter); image.fillOrigin = reader.GetIntAttribute(AttributeFillOrigin); image.fillAmount = reader.GetFloatAttribute(AttributeFillAmount); image.fillClockwise = reader.GetBoolAttribute(AttributeClockwise); image.preserveAspect = reader.GetBoolAttribute(AttributePreserveAspect); break; default: Debug.LogWarning("Unsupported image type -> " + image.type); break; } image.preserveAspect = reader.GetBoolAttribute(AttributePreserveAspect); }