/// <summary> /// Gets the presenter. /// </summary> /// <param name="view">The view.</param> /// <returns></returns> public IPresenterType GetPresenter <IPresenterType>(object view) where IPresenterType : IPresenter { if (container.Kernel.HasComponent(typeof(IPresenterType))) { IPresenterType _presenter = container.Resolve <IPresenterType>(); IPresenter presenter = (IPresenter)_presenter; object[] models = new object[presenter.TypeOfModels.Length]; for (int i = 0; i < models.Length; i++) { if (container.Kernel.HasComponent(presenter.TypeOfModels[i])) { models[i] = container.Resolve(presenter.TypeOfModels[i]); } else { models[i] = null; } } presenter.BindView(view); presenter.BindModels(models); return(_presenter); } return(default(IPresenterType)); }
/// <summary> /// Gets the presenter. /// </summary> /// <param name="view">The view.</param> /// <returns></returns> public IPresenterType GetPresenter <IPresenterType>(object view) { Check.Require(view != null, "view could not be null."); if (container.ServiceContainer.Kernel.HasComponent(typeof(IPresenterType))) { IPresenterType _presenter = (IPresenterType)container.ServiceContainer.Kernel[typeof(IPresenterType)]; if (typeof(IPresenter).IsAssignableFrom(_presenter.GetType())) { IPresenter presenter = (IPresenter)_presenter; object model = container.GetType().GetMethod("GetService").MakeGenericMethod(presenter.TypeOfModel).Invoke(container, null);; presenter.BindView(view); presenter.BindModel(model); return(_presenter); } else if (typeof(IPresenter2).IsAssignableFrom(_presenter.GetType())) { IPresenter2 presenter = (IPresenter2)_presenter; object[] models = new object[presenter.TypeOfModels.Length]; for (int i = 0; i < models.Length; i++) { models[i] = container.GetType().GetMethod("GetService").MakeGenericMethod(presenter.TypeOfModels[i]).Invoke(container, null);; } presenter.BindView(view); presenter.BindModels(models); return(_presenter); } } return(default(IPresenterType)); }
/// <summary> /// 打开窗口 /// </summary> /// <param name="varName">窗口名字</param> /// <param name="intent"></param> public void OpenWindow(string varName, IIntent intent) { List <Window> .Enumerator tempEnumList = mWindowCache.GetEnumerator(); Window tempOld = null; while (tempEnumList.MoveNext()) { if (tempEnumList.Current.gameObject.name.Equals(varName)) { tempOld = tempEnumList.Current; } } if (tempOld != null) { mWindowCache.Remove(tempOld); mWindowList.Add(tempOld); //手动调用,表示重用 tempOld.ReStart(intent); } else { //为了简单,所以这里就直接使用Resources加载了 UnityEngine.Object obj = Resources.Load(varName); GameObject go = GameObject.Instantiate(obj) as GameObject; //通过配置,关联界面和Presenter System.Type tempType = null; //tempType = PresenterCfg.pconfig[varName]; IPresenter p = System.Activator.CreateInstance(tempType) as IPresenter; Window w = go.AddComponent <Window>(); w.AddPresenter(p); if (mWindowList.Count > 0) { mWindowList[mWindowList.Count - 1].Hide(); } mWindowList.Add(w); p.SetIntent(intent); p.BindView(go); } }