Beispiel #1
0
        private RpcTypeDefinition(Type type)
        {
            List <ReflectionMethod> delegateMethodsList = new List <ReflectionMethod>();
            List <MethodInfo>       methods             = GetAllMethods(type, typeof(NetworkedBehaviour));

            for (int i = 0; i < methods.Count; i++)
            {
                MethodInfo       method     = methods[i];
                ParameterInfo[]  parameters = method.GetParameters();
                ReflectionMethod rpcMethod  = ReflectionMethod.Create(method, parameters, delegateMethodsList.Count);

                if (rpcMethod == null)
                {
                    continue;
                }

                Dictionary <ulong, ReflectionMethod> lookupTarget = rpcMethod.serverTarget ? serverMethods : clientMethods;

                lookupTarget.Add(HashMethodNameAndValidate(method.Name), rpcMethod);

                if (parameters.Length > 0)
                {
                    lookupTarget.Add(HashMethodNameAndValidate(NetworkedBehaviour.GetHashableMethodSignature(method)), rpcMethod);
                }

                if (rpcMethod.useDelegate)
                {
                    delegateMethodsList.Add(rpcMethod);
                }
            }

            delegateMethods = delegateMethodsList.ToArray();
        }
Beispiel #2
0
        private RpcTypeDefinition(Type type)
        {
            List <ReflectionMethod> delegateMethodsList = new List <ReflectionMethod>();
            List <MethodInfo>       methods             = GetAllMethods(type, typeof(NetworkedBehaviour));

            for (int i = 0; i < methods.Count; i++)
            {
                MethodInfo       method     = methods[i];
                ParameterInfo[]  parameters = method.GetParameters();
                ReflectionMethod rpcMethod  = ReflectionMethod.Create(method, parameters, delegateMethodsList.Count);

                if (rpcMethod == null)
                {
                    continue;
                }

                Dictionary <ulong, ReflectionMethod> lookupTarget = rpcMethod.serverTarget ? serverMethods : clientMethods;

                ulong nameHash = HashMethodNameAndValidate(method.Name);

                if (!lookupTarget.ContainsKey(nameHash))
                {
                    string p = "";
                    foreach (ParameterInfo pI in parameters)
                    {
                        p += pI.Name + ", ";
                    }
                    Debug.Log("Added RPC method: " + method.Name + ": " + nameHash + " (" + p + ")");
                    lookupTarget.Add(nameHash, rpcMethod);
                }

                if (parameters.Length > 0)
                {
                    ulong signatureHash = HashMethodNameAndValidate(NetworkedBehaviour.GetHashableMethodSignature(method));

                    if (!lookupTarget.ContainsKey(signatureHash))
                    {
                        lookupTarget.Add(signatureHash, rpcMethod);
                    }
                }

                if (rpcMethod.useDelegate)
                {
                    delegateMethodsList.Add(rpcMethod);
                }
            }

            delegateMethods = delegateMethodsList.ToArray();
        }