【问题标题】:Unity www yield return request works in editor but not in fb appUnity www yield return request 在编辑器中有效,但在 fb 应用程序中无效
【发布时间】:2014-04-03 15:15:58
【问题描述】:

目前我的问题简化是这样的:

下面的代码在统一编辑器中工作,我之前已经检查过 php 多次,现在发送的 url 工作正常,并且它返回正确的值,但是将构建上传到要在 facebook 应用程序中使用的空间中断由于某种原因,提供了 img 以显示它停止的位置。

其他一些细节:

环顾所有迹象表明它是 v3.0 的错误(我正在使用的版本是 v4.3.3f1),但是虽然我下面的代码在编辑器中工作没有问题,但它不会继续过去当我将它的构建上传到我提供的 html 空间时,yield 返回 www 请求。

在下面的块之前登录的当前工作方式是初始化 FB 游戏对象,登录到 facebook,检查没有错误,然后传回 FB UserID,然后将其传递给下面的代码 - 它按预期工作.

快速编辑 - 数据库连接器包含主 url,下面的代码添加了 php get 所需的字符串。

我不知道从哪里开始尝试修复它,除了如图所示更改正在显示的文本,这有助于将其隔离到我的问题。

它所在的登录屏幕图像:http://i.imgur.com/ti2YLrW.png?1

代码:

using UnityEngine;

using System.Collections;

using System;

public class ConnectToDataBase : MonoBehaviour {

    public bool bDatabaseConnected = false;
    public bool bConnectionFailed = false;

    public string sFacebookID;
    public WWWForm wwwForm;

    public void vStartConnection()
    {
        var text = GameObject.FindGameObjectWithTag ("Other");

        text.guiText.text = "Login : connectToDatabase: prepping query";

        //call databasequeries and get sDBConnect
        string sConnectPhp = GameObject.FindGameObjectWithTag("DBConnector").GetComponent<DatabaseQueries>().sDBConnect;

        //now ready the url with the necessary code for php's get, and the FacebookID
        string url = sConnectPhp + "?UserID=" + sFacebookID;

        text.guiText.text = "Login : connectToDatabase: url being sent:\n" + url;

        WWW wwwGet = new WWW(url);

        text.guiText.text = "Login : connectToDatabase: wwwGet created";

        text.guiText.text = "Login : connectToDatabase: starting coroutine";
        StartCoroutine(Connect(wwwGet));
    }

    IEnumerator Connect(WWW www)
    {
        var text = GameObject.FindGameObjectWithTag("Other");
        text.guiText.text = "Login : connectToDatabase: coroutine started - sending www request";

        yield return www;

        text.guiText.text = "Login : connectToDatabase: wwwGet yield return";

        string sTemp = www.text;

        if(www.error == null)
        {
            text.guiText.text = "Login : connectToDatabase: wwwGet has not errored";

            string newString = sTemp.ToString();
            int newInt = Convert.ToInt32(newString);

            //print (newString);
            text.guiText.text = "Login : connectToDatabase: checking wwwGet return as int";

            if(newInt == 0)
            {
                //if successfully connected set to true
                print ("connectToDatabase: olduser successful");
                text.guiText.text = "Login : connectToDatabase: olduser successful";

                bDatabaseConnected = true;
                yield break;
            }
            else if(newInt == 1)
            {
                //if successfully connected set to true
                print ("connectToDatabase: newuser successful");
                text.guiText.text = "Login : connectToDatabase: newuser successful";

                bDatabaseConnected = true;
                yield break;
            }
            else if(newInt == 2)
            {
                //game connection has failed
                print ("connectToDatabase: failed");
                text.guiText.text = "Login : connectToDatabase: failed";
                bDatabaseConnected = false;
                bConnectionFailed = true;
                yield break;
            }
            else
            {
                text.guiText.text = "Login : connectToDatabase: php did not return a 0/1/2 value";
            }
        }
        else
        {
            //game connection has failed
            print ("connectToDatabase: failed");
            text.guiText.text = "Login : connectToDatabase: wwwGet has errored:\n" + www.error;

            bDatabaseConnected = false;
            bConnectionFailed = true;
            yield break;
        }

        text.guiText.text = "Login : connectToDatabase: wwwGet if statement skipped entirely";
    }
}

【问题讨论】:

    标签: c# facebook unity3d facebook-unity-sdk


    【解决方案1】:

    在浏览器中运行时有不同的规则。如here 所述,该应用处于沙盒模式,因此您需要添加crossdomain 策略(我知道该链接适用于 Flash Player,但同样适用)。

    最后你需要这样的东西,保存在你的网络服务器根目录的 crossdomain.xml 文件中。

    <?xml version="1.0"?>
    <cross-domain-policy>
     <allow-access-from domain="*" secure="false"/>
    </cross-domain-policy>
    

    【讨论】:

    • 啊,好的,谢谢,明天我再次在实验室时会实施它。
    猜你喜欢
    • 1970-01-01
    • 2022-12-06
    • 2014-07-22
    • 1970-01-01
    • 2020-07-13
    • 2020-10-15
    • 2018-08-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多