Class VoteRules

Namespace
Unity.Multiplayer.Core

The rules every vote on a VoteBox follows, unless its VoteKind overrides the quorum or the time: who may start one, how many Yes votes pass it, how long it runs and how long a player whose vote failed waits before starting another. Defaults: anyone, two thirds rounded up, 15 seconds, no cooldown.

public sealed class VoteRules
Inheritance
VoteRules
Inherited Members

Fields

DefaultTimeoutSeconds

The default time a vote runs before it lapses, in seconds.

public const double DefaultTimeoutSeconds = 15

Field Value

double

TwoThirds

Two thirds: the default quorum fraction.

public const double TwoThirds = 0.6666666666666666

Field Value

double

Properties

CooldownSeconds

Seconds a player must wait after a vote they started fails (rejected, timed out, abandoned) before they may start another; 0 (the default) for no wait. Other players are not held up. A vote that passes never cools anyone down.

public double CooldownSeconds { get; set; }

Property Value

double

MayStart

Who may start a vote, by client id; null (the default) lets any player in the roster. For example only the host: rules.MayStart = id => id == NetSender.ServerClientId.

public Func<ulong, bool> MayStart { get; set; }

Property Value

Func<ulong, bool>

QuorumFraction

The fraction of the voters whose Yes passes a vote, rounded up (QuorumFor(int, double)): 2/3 by default (2 of 3, 3 of 4, 4 of 5), 0.5 for a simple half, 1 for everyone. Above 0, at most 1.

public double QuorumFraction { get; set; }

Property Value

double

StarterVotesYes

True (the default) when starting a vote counts as the starter's Yes.

public bool StarterVotesYes { get; set; }

Property Value

bool

TimeoutSeconds

Seconds before an undecided vote lapses (TimedOut). Above 0.

public double TimeoutSeconds { get; set; }

Property Value

double

Methods

Clone()

A copy, so one board's changes never reach another's.

public VoteRules Clone()

Returns

VoteRules

QuorumFor(int)

Yes votes needed from voters voters at this board's QuorumFraction.

public int QuorumFor(int voters)

Parameters

voters int

Returns

int

QuorumFor(int, double)

Yes votes needed from voters voters: ceil(voters x fraction), at least 1 and at most voters. At the default 2/3: 1 of 1, 2 of 2, 2 of 3, 3 of 4, 4 of 5, 4 of 6.

public static int QuorumFor(int voters, double fraction)

Parameters

voters int
fraction double

Returns

int

Exceptions

ArgumentOutOfRangeException

voters is below one, or the fraction is not in (0, 1].

Validate()

Throws when a value is out of range.

public void Validate()

Exceptions

ArgumentOutOfRangeException

The fraction is not in (0, 1], the timeout is not positive or the cooldown is negative.