public void CreateActor(global::System.String typename, global::System.String name, global::System.Action <global::Fenix.Common.DefaultErrCode, global::System.String, global::System.UInt64> callback) { var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient); if (this.FromHostId == toHostId) { 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, callback, context }); } else { Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { typename, name, callback }); } return; } 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); callback?.Invoke(cbMsg.code, cbMsg.arg1, cbMsg.arg2); }); this.CallRemoteMethod(OpCode.CREATE_ACTOR_REQ, msg, cb); }); }
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); }