用于在c#Unity中组合游戏对象的脚本

时间:2017-06-14 14:04:04

标签: c# unity3d combinations gameobject

我想创建一个脚本来生成像这样的游戏对象集合: (给定的游戏对象)a,b,c 结果:a,b,c,ab,ac,bc,abc 我找到了一个脚本

static IEnumerable<string> Combinations(List<string> characters, int length)
{
for (int i = 0; i < characters.Count; i++)
{
    // only want 1 character, just return this one
    if (length == 1)
        yield return characters[i];

    // want more than one character, return this one plus all combinations one shorter
    // only use characters after the current one for the rest of the combinations
    else
        foreach (string next in Combinations(characters.GetRange(i + 1, characters.Count - (i + 1)), length - 1))
            yield return characters[i] + next;
}
}

但它仅用于字符串,所以如果我错过任何可以在这里工作的解决方案,我将不胜感激。

0 个答案:

没有答案