Class PlayerVoteManager
Manages a generic vote operation for all players. Displayed by VoteUIDisplay<TData>.
public class PlayerVoteManager : IPlayerVoteManager, IDisposable, IEventListener<PlayerJoined>, IEventListener<PlayerLeft>
- Inheritance
-
PlayerVoteManager
- Implements
- Inherited Members
Constructors
PlayerVoteManager(ILoopTickerFactory, ILogger<PlayerVoteManager>)
public PlayerVoteManager(ILoopTickerFactory loopTickerFactory, ILogger<PlayerVoteManager> logger)
Parameters
loopTickerFactoryILoopTickerFactoryloggerILogger<PlayerVoteManager>
Properties
IsVoting
If there's a vote currently active.
public bool IsVoting { get; }
Property Value
VoteEnd
The time at which the vote will end (UTC).
public DateTime VoteEnd { get; }
Property Value
Exceptions
- InvalidOperationException
Not voting.
VoteStart
The time at which the vote started (UTC).
public DateTime VoteStart { get; }
Property Value
Exceptions
- InvalidOperationException
Not voting.
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
EndVoteAsync(CancellationToken, bool)
Ends the current vote
public UniTask EndVoteAsync(CancellationToken token = default, bool cancelled = false)
Parameters
tokenCancellationTokenCancellation token used to cancel ending the vote.
cancelledboolIf the vote should be cancelled instead of ended.
Returns
- UniTask
Exceptions
- InvalidOperationException
Not voting.
GetVoteCount(PlayerVoteState)
Gets the number of votes in a certain state.
public int GetVoteCount(PlayerVoteState vote)
Parameters
votePlayerVoteState
Returns
Exceptions
- InvalidOperationException
Not voting.
GetVoteState(CSteamID)
Gets a player's current vote state (unanswered/yes/no).
public PlayerVoteState GetVoteState(CSteamID player)
Parameters
playerCSteamID
Returns
Exceptions
- InvalidOperationException
Not voting.
RegisterVote(CSteamID, PlayerVoteState)
Registers a player's vote with the system, overriding their current vote if they've already voted.
public PlayerVoteState RegisterVote(CSteamID player, PlayerVoteState vote)
Parameters
playerCSteamIDThe player that's voting.
votePlayerVoteStateTheir vote, or Unanswered to remove thier vote.
Returns
- PlayerVoteState
Their previous vote, or Unanswered if they hadn't voted.
Exceptions
- InvalidOperationException
Not voting.
- ArgumentOutOfRangeException
Invalid vote.
StartVoteAsync(VoteSettings, Action<IVoteResult>?, CancellationToken)
Starts a new vote.
public UniTask StartVoteAsync(VoteSettings settings, Action<IVoteResult>? callback, CancellationToken startCancellationToken = default)
Parameters
settingsVoteSettingsGeneral settings for the vote.
callbackAction<IVoteResult>Invoked when the vote is completed or cancelled.
startCancellationTokenCancellationTokenCancellation token used to cancel starting the vote, not the same as the token used to cancel the vote.
Returns
- UniTask
Exceptions
- InvalidOperationException
Already voting.