public void Close() { if (this.mState != (int)FrameStatus.FS_OPEN) { return; } OnCloseFrame(); if (null != mScriptBinder) { mScriptBinder.DestroyWithFrame(); mScriptBinder = null; } userData = null; mFrameId = -1; mTypeId = -1; mLayer = 0; mModuleId = -1; if (null != gameObject) { Object.Destroy(gameObject); gameObject = null; } this.mState = (int)FrameStatus.FS_CLOSED; }
public void Open(int typeId, int frameId, int moduleId = -1, int layer = 1, GameObject root = null) { if (this.mState == (int)FrameStatus.FS_OPEN) { Debug.LogErrorFormat("this frame has opened ..."); return; } this.mLayer = layer; this.mTypeId = typeId; this.mFrameId = frameId; this.mModuleId = moduleId; this.mState = (int)FrameStatus.FS_INVALID; var path = GetPrefabPath(); if (!string.IsNullOrEmpty(path)) { gameObject = AssetLoaderManager.Instance().LoadResources <GameObject>(path, AssetType.AT_PREFAB); if (null == gameObject && MayLoadFromResourcesFile()) { var objRef = Resources.Load <GameObject>(path); if (null != objRef) { gameObject = Object.Instantiate(objRef) as GameObject; } } } else { frameItem = TableManager.Instance().GetTableItem <ProtoTable.FrameTypeTable>(mTypeId); if (null == frameItem) { Debug.LogErrorFormat("query frameItem failed for id = {0}, class = {1}", mTypeId, GetType().Name); return; } gameObject = AssetLoaderManager.Instance().LoadResources <GameObject>(frameItem.Prefab, AssetType.AT_PREFAB); } if (null == gameObject) { Debug.LogErrorFormat("load frame prefab failed for moduleId = {0} path = {1}", moduleId, path); return; } GameObject parent = root; if (parent == null) { var uiLayer = UIManager.Instance().GetLayer(mLayer); if (null != uiLayer) { parent = uiLayer.goLayer; } } if (null == parent) { Debug.LogErrorFormat("parent is null , create frame failed , typeId = {0}", mTypeId); return; } mScriptBinder = gameObject.GetComponent <ComScriptBinder>(); if (null != mScriptBinder) { _InitScriptBinder(); } gameObject.transform.SetParent(parent.transform, false); this.mState = (int)FrameStatus.FS_OPEN; OnOpenFrame(); }