コード例 #1
0
    /// <summary>
    /// Start listening for incoming UDP packets right away.
    /// </summary>

    void Start()
    {
        if (Application.isPlaying)
        {
            // We don't want mobile devices to dim their screen and go to sleep while the app is running
            Screen.sleepTimeout = SleepTimeout.NeverSleep;

            // Make it possible to use UDP using a random port
            TNManager.StartUDP(Random.Range(10000, 50000));
        }
    }
コード例 #2
0
    /// <summary>
    /// This function is called when a connection is either established or it fails to connect.
    /// Connecting to a server doesn't mean that the connected players are now immediately able
    /// to see each other, as they have not yet joined a channel. Only players that have joined
    /// some channel are able to see and interact with other players in the same channel.
    /// You can call TNManager.JoinChannel here if you like, but in this example we let the player choose.
    /// </summary>

    protected override void OnConnect(bool success, string message)
    {
        Debug.Log("Connected: " + success + " " + message + " (Player ID #" + TNManager.playerID + ")");
        mMessage = message;

        // Make it possible to use UDP using a random port
        if (!TNServerInstance.isLocal)
        {
            TNManager.StartUDP(Random.Range(10000, 50000));
        }
    }
コード例 #3
0
    /// <summary>
    /// Connect to the server.
    /// </summary>

    public void Connect()
    {
        // We don't want mobile devices to dim their screen and go to sleep while the app is running
        Screen.sleepTimeout = SleepTimeout.NeverSleep;

        // Make it possible to use UDP using a random port
        TNManager.StartUDP(Random.Range(10000, 50000));

        // Connect to the remote server
        TNManager.Connect(serverAddress, serverPort);
    }
コード例 #4
0
        /// <summary>
        /// On success -- join a channel.
        /// </summary>

        void OnConnect(bool result, string message)
        {
            if (result)
            {
                // Make it possible to use UDP using a random port
                if (allowUDP)
                {
                    TNManager.StartUDP(Random.Range(10000, 50000));
                }
                TNManager.JoinChannel(channelID, firstLevel, persistent, 10000, null);
            }
            else
            {
                Debug.LogError(message);
            }
        }
コード例 #5
0
    /// <summary>
    /// On success -- join a channel.
    /// </summary>

    void OnNetworkConnect(bool result, string message)
    {
        if (result)
        {
            // Make it possible to use UDP using a random port
            if (allowUDP)
            {
                TNManager.StartUDP(Random.Range(10000, 50000));
            }
            TNManager.JoinChannel(channelID, firstLevel, persistent, 10000, null);
        }
        else if (!string.IsNullOrEmpty(failureFunctionName))
        {
            UnityTools.Broadcast(failureFunctionName, message);
        }
        else
        {
            Debug.LogError(message);
        }
    }
コード例 #6
0
    // Use this for initialization
    void Start()
    {
        serverFileName = GameID + ".dat";
        if (Application.isPlaying)
        {
            // Start resolving IPs
            Tools.ResolveIPs(null);

            // We don't want mobile devices to dim their screen and go to sleep while the app is running
            Screen.sleepTimeout = SleepTimeout.NeverSleep;

            // Make it possible to use UDP using a random port
            TNManager.StartUDP(Random.Range(10000, 50000));

            StartCoroutine("UpdateServerList");

            joinGroup    = JoinPanel.GetComponent <CanvasGroup>();
            connectGroup = GetComponent <CanvasGroup>();
#if UNITY_WEBPLAYER
            ServerButton.gameObject.SetActive(false);
#endif
        }
        Init();
    }