0

我已经为我的 GameObject 的 GameManager Monobehaviour 设置了 Mode 类型的公共属性(枚举)“模式”,但是有时,特别是在回调中,为所述属性分配值不会做任何事情:

例如:

public class GameManager : uLink.MonoBehaviour {
    public static GameManager instance;

    public bool dedicated = false;
    public Mode mode = Mode.MainMenu;
    public List<Player> players = new List<Player> ();
    public Player localPlayer;


    // Use this for initialization
    void Start ()
    {
        GameManager.instance = this;
    }

    #region Server
        #region Network

    void uLink_OnServerInitialized ()
    {
        Debug.Log ("Server successfully started on port " + uLink.Network.listenPort);
        new Authenticator ("127.0.0.1", 1234, "DB", "dbUser", "dbPassword");
        mode = Mode.ServerDone;
    }
    (...)
    public enum Mode
    {
        MainMenu, //
        ServerInit, //Server start
        ServerStarting, //Server is starting
        ServerDone, //Server done loading
        ClientInit, //Client starting up
        ClientConnected, //Client connected
        ClientAwaitAuth,
        ClientAuthed, //Client authenticated
        ClientAuthFailed,
        Client //Client mode
    }
}

(这在使用 Unity3D 的网络和 uLink 的网络时都会发生)

回调发生并且日志被放置在控制台上,身份验证器单例也被创建,但模式没有改变。我已经尝试调试并放置一个断点,mode = Mode.ServerDone;但它只是说“未加载值”

如果我随后手动将模式更改为Mode.ServerDone使用编辑器,我的代码将完美运行。

我最好的猜测是,这是因为回调是由一个无法在属性上写入的协程调用的,但我不知道如何解决它。

4

1 回答 1

0

我找到了答案,结果 StartServer() 不是异步的,因此我的模式被替换了。

于 2013-05-02T11:29:06.737 回答