get_version只能从主线程

时间:2015-07-13 21:46:46

标签: c# database multithreading parse-platform unity3d

所以我使用parse.com(一个反手数据库提供商,由facebook制作)作为我的团结项目。我遇到了严重的问题。这是解释;

只要我从我的游戏中丢弃我的同步代码,一切正常但我需要它才能让玩家将他们的数据同步到服务器。

所以这就是错误:

  

get_version只能从主线程调用。    加载场景时,将从加载线程执行构造函数和字段初始值设定项。    不要在构造函数或字段初始值设定项中使用此函数,而是将初始化代码移动到唤醒或启动函数。

这是我的user.cs代码:

using UnityEngine;
using System.Collections;
using System.Threading;
using Parse;

public class User : MonoBehaviour {

    public bool isAuthenticated = false;
    public string userName = null;
    public int level;
    public int exp;
    public int money;
    public GoLobby golobby;
    public Sync sync;
    public bool isGoLobbyEnabled = false;

public void LoginUser(string username, string password)
    {

        var query = ParseObject.GetQuery("Member")
            .WhereEqualTo("Username", username)
            .WhereEqualTo("Password", password);
        query.FirstOrDefaultAsync().ContinueWith(t =>
                                       {
            ParseObject result = t.Result;
            //print (result);
            string playerName = result.Get<string>("Username");
            string playerPassword = result.Get<string>("Password");
            int playerLevel = result.Get<int>("Level");
            int playerexp = result.Get<int>("Experience");
            int playerMoney = result.Get<int>("Money");
            isAuthenticated = true;
            userName = playerName;
            money = playerMoney;
            exp = playerexp;
            sync.SyncToServer (userName, level, exp, money);
            isGoLobbyEnabled = true;
            GoLobby();
        });
    }

这是我的Sync.cs代码:

using UnityEngine;
using System.Collections;
using Parse;

public class Sync : MonoBehaviour {

    public void SyncToServer (string username, int level, int exp, int money)
    {
        var query2 = ParseObject.GetQuery ("Member")
            .WhereEqualTo ("Username", username);
        query2.FirstAsync ().ContinueWith (t =>
                                           {
            ParseObject obj = t.Result;
            Debug.Log (obj.ObjectId); //Works fine
            obj["Level"] = level;
            obj["Experience"] = exp;
            obj["Money"] = money;
            obj.SaveAsync();
        });
    }
}

1 个答案:

答案 0 :(得分:0)

这可能与Unity5和最新的解析权有关..? Unity5 +旧解析没有给出任何问题, Unity5 +新解析(PushNotifications)给出错误。 我们已经开通了解析SDK的问题单。

https://developers.facebook.com/bugs/390409301154954