private void OnLoaded(GameObject go) { if (!mActive) { mUILoader.UnloadInstance(go); return; } gameObject = go; RectTransform rectTrans = go.transform as RectTransform; rectTrans.SetParent(popup_root, false); rectTrans.offsetMin = Vector2.zero; rectTrans.offsetMax = Vector2.zero; rectTrans.localRotation = Quaternion.identity; rectTrans.localScale = Vector3.one; bool overlay = false; mBehaviours.Clear(); go.GetComponents <MonoBehaviour>(mBehaviours); bool paraSet = false; for (int i = 0, imax = mBehaviours.Count; i < imax; i++) { MonoBehaviour behaviour = mBehaviours[i]; IUIParameterHandler handler = behaviour as IUIParameterHandler; if (handler != null) { try { handler.SetParameter(param); } catch (System.Exception e) { Debug.LogError(e); } paraSet = true; } IPopupOverlay popupOverlay = behaviour as IPopupOverlay; if (popupOverlay != null && popupOverlay.Overlay) { overlay = true; } } if (param != null && !paraSet) { Debug.LogErrorFormat(go, "[UIManager] No parameter handler found for '{0]' !", name); } if (mFocusState == 1) { for (int i = 0, imax = mBehaviours.Count; i < imax; i++) { IUIFocusHandler handler = mBehaviours[i] as IUIFocusHandler; if (handler != null) { try { handler.OnFocus(); } catch (System.Exception e) { Debug.LogException(e); } } } mFocusState = 2; } go.SetActive(visible); LoadedCallback callback = mOnLoadedCallback; mOnLoadedCallback = null; callback(this, overlay); }
public void Close() { mActive = false; if (mGameObject != null) { for (int i = 0, imax = mBehaviours.Count; i < imax; i++) { IUIFocusHandler handler = mBehaviours[i] as IUIFocusHandler; if (handler != null) { try { handler.OnClose(); } catch (System.Exception e) { Debug.LogException(e); } } } mUILoader.UnloadInstance(mGameObject); mGameObject = null; mBehaviours.Clear(); } }