我需要有关我正在制作的记分板的帮助。这是我想要实现的记分板:
我实际上有四个表,每个表都有自己的记分板,但对于这个问题,我只需要表 1,所以这就是我如何创建这种记分板。
现在,到目前为止我已经做到了:
if (gametable_no == 1)
{
for (int i = 0; i < tzPlayInfo.Instance.bc_gametable_history_list.Count; i++)
{
newString[0] += tzPlayInfo.Instance.bc_gametable_history_list[i].r;
newString[0] += ",";
}
string[] groupedString = newString[0].Split(',');
foreach (string allchars in groupedString)
{
int x = 0;
int y = 0;
GameObject o = Instantiate(prefab_big_road[0]) as GameObject;
o.transform.SetParent(pos_big_road[0]);
o.transform.localScale = Vector3.one;
o.transform.localPosition = new Vector3(2.0f, -5.0f, 0f);
o.transform.localPosition = new Vector3(o.transform.localPosition.x + x,
o.transform.localPosition.y + y, o.transform.localPosition.z);
if (allchars.Contains(playerwinnopairboth))
{
o.GetComponent<UISprite>().spriteName = "layout_player_bigline-01";
NGUITools.SetActive(o, true);
}
if (allchars.Contains(bankerwinnopairboth))
{
o.GetComponent<UISprite>().spriteName = "layout_banker_bigline-01";
NGUITools.SetActive(o, true);
}
if (allchars.Contains(tienopairboth))
{
o.GetComponent<UISprite>().spriteName = "layout_tie_bigline-01";
NGUITools.SetActive(o, true);
}
}
}
这段代码只能实现这样的效果:
输出是随机生成的,例如我有以下输出数据:
Gametable 1 history : P ,P ,P ,B ,B P,P P,TBP
我需要知道游戏表 1 历史数据
中的角色是否变化。
例如:输出必须是这样的
如果值没有像 P ,P ,P
这样变化,那么位置只会在 y 轴上递增,然后如果下一个值不同,例如 B ,
然后它将移动到 x 轴。
有没有办法检测字符串数组中的字符是否与其他值不同?
已编辑
string[] newString = new string[4];
string[,] table = new string[70, 70];
string previousValue = "placeholder";
int xIndex = -1;
int yIndex = 0;
// First table
if (gametable_no == 1)
{
for (int i = 0; i < tzPlayInfo.Instance.bc_gametable_history_list.Count; i++)
{
newString[0] += tzPlayInfo.Instance.bc_gametable_history_list[i].r;
newString[0] += ",";
}
//string[] groupedString = GroupString(newString[0]);
string[] groupedString = newString[0].Split(',');
foreach (var allchars in groupedString)
{
GameObject o = Instantiate(prefab_big_road[0]) as GameObject;
o.transform.SetParent(pos_big_road[0]);
o.transform.localScale = Vector3.one;
if (table.GetLength(0) < xIndex)
{
break;
}
if (allchars.Equals(previousValue) && table.GetLength(1) < yIndex)
{
yIndex += 15;
table[xIndex, yIndex] = allchars;
}
else
{
xIndex += 15;
yIndex = 0;
table[xIndex, yIndex] = allchars;
}
previousValue = allchars;
o.transform.localPosition = new Vector3(xIndex, yIndex, 0f);
// Match the sprites
if (previousValue.Contains(playerwinnopairboth))
{
o.GetComponent<UISprite>().spriteName = "layout_player_bigline-01";
NGUITools.SetActive(o, true);
}
if (previousValue.Contains(bankerwinnopairboth))
{
o.GetComponent<UISprite>().spriteName = "layout_banker_bigline-01";
NGUITools.SetActive(o, true);
}
if (previousValue.Contains(tienopairboth))
{
o.GetComponent<UISprite>().spriteName = "layout_tie_bigline-01";
NGUITools.SetActive(o, true);
}
}
它只生成很少的预制件:
虽然我已经生成了这些数据:
在我的用户界面中它只显示两个:
最佳答案
我建议使用多维数组作为表格。 也许是这样的?
string[,] table = new string[30, 6];
string previousValue = "placeholder";
int xIndex = -1;
int yIndex = 0;
foreach (var value in groupedString)
{
if (table.GetLength(0) < xIndex)
{
break;
}
if (value.Equals(previousValue) && yIndex < table.GetLength(1))
{
yIndex += 1;
table[xIndex, yIndex] = value;
}
else
{
xIndex += 1;
yIndex = 0;
table[xIndex, yIndex] = value;
}
previousValue = value;
}
现在您应该有一个包含所有值的表格,然后您可以将其显示在 UI 上并相应地匹配正确的 Sprite 。
关于c# - 如果字符串数据数组不同,则增加位置 C# (Unity),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50126599/