BattleSimulator.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.IO;
  4. public static class BattleSimulator
  5. {
  6. public static void TestRecord()
  7. {
  8. //TextAsset ta = UnityEditor.AssetDatabase.LoadAssetAtPath<TextAsset>("Assets/Content/Test/records.txt");
  9. //if (ta == null) return;
  10. //string recordContent = CompressionUtil.UnCompress(ta.text);
  11. //DebugHelper.LogError(recordContent);
  12. //JSONObject json = JSONObject.Create(recordContent);
  13. //BattleRecorder battleRecord = new BattleRecorder(json);
  14. //BattleMgr.Instance.Replay(battleRecord);
  15. }
  16. public static void SaveBattleRecorder(string battleRecorder)
  17. {
  18. if (battleRecorder == null) return;
  19. string dir = Application.dataPath + "/Content/Test";
  20. if (!System.IO.Directory.Exists(dir))
  21. System.IO.Directory.CreateDirectory(dir);
  22. string filePath = Application.dataPath + "/Content/Test/records.txt";
  23. FileStream fs = new FileStream(filePath, FileMode.Create);
  24. string recorderStr = battleRecorder;
  25. byte[] buff = System.Text.Encoding.Default.GetBytes(recorderStr);
  26. fs.Write(buff, 0, buff.Length);
  27. fs.Flush();
  28. fs.Close();
  29. }
  30. public static void SaveSkillDataRecorder(JSONObject recorder)
  31. {
  32. if (recorder == null) return;
  33. string filePath = Application.dataPath + "/Content/Test/skilldata.txt";
  34. FileStream fs = new FileStream(filePath, FileMode.Create);
  35. string recorderStr = recorder.Print(true);
  36. byte[] buff = System.Text.Encoding.Default.GetBytes(recorderStr);
  37. fs.Write(buff, 0, buff.Length);
  38. fs.Flush();
  39. fs.Close();
  40. }
  41. public static int ReplayBattle(BattleRecorder recorder)
  42. {
  43. //LogicBattle battle = new LogicBattle(recorder, true);
  44. //battle.Start();
  45. //while (battle.CurrentState != LogicBattleStateType.End)
  46. //{
  47. // battle.Update(BattleMgr.c_targetFrameTime);
  48. // if (battle.FrameCount > 5400)
  49. // {
  50. // DebugHelper.LogError("simulate error!");
  51. // break;
  52. // }
  53. //}
  54. //return recorder.ReplayResultCode;
  55. return 0;
  56. }
  57. }