/// <summary> /// 初始化ViewController /// </summary> private async Task InitializeViewModel() { this.ViewModelContainer = this.GameObject.GetComponent <ViewControllerContainer>(); if (this.ViewModelContainer == null) { Debug.LogErrorFormat("Prefab {0} has not ViewContainer Component..", this.ViewName); return; } var rType = Type.GetType(this.ViewModelContainer.ViewControllerClass); if (rType == null) { Debug.LogErrorFormat("Can not find ViewModel Type: {0}", rType); return; } // 构建ViewController this.ViewController = HotfixReflectAssists.Construct(rType) as ViewController; this.ViewController.View = this; this.ViewController.BindingViewModels(this.ViewModelContainer); await this.ViewController.Initialize(); this.ViewController.DataBindingConnect(this.ViewModelContainer); }
public object DeserializeFrom(Type rType, byte[] rBytes) { var rObj = HotfixReflectAssists.Construct(rType) as HotfixSerializerBinary; using (var ms = new MemoryStream(rBytes)) { using (var br = new BinaryReader(ms)) { rObj.Deserialize(br); } } return(rObj); }
/// <summary> /// 初始化View controller /// </summary> protected virtual void InitializeViewController() { this.mViewController = HotfixReflectAssists.Construct(Type.GetType(this.ViewMB.HotfixName)) as ViewController; if (this.mViewController == null) { Debug.LogErrorFormat("Create View controller <color=blue>{0}</color> failed..", this.ViewMB.HotfixName); } else { this.mViewController.SetHotfix(this.ViewMB.HotfixName, this.GUID); this.mViewController.Initialize(this.ViewMB.Objects); } }
/// <summary> /// 把ViewModel绑定到ViewController里面 /// </summary> public void BindingViewModels(ViewModelContainer rViewModelContainer) { for (int i = 0; i < rViewModelContainer.ViewModels.Count; i++) { var rViewModelDataSource = rViewModelContainer.ViewModels[i]; ViewModel rViewModel = null; Type rViewModelType = Type.GetType(rViewModelDataSource.ViewModelPath); if (rViewModelType != null) { rViewModel = HotfixReflectAssists.Construct(rViewModelType) as ViewModel; } if (rViewModel != null) { this.AddViewModel(rViewModelDataSource.Key, rViewModel); } else { Debug.LogErrorFormat("Can not find ViewModel {0}.", rViewModelDataSource.ViewModelPath); } } // 指定ViewModel给子类的变量 通过HotfixBinding属性标签绑定 foreach (var rPair in this.ViewModels) { ViewModel rViewModel = rPair.Value; var rViewModelProp = this.GetType().GetFields(HotfixReflectAssists.flags_public) .Where(prop => { var rAttrObjs = prop.GetCustomAttributes(typeof(HotfixBindingAttribute), false); if (rAttrObjs == null || rAttrObjs.Length == 0) { return(false); } var rBindingAttr = rAttrObjs[0] as HotfixBindingAttribute; return(prop.FieldType.IsSubclassOf(typeof(ViewModel)) && rBindingAttr != null && rBindingAttr.Name.Equals(rPair.Key)); }).FirstOrDefault(); if (rViewModelProp != null) { rViewModelProp.SetValue(this, rViewModel); } else { Debug.LogErrorFormat("ViewModel {0} is not define in ViewController({1})", rViewModel.GetType(), this.GetType()); } } }
public ViewModel ReceiveViewModel(string rViewModelClassName) { ViewModel rViewModel = null; if (!this.mViewModels.TryGetValue(rViewModelClassName, out rViewModel)) { var rViewModelType = Type.GetType(rViewModelClassName); rViewModel = HotfixReflectAssists.Construct(rViewModelType) as ViewModel; rViewModel.Initialize(); this.mViewModels.Add(rViewModelClassName, rViewModel); } return(rViewModel); }
public static T Deserialize <T>(this BinaryReader rReader, T value) where T : HotfixSerializerBinary { bool bValid = rReader.Deserialize(false); if (!bValid) { return(null); } var rInstance = HotfixReflectAssists.Construct <T>(); rInstance.Deserialize(rReader); return(rInstance); }
public static T DeserializeDynamic <T>(this BinaryReader rReader, T rValue) where T : HotfixSerializerBinary { bool bValid = rReader.Deserialize(false); if (!bValid) { return(null); } var rFullName = rReader.Deserialize(string.Empty); var rInstance = HotfixReflectAssists.TConstruct <T>(Type.GetType(rFullName)); rInstance.Deserialize(rReader); return(rInstance); }
public object DeserializeFrom(Type rType, byte[] rBytes, int nIndex, int nCount) { var rObj = HotfixReflectAssists.Construct(rType) as HotfixSerializerBinary; using (MemoryStream ms = mRecyclableMSMgr.GetStream("protobuf", rBytes, nIndex, nCount)) { using (var br = new BinaryReader(ms)) { rObj.Deserialize(br); } } ISupportInitialize iSupportInitialize = rObj as ISupportInitialize; if (iSupportInitialize == null) { return(rObj); } iSupportInitialize.EndInit(); return(rObj); }