PlayerQuitHandler.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using NUnit.Framework.Interfaces;
  2. using UnityEngine.Networking.PlayerConnection;
  3. using UnityEngine.TestRunner.TestLaunchers;
  4. namespace UnityEngine.TestTools.TestRunner.Callbacks
  5. {
  6. internal class PlayerQuitHandler : MonoBehaviour, ITestRunnerListener
  7. {
  8. public void Start()
  9. {
  10. PlayerConnection.instance.Register(PlayerConnectionMessageIds.quitPlayerMessageId, ProcessPlayerQuiteMessage);
  11. }
  12. private void ProcessPlayerQuiteMessage(MessageEventArgs arg0)
  13. {
  14. //Some platforms don't quit, so we need to disconnect to make sure they will not connect to another editor instance automatically.
  15. PlayerConnection.instance.DisconnectAll();
  16. #if !UNITY_2021_1_OR_NEWER
  17. //XBOX has an error when quitting
  18. if (Application.platform == RuntimePlatform.XboxOne)
  19. {
  20. return;
  21. }
  22. #endif
  23. Application.Quit();
  24. }
  25. public void RunStarted(ITest testsToRun)
  26. {
  27. }
  28. public void RunFinished(ITestResult testResults)
  29. {
  30. }
  31. public void TestStarted(ITest test)
  32. {
  33. }
  34. public void TestFinished(ITestResult result)
  35. {
  36. }
  37. }
  38. }