/// <summary> /// /// </summary> /// <param name="commandId"></param> /// <param name="bytes"></param> public void OnReceiveMessage(int commandId, byte[] bytes) { try { if (bytes == null) { _onReceiveMessageCallback.Call(commandId, 0); } else { ByteBuffer data = new ByteBuffer(bytes); if (_onReceiveMessageCallback != null) { _onReceiveMessageCallback.Call(commandId, data.ReadBuffer()); } data.Close(); } } catch (Exception e) { DebugManager.LogError("Scoket OnReceiveMessage Error:" + commandId.ToString() + "," + e.Message); } }
static int Close(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); CFramework.ByteBuffer obj = (CFramework.ByteBuffer)ToLua.CheckObject <CFramework.ByteBuffer>(L, 1); obj.Close(); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
IEnumerator DoRegisterPB(LuaFunction processCallback, LuaFunction completeCallback) { string configFilePath = ""; string pbDir = ""; if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) { pbDir = FileUtil.Instance.GetWritePath("protobuf/"); } else { pbDir = FileUtil.Instance.GetAssetsPath("GameApp/Protobuf/").Replace("file://", ""); } configFilePath = pbDir + "proto.config"; Debugger.Log(configFilePath); string configFileStr = ""; if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) { WWW www = new WWW(configFilePath); yield return(www); if (www.isDone) { configFileStr = www.text; yield return(0); } else { DebugManager.LogError("DoRegisterPB Error:读取文件错误!" + configFilePath); } www.Dispose(); } else { if (File.Exists(configFilePath) == true) { try { configFileStr = File.ReadAllText(configFilePath); } catch (Exception e) { DebugManager.LogError("DoRegisterPB Error:读取配置文件错误!" + e.Message); yield break; } } else { DebugManager.LogError("DoRegisterPB Error:读取文件错误!" + configFilePath); } } DebugManager.Log("configFileStr:" + configFileStr); string[] pClassCommandList = configFileStr.Split(','); string fpath = pbDir + "message.pb"; DebugManager.Log("读取注册PB文件:" + fpath); if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) { WWW www = new WWW(fpath); yield return(www); if (www.isDone) { ByteBuffer data = new ByteBuffer(www.bytes); processCallback.Call(data); data.Close(); yield return(0); } else { DebugManager.LogError("DoRegisterPB Error:读取文件错误!" + fpath); } www.Dispose(); } else { try { ByteBuffer data = new ByteBuffer(File.ReadAllBytes(fpath)); processCallback.Call(data); data.Close(); } catch (Exception e) { DebugManager.LogError("DoRegisterPB Error:读取文件错误!" + fpath + "\n error:\n" + e.Message); } } completeCallback.Call(pClassCommandList); completeCallback.Dispose(); processCallback.Dispose(); }