Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLTFImage.cs ToTexture2D() ERROR: Cannot connect to destination host When Importing #239

Open
BatuhanCandr opened this issue Mar 1, 2023 · 0 comments

Comments

@BatuhanCandr
Copy link

IEnumerator DownloadAvatar()
{
Debug.LogError("Test 1 ");
string[] avatarUrls = new string[]
{
//URLs
};
Debug.LogError("Test 2 ");
for (int i = 0; i < avatarUrls.Length; i++)
{
Debug.LogError("Test 3 ");
using (UnityWebRequest www = UnityWebRequest.Get(avatarUrls[i]))
{
yield return www.SendWebRequest();

            if (www.result == UnityWebRequest.Result.Success)
            {
                string filePath = Application.persistentDataPath + "/" + Path.GetFileName(avatarUrls[i]);

                Debug.LogError("Test 7 ");
                File.WriteAllBytes(filePath, www.downloadHandler.data);
                Debug.LogError("Test 8");

                string extension = Path.GetExtension(filePath).ToLower();
                if (extension == ".bin")
                {
                    // do something with binary data
                    Debug.LogError("Test 11 ");
                }
                Debug.LogError("Test 9 ");
                if (extension == ".jpg")
                {
                    Debug.Log("jpg before");
                    _avatarTex = new Texture2D(2, 2);
                    defaultMat.mainTexture = _avatarTex;
                    _avatarTex.LoadImage(www.downloadHandler.data);
                    Debug.LogError("Test 10 ");
                }

               

                if (extension == ".gltf")
                {
                    GameObject result = Importer.LoadFromFile(filePath);
                    result.transform.GetChild(0).GetComponent<SkinnedMeshRenderer>().material = defaultMat;
                    result.transform.position = Vector3.zero;
                    Debug.LogError("Test 12 ");
                }
            }
            else
            {
                Debug.LogError("Error downloading file: " + www.error);
                Debug.LogError("Test 6 ");
            }
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant