ReplayInfo.cs 815 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using LitJson;
  5. public class ReplayInfo
  6. {
  7. public List<Player> playerList;
  8. public ReplayInfo(string json)
  9. {
  10. playerList = new List<Player> ();
  11. JsonData data = JsonMapper.ToObject (json);
  12. JsonData playerArr = data ["p"];
  13. for(int i=0; i<playerArr.Count; i++)
  14. {
  15. Player player = new Player ();
  16. player.FromJson (playerArr [i]);
  17. playerList.Add (player);
  18. }
  19. }
  20. public static string ToJson(BattleSession battleSession)
  21. {
  22. JsonData json = JsonMapper.ToObject ("{}");
  23. JsonData playerArr = JsonMapper.ToObject ("[]");
  24. List<Player> list = battleSession.GetPlayerList ();
  25. for(int i=0; i<list.Count; i++)
  26. {
  27. playerArr.Add (list [i].ToJson ());
  28. }
  29. json ["p"] = playerArr;
  30. return json.ToJson ();
  31. }
  32. }