Beispiel #1
0
    /// <summary>
    /// Calls a method remotely on all devices. The string must contain the name of the
    /// GameObject, the Component and the method all separated by dots. The arguments must
    /// match the parameter list of the method or else an error will be generated.
    /// Example: "GameManager.LockStepManager.Start"
    /// </summary>
    /// <param name="rpcIdentifier">the method identifier</param>
    /// <param name="rpcArgs">the arguments passed to the method</param>
    public void CallRpc(string rpcIdentifier, params object[] rpcArgs)
    {
        PrintDebug(DebugLevel.DATA_ONLY, "CallRpc identifier={0}, args={1}",
                   rpcIdentifier, rpcArgs);
        if (rpcIdentifier == null)
        {
            ReactToError("CallRpc called with rpcIdentifier == null");
            return;
        }
        if (rpcArgs == null)
        {
            ReactToError("CallRpc called with rpcArgs == null");
            return;
        }
        string[] parts = rpcIdentifier.Split('.');
        if (parts.Length != 3)
        {
            ReactToError("CallRpc called with illegal rpcIdentifier={0}", rpcIdentifier);
            return;
        }
        RpcMsg rpcMsg = new RpcMsg();

        rpcMsg.gameObjName   = parts[0];
        rpcMsg.componentName = parts[1];
        rpcMsg.methodName    = parts[2];
        rpcMsg.parameters    = rpcArgs;

        CallRpc(rpcMsg);
    }
Beispiel #2
0
    /// <summary>
    /// Calls a method remotely on all devices.
    /// </summary>
    /// <param name="rpcMsg">Data about the method that is to be called remotely.</param>
    public void CallRpc(RpcMsg rpcMsg)
    {
        PrintDebug(DebugLevel.DATA_ONLY, "CallRpc={0}.{1}.{2} ({3})",
                   rpcMsg.gameObjName, rpcMsg.componentName,
                   rpcMsg.methodName, rpcMsg.parameters);
        RpcNetworkData data = new RpcNetworkData();

        data.msgObj = rpcMsg;
        ClientSideBuffer.Add(data);
    }
Beispiel #3
0
    public void sendSetTo123Rpc()
    {
        RpcMsg rpcMsg = new RpcMsg();

        rpcMsg.gameObjName   = "LockstepManager";
        rpcMsg.componentName = "TestGameSkript";
        rpcMsg.methodName    = "SetTo";
        rpcMsg.parameters    = new System.Object[] { 123 };

        GameObject.Find("LockstepManager").GetComponent <LockStepManager>().CallRpc(rpcMsg);
    }
Beispiel #4
0
        private void OnRpc(RpcMsg msg)
        {
            var methodname = msg.methodeName;
            //for (var k = 0; k < args.Length; k++)
            //{
            //    name += "_" + args[k].GetType().Name;
            //}
            //fire(msg.methodeName, args);
            Dictionary <object, MethodInfo> rpcinfo = new Dictionary <object, MethodInfo>();

            if (rpcHandlerDict.TryGetValue(methodname, out rpcinfo))
            {
                object[] args = null;
                var      iter = rpcinfo.GetEnumerator();
                bool     flag = true;

                while (iter.MoveNext())
                {
                    var info = iter.Current;
                    if (flag)
                    {
                        flag = false;
                        try
                        {
                            if (!MsgHelper.UnpackMethod(info.Value, msg.data, out args))
                            {
                                throw new Exception("Parameter cannot be unpacked for rpc method " + methodname);
                            }
                        }
                        catch (Exception e)
                        {
                            throw new Exception("OnRpc UnpackMethod Execption for method name " + methodname + " exception:" + e);
                        }
                    }
                    info.Value.Invoke(info.Key, args);
                }

                return;
            }

            if (!entityDict.ContainsKey(msg.EntityID))
            {
                throw new Exception("entity id->" + msg.EntityID + " not exists!");
            }

            entityDict[msg.EntityID].OnRpc(methodname, msg.data);
        }
Beispiel #5
0
        public void Rpc(string methodname, params object[] args)
        {
            byte[] bytes;
            if (!MsgHelper.Pack(args, out bytes))
            {
                throw new Exception("Parameter cannot be pack for rpc call method:" + methodname);
            }

            RpcMsg req = new RpcMsg();

            //req.rpcType = rpctype;
            req.methodeName = methodname;
            req.data        = bytes;

            try
            {
                Send(req);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }