void PackAndUnpack(MonsterDataBase data) { byte[] bytes = ZeroFormatterSerializer.Serialize <MonsterDataBase>(data); MonsterDataBase loadData = ZeroFormatterSerializer.Deserialize <MonsterDataBase>(bytes); OutputToLog(loadData); }
void Awake() { instance = this; //用列表读取MonsterData的数据 monsterDatas = JsonToObject.JsonToObject_ByJsonContent <MonsterData>(MonsterDataJ.text); //列表数据读入字典 foreach (var a in monsterDatas) { monsterDataDictionary.Add(a.ID, a); } }
void OutputToLog(MonsterDataBase data) { switch (data.Version) { case MonsterDataBase.VersionType.MonsterDataV1: MonsterDataV1 version1 = data as MonsterDataV1; Debug.Log("Name:" + version1.Name); Debug.Log("HitPoint:" + version1.HitPoint); Debug.Log("HitRate:" + version1.HitRate); Debug.Log("Speed:" + version1.Speed); Debug.Log("Luck:" + version1.Luck); break; case MonsterDataBase.VersionType.MonsterDataV2: MonsterDataV2 version2 = data as MonsterDataV2; Debug.Log("Name:" + version2.Name); Debug.Log("HitPoint:" + version2.HitPoint); Debug.Log("HitRate:" + version2.HitRate); Debug.Log("Speed:" + version2.Speed); Debug.Log("Luck:" + version2.Luck); Debug.Log("Defense:" + version2.Defense); break; } }
void TestZeroFormatter() { Stopwatch stopWatch = new Stopwatch(); string name = null; uint hitPoint = 0; float hitRate = 0f; uint speed = 0; uint luck = 0; string path = Path.Combine(Application.persistentDataPath, ZERO_FORMATTER_FILE_NAME); //UnityEngine.Debug.Log("path:" + path); if (File.Exists(path)) { File.Delete(path); } stopWatch.Start(); for (int i = 0; i < COUNT; ++i) { // 読み込み if (File.Exists(path)) { MonsterDataBase dataBase = ZeroFormatterSerializer.Deserialize <MonsterDataBase>(File.ReadAllBytes(path)); switch (dataBase.Version) { case MonsterDataBase.VersionType.MonsterDataV1: { MonsterDataV1 data = dataBase as MonsterDataV1; name = data.Name; hitPoint = data.HitPoint; hitRate = data.HitRate; speed = data.Speed; luck = data.Luck; //UnityEngine.Debug.Log("[ZeroFormatter] Data load. hitPoint:" + hitPoint); break; } } } hitPoint++; hitRate += 1f; speed++; luck++; // 書き込み { MonsterDataV1 data = new MonsterDataV1() { Name = MONSTER_NAME, HitPoint = hitPoint, HitRate = hitRate, Speed = speed, Luck = luck, }; UnityEngine.Debug.Log("[ZeroFormatter] data:" + data); File.WriteAllBytes(path, ZeroFormatterSerializer.Serialize <MonsterDataBase>(data)); } //UnityEngine.Debug.Log("[ZeroFormatter] hitPoint:" + hitPoint); hitPoint = 0; } stopWatch.Stop(); _zeroFormatterElapsedTime = stopWatch.ElapsedMilliseconds; }