示例#1
0
        /// <summary>
        /// 还原所有的entity
        /// </summary>
        /// <param name="entity"></param>
        public void Load(BaseDataModelEntity entity)
        {
            //如果在字典中查找不到,找不到的一定不是动态创建生成的(动态生成会立刻写入ID)
            if (!AllEntity.ContainsKey(entity.objectID))
            {
                //如果还不包含,则return
                if (!AllEntity.ContainsKey(entity.objectID))
                {
#if UNITY_EDITOR
                    Debug.Log("can't find entity with objectID: [" + entity.objectID + "___" + entity.GetType() + "],is not storagedata");
#endif
                    return;
                }
            }
            //深拷贝,进行数据还原

            string str       = _serviceSerializer.SerializerObject(AllEntity[entity.objectID]);
            object tmpEntity = _serviceSerializer.DeSerializerObject(str);

            PropertyInfo[] propertyInfos = tmpEntity.GetType().GetProperties();
            FieldInfo[]    fieldInfos    = tmpEntity.GetType().GetFields();

            PropertyInfo[] propertyInfos1 = entity.GetType().GetProperties();
            FieldInfo[]    fieldInfos1    = entity.GetType().GetFields();

            for (int i = 0; i < propertyInfos1.Length; i++)
            {
                for (int j = 0; j < propertyInfos1.Length; j++)
                {
                    if (propertyInfos1[i].Name.Equals(propertyInfos[j].Name))
                    {
                        propertyInfos1[i].SetValue(entity, propertyInfos[j].GetValue(tmpEntity));
                    }
                }
            }

            for (int i = 0; i < fieldInfos1.Length; i++)
            {
                for (int j = 0; j < fieldInfos1.Length; j++)
                {
                    if (fieldInfos1[i].Name.Equals(fieldInfos[j].Name))
                    {
                        fieldInfos1[i].SetValue(entity, fieldInfos[j].GetValue(tmpEntity));
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// 将数据转为字符串
        /// </summary>
        public void ChunkToString()
        {
            string chunk = "";

            if (_writeState == 1)
            {
                chunk = _serviceSerializer.SerializerObject(recordBufferA);
            }
            else if (_writeState == 2)
            {
                chunk = _serviceSerializer.SerializerObject(recordBufferB);
            }

            byte[] rawData = System.Text.Encoding.UTF8.GetBytes(chunk);
            byte[] zipData = _serviceCompress.Compress(rawData);
            chunkData.Add(System.Convert.ToBase64String(zipData));
#if UNITY_EDITOR
            testChunkData.Add(chunk);
#endif
        }
示例#3
0
        /// <summary>
        /// 将回放还原数据合并写入文本
        /// </summary>
        /// <param name="t"></param>
        public void SaveStorageData()
        {
            //判断当前是否可保存
            if (!RestoreSystem.CanSave)
            {
#if UNITY_EDITOR
                Debug.Log("current state can not save");
#endif
                return;
            }

            JObject targetJObject = new JObject();
            targetJObject.Add("ReplayData", ReplayData());
            targetJObject.Add("RestoreData", RestoreData());



#if Local_Mode
#if UNITY_WEBGL
            //保存文件到本地
            _webApiService.SaveStringToLocalFile(targetJObject.ToString(), "Experiment.json");
#elif UNITY_STANDALONE_WIN
            //保存文件到本地
            _storgaeDataWrapper.DataToFile(filePath, targetJObject.ToString());
#endif
#if UNITY_EDITOR && UNITY_STANDALONE_WIN && Local_Mode_Debug
            //编辑器下生成测试数据
            string testReplay = _serviceSerializer.SerializerObject((RecordSystem.Instance.testChunkData));
            string allstr     = "";
            foreach (var item in RecordSystem.Instance.testChunkData)
            {
                allstr += item;
            }
            targetJObject["ReplayData"]  = allstr;
            targetJObject["RestoreData"] = _restoreSystem.testEntityData;
            _storgaeDataWrapper.DataToTestFile(testFilePath, targetJObject);
#endif
#endif


#if Lab_Mode
            //保存文件到实验室管理平台
            JObject jo = labInterSystem.SetRequestInfo();
            jo.Add("initScript", targetJObject.ToString());
            labInterSystem.LabRequest(LabInterType.uploadRepay, jo.ToString());
#endif


#if UNITY_EDITOR
            AssetDatabase.Refresh();
#endif
        }