Exemplo n.º 1
0
        /// <summary>
        /// 处理服务器到客户端的调用
        /// </summary>
        /// <param name="buf"></param>
        private void OnCallScript(KProtoBuf buf)
        {
            S2C_CALL_SCRIPT respond = buf as S2C_CALL_SCRIPT;

            ArrayList remoteObjects = UnpackAll(new MemoryStream(respond.data));

            uint       methodHash = (uint)remoteObjects[0];
            MethodInfo methodInfo = hash2MethodInfo.ContainsKey(methodHash) ? hash2MethodInfo[methodHash] : null;

            if (methodInfo == null)
            {
                //Debugger.LogErrorFormat("Remote call method error, no such function, protocolID = {0}, hashCode = {1}", respond.protocolID, methodHash);
                return;
            }

            //Debug.LogWarning(methodInfo.Name);

            if (Application.isEditor)
            {
                try
                {
                    methodInfo.Invoke(this, FixRemoteCallParams(remoteObjects, methodInfo.GetParameters()));
                }
                catch (System.Exception ex)
                {
                    Debug.LogError("Remote call method error in function hashCode = " + methodHash + " Methodinfo Name: " + methodInfo.Name);
                    Debug.LogException(ex);
                }
            }
            else
            {
                methodInfo.Invoke(this, FixRemoteCallParams(remoteObjects, methodInfo.GetParameters()));
            }

            //回收临时数据
            RemoteBool.ResetPosition();
            RemoteInt8.ResetPosition();
            RemoteInt16.ResetPosition();
            RemoteInt32.ResetPosition();
            RemoteUInt8.ResetPosition();
            RemoteUInt16.ResetPosition();
            RemoteUInt32.ResetPosition();
            RemoteFloat.ResetPosition();
            RemoteDouble.ResetPosition();
            RemoteString.ResetPosition();
            RemoteString.ResetPosition();
            RemoteUInt64.ResetPosition();
        }