Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 数组列表纹理_C#_Unity3d - Fatal编程技术网

C# 数组列表纹理

C# 数组列表纹理,c#,unity3d,C#,Unity3d,我在从arraylist创建按钮时遇到问题 下面是一些示例代码来说明我的问题: piclist = new ArrayList (); //texturename is name of texture in database to be downloaded, this is a loop to get all texture names, results get inserted into piclist. piclist.Insert (0, texturenam

我在从arraylist创建按钮时遇到问题

下面是一些示例代码来说明我的问题:

    piclist = new ArrayList ();

    //texturename is name of texture in database to be downloaded, this is a loop to get all texture names, results get inserted into piclist.

    piclist.Insert (0, texturename);

    Texture2D[ ] tex;

    tex= new Texture2D[piclist.Count];

        for (var i = 0; i < piclist.Count; i++) {

        // newString is url of image downloaded from web storage. piclist is used in a loop here to get urls. 
        WWW www = new WWW (newString);
        yield return www;
        Texture2D Ttex = new Texture2D (www.texture.width, www.texture.height, TextureFormat.RGB24, false);
        www.LoadImageIntoTexture (Ttex);  
        tex [i] = Ttex;
    }


        voidOnGUI(){
    GUILayout.BeginArea(logArea);
    scrollPosition2 = GUILayout.BeginScrollView (scrollPosition2, false, true);
    GUILayout.BeginVertical(GUI.skin.box);


     for(int i =0; i < tex.Length; i++)
        (GUILayout.Button(tex[ i ]));

    GUILayout.EndVertical();
    GUILayout.EndScrollView();
    GUILayout.EndArea();
}
piclist=newarraylist();
//texturename是要下载的数据库中的纹理名称,这是一个获取所有纹理名称的循环,结果被插入到piclist中。
piclist.Insert(0,texturename);
纹理2d[]tex;
tex=新纹理2d[piclist.Count];
对于(var i=0;i
问题是我创建了正确数量的按钮,但是它们都共享纹理名称,因此我最终得到了
n
数量的按钮,所有按钮都具有纹理
n

例如,如果我的数组包含纹理
[A、B、C]
,我将看到按以下顺序创建的按钮:

A->BB->CCC


如何从arraylist中定义每个按钮具有自己的纹理?

由于两个问题,该代码甚至无法编译。最好是复制并粘贴您正在使用的真实代码。如果您不这样做,您将得到一个与您的问题无关的答案,然后您和回答者将花一整天的时间更改问答中的代码。添加用于初始化tex变量的代码也是一个好主意。您可能需要添加C#标记以获得更多人的帮助,因为这里是C#。谢谢您的帮助。当我下班回家时,我添加了更多的示例代码。我可以成功调用我的tex[I]数组中各个纹理的名称,让Debug.Log显示纹理的名称,但是在显示纹理时,所有纹理都会加载并覆盖以前创建的按钮的纹理。我正在使用谷歌的Firebase从中获取数据库和存储,代码很混乱,但我可以通过www-call成功下载纹理,我将其存储在tex[]。