public async Task <__Fenix__Host__OnBeforeDisconnectNtf.Callback> OnBeforeDisconnectAsync(global::Fenix.Common.DisconnectReason reason, global::System.Action callback = null) { var t = new TaskCompletionSource <__Fenix__Host__OnBeforeDisconnectNtf.Callback>(); var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient); if (this.FromHostId == toHostId) { global::System.Action _cb = () => { var cbMsg = new __Fenix__Host__OnBeforeDisconnectNtf.Callback(); callback?.Invoke(); t.TrySetResult(cbMsg); }; var protoCode = OpCode.ON_BEFORE_DISCONNECT_NTF; 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[] { reason, _cb, context }); } else { Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { reason, _cb }); } } else { Action <__Fenix__Host__OnBeforeDisconnectNtf.Callback> _cb = (cbMsg) => { callback?.Invoke(); t.TrySetResult(cbMsg); }; await Task.Run(() => { var msg = new __Fenix__Host__OnBeforeDisconnectNtf() { reason = reason }; var cb = new Action <byte[]>((cbData) => { var cbMsg = cbData == null ? new __Fenix__Host__OnBeforeDisconnectNtf.Callback() : global::Fenix.Common.Utils.RpcUtil.Deserialize <__Fenix__Host__OnBeforeDisconnectNtf.Callback>(cbData); _cb?.Invoke(cbMsg); }); this.CallRemoteMethod(OpCode.ON_BEFORE_DISCONNECT_NTF, msg, cb); }); } return(await t.Task); }
public void CLIENT_API__Fenix__Host__on_before_disconnect(IMessage msg, Action <IMessage> cb, RpcContext context) { var _msg = (__Fenix__Host__OnBeforeDisconnectNtf)msg; this.OnBeforeDisconnect(_msg.reason, () => { var cbMsg = new __Fenix__Host__OnBeforeDisconnectNtf.Callback(); cb.Invoke(cbMsg); on_before_disconnect?.Invoke(_msg.reason, () => { var cbMsg = new __Fenix__Host__OnBeforeDisconnectNtf.Callback(); cb.Invoke(cbMsg); }); }, context); }