Exemplo n.º 1
0
        public void SERVER_ONLY_create_actor(IMessage msg, Action <IMessage> cb, RpcContext context)
        {
            var _msg = (CreateActorReq)msg;

            this.CreateActor(_msg.typename, _msg.name, (code, arg1, arg2) =>
            {
                var cbMsg  = new CreateActorReq.Callback();
                cbMsg.code = code;
                cbMsg.arg1 = arg1;
                cbMsg.arg2 = arg2;
                cb.Invoke(cbMsg);
            }, context);
        }
Exemplo n.º 2
0
        public async Task <CreateActorReq.Callback> CreateActorAsync(global::System.String typename, global::System.String name, global::System.Action <global::Fenix.Common.DefaultErrCode, global::System.String, global::System.UInt64> callback = null)
        {
            var t        = new TaskCompletionSource <CreateActorReq.Callback>();
            var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient);

            if (this.FromHostId == toHostId)
            {
                global::System.Action <global::Fenix.Common.DefaultErrCode, global::System.String, global::System.UInt64> _cb = (code, arg1, arg2) =>
                {
                    var cbMsg = new CreateActorReq.Callback();
                    cbMsg.code = code;
                    cbMsg.arg1 = arg1;
                    cbMsg.arg2 = arg2;
                    callback?.Invoke(cbMsg.code, cbMsg.arg1, cbMsg.arg2);
                    t.TrySetResult(cbMsg);
                };
                var protoCode = OpCode.CREATE_ACTOR_REQ;
                if (protoCode < OpCode.CALL_ACTOR_METHOD)
                {
                    var peer    = Global.NetManager.GetPeerById(this.FromHostId, this.NetType);
                    var context = new RpcContext(null, peer);
                    Global.Host.CallMethodWithParams(protoCode, new object[] { typename, name, _cb, context });
                }
                else
                {
                    Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { typename, name, _cb });
                }
            }
            else
            {
                Action <CreateActorReq.Callback> _cb = (cbMsg) =>
                {
                    callback?.Invoke(cbMsg.code, cbMsg.arg1, cbMsg.arg2);
                    t.TrySetResult(cbMsg);
                };
                await Task.Run(() => {
                    var msg = new CreateActorReq()
                    {
                        typename = typename,
                        name     = name
                    };
                    var cb = new Action <byte[]>((cbData) => {
                        var cbMsg = cbData == null ? new CreateActorReq.Callback() : RpcUtil.Deserialize <CreateActorReq.Callback>(cbData);
                        _cb?.Invoke(cbMsg);
                    });
                    this.CallRemoteMethod(OpCode.CREATE_ACTOR_REQ, msg, cb);
                });
            }
            return(await t.Task);
        }
Exemplo n.º 3
0
        public void SERVER_ONLY__Fenix__Host__create_actor(IMessage msg, Action <IMessage> cb, RpcContext context)
        {
#if ENABLE_IL2CPP || !DEBUG || RUNTIME
            var _msg = (CreateActorReq)msg;
            this.CreateActor(_msg.typename, _msg.name, (code, arg1) =>
            {
                var cbMsg  = new CreateActorReq.Callback();
                cbMsg.code = code;
                cbMsg.arg1 = arg1;
                cb.Invoke(cbMsg);
            }, context);
#else
            dynamic _msg = msg;
            self.CreateActor(_msg.typename, _msg.name, (global::System.Action <global::Fenix.Common.DefaultErrCode, global::Fenix.ActorInfo>)((code, arg1) =>
            {
                dynamic cbMsg = new CreateActorReq.Callback();
                cbMsg.code    = code;
                cbMsg.arg1    = arg1;
                cb.Invoke(cbMsg);
            }), context);
#endif
        }