例如,我有这些数据:
P, P, P, B, B, T, T, T, P, P
然后我就这样做了:
for (int i = 0; i < gametable_history_list.Count; i++)
{
newString[0] += gametable_history_list[i].r;
newString[0] += ",";
}
string[] newChars = newString[0].Split(',');
我想要的是检测数据现在是否具有相同的字符,例如像
if(newChars isnot changing character){
显示:P, P, P
else if(newChars is changing now){
显示:B,B
else if(newChars is changing now){
显示:T,T,T
else if(newChars is changing now){
显示:P,P
必须是这样的输出:
我得到的是什么
我真正的问题是我需要transform.localPosition
每个相同的数据(P,P,P)然后如果数据变化像(B,B)那么它必须移动到我需要的另一列移动x和y轴。
答案 0 :(得分:0)
这是一个(部分)示例(我不知道你如何创建显示的文本,或者它是如何定位的,所以我只能设置一个非常基本的例子,注释告诉你如何放置它们)
::更新::
我找到了您之前的问题,并在此答案中添加了您提供的代码以及Nand gopal的答案
//calling this with "PPPBBTTTPP" yields ["PPP","BB","TT","PP"]
//keep in mind that this is a separate method
//so it should go *outside* the create, initialise, and update methods
string[] GroupString(string inputString){
string result = " ";
foreach (var c in inputString)
{
result = result + (result.Last() == c ? "" : " ") + c;
}
return result.Trim().Split(' ');
}
//the logic for creating your table :
string newString = "";
for (int i = 0; i < gametable_history_list.Count; i++)
{
newString += gametable_history_list[i].r;
}
string[] groupedString = GroupString(newString);
//you can now iterate over groupedString
for(int x=0; x < groupedString.length; x++)
{
for(int y=0; y < groupedString[x].length; y++)
{
//display groupedString[x] at position determined using X and Y
//(i don't know how you do this since you did not provide example code for this part)
//update : assuming your previous question is related :
GameObject o = Instantiate(prefab_big_road[0]) as GameObject;
o.transform.SetParent(pos_big_road[0]);
o.transform.localScale = Vector3.one;
//the positioning happens here :
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);
}
}
}