3

这在 UnityScript 中会是什么样子?

void playerDataLoaded( List< GameCenterPlayer > players )
{
    foreach( GameCenterPlayer p in players )
    // do something with p
}

玩家是一个列表而不是一个数组。

我正在尝试处理来自 Apple GameCenter 的事件响应,该响应返回电镀属性列表。这些是错误:

“长度不是对象播放器的成员”

“类型‘对象’(播放器)不支持切片”

使用 iOS Game Center、Unity 和 prime31 GameCenter 插件。

4

5 回答 5

5
function removePlayersDataLoaded(players){
  for(var i = 0; i < players.length; i++){
    var p = players[i];
    // do something with p
  }
}
于 2011-12-16T00:05:44.530 回答
0

虽然 C# 的 List<> 与下面的不同,但类似这样

function Player(playerName, gameCenterPlayer)
{
   this.playerName = playerName;
   this.GameCenterPlayer = gameCenterPlayer; // i'm going to assume this has been calculated elsewhere, and all we need now is a boolean.
}

function playerDataLoaded(players) {
  this.players = players
  this.getCenterPlayer = function() {
var i = 0
  while (i < players.length) {
  if (players[i].GameCenterPlayer) {
console.log(players[i].playerName + " is the center player!");
}
i++;
}
}

}

var player1 = new Player("Ted", 0);
var player2 = new Player("Jane", 1);
var player3 = new Player("Doug", 0);
Players = new playerDataLoaded([player1, player2, player3]);

Players.getCenterPlayer()
于 2014-01-15T09:50:21.207 回答
0

它会是这样的:

var remotePlayersDataLoaded = function(players) {
  for (var i = 0; i < players.length; i++) {
    var player = players[i];
  }
};
于 2011-12-16T00:06:02.540 回答
0

.forEach用于为列表中的每个成员调用迭代器

function removePlayersDataLoaded(players) {
    players.forEach(doSomethingWithPlayer);

    function doSomethingWithPlayer(p) {
        // code
    }
}

或者在数组上使用for循环

function removePlayersDataLoaded(players) {
    for (var i = 0, len = players.length; i < len; i++) {
        var p = players[i];
        // code
    }
}
于 2011-12-16T00:08:17.983 回答
-2

我相信它是这样的:

function remotePlayersDataLoaded(players) {
for (p in players)
  {
  // do your thing with p
  } 
}

然而可能是错误的,它会抱怨吗?

于 2011-12-16T00:09:45.343 回答