PhotonTester.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using JetBrains.Annotations;
  3. using Photon.Pun;
  4. using Photon.Realtime;
  5. using UnityEngine;
  6. namespace TweenableObject.Networking
  7. {
  8. public class PhotonTester : MonoBehaviour
  9. {
  10. public void Awake()
  11. {
  12. //ConnectToRegion("sa");
  13. }
  14. public void Update()
  15. {
  16. if (Input.GetKeyDown(KeyCode.A))
  17. {
  18. //ConnectToRegion("usw");
  19. if (PhotonNetwork.IsConnected)
  20. {
  21. Debug.Log(PhotonNetwork.CloudRegion);
  22. }
  23. else
  24. {
  25. PhotonNetwork.ConnectUsingSettings();
  26. }
  27. }
  28. }
  29. public void ConnectToRegion(string region)
  30. {
  31. if (PhotonNetwork.IsConnected)
  32. {
  33. Debug.Log(PhotonNetwork.CloudRegion);
  34. }
  35. else
  36. {
  37. //Move this to a function at the start of the game so we always get the best ping every time we launch
  38. ServerSettings.ResetBestRegionCodeInPreferences();
  39. PhotonNetwork.ConnectUsingSettings();
  40. PhotonNetwork.ConnectToRegion(region);
  41. }
  42. }
  43. public void ResetConnection()
  44. {
  45. ServerSettings.ResetBestRegionCodeInPreferences();
  46. }
  47. }
  48. }