MasterServer.PollHostList 检索主机列表
static function PollHostList () : HostData[]
Description描述
Check for the latest host list received by using MasterServer.RequestHostList.
检索由MasterServer.RequestHostList获取的最新主机列表。
You can clear the current host list with MasterServer.ClearHostList. That way you can be sure that the list returned by is up to date.
你可以用MasterServer.ClearHostList清空当前的主机列表。这样你可以确保返回的列表是最新的。
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void Awake() {
MasterServer.ClearHostList();
MasterServer.RequestHostList("LarusTest");
}
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("LarusTest");
}
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();
}
}
最后修改:2011年1月4日 Tuesday 15:56