コード例 #1
0
    // End of declaration

    /// <summary>
    /// Connect to the SignalR server
    /// </summary>
    public void Connect()
    {
        signalRClient = this;
        connectVars   = GameObject.Find("ConnectVars").GetComponent <ConnectVars>();

        // Initialize the connection
        gameHub           = new GameHub(ref signalRClient, ref connectVars);
        signalRConnection = new Connection(uri, gameHub);
        signalRConnection.Open();

        signalRConnection.OnConnected += (conn) =>
        {
            Debug.Log("Connect Successfully!");
            connectVars.SetTextStatus("You connected successfully!\nTap START! to find an opponent...");

            // Disable buttonConnect, buttonRetry and Enable buttonStart
            connectVars.ButtonConnectSetActive(false);
            connectVars.ButtonRetrySetActive(false);
            connectVars.ButtonStartSetActive(true);
        };
        signalRConnection.OnError += (conn, err) =>
        {
            Debug.Log(err);
            connectVars.SetTextStatus("Can't connect to the server :(");
        };
    }
コード例 #2
0
        public GameHub(ref SignalRClient signalRClient, ref ConnectVars connectVars) : base("GameHub")
        {
            this.signalRClient = signalRClient;
            this.connectVars   = connectVars;

            // Register callback functions that received from the server
            base.On("JoinToOpponent", Joined);
            base.On("OpponentLeft", Left);
            base.On("OpponentTransformation", Transformation);
        }