void OnDestroy() { foreach (var pair in networkMap) { RPCNetwork network = pair.Value; network.CutOff(); } }
void Awake() { _perspectiveProjection = Camera.main.GetComponent <PerspectiveProjection>(); _leftCursorScript = leftCursor.GetComponent <NSCursor>(); _rightCursorScript = rightCursor.GetComponent <NSCursor>(); _NSObjects = new Dictionary <string, GameObject>(); _NSNetwork = this.gameObject.GetComponent <RPCNetwork>(); }
/// <summary> /// Try connecting to server /// </summary> public void BeginConnect(NetType netType, string host, int port) { if (!networkMap.ContainsKey(netType)) { CreateNetWork(netType, OnResponceNetMsg, OnNetException); } RPCNetwork network = networkMap[netType]; if (network == null) { Debug.Log(string.Format("NetType{0:D} craete failed", (int)netType)); return; } network.DoConnect(host, port); }
/// <summary> /// Submit NetMsg to client, called per frame /// </summary> void SubmitNetMsg(NetType netType) { if (!msgBufferMap.ContainsKey(netType)) { return; } List <NetMsgDef> msgList = msgBufferMap[netType]; if (msgList.Count < 1) { return; } RPCNetwork network = networkMap[netType]; network.SubmitNetMsg(msgList); msgList.Clear(); }
/// <summary> /// Create a instance of RPCNetwork /// </summary> public void CreateNetWork(NetType netType, RPCResponceCallback responceCallback, RPCExceptionCallback exceptionCallback) { RPCNetwork network = new RPCNetwork(netType, responceCallback, exceptionCallback); networkMap.Add(netType, network); }