public override void Close() { WindowMng.RemoveWindow(mWndObject, this); OnClose(); if (mWndObject != null) { GameObject.Destroy(mWndObject); mWndObject = null; } if (WindowStyle.WS_Ext <= mWindowStyle && mExtBackground != null) { GameObject.Destroy(mExtBackground); mExtBackground = null; } msInstance = null; }
public void Open() { //Debug.Log("Open Window:"+PrefabName); if (mWndObject) { Debug.LogError("Window:" + PrefabName + "The window already opened!!!!"); WindowMng.RemoveWindow(mWndObject, this); GameObject.Destroy(mWndObject);//这句话会导致一个界面上的成员变量没清理 if (WindowStyle.WS_Ext <= mWindowStyle) { GameObject.Destroy(mExtBackground); } //return; } #if UNITY_2017 || UNITY_5_5 mRootUI = GameObject.Find("Canvas"); if (mRootUI != null) { if (!CanvasMode()) { mWndObject = GameObject.Instantiate(Resources.Load <GameObject>(PrefabName), Vector3.zero, Quaternion.identity, mRootUI.transform) as GameObject; } else { mWndObject = GameObject.Instantiate(Resources.Load <GameObject>(PrefabName)); } } else { mWndObject = GameObject.Instantiate(Resources.Load <GameObject>(PrefabName)); } if (mRootUI != null) { if (!CanvasMode()) { WndObject.transform.SetParent(mRootUI.transform); WndObject.transform.localScale = Vector3.one; WndObject.transform.localRotation = Quaternion.identity; } RectTransform rectTran = WndObject.GetComponent <RectTransform>(); if (rectTran != null && rectTran.anchorMin == Vector2.zero && rectTran.anchorMax == Vector2.one) { if (rectTran.rect.width == 0 && rectTran.rect.height == 0) { rectTran.sizeDelta = new Vector2(0, 0); } } if (rectTran != null) { rectTran.anchoredPosition3D = new Vector3(0, 0, 0); } } else { //mRootUI = GameObject.Find("Anchor"); //if (mRootUI != null) // WndObject.transform.SetParent(mRootUI.transform); } #else mRootUI = GameObject.Find("Anchor"); WndObject.transform.parent = mRootUI.transform; #endif WndObject.transform.localScale = Vector3.one; //WndObject.transform.localPosition = new Vector3(GetX(), GetY(), GetZ()); WindowMng.AddWindow(mWndObject, this); OnOpen(); //attention Order //mCamera = GameObject.Find("Camera-CloseUp"); //if (mCamera != null) // mCullingMask = mCamera.GetComponent<Camera>().cullingMask; //阻挡UI之后其他的UI响应 if (mWindowStyle >= WindowStyle.WS_Ext) { mExtBackground = GameObject.Instantiate(Resources.Load("BackgroundExtWnd")) as GameObject; mExtBackground.transform.SetParent(WndObject.transform); mExtBackground.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f); mExtBackground.transform.localScale = Vector3.one; mExtBackground.transform.localRotation = Quaternion.identity; mExtBackground.transform.SetAsFirstSibling(); } //if (WindowStyle.WS_CullingMask <= mWindowStyle) //{ // Debug.Log("LayerMask NGUI : = " + LayerMask.NameToLayer("NGUI")); // //attention Order // if (mCamera != null) // mCamera.GetComponent<Camera>().cullingMask = LayerMask.NameToLayer("NGUI"); //} //AutoAdaptGUI(); }