Advertisement
Guest User

Untitled

a guest
Jan 16th, 2014
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Xml;
  4. using System.Xml.Serialization;
  5. using System.IO;
  6. using System.Collections.Generic;
  7.  
  8. [XmlRoot("CardCollection")]
  9. public class CardContainer
  10. {
  11. [XmlArray("Cards"),XmlArrayItem("Card")]
  12. public List<Card> Cards = new List<Card>();
  13.  
  14. public void Save(string path)
  15. {
  16. var serializer = new XmlSerializer(typeof(CardContainer));
  17. using(var stream = new FileStream(path, FileMode.Create))
  18. {
  19. serializer.Serialize(stream, this);
  20. }
  21. }
  22.  
  23. public static CardContainer Load(string path)
  24. {
  25. var serializer = new XmlSerializer(typeof(CardContainer));
  26. using(var stream = new FileStream(path, FileMode.Open))
  27. {
  28. return serializer.Deserialize(stream) as CardContainer;
  29. }
  30. }
  31.  
  32. //Loads the xml directly from the given string. Useful in combination with www.text.
  33. public static CardContainer LoadFromText(string text)
  34. {
  35. var serializer = new XmlSerializer(typeof(CardContainer));
  36. return serializer.Deserialize(new StringReader(text)) as CardContainer;
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement