public object Execute(object instance, params object[] parameters)
        {
            // TODO: catch reflection exceptions and NetworkException, what about other exceptions? can we rethrow them without unity crashing?

            try
            {
                return(info.Invoke(instance, parameters));
            }
            catch (Exception e)
            {
                string paramstr;

                if (parameters.Length != 0)
                {
                    paramstr = parameters[0].ToString();

                    for (int i = 1; i < parameters.Length; i++)
                    {
                        paramstr += ", " + parameters[i];
                    }
                }
                else
                {
                    paramstr = String.Empty;
                }

                NetworkLog.Error(NetworkLogFlags.RPC, "Failed to invoke ", this, " with ", parameters.Length, " parameter(s): ", paramstr);
                NetworkLog.Error(NetworkLogFlags.RPC, e);

                // swallow the exception, so that we don't actually stop the execution flow in uLink.
                return(null);
            }
        }
Ejemplo n.º 2
0
        private void _Initialize(Component source, UnityEngine.MonoBehaviour[] components, string rpcName, RuntimeTypeHandle messageInfoHandle)
        {
            string type = "";

            int typeIndex = rpcName.IndexOf(':');

            if (typeIndex != -1)
            {
                type    = rpcName.Substring(0, typeIndex);
                rpcName = rpcName.Substring(typeIndex + 1);
            }

            foreach (var component in components)
            {
                if (!String.IsNullOrEmpty(type) && component.GetType().Name != type)
                {
                    continue;
                }

                var candidate = new RPCMethod(component.GetType(), rpcName, true);
                if (candidate.isExecutable)
                {
                    if (instance.IsNotNull())
                    {
                        NetworkLog.Error(NetworkLogFlags.RPC, "Found two or more RPCs named '", rpcName, "' inside the receivers at ", source);

                        instance = null;
                        return;
                    }

                    instance = component;
                    method   = candidate;
                }
            }

            if (instance.IsNotNull())
            {
                reader = new ParameterReader(method, messageInfoHandle);
            }
            else
            {
                Log.Error(NetworkLogFlags.RPC, "No receiver found for RPC '", rpcName, "' at ", source);
            }
        }