Exemplo n.º 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));
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 更新容器类数值
        /// </summary>
        /// <param name="targetEntity"></param>
        /// <param name="propertyPath"></param>
        /// <param name="newValue"></param>
        public void UpdateWatchable(BaseDataModelEntity targetEntity, string propertyPath, object newValue)
        {
            string[] nameOfValue = propertyPath.Split('#');
            var      fieldInfo   = targetEntity.GetType().GetField(nameOfValue[0]);

            if (fieldInfo.FieldType == typeof(WatchableArrayList))
            {
                return;
                //UpdateWatchArrayList(targetEntity, fieldInfo, nameOfValue[1], newValue);
            }
            else if (fieldInfo.FieldType.GetGenericTypeDefinition() == typeof(WatchableList <>))
            {
                UpdateWatchList(targetEntity, fieldInfo, nameOfValue[1], newValue);
            }
            else if (fieldInfo.FieldType.GetGenericTypeDefinition() == typeof(WatchableDictionary <,>))
            {
                UpdateWatchDic(targetEntity, fieldInfo, nameOfValue[1], newValue);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 回放设置对应的属性值
        /// </summary>
        /// <param name="item"></param>
        public void UpdateEntityValue(RecordItem item)
        {
            //获取实体对象实例
            BaseDataModelEntity targetEntity = GetModelEntityByUuid(item.ObjectId);

            if (targetEntity == null)
            {
                targetEntity = RestoreSystem.GetEntity(item.ObjectId);
            }
            if (targetEntity == null)
            {
                return;
            }
            if (item.PropertyPath.Contains("#"))
            {
                UpdateWatchable(targetEntity, item.PropertyPath, item.NewValue);
            }
            //通过Property方式查找属性并设置属性值
            PropertyInfo propertyInfo = null;

            propertyInfo = targetEntity.GetType().GetProperty(item.PropertyPath);
            if (propertyInfo != null)
            {
                if (propertyInfo.PropertyType == typeof(System.Single))
                {
                    System.Single _value = System.Convert.ToSingle(item.NewValue);
                    propertyInfo.SetValue(targetEntity, _value);
                }
                else if (propertyInfo.PropertyType == typeof(System.Int32))
                {
                    System.Int32 _value = System.Convert.ToInt32(item.NewValue);
                    propertyInfo.SetValue(targetEntity, _value);
                }
                else
                {
                    propertyInfo.SetValue(targetEntity, item.NewValue, null);
                }

                return;
            }

            //通过Field方式查找属性并设置属性值
            FieldInfo fieldInfo = targetEntity.GetType().GetField(item.PropertyPath);

            if (fieldInfo != null)
            {
                if (fieldInfo.FieldType == typeof(System.Single))
                {
                    System.Single _value = System.Convert.ToSingle(item.NewValue);
                    fieldInfo.SetValue(targetEntity, _value);
                }
                else if (fieldInfo.FieldType == typeof(System.Int32))
                {
                    System.Int32 _value = System.Convert.ToInt32(item.NewValue);
                    fieldInfo.SetValue(targetEntity, _value);
                }
                else
                {
                    fieldInfo.SetValue(targetEntity, item.NewValue);
                }
            }
        }