private void OnLoadViewRes(Resource res, bool succ) { if (succ) { string viewname = ViewConfig.GetViewName(res.path); BaseViewController vc; //此处为修改框架,防止同时存在两个view,直接覆盖 if (views.TryGetValue(viewname, out vc)) { views.Remove(viewname); vc.Close(); } GameObject go = GameObject.Instantiate(res.UnityObj) as GameObject; switch (ViewConfig.Instance.GetViewCo(viewname).viewtype) { case ViewType.Dialog: go.transform.SetParent(DialogRoot, false); break; case ViewType.Window: go.transform.SetParent(WindowRoot, false); break; case ViewType.Full: go.transform.SetParent(FullScreenRoot, false); break; default: throw new ArgumentOutOfRangeException(); } vc = BaseViewController.Create(viewname, go); views.Add(viewname, vc); //从此处跳转到View覆盖方法 vc.Build(); vc.OnBuild(); vc.Open(); vc.OnOpen(); // Debug.Log(string.Format("<color=#ffffffff><---{0}-{1}----></color>", go.name, "test1")); GlobalDispatcher.Instance.Dispatch(GlobalEvent.OnViewLoadFinished, go); } else { Debug.LogError("load view " + res.path + " fail"); } }
public void Open(string viewName, object p = null) { BaseViewController vc; if (views.TryGetValue(viewName, out vc)) { if (!vc.IsOpen) { vc.Open(); vc.OnOpen(); } } else { string viewpath = ViewConfig.GetViewPath(viewName); ResourceMgr.Instance.LoadResource(viewpath, OnLoadViewRes); } }