/// <summary> /// This menu is shown if the player has joined a channel. /// </summary> void DrawExampleMenu() { Rect rect = new Rect(0f, Screen.height - buttonHeight, buttonWidth, buttonHeight); if (GUI.Button(rect, "Main Menu", button)) { // Leaving the channel will cause the "OnNetworkLeaveChannel" to be sent out. TNManager.LeaveChannel(); } }
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); } }
public void LeaveChannel() { TNManager.LeaveChannel(); }