コード例 #1
0
    // Called when Unity3D updates its UI
    void OnGUI()
    {
        if (rgc == null)
        {
            rgc = BalanceUnity.ACCESS().GetRGC();
        }

        if (rgc == null || !rgc.IsReady())
        {
            GUI.Label(new Rect(10, 10, 100, 20), "Getting ready..");
            return;
        }

        //MM-Queue
        if (!rgc.IsInQueue() && !rgc.IsInMatch() && !rgc.IsConfirmationOpen())
        {
            if (GUI.Button(new Rect(10, 10, 126, 30), "Join Match-Making"))
            {
                rgc.JoinMatchMakingQueue();
            }
        }

        if (rgc.IsInQueue() && !rgc.IsConfirmationOpen())
        {
            if (GUI.Button(new Rect(10, 10, 146, 30), "Leave Match-Making"))
            {
                rgc.LeaveMatchMakingQueue();
            }
        }

        //Match-Confirmation
        if (rgc.IsConfirmationOpen() && !rgc.HasClientConfirmed())
        {
            if (GUI.Button(new Rect(10, 50, 126, 30), "Confirm Match"))
            {
                rgc.ConfirmMatchRequest();
            }
        }

        //Match
        if (rgc.IsInMatch())
        {
            if (GUI.Button(new Rect(10, 90, 126, 30), "Leave Match"))
            {
                rgc.ExitMatch();
            }
        }

        /*
         * //Reconnect
         * if (rgc.IsReady())
         * {
         *  if (GUI.Button(new Rect(10, 130, 126, 30), "Reconnect"))
         *  {
         *      BalanceUnity.ACCESS().Reconnect();
         *  }
         * } */
    }
コード例 #2
0
    public static BalanceUnity ACCESS()
    {
        if (Camera.main == null)
        {
            Debug.LogWarning("There is not Main-Camera in the scene, cannot access balance unity.");
            return(null);
        }

        BalanceUnity bu = Camera.main.GetComponent <BalanceUnity>();

        if (bu == null)
        {
            Debug.LogWarning("There is not BalanceUnity Instance present on the Main-Camera.");
        }

        return(bu);
    }
コード例 #3
0
 // Use this for initialization
 void Start()
 {
     bu = BalanceUnity.ACCESS();
 }
コード例 #4
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());
                }
            }
        }
    }