2016-04-28 3 views
0

私はインポートOBJ、そのマテリアルとテクスチャの仲間に私を可能にシンプルOBJのという名前の資産を、使用しています。これはエディタでは正常に動作しますが、スタンドアロンでは動作しません。 私のOBJは私の参考資料のファイルにありません、私はWWWメソッドを使用して別のファイルから取り出します。ここでテクスチャエディタの荷重ではなく、スタンドアロンで(ピンク表示されます)

は、私はそれを行う方法、トン彼のダウンロード私のOBJ、ゲームオブジェクトを作成し、私のシーンに置きます:/

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); 
    } 

} 

そして、ここでは私のエディタで起こるものだスタンドアロンenter image description here

答えて

3

ピンクの外観は、メッシュレンダラーコンポーネント上のマテリアル割り当てが不足しているか、ビルド内にシェーダーがないことを意味します。

実行時にマテリアルまたはシェーダを割り当てる場合は、ビルドにシェーダを含めるようにしてください。

あなたは、私はあなたよりも同じものを持って 編集/プロジェクト設定/グラフィックス

enter image description here

+0

にリストに追加することにより、任意のシェーダを含めるために団結を強制することができ、より私がすべきものがあります含める? –

+0

これらのモデルではど​​のシェーダを使用していますか?リストにあることを確認してください。 –

+1

私は解決策を見つけました。あなたのおかげで、答えを少し改善したいのですが、エディタモードで使用していたすべてのシェーダを見て、スタンドアロンのシェーダに含める必要があります。そうするために、私はプリロードされたシェーダをアセットに保存し、このアセット内のシェーダが何かを調べます。私は明らかかどうか分からない? –

関連する問題