Class VoteKind

Namespace
Unity.Multiplayer.Core

One kind of vote a game offers (reset the level, change the map, kick a player...): its id, how its question reads, which requests are valid, who votes on it and what happens on the server when it passes. Register it on the server's VoteBox (or a VoteBoard); clients start one by its Id.

public sealed class VoteKind
Inheritance
VoteKind
Inherited Members

Examples

new VoteKind("level", r => "Switch to Level " + r.Number + "?")
{
    Check  = r => levels.Exists((int)r.Number) ? null : "There is no level " + r.Number + ".",
    Passed = v => levels.Load((int)v.Number),
};

Constructors

VoteKind(string, Func<VoteRequest, string>)

A kind whose question is worded from the request (title), e.g. from its number payload.

public VoteKind(string id, Func<VoteRequest, string> title)

Parameters

id string
title Func<VoteRequest, string>

Exceptions

ArgumentException

id is empty.

ArgumentNullException

title is null.

VoteKind(string, string)

A kind whose question is always title.

public VoteKind(string id, string title)

Parameters

id string
title string

Exceptions

ArgumentException

id or title is empty.

Properties

Check

Server side, before the vote starts: null or empty when the request is valid, else the sentence the starter is told (Invalid). Null (the default) accepts every request.

public Func<VoteRequest, string> Check { get; set; }

Property Value

Func<VoteRequest, string>

Description

An optional second line under the question; null for none.

public Func<VoteRequest, string> Description { get; set; }

Property Value

Func<VoteRequest, string>

Id

What clients pass to start one ("reset", "level", "kick").

public string Id { get; }

Property Value

string

MayVote

Which roster members vote on it, by client id; null (the default) lets all of them. A kick vote leaves its target out. The quorum counts only the voters left.

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

Property Value

Func<VoteRequest, ulong, bool>

Passed

Server side: what happens when it passes. Runs before every peer is told it passed.

public Action<Vote> Passed { get; set; }

Property Value

Action<Vote>

QuorumFraction

This kind's quorum fraction; null (the default) uses the box's QuorumFraction.

public double? QuorumFraction { get; set; }

Property Value

double?

TimeoutSeconds

This kind's time limit in seconds; null (the default) uses the box's TimeoutSeconds.

public double? TimeoutSeconds { get; set; }

Property Value

double?

Title

The question every peer sees ("Kick Bob?"), worded on the server when the vote starts.

public Func<VoteRequest, string> Title { get; }

Property Value

Func<VoteRequest, string>

Methods

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.