本文整理汇总了C#中CallbackManager.Add方法的典型用法代码示例。如果您正苦于以下问题:C# CallbackManager.Add方法的具体用法?C# CallbackManager.Add怎么用?C# CallbackManager.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CallbackManager
的用法示例。
在下文中一共展示了CallbackManager.Add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetupDotaClientCallbacks
/// <summary>
/// Setup the DOTA client callbacks
/// </summary>
/// <param name="cb"></param>
private void SetupDotaClientCallbacks(CallbackManager cb)
{
cb.Add<DotaGameClient.HandshakeRejected>(rej =>
{
log.ErrorFormat("Connection to the game rejected with reason {0}. Attempts {1}/{2}.", rej.reason, _connAttempts, maxAttempts);
});
cb.Add<DotaGameClient.SessionStateTransition>(tra =>
{
log.Debug("[GameClient] "+tra.OldStatus.ToString("G")+" => "+tra.NewStatus.ToString("G"));
if (tra.NewStatus == States.PLAY)
{
_connAttempts = 0;
}
if (tra.NewStatus != States.DISCONNECTED || _state.State != State.DotaPlay) return;
log.WarnFormat("Client has disconnected, attempts {0}/{1}.{2}", _connAttempts, maxAttempts, _connAttempts<maxAttempts ? " Retrying." : " Not retrying.");
if (_connAttempts < maxAttempts)
StartDotaGameConnection();
});
cb.Add<DotaGameClient.LogMessage>(msg =>
{
log.Debug("[GameClient] "+msg.message);
});
}
示例2: SetupSteamCallbacks
/// <summary>
/// Setup steam client callbacks
/// </summary>
/// <param name="cb"></param>
private void SetupSteamCallbacks(CallbackManager cb)
{
// Handle general connection stuff
cb.Add<SteamUser.AccountInfoCallback>(a =>
{
log.DebugFormat("Current name is: {0}, flags {1}, ", a.PersonaName, a.AccountFlags.ToString("G"));
UpdatePersona();
});
cb.Add<SteamClient.ConnectedCallback>(a => SteamUser.LogOn(_logonDetails));
cb.Add<SteamClient.DisconnectedCallback>(a => _state.Fire(Trigger.SteamDisconnected));
cb.Add<SteamUser.LoggedOnCallback>(a =>
{
log.DebugFormat("Steam signin result: {0}", a.Result.ToString("G"));
switch (a.Result)
{
case EResult.OK:
_state.Fire(Trigger.SteamConnected);
break;
case EResult.ServiceUnavailable:
case EResult.ServiceReadOnly:
case EResult.TryAnotherCM:
case EResult.AccountLoginDeniedThrottle:
case EResult.AlreadyLoggedInElsewhere:
case EResult.BadResponse:
case EResult.Busy:
case EResult.ConnectFailed:
_state.Fire(Trigger.SteamDisconnected); //retry state
break;
default:
_state.Fire(Trigger.SteamInvalidCreds);
break;
}
});
}
示例3: SetupDotaGCCallbacks
/// <summary>
/// Setup DOTA 2 game coordinator callbacks
/// </summary>
/// <param name="cb">Manager</param>
private void SetupDotaGCCallbacks(CallbackManager cb)
{
cb.Add<DotaGCHandler.GCWelcomeCallback>(a => { log.Debug("GC session welcomed"); _state.Fire(Trigger.DotaConnected); });
cb.Add<DotaGCHandler.ConnectionStatus>(a =>
{
log.DebugFormat("GC connection status: {0}", a.result.status.ToString("G"));
if (a.result.status == GCConnectionStatus.GCConnectionStatus_HAVE_SESSION)
_state.Fire(Trigger.DotaConnected);
else _state.Fire(Trigger.DotaDisconnected);
});
cb.Add<DotaGCHandler.Popup>(a => log.DebugFormat("GC popup message: {0}", a.result.id.ToString("G")));
cb.Add<DotaGCHandler.PracticeLobbySnapshot>(a => HandleLobbyUpdate(a.lobby));
cb.Add<DotaGCHandler.PracticeLobbyLeave>(a => HandleLobbyUpdate(null));
cb.Add<DotaGCHandler.PracticeLobbyUpdate>(a => HandleLobbyUpdate(a.lobby));
cb.Add<DotaGCHandler.JoinChatChannelResponse>(a =>
{
if (DotaGCHandler.Lobby != null && a.result.channel_id != 0 &&
a.result.channel_name == "Lobby_" + DotaGCHandler.Lobby.lobby_id)
lobbyChannelId = a.result.channel_id;
});
cb.Add<DotaGCHandler.ChatMessage>(
a =>
{
log.DebugFormat("[Chat][" +
(a.result.channel_id == lobbyChannelId ? "Lobby" : a.result.channel_id + "") + "] " +
a.result.persona_name + ": " + a.result.text);
if (a.result.channel_id == lobbyChannelId)
{
if(a.result.text.Contains("!start")) DotaGCHandler.LaunchLobby();
}
});
}
示例4: InitAndConnect
private void InitAndConnect()
{
if (client == null)
{
client = new SteamClient();
DotaGCHandler.Bootstrap(client);
user = client.GetHandler<SteamUser>();
friends = client.GetHandler<SteamFriends>();
dota = client.GetHandler<DotaGCHandler>();
manager = new CallbackManager(client);
isRunning = true;
manager.Add<SteamClient.ConnectedCallback>(c =>
{
if (c.Result != EResult.OK)
{
fsm.FirePriority(Events.Disconnected);
isRunning = false;
return;
}
user.LogOn(details);
});
manager.Add<SteamClient.DisconnectedCallback>(
c =>
{
fsm?.Fire(Events.Disconnected);
});
manager.Add<SteamUser.LoggedOnCallback>(c =>
{
if (c.Result != EResult.OK)
{
log.Error("Logon failure, result: " + c.Result);
switch (c.Result)
{
case EResult.AccountLogonDenied:
fsm.Fire(Events.LogonFailSteamGuard);
return;
case EResult.ServiceUnavailable:
case EResult.TryAnotherCM:
fsm.Fire(Events.LogonFailSteamDown);
return;
}
fsm.Fire(Events.LogonFailBadCreds);
}
else
{
fsm.Fire(Events.Connected);
}
});
manager.Add<DotaGCHandler.UnhandledDotaGCCallback>(
c => log.Debug("Unknown GC message: " + c.Message.MsgType));
manager.Add<DotaGCHandler.GCWelcomeCallback>(
c => fsm.Fire(Events.DotaGCReady));
manager.Add<SteamFriends.FriendsListCallback>(c => log.Debug(c.FriendList));
manager.Add<DotaGCHandler.PracticeLobbySnapshot>(c =>
{
log.DebugFormat("Lobby snapshot received with state: {0}", c.lobby.state);
fsm.Fire(c.lobby.state == CSODOTALobby.State.RUN
? Events.DotaEnterLobbyRun
: Events.DotaEnterLobbyUI);
switch (c.lobby.state)
{
case CSODOTALobby.State.UI:
fsm.FirePriority(Events.DotaEnterLobbyUI);
break;
case CSODOTALobby.State.RUN:
fsm.FirePriority(Events.DotaEnterLobbyRun);
break;
}
LobbyUpdate?.Invoke(c.lobby);
});
manager.Add<DotaGCHandler.PingRequest>(c =>
{
log.Debug("GC Sent a ping request. Sending pong!");
dota.Pong();
});
manager.Add<DotaGCHandler.Popup>(
c => { log.DebugFormat("Received message (popup) from GC: {0}", c.result.id); });
manager.Add<DotaGCHandler.ConnectionStatus>(
c => log.DebugFormat("GC Connection Status: {0}", JObject.FromObject(c.result)));
manager.Add<DotaGCHandler.PracticeLobbySnapshot>(c =>
{
log.DebugFormat("Lobby snapshot received with state: {0}", c.lobby.state);
if (c.lobby != null)
{
switch (c.lobby.state)
{
case CSODOTALobby.State.UI:
fsm.FirePriority(Events.DotaEnterLobbyUI);
break;
case CSODOTALobby.State.RUN:
fsm.FirePriority(Events.DotaEnterLobbyRun);
break;
}
}
LobbyUpdate?.Invoke(c.lobby);
});
//.........这里部分代码省略.........