将 Texture2D 保存在字典中,然后检索它

本文关键字:然后 检索 字典 Texture2D 保存 存在 | 更新日期: 2023-09-27 17:55:45

我正在将配置文件图像从 Parse.com 导入到我的 Unity 项目中,并将它们插入字典列表中,其中特定用户 id 作为键,图像 (Texture2D) 作为值,如下所示:

public Dictionary<string, string> oppimageslinks = new Dictionary<string, string>();
public Dictionary<string, Texture2D> oppimages = new Dictionary<string, Texture2D>();
foreach(KeyValuePair<string, string> image in oppimageslinks){
    var oppImageRequest = new WWW(image.Value);
    yield return oppImageRequest;
    oppimages.Add(image.Key,oppImageRequest.texture);
}

这部分工作得很好。现在,我的问题是如何将 Texture2D 放入我的游戏对象中?这是我尝试这样做的方法:

if(oppimages.ContainsKey(game.Value[2])){
    UITexture picture = GameObject.Find("Game"+mc+"/Background/ProfileImg").GetComponent<UITexture>();
    picture.mainTexture = oppimages.Value;
}

游戏。值[2] 是当前对手的用户 ID。

尝试执行此操作时出现此错误:

键入 System.Collections.Generic.Dictionary<string,UnityEngine.Texture2D>' does not contain a definition for Value",并且找不到 System.Collections.Generic.Dictionary' Value' of type扩展方法(您是否缺少 using 指令或程序集引用?

我不确定如何解决这个问题,并希望在这件事上得到一些帮助。

将 Texture2D 保存在字典中,然后检索它

我不知道

发生了什么。也许你可以试试这个?

if(oppimages.ContainsKey(game.Value[2])){
UITexture picture = GameObject.Find("Game"+mc+"/Background/ProfileImg").GetComponent<UITexture>();
picture.mainTexture = oppimages[game.Value[2]];
}