Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to save converted assets #111

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).



Expand Down
12 changes: 4 additions & 8 deletions README_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -702,21 +702,17 @@ Compiler Error at Library\PackageCache\[email protected]\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など)にコミットしてください。



Expand Down
57 changes: 40 additions & 17 deletions Runtime/Settings/AutopilotSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
}
}

Expand All @@ -290,10 +291,14 @@ 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;
#if UNITY_EDITOR
EditorUtility.SetDirty(this);
#endif
}

[Obsolete("Remove this method when bump major version")]
Expand All @@ -305,10 +310,11 @@ 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;
#if UNITY_EDITOR
EditorUtility.SetDirty(this);
#endif
Expand All @@ -324,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<SlackReporter>();
Expand All @@ -337,7 +343,12 @@ internal void ConvertSlackReporterFromObsoleteSlackSettings(ILogger logger)
convertedReporter.description = AutoConvertingMessage;
SaveConvertedObject(convertedReporter);
#endif

this.reporters.Add(convertedReporter);
this.slackToken = null;
this.slackChannels = null;
this.mentionSubTeamIDs = null;
this.addHereInSlackMessage = false;
#if UNITY_EDITOR
EditorUtility.SetDirty(this);
#endif
Expand All @@ -353,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<JUnitXmlReporter>();
Expand All @@ -363,15 +374,17 @@ internal void ConvertJUnitXmlReporterFromObsoleteJUnitReportPath(ILogger logger)
convertedReporter.description = AutoConvertingMessage;
SaveConvertedObject(convertedReporter);
#endif

this.Reporter.reporters.Add(convertedReporter);
this.junitReportPath = null;
#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))
{
Expand All @@ -380,8 +393,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)
Expand All @@ -392,10 +405,14 @@ 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;
#if UNITY_EDITOR
EditorUtility.SetDirty(this);
#endif
}

[Obsolete("Remove this method when bump major version")]
Expand All @@ -411,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<ErrorHandlerAgent>();
Expand All @@ -425,7 +442,13 @@ internal void ConvertErrorHandlerAgentFromObsoleteSettings(ILogger logger)
convertedAgent.description = AutoConvertingMessage;
SaveConvertedObject(convertedAgent);
#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
Expand Down
47 changes: 30 additions & 17 deletions Tests/Runtime/Settings/AutopilotSettingsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ 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.
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]
Expand Down Expand Up @@ -115,11 +116,12 @@ 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.
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]
Expand Down Expand Up @@ -159,15 +161,19 @@ 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.
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]
Expand Down Expand Up @@ -217,11 +223,12 @@ 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.
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]
Expand Down Expand Up @@ -259,12 +266,13 @@ 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.
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]
Expand Down Expand Up @@ -323,11 +331,16 @@ 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.
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]
Expand Down
Loading