【问题标题】:Callback never gets executed in Unity Web Player回调永远不会在 Unity Web Player 中执行
【发布时间】:2014-01-04 03:59:43
【问题描述】:

所以我试图发布到我的 web api 并在发布完成时使用回调。这一切都可以在 Unity 编辑器和桌面应用程序中完美运行,但不能在 Web Player 中运行。我已将其范围缩小到实际上没有被调用的回调。如何使用回调?这是我的代码:

void ui_login() { 
if (uiBase == null) 
     return; 

Debug.LogError(uiBase); clicks++; status = "(" + clicks + ")" + "working";

var username = uiBase.UIElements.FirstOrDefault(e => e.Name == "txt_username");
var password = uiBase.UIElements.FirstOrDefault(e => e.Name == "txt_password");
try
{
    var request = new LoginRequest()
    {
        Email = username.Text,
        Password = password.Text
    };
    StartCoroutine(WaitForRequest<LoginResponse>(request, loginCallback));
}
catch (Exception e)
{
    status = "(" + clicks + ")" + e;
}
}

void loginCallback(LoginResponse response, WWW www)
{
if (www.error != null)
    status = www.error;
if (response != null)
    status = response.ErrorMessage;
}

IEnumerator WaitForRequest<TResponse>(
LoginRequest request, Action<TResponse, WWW> callback)
{
var json = JsonMapper.ToJson(request);
var www = new WWW("http://someurl.com", json.ToBytes());
yield return www;
TResponse response;
if (www.error == null && www.isDone)
{
    var str = Encoding.UTF8.GetString(www.bytes);
    print(str);
    status = str;
    response = JsonConvert.DeserializeObject<TResponse>(str);
}

else
    response = default(TResponse);

print("somthif");
callback(response, www);
}

【问题讨论】:

    标签: c# callback unity3d


    【解决方案1】:

    出于安全原因,Unity Web Player 在沙盒中运行,会阻止您的 HTTP 请求。

    要解决此问题,请按照此链接中描述的过程进行操作:http://docs.unity3d.com/Documentation/Manual/SecuritySandbox.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-07
      相关资源
      最近更新 更多