static int _Show(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); Wnd obj = (Wnd)ToLua.CheckObject(L, 1, typeof(Wnd)); float arg0 = (float)LuaDLL.luaL_checknumber(L, 2); obj._Show(arg0); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
IEnumerator coDoCmd() { while (m_Cmds.Count > 0) { var aInfo = m_Cmds[0]; m_Cmds.RemoveAt(0); var wndName = aInfo.name; var subID = ""; string[] sArray = aInfo.name.Split('&'); if (sArray.Length == 2) { wndName = sArray[0]; subID = '&' + sArray[1]; } if (!m_wndInfos.ContainsKey(aInfo.name)) { if (sArray.Length == 2) { wndInfo wInfo2 = (wndInfo)m_wndInfos[wndName].Clone(); wInfo2.name = aInfo.name; m_wndInfos.Add(wInfo2.name, wInfo2); } else { Debug.LogError("窗体注册信息不存在 " + wndName); continue; } } if (aInfo.needVisible != WShowType.hide && aInfo.needVisible != WShowType.destroy) { //标记是否第一次打开(包括释放后再打开) bool isFirstShow = false; //从最近隐藏记录中清除 if (m_wndLastHideTime.ContainsKey(wndName + subID)) { m_wndLastHideTime.Remove(wndName + subID); } isFirstShow = !m_wndInstances.ContainsKey(wndName + subID); //窗体不存在,则创建 if (isFirstShow) { IEnumerator it = LoadDepend(wndName); while (it.MoveNext()) { yield return(null); } wndInfo wInfo = m_wndInfos[wndName + subID]; //创建一个uipanel GameObject uipanel = new GameObject(wInfo.name + "_panel"); uipanel.transform.parent = UIRootObj.transform; uipanel.transform.localScale = new Vector3(1, 1, 1); uipanel.transform.localRotation = new Quaternion(0, 0, 0, 1); uipanel.transform.localPosition = new Vector3(0, 0, 0); uipanel.layer = LayerMask.NameToLayer("UI");//设置层 UIPanel cmpanel = uipanel.AddComponent <UIPanel>(); GameObject wnd_Obj = GameObjectExtension.InstantiateFromPacket(wInfo.dependPackets[1], wndName + ".prefab", uipanel); if (wnd_Obj == null) { //删除刚创建的uipanel GameObject.Destroy(uipanel); Debug.LogError(String.Format("实例化窗体错误, packet:{0} wndName:{1}", wInfo.dependPackets[1], wInfo.name)); throw new Exception(); } //设置新创建的panel锚点 { UIRect rectCM = uipanel.GetComponent <UIRect>(); rectCM.SetAnchor(UIRootObj, 0, 0, 0, 0); rectCM.updateAnchors = UIRect.AnchorUpdate.OnStart; } //设置预置锚点 const int safev = 1; { UIRect rectCM = wnd_Obj.GetComponent <UIRect>(); rectCM.SetAnchor(uipanel, -safev, -safev, safev, safev); rectCM.updateAnchors = UIRect.AnchorUpdate.OnStart; } //创建挡板 GameObject uibaffle; { uibaffle = new GameObject(wInfo.name + "_baffle"); uibaffle.layer = LayerMask.NameToLayer("UI");//设置层 uibaffle.transform.parent = uipanel.transform; uibaffle.transform.localScale = Vector3.one; uibaffle.transform.localRotation = Quaternion.identity; uibaffle.transform.localPosition = Vector3.zero; //增加碰撞盒 var cl = uibaffle.AddComponent <BoxCollider>(); //增加UIWidget组件 var cmBaffleWidget = uibaffle.AddComponent <UIWidget>(); cl.isTrigger = true; cmBaffleWidget.autoResizeBoxCollider = true; cmBaffleWidget.updateAnchors = UIRect.AnchorUpdate.OnStart; cmBaffleWidget.SetAnchor(uipanel, -safev, -safev, safev, safev);//设置锚点 cmBaffleWidget.depth = -99; } wnd_Obj.name = wndName + subID; wnd_Obj.SetActive(true); uipanel.SetActive(false); m_wndInstances.Add(wndName + subID, new Wnd(uipanel, uibaffle, wInfo)); if (aInfo.isWithBg)//再加一个gameobject的原因是如果做动画底板需要层级高于预制,底板会压在预制上 { //TODODO 图片放到了Resources目录 UITexture ut = NGUITools.AddWidget <UITexture>(uipanel, -99); Texture texure = Resources.Load <Texture>("zanting_jiashenceng"); ut.mainTexture = texure; UIStretch stretch = ut.gameObject.AddComponent <UIStretch>(); stretch.style = UIStretch.Style.Both; // set relative size bigger stretch.relativeSize = new Vector2(3, 3); } } //显示 Wnd wnd = m_wndInstances[wndName + subID]; if (aInfo.needVisible == WShowType.preLoad) { yield return(null); Wnd.OnPreLoadFinish.Call(wnd); } else if (aInfo.needVisible == WShowType.show) { wnd._Show(aInfo.duration); //等待窗体组件准备就绪 yield return(null); if (isFirstShow) { Wnd.OnShowFinish.Call(wnd); } else { Wnd.OnReOpenWnd.Call(wnd); } if (OnWndOpen != null) { OnWndOpen.Call(wndName); } } } else { if (m_wndInstances.ContainsKey(wndName + subID)) { //从最近隐藏记录中清除 if (aInfo.needVisible == WShowType.destroy && m_wndLastHideTime.ContainsKey(wndName + subID)) { m_wndLastHideTime.Remove(wndName + subID); } Wnd wnd = m_wndInstances[wndName + subID]; wnd._Hide(aInfo.duration, aInfo.needVisible, aInfo.PlantfromDetph); if (aInfo.needVisible == WShowType.hide) { Wnd.OnHideFinish.Call(wnd); } else if (aInfo.needVisible == WShowType.destroy) { Wnd.OnDestroyFinish.Call(wnd); } } } yield return(null); } m_coIsRuning = false; }