InstallUtility.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.IO;
  3. using SingularityGroup.HotReload.DTO;
  4. using SingularityGroup.HotReload.Editor.Cli;
  5. using SingularityGroup.HotReload.EditorDependencies;
  6. using UnityEditor;
  7. using UnityEngine;
  8. #if UNITY_2019_4_OR_NEWER
  9. using System.Reflection;
  10. using Unity.CodeEditor;
  11. #endif
  12. namespace SingularityGroup.HotReload.Editor {
  13. static class InstallUtility {
  14. const string installFlagPath = PackageConst.LibraryCachePath + "/installFlag.txt";
  15. public static void DebugClearInstallState() {
  16. File.Delete(installFlagPath);
  17. }
  18. // HandleEditorStart is only called on editor start, not on domain reload
  19. public static void HandleEditorStart(string updatedFromVersion) {
  20. var showOnStartup = HotReloadPrefs.ShowOnStartup;
  21. if (showOnStartup == ShowOnStartupEnum.Always || (showOnStartup == ShowOnStartupEnum.OnNewVersion && !String.IsNullOrEmpty(updatedFromVersion))) {
  22. // Don't open Hot Reload window inside Virtual Player folder
  23. // This is a heuristic since user might have the main player inside VP user-created folder, but that will be rare
  24. if (new DirectoryInfo(Path.GetFullPath("..")).Name != "VP" && !HotReloadPrefs.DeactivateHotReload) {
  25. HotReloadWindow.Open();
  26. }
  27. }
  28. if (HotReloadPrefs.LaunchOnEditorStart && !HotReloadPrefs.DeactivateHotReload) {
  29. EditorCodePatcher.DownloadAndRun().Forget();
  30. }
  31. RequestHelper.RequestEditorEventWithRetry(new Stat(StatSource.Client, StatLevel.Debug, StatFeature.Editor, StatEventType.Start)).Forget();
  32. }
  33. public static void CheckForNewInstall() {
  34. if(File.Exists(installFlagPath)) {
  35. return;
  36. }
  37. Directory.CreateDirectory(Path.GetDirectoryName(installFlagPath));
  38. using(File.Create(installFlagPath)) { }
  39. //Avoid opening the window on domain reload
  40. EditorApplication.delayCall += HandleNewInstall;
  41. }
  42. static void HandleNewInstall() {
  43. if (EditorCodePatcher.licenseType == UnityLicenseType.UnityPro) {
  44. RedeemLicenseHelper.I.StartRegistration();
  45. }
  46. // Don't open Hot Reload window inside Virtual Player folder
  47. // This is a heuristic since user might have the main player inside VP user-created folder, but that will be rare
  48. if (new DirectoryInfo(Path.GetFullPath("..")).Name != "VP") {
  49. HotReloadWindow.Open();
  50. }
  51. HotReloadPrefs.AllowDisableUnityAutoRefresh = true;
  52. HotReloadPrefs.AllAssetChanges = true;
  53. HotReloadPrefs.AutoRecompileUnsupportedChanges = true;
  54. HotReloadPrefs.AutoRecompileUnsupportedChangesOnExitPlayMode = true;
  55. if (HotReloadCli.CanOpenInBackground) {
  56. HotReloadPrefs.DisableConsoleWindow = true;
  57. }
  58. }
  59. }
  60. }