Unity上的Azure数据库

时间:2018-12-24 05:15:29

标签: azure unity3d azure-sql-database vuforia

我正在使用Unity和Vuforia开发一个AR应用程序。我需要将按钮onclick发送到天蓝色的sql并从中获取数据。如何做到团结一致?

1 个答案:

答案 0 :(得分:1)

请查看Git Hub上的this演示项目。从该演示项目中,您可以尝试以下方法进行连接:

    public class AzureConnect : MonoBehaviour {
    private MobileServiceClient _client;
    private MobileServiceTable<Score> _table;
    // Use this for initialization
    void Start () {
        _client = new MobileServiceClient("https://myService.azurewebsites.net"); // <- add your app url here.
        _table = _client.GetTable<Score>("Score");
        ReadItems();
    }
    private void ReadItems()
    {
        StartCoroutine(_table.Read<Score>(OnReadItemsCompleted));
    }

    private void OnReadItemsCompleted(IRestResponse<Score[]> response)
    {
        if (!response.IsError)
        {
            Debug.Log("OnReadCompleted: " + response.Url + " data: " + response.Content);//content shows the content of the table properly
            Score[] items = response.Data;//Data is always null
            Debug.Log("Todo items count: " + items.Length);
        }
        else
        {
            Debug.LogWarning("Read Error Status:" + response.StatusCode + " Url: " + response.Url);
        }
    }
}