Seven is the number.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.1 KiB

4 years ago
  1. using UdpKit;
  2. using UnityEngine;
  3. using Process = System.Diagnostics.Process;
  4. public partial class BoltDebugStart : BoltInternal.GlobalEventListenerBase
  5. {
  6. UdpEndPoint _serverEndPoint;
  7. UdpEndPoint _clientEndPoint;
  8. void Awake()
  9. {
  10. DontDestroyOnLoad(gameObject);
  11. Application.targetFrameRate = 60;
  12. }
  13. void Start()
  14. {
  15. #if UNITY_EDITOR_OSX
  16. Process p = new Process();
  17. p.StartInfo.FileName = "osascript";
  18. p.StartInfo.Arguments =
  19. @"-e 'tell application """ + UnityEditor.PlayerSettings.productName + @"""
  20. activate
  21. end tell'";
  22. p.Start();
  23. #endif
  24. BoltRuntimeSettings settings = BoltRuntimeSettings.instance;
  25. _serverEndPoint = new UdpEndPoint(UdpIPv4Address.Localhost, (ushort)settings.debugStartPort);
  26. _clientEndPoint = new UdpEndPoint(UdpIPv4Address.Localhost, 0);
  27. BoltConfig cfg;
  28. cfg = settings.GetConfigCopy();
  29. cfg.connectionTimeout = 60000000;
  30. cfg.connectionRequestTimeout = 500;
  31. cfg.connectionRequestAttempts = 1000;
  32. if (string.IsNullOrEmpty(settings.debugStartMapName) == false)
  33. {
  34. if (BoltDebugStartSettings.DebugStartIsServer)
  35. {
  36. BoltLauncher.StartServer(_serverEndPoint, cfg);
  37. }
  38. else if (BoltDebugStartSettings.DebugStartIsClient)
  39. {
  40. BoltLauncher.StartClient(_clientEndPoint, cfg);
  41. }
  42. BoltDebugStartSettings.PositionWindow();
  43. }
  44. else
  45. {
  46. BoltLog.Error("No map found to start from");
  47. }
  48. }
  49. public override void BoltStartFailed()
  50. {
  51. BoltLog.Error("Failed to start debug mode");
  52. }
  53. public override void BoltStartDone()
  54. {
  55. if (BoltNetwork.IsServer)
  56. {
  57. BoltNetwork.LoadScene(BoltRuntimeSettings.instance.debugStartMapName);
  58. }
  59. else
  60. {
  61. BoltNetwork.Connect((ushort)BoltRuntimeSettings.instance.debugStartPort);
  62. }
  63. }
  64. public override void SceneLoadLocalDone(string map)
  65. {
  66. Destroy(gameObject);
  67. }
  68. }