/// <summary> /// 将动态生成的物体,注册到回放和还原系统当中 /// </summary> /// <param name="obj"></param> public static void RegisterPrefab(GameObject obj) { number += 1; if (obj.GetComponent <DataModelBehaviour>() != null) { DataModelBehaviour dataModel = obj.GetComponent <DataModelBehaviour>(); int id = DynamicIds.SetId(dataModel); } string sceneName = SceneManager.GetActiveScene().name; _sceneIdNameOfPrefab.Add(sceneName + "=" + number.ToString() + "=" + obj.name.Split('(')[0]); }
/// <summary> /// 监视自身,绑定ID 添加自身到Record /// </summary> protected virtual void Start() { //如果当前ID是-1,即不是预制体,设置对应的ID if (DataEntity.objectID == -1) { DataEntity.objectID = GetComponent <UniqueID>().UniqueId; } //取消对TransInfo事件的触发 OffFire(this.DataEntity, "objectID"); OffFire(this.DataEntity, "transInfo"); DynamicIdSupport = GameObject.FindObjectOfType <DynamicIds>(); if (DynamicIdSupport == null) { Debug.Log("请在GameObject[StorageSystom]上添加DynamicIds"); } }
/// <summary> /// 重新绑定实体对象 /// </summary> /// <param name="entity"></param> public void Rebinding(BaseDataModelEntity entity) { //如果绑定对象为空则返回 if (entity == null) { return; } //如果绑定对象为空实体则返回 if (entity is EmptyEntity) { return; } //取消绑定、Watch、初始化状态 RestoreSystem.RemoveDataModel(DataEntity.objectID); _bindingTable.Reset(); isViewInitialized = false; //重新设置实体对象并监听实体对象 this.DataEntity = entity; //当entity的ID为-1时表示对象为新创建对象, //此时需要生成一个ID if (entity.objectID == -1) { // this.DataEntity.objectID = ObjectIdentity.GenerateRuntimeId().id; //注册动态id,并添加到存储字典中 DynamicIds.SetId(this); } //重监听 ReWatch(this); //根据继承类属性和字段的Binding注解添加绑定条目 PropertyInfo[] pInfos = this.GetType().GetProperties(); FieldInfo[] fInfos = this.GetType().GetFields(); //获取公有属性 foreach (PropertyInfo info in pInfos) { Binding attr = info.GetCustomAttribute <Binding>(); if (attr == null) { continue; } _bindingTable.AddItem(this.DataEntity, attr.EntityPropertyName, info.GetValue(this), "Value"); } //获取公有字段 foreach (FieldInfo info in fInfos) { Binding attr = info.GetCustomAttribute <Binding>(); if (attr == null) { continue; } _bindingTable.AddItem(this.DataEntity, attr.EntityPropertyName, info.GetValue(this), "Value"); } //执行绑定过程 List <BindingItem> items = _bindingTable.GetItems(); foreach (BindingItem item in items) { this.watchTable.Watch(item.BindedView, item.BindedViewProperty, OnViewValueChanged); } }