Textures loads in editor but not in standalone (appears pink)

别说谁变了你拦得住时间么 提交于 2020-01-14 03:04:28

问题


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.

Here's how I do it, this download my OBJ, create a Gameobject and place it in my scene :

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 :


回答1:


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



来源:https://stackoverflow.com/questions/36909567/textures-loads-in-editor-but-not-in-standalone-appears-pink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!