updated: hot reload to 1.13.7

This commit is contained in:
Chris
2025-07-09 23:24:14 -04:00
parent 236f9ea5df
commit 7641b83b6a
45 changed files with 2018 additions and 462 deletions

View File

@@ -90,7 +90,7 @@ namespace SingularityGroup.HotReload.Editor {
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.LabelField("Comany size (number of employees)");
EditorGUILayout.LabelField("Company size (number of employees)");
GUI.SetNextControlName("company_size");
_pendingCompanySize = EditorGUILayout.TextField(_pendingCompanySize)?.Trim();
EditorGUILayout.Space();

View File

@@ -79,22 +79,30 @@ namespace SingularityGroup.HotReload.Editor {
} catch {
// ignore
}
// Get relative path
TextAsset file = null;
foreach (var path in supportedPaths) {
int lastprojectIndex = 0;
int attempt = 0;
while (attempt++ < 100 && !file) {
lastprojectIndex = errorString.IndexOf(path, lastprojectIndex + 1, StringComparison.Ordinal);
if (lastprojectIndex == -1) {
break;
try {
foreach (var path in supportedPaths) {
int lastprojectIndex = 0;
int attempt = 0;
while (attempt++ < 100 && !file) {
lastprojectIndex = errorString.IndexOf(path, lastprojectIndex + 1, StringComparison.Ordinal);
if (lastprojectIndex == -1) {
break;
}
var fullCsIndex = errorString.IndexOf(".cs", lastprojectIndex, StringComparison.Ordinal);
var l = fullCsIndex - lastprojectIndex + ".cs".Length;
if (l <= 0) {
continue;
}
var candidateAbsolutePath = errorString.Substring(lastprojectIndex, fullCsIndex - lastprojectIndex + ".cs".Length);
var candidateRelativePath = EditorCodePatcher.GetRelativePath(filespec: candidateAbsolutePath, folder: path);
file = AssetDatabase.LoadAssetAtPath<TextAsset>(candidateRelativePath);
}
var fullCsIndex = errorString.IndexOf(".cs", lastprojectIndex, StringComparison.Ordinal);
var candidateAbsolutePath = errorString.Substring(lastprojectIndex, fullCsIndex - lastprojectIndex + ".cs".Length);
var candidateRelativePath = EditorCodePatcher.GetRelativePath(filespec: candidateAbsolutePath, folder: path);
file = AssetDatabase.LoadAssetAtPath<TextAsset>(candidateRelativePath);
}
} catch {
// ignore
}
// Get the line number
@@ -397,17 +405,14 @@ namespace SingularityGroup.HotReload.Editor {
GUI.Label(startRect, new GUIContent(title, icon), style);
}
bool clickableDescription = alertEntry.title == "Unsupported change" || alertEntry.title == "Compile error" || alertEntry.title == "Failed applying patch to method";
bool clickableDescription = (alertEntry.title == "Unsupported change" || alertEntry.title == "Compile error" || alertEntry.title == "Failed applying patch to method") && alertEntry.alertData.alertEntryType != AlertEntryType.InlinedMethod;
if (HotReloadTimelineHelper.expandedEntries.Contains(alertEntry) || alertEntry.alertType == AlertType.CompileError) {
using (new EditorGUILayout.VerticalScope()) {
using (new EditorGUILayout.HorizontalScope()) {
using (new EditorGUILayout.VerticalScope(entryType == EntryType.Child ? HotReloadWindowStyles.ChildEntryBoxStyle : HotReloadWindowStyles.EntryBoxStyle)) {
if (alertEntry.alertType == AlertType.Suggestion) {
if (alertEntry.alertType == AlertType.Suggestion || !clickableDescription) {
GUILayout.Label(alertEntry.description, HotReloadWindowStyles.LabelStyle);
} else if (!clickableDescription) {
string text = alertEntry.description;
GUILayout.Label(text, HotReloadWindowStyles.LabelStyle);
}
if (alertEntry.actionData != null) {
alertEntry.actionData.Invoke();
@@ -659,18 +664,29 @@ namespace SingularityGroup.HotReload.Editor {
if (!firstDialoguePass) {
return;
}
var secondDialoguePass = !Application.isPlaying
|| EditorUtility.DisplayDialog(
title: "Stop Play Mode and Recompile?",
message: "Using the Recompile button will stop Play Mode.\n\nDo you wish to proceed?",
ok: "Stop and Recompile",
cancel: "Cancel");
if (!secondDialoguePass) {
if (!ConfirmExitPlaymode("Using the Recompile button will stop Play Mode.\n\nDo you wish to proceed?")) {
return;
}
Recompile();
}
#if UNITY_2020_1_OR_NEWER
public static void SwitchToDebugMode() {
CompilationPipeline.codeOptimization = CodeOptimization.Debug;
HotReloadRunTab.Recompile();
HotReloadSuggestionsHelper.SetSuggestionInactive(HotReloadSuggestionKind.SwitchToDebugModeForInlinedMethods);
}
#endif
public static bool ConfirmExitPlaymode(string message) {
return !Application.isPlaying
|| EditorUtility.DisplayDialog(
title: "Stop Play Mode and Recompile?",
message: message,
ok: "Stop and Recompile",
cancel: "Cancel");
}
public static bool recompiling;
public static void Recompile() {
recompiling = true;
@@ -697,7 +713,7 @@ namespace SingularityGroup.HotReload.Editor {
EditorCodePatcher.DownloadAndRun().Forget();
}
} else if (currentState.running && !currentState.starting) {
if (HotReloadWindowStyles.windowScreenWidth > 150 && HotReloadTimelineHelper.CompileErrorsCount == 0) {
if (HotReloadWindowStyles.windowScreenWidth > 150) {
RenderRecompileButton();
}
string stopText = HotReloadWindowStyles.windowScreenWidth > Constants.StartButtonTextHideWidth ? " Stop" : "";

View File

@@ -98,18 +98,12 @@ namespace SingularityGroup.HotReload.Editor {
using (new EditorGUILayout.HorizontalScope(HotReloadWindowStyles.SectionOuterBoxCompact)) {
using (new EditorGUILayout.HorizontalScope(HotReloadWindowStyles.SectionInnerBoxWide)) {
using (new EditorGUILayout.VerticalScope()) {
HotReloadPrefs.ShowConfiguration = EditorGUILayout.Foldout(HotReloadPrefs.ShowConfiguration, "Configuration", true, HotReloadWindowStyles.FoldoutStyle);
HotReloadPrefs.ShowConfiguration = EditorGUILayout.Foldout(HotReloadPrefs.ShowConfiguration, "Settings", true, HotReloadWindowStyles.FoldoutStyle);
if (HotReloadPrefs.ShowConfiguration) {
EditorGUILayout.Space();
RenderUnityAutoRefresh();
RenderAssetRefresh();
if (HotReloadPrefs.AllAssetChanges) {
using (new EditorGUILayout.VerticalScope(paddedStyle ?? (paddedStyle = new GUIStyle { padding = new RectOffset(20, 0, 0, 0) }))) {
RenderIncludeShaderChanges();
}
EditorGUILayout.Space();
}
// main section
RenderUnityAutoRefresh();
using (new EditorGUI.DisabledScope(!EditorCodePatcher.autoRecompileUnsupportedChangesSupported)) {
RenderAutoRecompileUnsupportedChanges();
if (HotReloadPrefs.AutoRecompileUnsupportedChanges && EditorCodePatcher.autoRecompileUnsupportedChangesSupported) {
@@ -118,22 +112,49 @@ namespace SingularityGroup.HotReload.Editor {
RenderAutoRecompileUnsupportedChangesOnExitPlayMode();
RenderAutoRecompileUnsupportedChangesInPlayMode();
RenderAutoRecompilePartiallyUnsupportedChanges();
RenderDisplayNewMonobehaviourMethodsAsPartiallySupported();
}
}
EditorGUILayout.Space();
}
RenderConsoleWindow();
RenderAutostart();
RenderAssetRefresh();
if (HotReloadPrefs.AllAssetChanges) {
using (new EditorGUILayout.VerticalScope(paddedStyle ?? (paddedStyle = new GUIStyle { padding = new RectOffset(20, 0, 0, 0) }))) {
RenderIncludeShaderChanges();
}
EditorGUILayout.Space();
}
RenderDebuggerCompatibility();
// // fields
// RenderShowFeatures();
// using (new EditorGUILayout.VerticalScope(paddedStyle ?? (paddedStyle = new GUIStyle { padding = new RectOffset(20, 0, 0, 0) }))) {
// RenderShowApplyfieldInitializerEditsToExistingClassInstances();
//
// EditorGUILayout.Space();
// }
// visual feedback
if (EditorWindowHelper.supportsNotifications) {
RenderShowNotifications();
using (new EditorGUILayout.VerticalScope(paddedStyle ?? (paddedStyle = new GUIStyle { padding = new RectOffset(20, 0, 0, 0) }))) {
RenderShowPatchingNotifications();
RenderShowCompilingUnsupportedNotifications();
}
EditorGUILayout.Space();
using (new EditorGUILayout.VerticalScope(paddedStyle ?? (paddedStyle = new GUIStyle { padding = new RectOffset(20, 0, 0, 0) }))) {
RenderShowPatchingNotifications();
RenderShowCompilingUnsupportedNotifications();
}
EditorGUILayout.Space();
}
// misc
RenderMiscHeader();
using (new EditorGUILayout.VerticalScope(paddedStyle ?? (paddedStyle = new GUIStyle { padding = new RectOffset(20, 0, 0, 0) }))) {
RenderAutostart();
RenderConsoleWindow();
EditorGUILayout.Space();
}
EditorGUILayout.Space();
using (new EditorGUILayout.HorizontalScope()) {
GUILayout.FlexibleSpace();
@@ -161,24 +182,38 @@ namespace SingularityGroup.HotReload.Editor {
}
}
}
using (new EditorGUILayout.HorizontalScope(HotReloadWindowStyles.SectionOuterBoxCompact)) {
using (new EditorGUILayout.HorizontalScope(HotReloadWindowStyles.SectionInnerBoxWide)) {
using (new EditorGUILayout.VerticalScope()) {
HotReloadPrefs.ShowAdvanced = EditorGUILayout.Foldout(HotReloadPrefs.ShowAdvanced, "Advanced", true, HotReloadWindowStyles.FoldoutStyle);
if (HotReloadPrefs.ShowAdvanced) {
EditorGUILayout.Space();
DeactivateHotReload();
DisableDetailedErrorReporting();
}
}
}
}
}
}
}
void RenderUnityAutoRefresh() {
var newSettings = EditorGUILayout.BeginToggleGroup(new GUIContent("Allow to manage Unity's Auto Compile settings (recommended)"), HotReloadPrefs.AllowDisableUnityAutoRefresh);
var newSettings = EditorGUILayout.BeginToggleGroup(new GUIContent("Manage Unity auto-refresh (recommended)"), HotReloadPrefs.AllowDisableUnityAutoRefresh);
if (newSettings != HotReloadPrefs.AllowDisableUnityAutoRefresh) {
HotReloadPrefs.AllowDisableUnityAutoRefresh = newSettings;
}
string toggleDescription;
if (HotReloadPrefs.AllowDisableUnityAutoRefresh) {
toggleDescription = "Hot Reload will manage Unity's Auto Refresh and Script Compilation settings when it's running. Previous settings will be restored when Hot Reload is stopped.";
toggleDescription = "To avoid unnecessary recompiling, Hot Reload will automatically change Unity's Auto Refresh and Script Compilation settings. Previous settings will be restored when Hot Reload is stopped";
} else {
toggleDescription = "Enable to allow Hot Reload to manage Unity's Auto Refresh and Script Compilation settings when it's running. If enabled, previous settings will be restored when Hot Reload is stopped.";
toggleDescription = "Enabled this setting to auto-manage Unity's Auto Refresh and Script Compilation settings. This reduces unncessary recompiling";
}
EditorGUILayout.LabelField(toggleDescription, HotReloadWindowStyles.WrapStyle);
EditorGUILayout.EndToggleGroup();
EditorGUILayout.Space(3f);
EditorGUILayout.Space(6f);
}
void RenderAssetRefresh() {
@@ -190,7 +225,7 @@ namespace SingularityGroup.HotReload.Editor {
var restartServer = EditorUtility.DisplayDialog("Hot Reload",
$"When changing 'Asset refresh', the Hot Reload server must be restarted for this to take effect." +
"\nDo you want to restart it now?",
"Restart server", "Don't restart");
"Restart Hot Reload", "Don't restart");
if (restartServer) {
EditorCodePatcher.RestartCodePatcher().Forget();
}
@@ -198,13 +233,30 @@ namespace SingularityGroup.HotReload.Editor {
}
string toggleDescription;
if (HotReloadPrefs.AllAssetChanges) {
toggleDescription = "Hot Reload will refresh changed assets in the project.";
toggleDescription = "Hot Reload will refresh changed assets such as sprites, prefabs, etc";
} else {
toggleDescription = "Enable to allow Hot Reload to refresh changed assets in the project. All asset types are supported including sprites, prefabs, shaders etc.";
toggleDescription = "Enable to allow Hot Reload to refresh changed assets in the project. All asset types are supported including sprites, prefabs, shaders etc";
}
EditorGUILayout.LabelField(toggleDescription, HotReloadWindowStyles.WrapStyle);
EditorGUILayout.EndToggleGroup();
EditorGUILayout.Space(3f);
EditorGUILayout.Space(6f);
}
void RenderDebuggerCompatibility() {
var newSettings = EditorGUILayout.BeginToggleGroup(new GUIContent("Auto-disable Hot Reload while a debugger is attached (recommended)"), HotReloadPrefs.AutoDisableHotReloadWithDebugger);
if (newSettings != HotReloadPrefs.AutoDisableHotReloadWithDebugger) {
HotReloadPrefs.AutoDisableHotReloadWithDebugger = newSettings;
CodePatcher.I.debuggerCompatibilityEnabled = !HotReloadPrefs.AutoDisableHotReloadWithDebugger;
}
string toggleDescription;
if (HotReloadPrefs.AutoDisableHotReloadWithDebugger) {
toggleDescription = "Hot Reload automatically disables itself while a debugger is attached, as it can otherwise interfere with certain debugger features. Please read the documentation if you consider disabling this setting.";
} else {
toggleDescription = "When a debugger is attached, Hot Reload will be active, but certain debugger features might not work as expected. Please read our documentation to learn about the limitations.";
}
EditorGUILayout.LabelField(toggleDescription, HotReloadWindowStyles.WrapStyle);
EditorGUILayout.EndToggleGroup();
EditorGUILayout.Space(6f);
}
void RenderIncludeShaderChanges() {
@@ -245,9 +297,71 @@ namespace SingularityGroup.HotReload.Editor {
}
EditorGUILayout.LabelField(toggleDescription, HotReloadWindowStyles.WrapStyle);
EditorGUILayout.EndToggleGroup();
EditorGUILayout.Space(3f);
EditorGUILayout.Space(6f);
}
void DeactivateHotReload() {
var newSettings = EditorGUILayout.BeginToggleGroup(new GUIContent("Deactivate Hot Reload"), HotReloadPrefs.DeactivateHotReload);
if (newSettings != HotReloadPrefs.DeactivateHotReload) {
DeactivateHotReloadInner(newSettings);
}
string toggleDescription;
if (HotReloadPrefs.DeactivateHotReload) {
toggleDescription = "Hot Reload is deactivated.";
} else {
toggleDescription = "Enable to deactivate Hot Reload.";
}
EditorGUILayout.LabelField(toggleDescription, HotReloadWindowStyles.WrapStyle);
EditorGUILayout.EndToggleGroup();
EditorGUILayout.Space(6f);
}
void DisableDetailedErrorReporting() {
var newSettings = EditorGUILayout.BeginToggleGroup(new GUIContent("Disable Detailed Error Reporting"), HotReloadPrefs.DisableDetailedErrorReporting);
DisableDetailedErrorReportingInner(newSettings);
string toggleDescription;
if (HotReloadPrefs.DisableDetailedErrorReporting) {
toggleDescription = "Detailed error reporting is disabled.";
} else {
toggleDescription = "Toggle on to disable detailed error reporting.";
}
EditorGUILayout.LabelField(toggleDescription, HotReloadWindowStyles.WrapStyle);
EditorGUILayout.EndToggleGroup();
EditorGUILayout.Space(6f);
}
public static void DisableDetailedErrorReportingInner(bool newSetting) {
if (newSetting == HotReloadPrefs.DisableDetailedErrorReporting) {
return;
}
HotReloadPrefs.DisableDetailedErrorReporting = newSetting;
// restart when setting changes
if (ServerHealthCheck.I.IsServerHealthy) {
var restartServer = EditorUtility.DisplayDialog("Hot Reload",
$"When changing 'Disable Detailed Error Reporting', the Hot Reload server must be restarted for this to take effect." +
"\nDo you want to restart it now?",
"Restart server", "Don't restart");
if (restartServer) {
EditorCodePatcher.RestartCodePatcher().Forget();
}
}
}
static void DeactivateHotReloadInner(bool deactivate) {
var confirmed = !deactivate || EditorUtility.DisplayDialog("Hot Reload",
$"Hot Reload will be completely deactivated (unusable) until you activate it again." +
"\n\nDo you want to proceed?",
"Deactivate", "Cancel");
if (confirmed) {
HotReloadPrefs.DeactivateHotReload = deactivate;
if (deactivate) {
EditorCodePatcher.StopCodePatcher(recompileOnDone: true).Forget();
} else {
HotReloadRunTab.Recompile();
}
}
}
void RenderAutostart() {
var newSettings = EditorGUILayout.BeginToggleGroup(new GUIContent("Autostart on Unity open"), HotReloadPrefs.LaunchOnEditorStart);
if (newSettings != HotReloadPrefs.LaunchOnEditorStart) {
@@ -265,15 +379,25 @@ namespace SingularityGroup.HotReload.Editor {
}
void RenderShowNotifications() {
GUILayout.Label("Indications", HotReloadWindowStyles.NotificationsTitleStyle);
EditorGUILayout.Space(10f);
GUILayout.Label("Visual Feedback", HotReloadWindowStyles.NotificationsTitleStyle);
EditorGUILayout.Space(10f);
string toggleDescription;
if (!EditorWindowHelper.supportsNotifications && !UnitySettingsHelper.I.playmodeTintSupported) {
toggleDescription = "Indications are not supported in the Unity version you use.";
} else {
toggleDescription = "Chosen indications are enabled:";
var toggleDescription = "Indications are not supported in the Unity version you use.";
EditorGUILayout.LabelField(toggleDescription, HotReloadWindowStyles.WrapStyle);
}
EditorGUILayout.LabelField(toggleDescription, HotReloadWindowStyles.WrapStyle);
}
// void RenderShowFields() {
// EditorGUILayout.Space(14f);
// GUILayout.Label("Fields", HotReloadWindowStyles.NotificationsTitleStyle);
// }
void RenderMiscHeader() {
EditorGUILayout.Space(10f);
GUILayout.Label("Misc", HotReloadWindowStyles.NotificationsTitleStyle);
EditorGUILayout.Space(10f);
}
void RenderShowPatchingNotifications() {
@@ -289,6 +413,36 @@ namespace SingularityGroup.HotReload.Editor {
EditorGUILayout.LabelField(toggleDescription, HotReloadWindowStyles.WrapStyle);
EditorGUILayout.EndToggleGroup();
}
// void RenderShowApplyfieldInitializerEditsToExistingClassInstances() {
// var newSetting = EditorGUILayout.BeginToggleGroup(new GUIContent("Apply field initializer edits to existing class instances"), HotReloadPrefs.ApplyFieldInitiailzerEditsToExistingClassInstances);
// ApplyApplyFieldInitializerEditsToExistingClassInstances(newSetting);
// string toggleDescription;
// if (HotReloadPrefs.ApplyFieldInitiailzerEditsToExistingClassInstances) {
// toggleDescription = "New field initializers with constant value will update field value of existing objects.";
// } else {
// toggleDescription = "New field initializers will not modify existing objects.";
// }
// EditorGUILayout.LabelField(toggleDescription, HotReloadWindowStyles.WrapStyle);
// EditorGUILayout.EndToggleGroup();
// }
[Obsolete("Not implemented")]
public static void ApplyApplyFieldInitializerEditsToExistingClassInstances(bool newSetting) {
if (newSetting != HotReloadPrefs.ApplyFieldInitiailzerEditsToExistingClassInstances) {
HotReloadPrefs.ApplyFieldInitiailzerEditsToExistingClassInstances = newSetting;
// restart when setting changes
if (ServerHealthCheck.I.IsServerHealthy) {
var restartServer = EditorUtility.DisplayDialog("Hot Reload",
$"When changing 'Apply field initializer edits to existing class instances' setting, the Hot Reload server must restart for it to take effect." +
"\nDo you want to restart it now?",
"Restart server", "Don't restart");
if (restartServer) {
EditorCodePatcher.RestartCodePatcher().Forget();
}
}
}
}
void RenderShowCompilingUnsupportedNotifications() {
HotReloadPrefs.ShowCompilingUnsupportedNotifications = EditorGUILayout.BeginToggleGroup(new GUIContent("Compiling Unsupported Changes Indication"), HotReloadPrefs.ShowCompilingUnsupportedNotifications);
@@ -310,9 +464,9 @@ namespace SingularityGroup.HotReload.Editor {
if (!EditorCodePatcher.autoRecompileUnsupportedChangesSupported) {
toggleDescription = "Auto recompiling unsupported changes is not supported in the Unity version you use.";
} else if (HotReloadPrefs.AutoRecompileUnsupportedChanges) {
toggleDescription = "Hot Reload will recompile when unsupported changes are detected.";
toggleDescription = "Hot Reload will recompile automatically after code changes that Hot Reload doesn't support.";
} else {
toggleDescription = "Enable to recompile when unsupported changes are detected.";
toggleDescription = "When enabled, recompile happens automatically after code changes that Hot Reload doesn't support.";
}
EditorGUILayout.LabelField(toggleDescription, HotReloadWindowStyles.WrapStyle);
EditorGUILayout.EndToggleGroup();
@@ -330,6 +484,18 @@ namespace SingularityGroup.HotReload.Editor {
EditorGUILayout.EndToggleGroup();
}
void RenderDisplayNewMonobehaviourMethodsAsPartiallySupported() {
HotReloadPrefs.DisplayNewMonobehaviourMethodsAsPartiallySupported = EditorGUILayout.BeginToggleGroup(new GUIContent("Display new Monobehaviour methods as partially supported"), HotReloadPrefs.DisplayNewMonobehaviourMethodsAsPartiallySupported);
string toggleDescription;
if (HotReloadPrefs.DisplayNewMonobehaviourMethodsAsPartiallySupported) {
toggleDescription = "Hot Reload will display new monobehaviour methods as partially unsupported.";
} else {
toggleDescription = "Enable to display new monobehaviour methods as partially unsupported.";
}
EditorGUILayout.LabelField(toggleDescription, HotReloadWindowStyles.WrapStyle);
EditorGUILayout.EndToggleGroup();
}
void RenderAutoRecompileUnsupportedChangesImmediately() {
HotReloadPrefs.AutoRecompileUnsupportedChangesImmediately = EditorGUILayout.BeginToggleGroup(new GUIContent("Recompile immediately"), HotReloadPrefs.AutoRecompileUnsupportedChangesImmediately);
string toggleDescription;