Unity3D尝试在构建后加载纹理资源

时间:2014-12-20 05:56:45

标签: unity3d

我有一个使用位于Assets下的Resources目录中的纹理(图像)的材质。使用Resources.load在编辑器中工作。纹理也在构建上正确加载,但我想在构建之后通过在构建的Resources目录中放置不同的图像(具有相同的名称)来替换该图像。

在Windows上,我认为该目录是buildname_Data>资源,在Mac上我认为它是内容>资源(打开包内容后)。这适用于我用来在启动时加载一些数据的文本文件,但是这个过程有点不同,因为我没有使用Resources.load。

我遇到的问题是,只是在(我认为)正确的位置放置一个新图像不会覆盖应用程序构建的图像。我还在看原始图像。在过去的几天里,我一直在摸不着头脑,而且文档(以及各种谷歌搜索)都没有深入了解解决方案(虽然它很可能正好盯着我看。)

var MyTexture : Texture = Resources.Load("colorPatch");

var wbpLineRenderer : LineRenderer = someGameObject.AddComponent(LineRenderer);
wbpLineRenderer.material = new Material (Shader.Find("Particles/Alpha Blended"));
wbpLineRenderer.material = Resources.Load("curveLine") as Material;
wbpLineRenderer.material.mainTexture = MyTexture;

curveLine是编辑器的Assets / Resources目录中的材料。

colorPatch是编辑器的Assets / Resources目录中名为colorPatch.png的图像文件

有人可以直截了当地问我的头吗?我可以在构建后实际交换纹理上使用的图像吗?

1 个答案:

答案 0 :(得分:0)

经过一顿丰盛的早餐和更多谷歌搜索后,我(重新)发现了解决方案,详细here

我的实施如下:

var textureURL : String = "file://" + Application.dataPath + "/Resources/colorPatch.png";
var www : WWW = new WWW(textureURL);
var tempTexture : Texture2D = new Texture2D(2, 2); //doesn't have to be the actual size
www.LoadImageIntoTexture(tempTexture); //image loads at 100% not 2x2 specified above

var wbpLineRenderer : LineRenderer = wellBorePath.AddComponent(LineRenderer);
wbpLineRenderer.material = new Material (Shader.Find("Particles/Alpha Blended"));
wbpLineRenderer.material = Resources.Load("curveLine") as Material;
wbpLineRenderer.material.mainTexture = tempTexture;

构建应用程序后,将名为colorPatch.png的图像放在以下位置:

Windows - appname_Data / Resources
Mac - 内容/资源(打开包装内容后)。

将图像colorPatch.png与另一个图像(但仍然标题为colorPatch.png)关闭,然后启动应用程序,将新图像显示为纹理。