From 96ec7ed13503b9802aae5acd07af74b09aaf4301 Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Mon, 18 Nov 2024 20:02:07 +0900 Subject: [PATCH 1/3] Fix to save converted assets --- Runtime/Settings/AutopilotSettings.cs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Runtime/Settings/AutopilotSettings.cs b/Runtime/Settings/AutopilotSettings.cs index f8c15c6..6d42579 100644 --- a/Runtime/Settings/AutopilotSettings.cs +++ b/Runtime/Settings/AutopilotSettings.cs @@ -265,6 +265,10 @@ private static void Initialize() settings.ConvertSceneCrossingAgentsFromObsoleteObserverAgent(logger); // Note: before convert other Agents. settings.ConvertErrorHandlerAgentFromObsoleteSettings(logger); + +#if UNITY_EDITOR + AssetDatabase.SaveAssetIfDirty(settings); +#endif } private void CreateDefaultLoggerIfNeeded() @@ -275,9 +279,6 @@ private void CreateDefaultLoggerIfNeeded() // not change field directly. this.LoggerAsset.Logger.Log("Create default logger."); -#if UNITY_EDITOR - EditorUtility.SetDirty(this); -#endif } } @@ -294,6 +295,9 @@ internal void ConvertLoggersFromObsoleteLogger() This time, temporarily converting."); this.loggerAssets.Add(this.loggerAsset); +#if UNITY_EDITOR + EditorUtility.SetDirty(this); +#endif } [Obsolete("Remove this method when bump major version")] @@ -337,6 +341,7 @@ internal void ConvertSlackReporterFromObsoleteSlackSettings(ILogger logger) convertedReporter.description = AutoConvertingMessage; SaveConvertedObject(convertedReporter); #endif + this.reporters.Add(convertedReporter); #if UNITY_EDITOR EditorUtility.SetDirty(this); @@ -363,15 +368,16 @@ internal void ConvertJUnitXmlReporterFromObsoleteJUnitReportPath(ILogger logger) convertedReporter.description = AutoConvertingMessage; SaveConvertedObject(convertedReporter); #endif + this.Reporter.reporters.Add(convertedReporter); #if UNITY_EDITOR EditorUtility.SetDirty(this); #endif } +#if UNITY_EDITOR private void SaveConvertedObject(Object obj) { -#if UNITY_EDITOR var settingsPath = AssetDatabase.GetAssetPath(this); if (string.IsNullOrEmpty(settingsPath)) { @@ -380,8 +386,8 @@ private void SaveConvertedObject(Object obj) var dir = Path.GetDirectoryName(settingsPath) ?? "Assets"; AssetDatabase.CreateAsset(obj, Path.Combine(dir, $"New {obj.GetType().Name}.asset")); -#endif } +#endif [Obsolete("Remove this method when bump major version")] internal void ConvertSceneCrossingAgentsFromObsoleteObserverAgent(ILogger logger) @@ -396,6 +402,9 @@ internal void ConvertSceneCrossingAgentsFromObsoleteObserverAgent(ILogger logger This time, temporarily converting."); this.sceneCrossingAgents.Add(this.observerAgent); +#if UNITY_EDITOR + EditorUtility.SetDirty(this); +#endif } [Obsolete("Remove this method when bump major version")] @@ -425,6 +434,7 @@ internal void ConvertErrorHandlerAgentFromObsoleteSettings(ILogger logger) convertedAgent.description = AutoConvertingMessage; SaveConvertedObject(convertedAgent); #endif + this.sceneCrossingAgents.Add(convertedAgent); #if UNITY_EDITOR EditorUtility.SetDirty(this); From c8538a54bff6485479cb57e21c88e0b81a5eefca Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Mon, 18 Nov 2024 21:03:39 +0900 Subject: [PATCH 2/3] Add clean old field values --- Runtime/Settings/AutopilotSettings.cs | 13 +++++++++++ .../Runtime/Settings/AutopilotSettingsTest.cs | 23 +++++++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Runtime/Settings/AutopilotSettings.cs b/Runtime/Settings/AutopilotSettings.cs index 6d42579..76952a3 100644 --- a/Runtime/Settings/AutopilotSettings.cs +++ b/Runtime/Settings/AutopilotSettings.cs @@ -295,6 +295,7 @@ internal void ConvertLoggersFromObsoleteLogger() This time, temporarily converting."); this.loggerAssets.Add(this.loggerAsset); + this.loggerAsset = null; #if UNITY_EDITOR EditorUtility.SetDirty(this); #endif @@ -313,6 +314,7 @@ internal void ConvertReportersFromObsoleteReporter(ILogger logger) This time, temporarily converting."); this.reporters.Add(this.reporter); + this.reporter = null; #if UNITY_EDITOR EditorUtility.SetDirty(this); #endif @@ -343,6 +345,10 @@ internal void ConvertSlackReporterFromObsoleteSlackSettings(ILogger logger) #endif this.reporters.Add(convertedReporter); + this.slackToken = null; + this.slackChannels = null; + this.mentionSubTeamIDs = null; + this.addHereInSlackMessage = false; #if UNITY_EDITOR EditorUtility.SetDirty(this); #endif @@ -370,6 +376,7 @@ internal void ConvertJUnitXmlReporterFromObsoleteJUnitReportPath(ILogger logger) #endif this.Reporter.reporters.Add(convertedReporter); + this.junitReportPath = null; #if UNITY_EDITOR EditorUtility.SetDirty(this); #endif @@ -402,6 +409,7 @@ internal void ConvertSceneCrossingAgentsFromObsoleteObserverAgent(ILogger logger This time, temporarily converting."); this.sceneCrossingAgents.Add(this.observerAgent); + this.observerAgent = null; #if UNITY_EDITOR EditorUtility.SetDirty(this); #endif @@ -436,6 +444,11 @@ internal void ConvertErrorHandlerAgentFromObsoleteSettings(ILogger logger) #endif this.sceneCrossingAgents.Add(convertedAgent); + this.handleException = false; + this.handleError = false; + this.handleAssert = false; + this.handleWarning = false; + this.ignoreMessages = null; #if UNITY_EDITOR EditorUtility.SetDirty(this); #endif diff --git a/Tests/Runtime/Settings/AutopilotSettingsTest.cs b/Tests/Runtime/Settings/AutopilotSettingsTest.cs index 1c3488f..f4c7c51 100644 --- a/Tests/Runtime/Settings/AutopilotSettingsTest.cs +++ b/Tests/Runtime/Settings/AutopilotSettingsTest.cs @@ -75,6 +75,7 @@ public void ConvertLoggersFromObsoleteLogger_HasLogger_IncludeToLoggers() settings.ConvertLoggersFromObsoleteLogger(); Assert.That(settings.loggerAssets.Count, Is.EqualTo(1)); Assert.That(settings.loggerAssets, Has.Member(legacyLogger)); + Assert.That(settings.loggerAsset, Is.Null); Assert.That(legacyLogger.Logs, Has.Member((LogType.Warning, @"Single Logger setting in AutopilotSettings has been obsolete. @@ -115,6 +116,7 @@ public void ConvertReportersFromObsoleteReporter_HasReporter_IncludeToReporters( settings.ConvertReportersFromObsoleteReporter(spyLogger.Logger); Assert.That(settings.reporters.Count, Is.EqualTo(1)); Assert.That(settings.reporters, Has.Member(legacyReporter)); + Assert.That(settings.reporter, Is.Null); Assert.That(spyLogger.Logs, Has.Member((LogType.Warning, @"Single Reporter setting in AutopilotSettings has been obsolete. @@ -159,10 +161,14 @@ public void ConvertSlackReporterFromObsoleteSlackSettings_HasSlackSettings_Gener Assert.That(settings.reporters.Count, Is.EqualTo(1)); var slackReporter = settings.reporters[0] as SlackReporter; Assert.That(slackReporter, Is.Not.Null); - Assert.That(slackReporter.slackToken, Is.EqualTo(settings.slackToken)); - Assert.That(slackReporter.slackChannels, Is.EqualTo(settings.slackChannels)); - Assert.That(slackReporter.mentionSubTeamIDs, Is.EqualTo(settings.mentionSubTeamIDs)); - Assert.That(slackReporter.addHereInSlackMessage, Is.EqualTo(settings.addHereInSlackMessage)); + Assert.That(slackReporter.slackToken, Is.EqualTo("token")); + Assert.That(slackReporter.slackChannels, Is.EqualTo("channels")); + Assert.That(slackReporter.mentionSubTeamIDs, Is.EqualTo("subteam")); + Assert.That(slackReporter.addHereInSlackMessage, Is.True); + Assert.That(settings.slackToken, Is.Null); + Assert.That(settings.slackChannels, Is.Null); + Assert.That(settings.mentionSubTeamIDs, Is.Null); + Assert.That(settings.addHereInSlackMessage, Is.False); Assert.That(spyLogger.Logs, Has.Member((LogType.Warning, @"Slack settings in AutopilotSettings has been obsolete. @@ -217,6 +223,7 @@ public void ConvertSceneCrossingAgentsFromObsoleteObserverAgent_HasObserverAgent settings.ConvertSceneCrossingAgentsFromObsoleteObserverAgent(spyLogger.Logger); Assert.That(settings.sceneCrossingAgents.Count, Is.EqualTo(1)); Assert.That(settings.sceneCrossingAgents, Has.Member(legacyObserverAgent)); + Assert.That(settings.observerAgent, Is.Null); Assert.That(spyLogger.Logs, Has.Member((LogType.Warning, @"ObserverAgent setting in AutopilotSettings has been obsolete. @@ -259,7 +266,8 @@ public void ConvertJUnitXmlReporterFromObsoleteJUnitReportPath_HasJUnitReportPat Assert.That(settings.Reporter.reporters.Count, Is.EqualTo(1)); var reporter = settings.Reporter.reporters[0] as JUnitXmlReporter; Assert.That(reporter, Is.Not.Null); - Assert.That(reporter.outputPath, Is.EqualTo(settings.junitReportPath)); + Assert.That(reporter.outputPath, Is.EqualTo("Path/To/JUnitReport.xml")); + Assert.That(settings.junitReportPath, Is.Null); Assert.That(spyLogger.Logs, Has.Member((LogType.Warning, @"JUnitReportPath setting in AutopilotSettings has been obsolete. @@ -323,6 +331,11 @@ public void ConvertErrorHandlerAgentFromObsoleteSettings_HasAnyHandlingFlag_Gene Assert.That(errorHandlerAgent.handleWarning, Is.EqualTo(handleWarning ? HandlingBehavior.TerminateAutopilot : HandlingBehavior.Ignore)); Assert.That(errorHandlerAgent.ignoreMessages, Is.EqualTo(ignoreMessages)); + Assert.That(settings.handleException, Is.False); + Assert.That(settings.handleError, Is.False); + Assert.That(settings.handleAssert, Is.False); + Assert.That(settings.handleWarning, Is.False); + Assert.That(settings.ignoreMessages, Is.Null); Assert.That(spyLogger.Logs, Has.Member((LogType.Warning, @"Error handling settings in AutopilotSettings has been obsolete. From b7f2a1e9a7ad63c44d7f383b6ed84b4b0520dd9d Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Tue, 19 Nov 2024 04:58:24 +0900 Subject: [PATCH 3/3] Fix automatically converting messages --- README.md | 11 ++++----- README_ja.md | 12 ++++------ Runtime/Settings/AutopilotSettings.cs | 24 +++++++++---------- .../Runtime/Settings/AutopilotSettingsTest.cs | 24 +++++++++---------- 4 files changed, 32 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 207cebb..d06a504 100644 --- a/README.md +++ b/README.md @@ -692,20 +692,17 @@ Find out why you have an old UniTask installed. e.g., Check the contents of Packages/packages-lock.json generated by the Unity editor; use your IDE's code definition jump function to check where the source file of `UniTask.WaitForEndOfFrame()` is. -### Warning message "settings has been obsolete" when running autopilot +### Warning message "settings has been obsolete" when launch Autopilot For example, the following warning message may be output log. ``` Slack settings in AutopilotSettings has been obsolete. -Please delete the value using Debug Mode in the Inspector window. And create a SlackReporter asset file. +Now, automatically converted it to SlackReporter asset file. Check it out and commit it to your VCS. ``` -Even if you have already migrated to a new setting method (`SlackReporter` in the above example), you are warned that values remain in obsolete fields. -You can edit obsolete fields by opening the settings file in the Inspector window and switching to **Debug Mode**. - -For information on how to use the Inspector window, see the Unity manual: -[Manual: Working in the Inspector](https://docs.unity3d.com/Manual/InspectorOptions.html) +This message that the obsolete setting item has been automatically converted to the new setting method (`SlackReporter` in the above example). +The settings file has been updated, so please check it out and commit it to your VCS (e.g., Git). diff --git a/README_ja.md b/README_ja.md index 2e4e8c1..af6d6ad 100644 --- a/README_ja.md +++ b/README_ja.md @@ -702,21 +702,17 @@ Compiler Error at Library\PackageCache\com.dena.anjin@1.0.1\Runtime\Reporters\Sl Unityエディターが生成するPackages/packages-lock.jsonの中身を確認するか、お使いのIDEのコード定義ジャンプ機能で `UniTask.WaitForEndOfFrame()` のソースファイルがどこにあるかを確認するなどして、古いUniTaskがインストールされている原因を突き止められます。 -### 実行中に "settings has been obsolete" 警告が出る +### 起動時に "settings has been obsolete" 警告が出る たとえば次のような警告メッセージが出力されることがあります。 ``` Slack settings in AutopilotSettings has been obsolete. -Please delete the value using Debug Mode in the Inspector window. And create a SlackReporter asset file. +Now, automatically converted it to SlackReporter asset file. Check it out and commit it to your VCS. ``` -すでに新しい設定方法(上例では `SlackReporter` )に移行済みであっても、廃止されたフィールドに値が残っていることを警告されています。 -設定ファイルをInspectorウィンドウで開き、**Debug Mode** に切り替えることで廃止されたフィールドを編集できます。 - -Inspectorウィンドウの操作については、Unityマニュアルの -[Inspector の使用 - Unity マニュアル](https://docs.unity3d.com/ja/current/Manual/InspectorOptions.html) -を参照してください。 +これは、廃止された設定項目を新しい設定方法(上例では `SlackReporter` )に自動変換したことを示しています。 +設定ファイルが更新されていますので、確認してVCS(Gitなど)にコミットしてください。 diff --git a/Runtime/Settings/AutopilotSettings.cs b/Runtime/Settings/AutopilotSettings.cs index 76952a3..336a97a 100644 --- a/Runtime/Settings/AutopilotSettings.cs +++ b/Runtime/Settings/AutopilotSettings.cs @@ -291,8 +291,8 @@ internal void ConvertLoggersFromObsoleteLogger() } this.loggerAsset.Logger.Log(LogType.Warning, @"Single Logger setting in AutopilotSettings has been obsolete. -Please delete the reference using Debug Mode in the Inspector window. And add to the list Loggers. -This time, temporarily converting."); +Now, automatically converted it to Logger*s*. +Check it out and commit it to your VCS."); this.loggerAssets.Add(this.loggerAsset); this.loggerAsset = null; @@ -310,8 +310,8 @@ internal void ConvertReportersFromObsoleteReporter(ILogger logger) } logger.Log(LogType.Warning, @"Single Reporter setting in AutopilotSettings has been obsolete. -Please delete the reference using Debug Mode in the Inspector window. And add to the list Reporters. -This time, temporarily converting."); +Now, automatically converted it to Reporter*s*. +Check it out and commit it to your VCS."); this.reporters.Add(this.reporter); this.reporter = null; @@ -330,8 +330,8 @@ internal void ConvertSlackReporterFromObsoleteSlackSettings(ILogger logger) } const string AutoConvertingMessage = @"Slack settings in AutopilotSettings has been obsolete. -Please delete the value using Debug Mode in the Inspector window. And create a SlackReporter asset file. -This time, temporarily generate and use SlackReporter instance."; +Now, automatically converted it to SlackReporter asset file. +Check it out and commit it to your VCS."; logger.Log(LogType.Warning, AutoConvertingMessage); var convertedReporter = CreateInstance(); @@ -364,8 +364,8 @@ internal void ConvertJUnitXmlReporterFromObsoleteJUnitReportPath(ILogger logger) } const string AutoConvertingMessage = @"JUnitReportPath setting in AutopilotSettings has been obsolete. -Please delete the reference using Debug Mode in the Inspector window. And create a JUnitXmlReporter asset file. -This time, temporarily converting."; +Now, automatically converted it to JUnitXmlReporter asset file. +Check it out and commit it to your VCS."; logger.Log(LogType.Warning, AutoConvertingMessage); var convertedReporter = CreateInstance(); @@ -405,8 +405,8 @@ internal void ConvertSceneCrossingAgentsFromObsoleteObserverAgent(ILogger logger } logger.Log(LogType.Warning, @"ObserverAgent setting in AutopilotSettings has been obsolete. -Please delete the value using Debug Mode in the Inspector window. And using the SceneCrossingAgents. -This time, temporarily converting."); +Now, automatically converted it to SceneCrossingAgents. +Check it out and commit it to your VCS."); this.sceneCrossingAgents.Add(this.observerAgent); this.observerAgent = null; @@ -428,8 +428,8 @@ internal void ConvertErrorHandlerAgentFromObsoleteSettings(ILogger logger) } const string AutoConvertingMessage = @"Error handling settings in AutopilotSettings has been obsolete. -Please delete the value using Debug Mode in the Inspector window. And create an ErrorHandlerAgent asset file. -This time, temporarily generate and use ErrorHandlerAgent instance."; +Now, automatically converted it to ErrorHandlerAgent asset file. +Check it out and commit it to your VCS."; logger.Log(LogType.Warning, AutoConvertingMessage); var convertedAgent = CreateInstance(); diff --git a/Tests/Runtime/Settings/AutopilotSettingsTest.cs b/Tests/Runtime/Settings/AutopilotSettingsTest.cs index f4c7c51..3be79e9 100644 --- a/Tests/Runtime/Settings/AutopilotSettingsTest.cs +++ b/Tests/Runtime/Settings/AutopilotSettingsTest.cs @@ -79,8 +79,8 @@ public void ConvertLoggersFromObsoleteLogger_HasLogger_IncludeToLoggers() Assert.That(legacyLogger.Logs, Has.Member((LogType.Warning, @"Single Logger setting in AutopilotSettings has been obsolete. -Please delete the reference using Debug Mode in the Inspector window. And add to the list Loggers. -This time, temporarily converting."))); +Now, automatically converted it to Logger*s*. +Check it out and commit it to your VCS."))); } [Test] @@ -120,8 +120,8 @@ public void ConvertReportersFromObsoleteReporter_HasReporter_IncludeToReporters( Assert.That(spyLogger.Logs, Has.Member((LogType.Warning, @"Single Reporter setting in AutopilotSettings has been obsolete. -Please delete the reference using Debug Mode in the Inspector window. And add to the list Reporters. -This time, temporarily converting."))); +Now, automatically converted it to Reporter*s*. +Check it out and commit it to your VCS."))); } [Test] @@ -172,8 +172,8 @@ public void ConvertSlackReporterFromObsoleteSlackSettings_HasSlackSettings_Gener Assert.That(spyLogger.Logs, Has.Member((LogType.Warning, @"Slack settings in AutopilotSettings has been obsolete. -Please delete the value using Debug Mode in the Inspector window. And create a SlackReporter asset file. -This time, temporarily generate and use SlackReporter instance."))); +Now, automatically converted it to SlackReporter asset file. +Check it out and commit it to your VCS."))); } [Test] @@ -227,8 +227,8 @@ public void ConvertSceneCrossingAgentsFromObsoleteObserverAgent_HasObserverAgent Assert.That(spyLogger.Logs, Has.Member((LogType.Warning, @"ObserverAgent setting in AutopilotSettings has been obsolete. -Please delete the value using Debug Mode in the Inspector window. And using the SceneCrossingAgents. -This time, temporarily converting."))); +Now, automatically converted it to SceneCrossingAgents. +Check it out and commit it to your VCS."))); } [Test] @@ -271,8 +271,8 @@ public void ConvertJUnitXmlReporterFromObsoleteJUnitReportPath_HasJUnitReportPat Assert.That(spyLogger.Logs, Has.Member((LogType.Warning, @"JUnitReportPath setting in AutopilotSettings has been obsolete. -Please delete the reference using Debug Mode in the Inspector window. And create a JUnitXmlReporter asset file. -This time, temporarily converting."))); +Now, automatically converted it to JUnitXmlReporter asset file. +Check it out and commit it to your VCS."))); } [Test] @@ -339,8 +339,8 @@ public void ConvertErrorHandlerAgentFromObsoleteSettings_HasAnyHandlingFlag_Gene Assert.That(spyLogger.Logs, Has.Member((LogType.Warning, @"Error handling settings in AutopilotSettings has been obsolete. -Please delete the value using Debug Mode in the Inspector window. And create an ErrorHandlerAgent asset file. -This time, temporarily generate and use ErrorHandlerAgent instance."))); +Now, automatically converted it to ErrorHandlerAgent asset file. +Check it out and commit it to your VCS."))); } [Test]