TextureImporter class 是否在运行时工作?

Does TextureImporter class works in runtime?

我目前正在 Unity 中为 Android 制作 360 度图片查看器。所有等距柱状图都加载到resources文件夹中

我想知道是否可以使用 TextureImporter class 在运行时将 2d 纹理转换为 Cubemap。

目前,我正在将 2d 纹理转换为立方体贴图。为其中的每一个创建了 materials。并在主相机中添加的天空盒组件下加载此 material。使用这种方法的缺点是 apk 大小超过 250 mb。

如果我可以即时制作立方体贴图,我可以节省大量 space。

请帮忙!

I want to know if TextureImporter class can be used to convert the 2d textures into Cubemap during runtime.

不,不能。

请参阅 TextureImporter 的文档。它是 UnityEditor 命名空间中的 class。该命名空间中的任何 class 或 API 都不能在构建中使用它仅供编辑器使用。


您可以使用 Cubemap class 创建立方体贴图。您可以使用 Texture2D.GetPixels(); 获取纹理的像素,并使用 Cubemap.SetPixels() 将像素设置为立方体贴图。

例如:

public Cubemap c;
private Color[] CubeMapColors;
public Texture2D t;
void Start() 
{
    CubeMapColors = t.GetPixels();
    c.SetPixels(CubeMapColors, CubemapFace.PositiveX);
    c.Apply();
}