【问题标题】:Calling Resources.Load on a texture is not working在纹理上调用 Resources.Load 不起作用
【发布时间】:2013-04-12 02:43:48
【问题描述】:

我正在尝试从Resources 文件夹加载Texture,但它不断返回null

t = (Texture)Resources.Load("Circle") as Texture;

圆形纹理的扩展名为.tga

【问题讨论】:

  • 什么编程语言?
  • 为你添加了 C# 标签。
  • 为什么要转换成 Texture,然后再尝试将结果解析成 Texture?
  • t = Resources.Load("Circle") as Texture;
  • 我也尝试过这种方式,我认为可能没有投射它可能是问题所在。

标签: c# resources unity3d textures


【解决方案1】:

您必须将 Circle.tga 放在 Assets/Resources 文件夹中。另外,如果您有子文件夹,例如 Resources/Textures/Circle.tga 然后这样做:

Texture t = Resources.Load("Textures/Circle") as Texture;

【讨论】:

  • "您必须将 Circle.tga 放在 Assets/Resources 文件夹中。"感谢这条线。
【解决方案2】:

文件的扩展名不是必需的。所以这是正确的:

t = (Texture)Resources.Load("Circle") as Texture;

这不是:

t = (Texture)Resources.Load("Circle.npg") as Texture;

【讨论】:

    【解决方案3】:

    单一纹理文件

    纹理文件应添加到 Resources 文件夹中 之后使用下面的代码行加载纹理

    var Texture_1 : Texture2D;
    Texture_1 = Resources.Load("TextureName");
    

    对于文件夹

    文件夹应保存在 Resources 文件夹中 之后使用下面的代码行加载纹理文件夹

    var textures : Object[];
    textures = Resources.LoadAll("FolderName");
    

    【讨论】:

    • 谢谢,我的问题是“资源”文件夹,我不知道。
    【解决方案4】:

    @Massimiliano Uguccioni 谢谢...解决了我的问题。

    Resources.load 使用步骤:

    1. 确保它在 Resources 文件夹中
    2. 引用不带资源的完整相对路径:例如:textures/texture1,其中纹理是资源中的文件夹
    3. 就像 Massimiliano Uguccioni 所说的不包含文件扩展名

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多