MasterServer.ClearHostList 清空主机列表

static function ClearHostList () : void

Description描述

Clear the host list which was received by MasterServer.PollHostList.

清空由MasterServer.PollHostList获取的主机列表。

Useful if you want to update the list and want to make sure you don't use the older data.

如果你想更新列表而且想确保你用的不是旧数据,它将很有用。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	void Awake() {
		MasterServer.ClearHostList();
		MasterServer.RequestHostList("MyUniqueGameType");
	}
	void Update() {
		if (MasterServer.PollHostList().Length != 0) {
			HostData[] hostData = MasterServer.PollHostList();
			int i = 0;
			while (i < hostData.Length) {
				Debug.Log("Game name: " + hostData[i].gameName);
				i++;
			}
			MasterServer.ClearHostList();
		}
	}
}
function Awake() {
	// Make sure list is empty and request a new list
	//确保列表是空的,请求一个新的列表。
	MasterServer.ClearHostList();
	MasterServer.RequestHostList("MyUniqueGameType");
}

function Update() {
	// If any hosts were received, display game name, the clear host list again
	//如果任何主机被接收到,显示游戏名字,然后再次清空主机列表。
	if (MasterServer.PollHostList().Length != 0) {
		var hostData : HostData[] = MasterServer.PollHostList();
		for (var i : int = 0; i < hostData.Length; i++)
			Debug.Log("Game name: " + hostData[i].gameName);
		MasterServer.ClearHostList();
	}
}
Page last updated: 2011-1-4