【发布时间】:2013-11-05 16:59:36
【问题描述】:
Another follow on question from my last one.
我已经设置了我的字典,我正在传递键值和另一个设备的距离值。我希望我的程序根据距离值更新一些局部变量,但仅更新那些与字典中的键号相关联的变量。
所有这些代码如下所示:
Dictionary<string, string> myDictonary = new Dictionary<string, string>();
string Value1 = "";
string Value2 = "";
string Value3 = "";
string Value4 = "";
string Value5 = "";
string Value6 = "";
void Start()
{
myDictonary.Add("11111111", Value1);
myDictonary.Add("22222222", Value2);
myDictonary.Add("33333333", Value3);
myDictonary.Add("44444444", Value4);
myDictonary.Add("55555555", Value5);
myDictonary.Add("66666666", Value6);
}
private void AppendString(string message)
{
testMessage = message;
string[] messages = message.Split(',');
foreach(string w in messages)
{
if(!message.StartsWith(" "))
outputContent.text += w + "\n";
}
messageCount = "RSSI number " + messages[0];
uuidString = "UUID number " + messages[1];
if(myDictonary.ContainsKey(messages[1]))
{
myDictonary[messages[1]] = messageCount;
}
}
在同一个应用程序中,我还将我的所有值都显示在屏幕上,以便我可以正确地看到它们。这部分程序如下所示:
void OnGUI()
{
GUI.Label(new Rect(100, Screen.height/2 + 100, 150, 100), "value 1 " + Value1);
GUI.Label(new Rect(100, Screen.height/2 + 120, 200, 100), "value 2 " + Value2);
GUI.Label(new Rect(100, Screen.height/2 + 140, 250, 100), "value 3 " + Value3);
GUI.Label(new Rect(100, Screen.height/2 + 160, 300, 100), "value 4 " + Value4);
GUI.Label(new Rect(100, Screen.height/2 + 180, 350, 100), "value 5 " + Value5);
GUI.Label(new Rect(100, Screen.height/2 + 200, 400, 100), "value 6 " + Value6);
}
在我从my last question 实施修复之前,虽然它可能是错误的,但字符串确实更新并显示在我的屏幕上。自从我放入新代码后,什么也没有发生。
我已尝试更改以下方法:
if(myDictonary.ContainsKey(messages[1]))
{
myDictonary[messages[1]] = messageCount;
}
因此,不是数组中的第一条消息得到检查并传递给两者之间的每个可能的组合。系统中仍然存在同样的问题。
任何人都可以看到任何东西吗?
【问题讨论】:
-
如果您上一个问题的答案不起作用,您为什么接受它作为答案,而不是在对该答案的评论中解释它为什么不起作用?
标签: c# string dictionary unity3d