纹理会在编辑器中加载,但不能独立加载(显示为粉红色) [英] Textures loads in editor but not in standalone (appears pink)

查看:159
本文介绍了纹理会在编辑器中加载,但不能独立加载(显示为粉红色)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用名为 Simple Obj 的资产,该资产允许我导入obj,它们的材质和纹理关联.这在我的编辑器中可以正常工作,但在我的独立版本中却不能. 我的 OBJ不在我的资源文件中,我使用WWW方法从另一个文件中获取它.

I'm using an asset named Simple Obj, that allows me to import an obj, their materials and the textures associate. This works fine in my editor but not in my standalone. My OBJ are not in my resources file, I take it from another file with the WWW method.

这是我的操作方式,他下载了我的OBJ,创建了一个Gameobject并将其放置在我的场景中:

private IEnumerator DownloadAndImportAllInBackground(string url, Plane newPlane)
{
    string objString = null;
    string mtlString = null;
    Hashtable textures = null;
    GameObject planeObject = null;
    bool gameObjectPerGroup = false;
    bool subMeshPerGroup = false;
    bool usesRightHanded = true;

    yield return StartCoroutine(DownloadFile(url, retval => objString = retval));
        yield return StartCoroutine(DownloadFile(url.Substring(0, url.Length - 4) + ".mtl", retval => mtlString = retval));
        if (mtlString != null && mtlString.Length > 0)
        {
            string path = url;
            int lastSlash = path.LastIndexOf('/', path.Length - 1);
            if (lastSlash >= 0) path = path.Substring(0, lastSlash + 1);
            Hashtable[] mtls = ObjImporter.ImportMaterialSpecs(mtlString);
            for (int i = 0; i < mtls.Length; i++)
            {
                if (mtls[i].ContainsKey("mainTexName"))
                {
                    Texture2D texture = null;
                    string texUrl = path + mtls[i]["mainTexName"];
                    yield return StartCoroutine(DownloadTexture(texUrl, retval => texture = retval));
                    if (texture != null)
                    {
                        if (textures == null) textures = new Hashtable();
                        textures[mtls[i]["mainTexName"]] = texture;
                    }
                }
            }
        }

    yield return StartCoroutine(DownloadFile(url, retval => objString = retval));

    if (objString != null && objString.Length > 0)
    {
        yield return StartCoroutine(ObjImporter.ImportInBackground(objString, mtlString, textures, retval => planeObject = retval, gameObjectPerGroup, subMeshPerGroup, usesRightHanded));
        planeObject.transform.localScale = new Vector3(0.0005f, 0.0005f, 0.0005f);
        if (planeObject == null)
        {
            Debug.Log("Null gameobject");
        }
        planeObject.name = newPlane.Callsign;
        planeObject.transform.position = new Vector3((float)newPlane.X, (float)newPlane.Afl / (3.2808f * 1852f), (float)newPlane.Y);
        planeObject.transform.eulerAngles = new Vector3(0, -180 + newPlane.Heading, 0);
        planeId_Object_Dictionnary.Add(newPlane.Flight, planeObject);
    }

}

这是我的编辑器/独立版中发生的事情:

And here's what happen in my editor/standalone :

推荐答案

粉红色外观意味着您的构建缺少网格渲染器组件上的材质分配或构建中的着色器.

Pink appearance means your build have missing material assignment on the mesh renderer component or missing shader in the build.

如果要在运行时分配材质或着色器,请确保在构建中包括着色器.

If you are assigning materials or shaders at runtime make sure you include the shader in the build.

您可以通过将统一着色器添加到以下列表中的列表来强制统一性: 编辑/项目设置/图形

You can force unity to include any shader by adding it to the list in Edit/Project Settings/Graphics

这篇关于纹理会在编辑器中加载,但不能独立加载(显示为粉红色)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆