コード例 #1
0
ファイル: ExampleMenu.cs プロジェクト: SirLpc/CubeNetGame
    /// <summary>
    /// This menu is shown when a connection has been established and the player has not yet joined any channel.
    /// </summary>

    void DrawSelectionMenu()
    {
        int count = examples.Length;

        Rect rect = new Rect(
            Screen.width * 0.5f - buttonWidth * 0.5f,
            Screen.height * 0.5f - buttonHeight * 0.5f * count,
            buttonWidth, buttonHeight);

        channelId = GUILayout.TextField(channelId, input, GUILayout.Width(200f));
        for (int i = 0; i < count; ++i)
        {
            string sceneName = examples[i];

            if (GUI.Button(rect, sceneName, button))
            {
                // When a button is clicked, join the specified channel.
                // Whoever creates the channel also sets the scene that will be loaded by everyone who joins.
                // In this case, we are specifying the name of the scene we've just clicked on.
                TNManager.JoinChannel(i + 1 + int.Parse(channelId), sceneName, true, 255, null);
            }
            rect.y += buttonHeight;
        }
        rect.y += 20f;
    }
コード例 #2
0
 void OnNetworkConnect(bool success, string error)
 {
     if (success)
     {
         TNManager.JoinChannel(Channel, JoinPeristent, true);
     }
 }
コード例 #3
0
    void RFC_EnterGame(int channelid)
    {
        //set Que to false here
        //or set when entering any new channel via the callback

        TNManager.SetPlayerData("isQue", false);

        TNManager.JoinChannel(channelid, gameScene, false, roomPlayerCount, null, true);
    }
コード例 #4
0
 /// <summary>
 /// Called with the connection result, on both success and failure. If failed, ‘message’ contains the error message.
 /// </summary>
 /// <param name="success">If set to <c>true</c> success.</param>
 /// <param name="message">Message.</param>
 public void OnNetworkConnect(bool success, string message)
 {
     if (success)
     {
         //Debug.Log ("Joining Channel");
         TNManager.JoinChannel(0, null, false, 4, "");
         // The "" is the password
     }
     else
     {
         //Debug.Log ("Failed To Connect");
     }
 }
    void PeriodicCheck()
    {
        Vector3       myPos           = transform.position;
        ExampleRegion closestRegion   = null;
        float         closestDistance = float.MaxValue;

        // First find the closest region -- this is the region the player avatar should belong to
        for (int i = 0; i < ExampleRegion.list.size; ++i)
        {
            ExampleRegion region   = ExampleRegion.list[i];
            float         distance = Vector3.Distance(region.transform.position, myPos);

            if (distance < closestDistance)
            {
                closestDistance = distance;
                closestRegion   = region;
            }
        }

        // Now ensure we've joined all the nearby regions in addition to the closest region
        for (int i = 0; i < ExampleRegion.list.size; ++i)
        {
            ExampleRegion region   = ExampleRegion.list[i];
            float         distance = Vector3.Distance(region.transform.position, myPos);

            if (distance < joinDistance || region == closestRegion)
            {
                // We're close -- join the region's channel
                if (!TNManager.IsInChannel(region.channelID))
                {
                    TNManager.JoinChannel(region.channelID, true);
                }
            }
            else if (distance > leaveDistance && tno.channelID != region.channelID)
            {
                // We're far away -- leave the region's channel
                if (TNManager.IsInChannel(region.channelID))
                {
                    TNManager.LeaveChannel(region.channelID);
                }
            }
        }

        // Transfer the car to the closest region's channel
        if (closestRegion != null && tno.channelID != closestRegion.channelID)
        {
            tno.TransferToChannel(closestRegion.channelID);
        }
    }
コード例 #6
0
    /// <summary>
    /// On success -- join a channel.
    /// </summary>

    void OnNetworkConnect(bool result, string message)
    {
        if (result)
        {
            TNManager.JoinChannel(channelID, firstLevel);
        }
        else if (!string.IsNullOrEmpty(failureFunctionName))
        {
            UnityTools.Broadcast(failureFunctionName, message);
        }
        else
        {
            Debug.LogError(message);
        }
    }
コード例 #7
0
    private void network_onConnect(bool success, string message)
    {
        if (success)
        {
            button_disconnect.interactable = true;
            IsConnected = true;

            //everyone joins main catch-all lobby channel
            TNManager.JoinChannel(1000, "lobby", true, 500, null, true);
        }
        else
        {
            Debug.Log(string.Format("network_onConnect: success={0} message={1}", success, message));
        }
    }
コード例 #8
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);
            }
        }
コード例 #9
0
ファイル: JoinMenu.cs プロジェクト: harko12/Battle
    IEnumerator UpdateChannelList()
    {
        var channelList = GetComponent <TNChannelList>();

        while (true)
        {
            var list = channelList.Channels;
            // the channel list script keeps an updated list of the channels
            for (int i = 0; i < list.size; ++i)
            {
                GameObject go = null;
                if (ChannelLines.Count <= i)
                {
                    go = GameObject.Instantiate(ChannelLine) as GameObject;
                    go.transform.SetParent(ChannelListRoot.transform);
                    ChannelLines.Add(go);
                }
                var ent = list.buffer[i];
                go = ChannelLines.buffer[i];
                go.SetActive(true);
                var button      = go.GetComponentInChildren <UnityEngine.UI.Button>();
                var textFields  = go.GetComponentsInChildren <Text>();
                var channelData = ent.data; // jsonize at somepoint.. for now just the channel name
                var channelName = (string.IsNullOrEmpty(channelData) ? "loading.." : channelData);
                textFields[0].text = channelName;
                textFields[1].text = ent.level;
                textFields[2].text = "no info right now";
                button.onClick.RemoveAllListeners();
                button.onClick.AddListener(delegate
                {
                    Debug.LogFormat("joining id:{0} level:{1}", ent.id, ent.level);
                    TNManager.SetTimeout(120); // stupid levels take forever to load
                    SceneManager.LoadScene("Game", LoadSceneMode.Single);
                    TNManager.JoinChannel(ent.id, false, true);
                    //                    TNManager.JoinChannel(ent.id, ent.level);
                });
            }
            // hide any extra lines
            for (int i = list.size; i < ChannelLines.Count; i++)
            {
                ChannelLines[i].SetActive(false);
            }

            yield return(new WaitForSeconds(GetComponent <TNChannelList>().RefreshInterval));
        }
    }
コード例 #10
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);
        }
    }
コード例 #11
0
ファイル: JoinMenu.cs プロジェクト: harko12/Battle
    public void OnCreateRoom()
    {
        var dlg = InputDialog.instance;

        dlg.AcceptValues();
        var servername = dlg.GetValueString(LevelInfo.INPUT_RoomName);
        var maxPlayers = dlg.GetValueInt(LevelInfo.INPUT_MaxPlayers);

        if (!string.IsNullOrEmpty(servername))
        {
            TNServerInstance.serverName = servername;
        }
        if (maxPlayers <= 2)
        {
            maxPlayers = 2;
        }
        var targetSceneName = dlg.GetValueString(LevelInfo.INPUT_LevelName);
        int count           = GetComponent <TNChannelList>().Count;

        SceneManager.LoadScene(targetSceneName, LoadSceneMode.Single);
        TNManager.JoinChannel(count, false, true);
    }
コード例 #12
0
    /// <summary>
    /// Notification of another player leaving the channel.
    /// </summary>

    void OnPlayerLeave(int channelID, Player p)
    {
        AddToChat(p.name + " has left channel " + channelID, Color.black);
        TNManager.JoinChannel(1000, "lobby", true, 500, null, true);
    }