public bool DoUnload() { bool ret = false; do { if (!this._viewMgr.CanUnload(this)) { ZLog.E(this._uiObj, " ui {0} order {1} can not unload by frame", this.GetName(), this.ZOrder); break; } if (!this.OnUnload()) { ZLog.E(this._uiObj, " ui {0} order {1} can not unload by view", this.GetName(), this.ZOrder); break; } if (this._evtSet.Count > 0) { foreach (var evt_cate in _evtSet) { EventMgr.Instance.AddEvt(ViewEvtHandler, evt_cate, false); } } this._viewMgr.DestoryView(this); ret = true; } while (false); return(ret); }
public virtual void InitArgs(int zOrder, GameObject go, IViewMgr mgr, params object[] args) { this._zOrder = zOrder; this._uiObj = go; this._viewMgr = mgr; this._evtSet = new HashSet <string>(); try { CnUiComponent comp = this.GetCnUiComponent(); if (comp != null) { bool ret = comp.InitUiComponent(this._uiObj.transform); ZLog.I(this._uiObj, "ui {0} init compent {1}", this.GetName(), ret ?"ok":"failed"); } else { ZLog.I(this._uiObj, "ui {0} no init compent", this.GetName()); } this.OnLoad(args); }catch (Exception e) { ZLog.E(this._uiObj, " ui {0} OnLoad err {1}", this.GetName(), e.ToString()); } }
public void Close(bool bSync = true) { if (socket != null) { if (socket.Connected && 0 == _tryDisconnect) { _tryDisconnect = WAIT_DISCONNECT_TIMES; this.socket.Shutdown(SocketShutdown.Both); if (bSync) { socket.Disconnect(false); } else { try { var args = new SocketAsyncEventArgs(); socket.DisconnectAsync(args); } catch (Exception e) { socket.Disconnect(false); ZLog.E(null, "Close err {0}", e.ToString()); } } } } }
public GameObject InitResEx(string name, Transform parent) { GameObject ins = null; do { GameObject go = this.FindUIRes(name); if (null == go) { ZLog.E(null, "no ui {0}", name); break; } ins = GameObject.Instantiate(go) as GameObject; if (ins == null) { ZLog.E(null, "{0} Instantiate fail", name); break; } string[] strList = name.Split(new Char[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries); string new_name = strList[strList.Length - 1]; ins.transform.SetParent(parent, false); ins.transform.localPosition = Vector3.zero; ins.transform.localScale = Vector3.one; ins.transform.localRotation = Quaternion.identity; ins.name = new_name; ZLog.I(null, "Load {0} ok", name); } while (false); return(ins); }
void OnMessage(object sender, EventArgs e) { MessageEventArgs me = e as MessageEventArgs; do { if (me.IsText) { lock (_resvMsgQueue) { this._resvMsgQueue.Enqueue(new WsMsg(me.Data)); } break; } if (me.IsBinary) { lock (_resvMsgQueue) { this._resvMsgQueue.Enqueue(new WsMsg(me.RawData)); } break; } ZLog.E(_mb, "unkonwn msg {0}", me.ToString()); } while (false); }
public void Callback_ReceiveHeadOK(IAsyncResult ar) { int reason = 0; string err = ""; try { int receiveLen = socket.EndReceive(ar); do { if (receiveLen <= 0) { reason = 4; err = "recv header sz " + receiveLen.ToString(); break; } MessagePacket mp = (MessagePacket)ar.AsyncState; mp._curBytes += receiveLen;//自增接收到的数据 if (!mp.IsAllRecieve()) { //获取的数据长度小于头长度 socket.BeginReceive(mp._buffer, mp._curBytes, mp.NeedRecieveBytes(), 0, new AsyncCallback(Callback_ReceiveHeadOK), mp); break; } int bodyLen = this._protocol.GetBodySize(this._curRecvMsg._headerPack); if (bodyLen > _protocol.GetMaxSize()) { reason = 4; err = string.Format("too max sz {0} allow {1}", bodyLen, _protocol.GetMaxSize()); ZLog.E(_mb, err); break; } else if (bodyLen == 0) { lock (_resvMsgQueue) { _resvMsgQueue.Enqueue(_curRecvMsg); } this.StartRecvHeader(); break; } _curRecvMsg._bodyPack = new MessagePacket(bodyLen); socket.BeginReceive(this._curRecvMsg._bodyPack._buffer, 0, bodyLen, 0, new AsyncCallback(Callback_ReceiveBodyOK), this._curRecvMsg._bodyPack); } while (false); } catch (Exception e) { reason = 5; err = e.ToString(); } if (reason > 0) { Dispose(); OnDisconnect(reason, err); } }
protected Transform GetChild(Transform parent, string childName) { var res = parent.Find(childName); if (res == null) { ZLog.E(this._uiObj, string.Format("{0}不存在", childName)); } return(res); }
public void TriggerEvt(object sender, int event_type, object param) { if (_evtHandler != null) { _evtHandler(sender, _name, event_type, param); } else { ZLog.E(null, "event {0} no handler", event_type); } }
static public UnityEngine.Object Load(string path) { var obj = Resources.Load(path); if (obj == null) { ZLog.E(null, "{0} load fail", path); return(null); } return(obj); }
public bool CanUnload(CnPanelObj view) { if (this._viewStack.Contains(view)) { return(true); } else { ZLog.E(null, "{0} no view {1}_{2}", this._root.name, view.GetName(), view.ZOrder); } return(false);// this.IsTop(view); }
private void OnDisconnect(int reason, string str) { if (netWorkState != NetWorkState.CLOSING) { netWorkState = NetWorkState.CLOSING; _disReason = reason; _err = str; } else { ZLog.E(_mb, "OnDisconnect state err {0}", netWorkState); } }
public void SetClickEventOnce(Button btn, Action <object[]> method, object[] args) { if (btn == null) { ZLog.E(this._uiObj, "btn null"); return; } btn.onClick.RemoveAllListeners(); btn.onClick.AddListener(() => { method(args); }); ZLog.D(this._uiObj, "Add btn evt ok"); }
protected T GetElement <T>(Transform parent, string childName) where T : Component { var child = GetChild(parent, childName); if (child) { var res = child.GetComponent <T>(); if (res == null) { ZLog.E(this._uiObj, string.Format("{1}不存在节点不存在{2}", childName, typeof(T).Name)); } return(res); } return(null); }
public GameObject Instantiate(string loader_name, string res_name, Transform parent, bool active) { GameObject go = null; do { TmplLoaderBase loader = this.FindResLoader(loader_name); if (null == loader) { ZLog.E(null, "loader {0} not found", loader_name); break; } go = loader.Instantiate(res_name, parent, active); } while (false); return(go); }
public GameObject FindTmpl(string loader_name, string res_name) { GameObject go = null; do { TmplLoaderBase loader = this.FindResLoader(loader_name); if (null == loader) { ZLog.E(null, "loader {0} not found", loader_name); break; } go = loader.FindTmpl(res_name); }while(false); return(go); }
private IEnumerator _AutoUpdate() { bool running = true; while (running) { try { running = Update(); }catch (Exception e) { ZLog.E(_mb, "{0}", e); } yield return(1); } ZLog.I(_mb, "{0}:{1} exit loop", _host, _port); }
public GameObject Instantiate(string res_name, Transform parent, bool active = false) { GameObject go = null; do { GameObject tmpl = this.FindTmpl(res_name); if (null == tmpl) { ZLog.E(null, "loader, {0} res {1} not found", _loaderName, res_name); break; } go = GameObject.Instantiate(tmpl) as GameObject; go.name = tmpl.name; go.transform.SetParent(parent, active); } while (false); return(go); }
public void RegisertEvt(string evt) { do { if (null == evt || evt.Length == 0) { ZLog.E(null, "evt type err"); break; } if (_evtSet.Contains(evt)) { ZLog.E(null, "evt {0} already register", evt); break; } EventMgr.Instance.AddEvt(ViewEvtHandler, evt, true); _evtSet.Add(evt); } while (false); }
static public UnityEngine.GameObject LoadAsGameObj(string path) { GameObject ins = null; var obj = LoadResource.Load(path); if (obj != null) { ins = UnityEngine.Object.Instantiate(obj) as GameObject; if (null != ins) { ins.name = obj.name; } else { ZLog.E(null, "{0} Instantiate fail", path); } } return(ins); }