Ejemplo n.º 1
0
        private static void AddToNew(MethodInfo method, Type type)
        {
            ParameterInfo[] parameters = method.GetParameters();

            RpcMethodInfo rpcMethod = new RpcMethodInfo {
                Name             = method.Name,
                MethodInfoLookup = new Dictionary <Type, MethodInfo>()
            };

            rpcMethod.MethodInfoLookup.Add(type, method);

            foreach (ParameterInfo parameter in parameters)
            {
                if (parameter.ParameterType.IsGenericType &&
                    parameter.ParameterType.GetGenericTypeDefinition() == typeof(NetRequest <>))
                {
                    rpcMethod.TakesRequests = true;
                }
                rpcMethod.ParamTypes.Add(parameter.ParameterType);
            }

            if (method.ReturnType != typeof(void) && method.ReturnType != typeof(IEnumerator))
            {
                rpcMethod.TakesRequests = true;
            }

            Cache.Add(rpcMethod.Name, rpcMethod);
        }
Ejemplo n.º 2
0
        private static void AddToExisting(MethodInfo method, Type type)
        {
            RpcMethodInfo rpc = Cache[method.Name];

            ParameterInfo[] paramArray = method.GetParameters();

            if (paramArray.Length != rpc.ParamTypes.Count)
            {
                throw new Exception("Duplicate RPC method with incompatible param count: " + method.Name);
            }
            if (method.ReturnType != rpc.MethodInfoLookup.Values.First().ReturnType)
            {
                throw new Exception("Duplicate RPC method with incompatible return type: " + method.Name);
            }
            for (int i = 0; i < paramArray.Length; i++)
            {
                if (paramArray[i].ParameterType != rpc.ParamTypes[i])
                {
                    throw new Exception("Duplicate RPC method with incompatible param types: " + method.Name);
                }
            }
            rpc.MethodInfoLookup.Add(type, method);
        }
Ejemplo n.º 3
0
        /// <summary> Invokes RPC with parameters from the NetMessage. </summary>
        internal void Invoke(object instance, string methodName, NetMessage message, NetConnection sender)
        {
            RpcMethodInfo rpcInfo = RpcInfoCache.Get(methodName);
            MethodInfo    method  = rpcInfo.MethodInfoLookup[instance.GetType()];

            if (rpcInfo.TakesRequests && Socket.Request.Dispatch(message, sender, method, instance))
            {
                return;
            }

            if (method.ReturnType == typeof(IEnumerator))
            {
                var coroutine = (IEnumerator)method.Invoke(instance, message.Parameters);
                var behaviour = (MonoBehaviour)instance;
                if (coroutine != null)
                {
                    behaviour.StartCoroutine(coroutine);
                }
            }
            else
            {
                method.Invoke(instance, message.Parameters);
            }
        }
Ejemplo n.º 4
0
        private static void AddToNew(MethodInfo method, Type type) {

            ParameterInfo[] parameters = method.GetParameters();

            RpcMethodInfo rpcMethod = new RpcMethodInfo {
                                                            Name = method.Name,
                                                            MethodInfoLookup = new Dictionary<Type, MethodInfo>()
                                                        };

            rpcMethod.MethodInfoLookup.Add(type, method);

            foreach (ParameterInfo parameter in parameters) {
                if (parameter.ParameterType.IsGenericType &&
                    parameter.ParameterType.GetGenericTypeDefinition() == typeof (NetRequest<>))
                    rpcMethod.TakesRequests = true;
                rpcMethod.ParamTypes.Add(parameter.ParameterType);
            }

            if (method.ReturnType != typeof (void) && method.ReturnType != typeof (IEnumerator)) {
                rpcMethod.TakesRequests = true;
            }

            Cache.Add(rpcMethod.Name, rpcMethod);
        }