簡體   English   中英

使用Azure存儲Unity UWP應用進行NameResolutionFailure(在Player中工作)

[英]NameResolutionFailure with Azure Storage Unity UWP app (works in Player)

我有一個Hololens應用程序,應從Azure存儲加載數據。 當使用WindowsAzure.Storage包轉換為unitypackage時 ,我可以在使用Unity Player時加載數據,並且在使用常規2D XAML UWP應用進行測試時,也可以在Hololens上使用該API加載數據,但是,在調試IL2CPP時項目,我得到一個“ WebException:錯誤:NameResolutionFailure”( 完整日志 )。

以下是構建簡化的測試項目的步驟:

  • 打開Unity 2018.2(我使用2018.2.14f,使用https必須使用2018.2,這顯然是連接到Azure所必需的)
  • 將Unity項目的.NET版本設置為4.x,因為Azure存儲API使用等待/異步,所以我使用IL2CPP作為后端。 .NET后端給出有關找不到某些Newtonsoft.JSON函數的錯誤,這可能是導致我出現問題的原因? 存在Assets / Plugins / Newtonsoft.Json.dll並引用.NET v4.0.30319。

錯誤:方法System.Threading.Tasks.Task 1 Newtonsoft.Json.Linq.JObject :: LoadAsync(Newtonsoft.Json.JsonReader,System.Threading.CancellationToken)在目標框架中不存在。 從System.Void Microsoft.WindowsAzure.Storage.ODataErrorHelper / d__2 :: MoveNext()的Microsoft.WindowsAzure.Storage.dll引用。

  • 在(0,0,2)創建一個名為ImageGrid的空游戲對象
  • 將下面的腳本PopulateImageGrid.cs導入到項目中,並將其附加到ImageGrid
  • 從1 * 1 * 0.1多維數據集創建一個預制件,並將Image Grid游戲對象的公共字段Image Grid Tile設置為該預制件
  • 刪除Assets / Plugins / Microsoft.CSharp.dll,因為Unity兩次抱怨它存在
  • 作為UWP進行構建,在Visual Studio中加載已構建的項目,並從Release和x86選擇開始(或部署到Hololens)

這是PopulateImageGrid.cs。 可以隨意連接代碼中提供的帳戶詳細信息,因為它是一個免費帳戶,沒有敏感數據。

using System.Collections;
using System.Collections.Generic;
// using UnityEditor.PackageManager;
using UnityEngine;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.File;
using System;

public class PopulateImageGrid : MonoBehaviour {

    public Transform ImageGridTile;

    async void Start()
    {
        Debug.Log("In PopulateImageGrid.Start()");
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(@"DefaultEndpointsProtocol=https;FileEndpoint=https://meshiconstorage.file.core.windows.net;AccountName=meshiconstorage;AccountKey=2Myeg/WUowehkrAY8Lgl361xxylfkMdITrVapKKVPyo9bVFqN6/uD1S66CB4oTPnnWncLubiVjioBUIT+4utaw==");
        CloudFileClient cloudFileClient = storageAccount.CreateCloudFileClient();
        string shareName = "meshicon-share1";
        var cloudFileShare = cloudFileClient.GetShareReference(shareName);
        CloudFileDirectory rootDirectory = cloudFileShare.GetRootDirectoryReference();
        var fileDirectory = rootDirectory.GetDirectoryReference("images");

        FileContinuationToken token = null;

        int row = 0;
        int col = 0;
        const int width = 32;
        const int height = 32;
        do
        {
            FileResultSegment frs = await fileDirectory.ListFilesAndDirectoriesSegmentedAsync(token);
            foreach (var result in frs.Results)
            {
                Debug.Log("In loop with " + result.ToString());
                Vector3 position = new Vector3(col++ * 0.13f - 0.39f, row * 0.13f - 0.26f, 0f);
                Quaternion rotation = Quaternion.identity;
                Transform gridTile = Instantiate(ImageGridTile);
                gridTile.transform.parent = gameObject.transform;
                gridTile.localPosition = position;
                gridTile.localRotation = rotation;
                if (col > 6)
                {
                    row++;
                    col = 0;
                }
                byte[] imgData = new byte[10000];
                int size = await ((CloudFile)result).DownloadToByteArrayAsync(imgData, 0);
                Debug.Log("Downloaded to byte[]");
                Texture2D texture = new Texture2D(width, height);
                byte[] realImgData = new byte[size];
                Array.Copy(imgData, realImgData, size);
                texture.LoadImage(imgData);
                gridTile.GetComponent<MeshRenderer>().material.mainTexture = texture;
            }
        } while (token != null);
    }
}

訣竅是要等到30秒超時后,出現NameResolutionFailure的錯誤消息,這對我來說很明顯我應該在appxmanifest中激活Internet權限。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM