Beispiel #1
0
        /// <summary>
        /// 从文件中读取数据到字符串数组中
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public string[] FileToString(string filePath)
        {
            string[] data = null;
#if Local_Mode
#if UNITY_STANDALONE_WIN
            using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            {
                StreamReader sr     = new StreamReader(fs);
                string       allstr = sr.ReadToEnd();
                JObject      jo     = (JObject)_serviceSerializer.DeSerializerObject(allstr);
                data = new string[] { jo["ReplayData"].ToString(), jo["RestoreData"].ToString() };
                sr.Close();
            }
#endif
#if UNITY_WEBGL
            JObject jo = (JObject)_serviceSerializer.DeSerializerObject(filePath);
            data = new string[] { jo["ReplayData"].ToString(), jo["RestoreData"].ToString() };
#endif
#endif
#if Lab_Mode
            JObject jo = (JObject)_serviceSerializer.DeSerializerObject(filePath);
            data = new string[] { jo["ReplayData"].ToString(), jo["RestoreData"].ToString() };
#endif
            return(data);
        }
Beispiel #2
0
        public void StringToChunk(string base64String)
        {
            chunkData.Clear();
            JObject jo     = (JObject)_serviceSerializer.DeSerializerObject(base64String);
            int     number = jo["TotalChunk"].ToObject <int>();

            TotalFrameCount = jo["FrameCount"].ToObject <int>();

            for (int i = 0; i < number; i++)
            {
                chunkData.Add(jo[i.ToString()].ToString());
            }
        }
Beispiel #3
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));
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// 填充实验室相关数据
        /// </summary>
        public void SetLabInfoParams(string infoParams)
        {
            JObject jObject = _serviceSerializer.DeSerializerObject <JObject>(infoParams);

#if UNITY_WEBGL || UNITY_WEBPLAYER
            //调用jslib返回数据
            labInfoParams.role     = jObject["role"].ToString();
            labInfoParams.numberId = jObject["numberId"].ToString();
            labInfoParams.name     = jObject["name"].ToString();
            labInfoParams.eid      = jObject["eid"].ToString();
#elif UNITY_STANDALONE_WIN || UNITY_5
            //发送http请求接收数据

            labInfoParams.role     = jObject["role"].ToString();
            labInfoParams.numberId = jObject["numberId"].ToString();
            labInfoParams.name     = jObject["name"].ToString();
            //eid在登录模块中设置
#endif
        }
        /// <summary>
        /// 登录回调,选择实验,设置eid
        /// </summary>
        /// <param name="data">状态码000,101,102</param>
        public void LoginInCallBack(string data)
        {
            JObject jObject = _serviceSerializer.DeSerializerObject <JObject>(data);

            string status = jObject["status"].ToString();
            //获取实验列表集合
            IEnumerable <JToken> expList = jObject["expList"];

            Dictionary <string, string> expNameId = new Dictionary <string, string>();


            foreach (var item in expList)
            {
                expNameId.Add(item["name"].ToString(), item["id"].ToString());
            }
            switch (status)
            {
            case "000":
                Debug.Log("登录成功");
                //设置实验的eid
                string eid = "";
                if (expNameId.TryGetValue(_ExpInfoSettings.experimentName, out eid))
                {
                    labInterSystem.labInfoParams.eid = eid;
                    //加载场景
                    LoadTargetScene();
                }
                else
                {
                    Debug.Log("实验名称与平台实验名称不一致");
                }
                break;

            case "101":
                Debug.Log("账户不存在或密码错误");
                break;

            case "102":
                Debug.Log("用户被禁用");
                break;

            default:
                break;
            }
        }
Beispiel #6
0
        public void UpdateWatchArrayList(BaseDataModelEntity targetEntity, FieldInfo fieldInfo, string operation, object newValue)
        {
            //获取Remove时没有产生歧义
            var method = fieldInfo.FieldType.GetMethod(operation);

            if (method == null && !operation.Equals("[]"))
            {
                return;
            }

            System.Type tType = fieldInfo.FieldType.GetElementType();

            switch (operation)
            {
            case "Add":
                //原值是int32,回放添加进去的默认为int64
                method.Invoke(fieldInfo.GetValue(targetEntity), new object[] { newValue });
                break;

            case "Remove":
                newValue = _serviceSerializer.DeSerializerObject(newValue.ToString(), tType);
                method.Invoke(fieldInfo.GetValue(targetEntity), new object[] { newValue });
                break;

            case "RemoveAt":
                //RemoveAt操作,newValue为Index
                int removeIndex = System.Convert.ToInt32(newValue);
                method.Invoke(fieldInfo.GetValue(targetEntity), new object[] { removeIndex });
                break;

            case "Clear":
                method.Invoke(fieldInfo.GetValue(targetEntity), null);
                break;

            case "Insert":
                JObject insertJObject = (JObject)newValue;
                int     insertIndex   = insertJObject["Key"].ToObject <int>();
                object  insertValue   = insertJObject["Value"]; // _serviceSerializer.DeSerializerObject(insertJObject["Value"].ToString(), tType);
                method.Invoke(fieldInfo.GetValue(targetEntity), new object[] { insertIndex, insertValue });
                break;

            case "[]":
                JObject keyValue = (JObject)newValue;
                int     index    = keyValue["Key"].ToObject <int>();
                object  value    = _serviceSerializer.DeSerializerObject(keyValue["Value"].ToString(), tType);
                method = fieldInfo.FieldType.GetMethod("set_Item");
                method.Invoke(fieldInfo.GetValue(targetEntity), new object[] { index, value });
                break;

            default:
                break;
            }
        }