首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将纹理添加到序列化列表中

将纹理添加到序列化列表中
EN

Stack Overflow用户
提问于 2022-07-06 12:40:41
回答 2查看 35关注 0票数 0

我在TextureInfo里面有一个纹理列表。我想在列表中添加一个纹理,如下面的示例所示。

代码语言:javascript
复制
[System.Serializable]
 public class TextureInfo
  {
    public List<Texture> textures = new List<Texture>();
  }

public List<TextureInfo> texInfo = new List<TextureInfo>();

public Texture texture;

public void Start(){
 texInfo.textures.Add(new TextureInfo {textures.Add(texture)}); //How do I add one row to texInfo and then one row to textures?
}

问题是我不知道如何添加到序列化列表中。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-07-06 12:50:04

我只想把一字一句留在这个场合,然后像这样把它修好。

代码语言:javascript
复制
     [System.Serializable]
     public class TextureInfo
      {
        public List<Texture> textures = new List<Texture>();
      }
    
     public List<TextureInfo> texInfo = new List<TextureInfo>();
    
     public Texture texture;
     public void Start()
     {
        var variableName = new TextureInfo();
        variableName.textures.Add(texture);

        texInfo.Add(variableName);
     }
票数 1
EN

Stack Overflow用户

发布于 2022-07-06 12:50:52

代码语言:javascript
复制
TextureInfo tinfo = new TextureInfo(); //Create new texture info
tinfo.textures.Add(texture); // Add texture to the list of textures in texture info
texInfo.Add(tinfo); // add texture info to the texture info list
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72883744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档