Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (rgc == null)
        {
            rgc = BalanceUnity.ACCESS().GetRGC();

            rgc.OnMatchDisband += packet => {
                MainThread.Call(() =>
                {
                    removeOthers();
                    removePlayer();
                });
            };

            rgc.OnMatchEnd += packet => {
                MainThread.Call(() =>
                {
                    removeOthers();
                    removePlayer();
                });
            };

            rgc.OnMatchExit += () => {
                MainThread.Call(() =>
                {
                    removeOthers();
                    removePlayer();
                });
            };

            rgc.OnOtherMatchExit += otherId => {
                MainThread.Call(() =>
                {
                    removeSingleOther(otherId);
                });
            };

            rgc.OnUdpClientClose += () =>
            {
                Debug.Log("udp disconnected.");

                MainThread.Call(() =>
                {
                    removeOthers();
                    removePlayer();
                });
            };

            rgc.OnMatchStart += packet =>
            {
                Debug.Log("OnMatchStart.");

                MainThread.Call(() =>
                {
                    spawnPlayer();
                });
            };

            rgc.OnMatchValidated += () =>
            {
                Debug.Log("OnMatchValidated.");
            };

            rgc.OnStatesUpdate += states =>
            {
                //Debug.Log("OnStatesUpdate.");

                MainThread.Call(() =>
                {
                    handleStates(states);
                });
            };
        }

        int now = (int)(Time.time * 1000);

        if (now - lastUpdated >= updateMs)
        {
            lastUpdated = now;
            if (rgc.IsInMatch())
            {
                if (Player != null && Player.transform != null)
                {
                    rgc.SendUdpStateUpdate(getStateUpdate());
                }
            }
        }
    }