Skip to content

Commit

Permalink
Merge pull request #78 from nowsprinting/chore/obsolete
Browse files Browse the repository at this point in the history
Hide obsolete setting fields on inspector
  • Loading branch information
asurato authored Oct 21, 2024
2 parents a021e22 + 8ab6fcd commit 88b6016
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 95 deletions.
90 changes: 50 additions & 40 deletions Editor/Localization/ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -103,46 +103,6 @@ msgstr "レポータ"
msgid "Reporter that called when some errors occurred in target application"
msgstr "対象のアプリケーションで発生したエラーを通知するレポータを指定します"

# obsolete slack settings
msgid "Slack settings will be moved to SlackReporter"
msgstr "Slack 設定は SlackReporter へ移動しました"

# slackToken
msgid "Slack Token"
msgstr "Slackトークン"

# slackToken tooltip
msgid "Slack API token"
msgstr "Slack通知に使用するWeb APIトークン(省略時は通知されない)"

# slackChannels
msgid "Slack Channels"
msgstr "Slackチャンネル"

# slackChannels tooltip
msgid "Slack channels to send notification"
msgstr "Slack通知を送るチャンネル(省略時は通知されない。現時点では1チャンネルのみ有効ですが、将来的にはカンマ区切りで複数指定対応予定)"

# Header: Slack Mention Settings
msgid "Slack Mention Settings"
msgstr "Slackメンション設定"

# mentionSubTeamIDs
msgid "Sub Team IDs to Mention"
msgstr "メンション宛先"

# mentionSubTeamIDs tooltip
msgid "Sub team IDs to mention (comma separates)"
msgstr "Slack通知メッセージでメンションするチームのIDをカンマ区切りで指定します"

# addHereInSlackMessage
msgid "Add @here Into Slack Message"
msgstr "@hereをメッセージにつける"

# addHereInSlackMessage tooltip
msgid "Whether adding @here into Slack messages or not"
msgstr "Slack通知メッセージに@hereを付けます"

# Header: Error Handling Settings
msgid "Error Handling Settings"
msgstr "エラーハンドリング設定"
Expand Down Expand Up @@ -489,3 +449,53 @@ msgstr "タイムスタンプを追加"
# Timestamp tooltip
msgid "Output timestamp to log entities"
msgstr "ログエンティティにタイムスタンプを出力します"


#: Editor/UI/Reporters/ 共通

# description
msgid "Description"
msgstr "説明"

# description tooltip
msgid "Description about this setting instance"
msgstr "このReporterインスタンスの説明"


#: Editor/UI/Reporters/SlackReporterEditor.cs

# slackToken
msgid "Slack Token"
msgstr "Slackトークン"

# slackToken tooltip
msgid "Slack API token"
msgstr "Slack通知に使用するWeb APIトークン(省略時は通知されない)"

# slackChannels
msgid "Slack Channels"
msgstr "Slackチャンネル"

# slackChannels tooltip
msgid "Slack channels to send notification"
msgstr "Slack通知を送るチャンネル(省略時は通知されない。現時点では1チャンネルのみ有効ですが、将来的にはカンマ区切りで複数指定対応予定)"

# Header: Slack Mention Settings
msgid "Slack Mention Settings"
msgstr "Slackメンション設定"

# mentionSubTeamIDs
msgid "Sub Team IDs to Mention"
msgstr "メンション宛先"

# mentionSubTeamIDs tooltip
msgid "Sub team IDs to mention (comma separates)"
msgstr "Slack通知メッセージでメンションするチームのIDをカンマ区切りで指定します"

# addHereInSlackMessage
msgid "Add @here Into Slack Message"
msgstr "@hereをメッセージにつける"

# addHereInSlackMessage tooltip
msgid "Whether adding @here into Slack messages or not"
msgstr "Slack通知メッセージに@hereを付けます"
13 changes: 11 additions & 2 deletions Editor/UI/Reporters/CompositeReporterEditor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023 DeNA Co., Ltd.
// Copyright (c) 2023-2024 DeNA Co., Ltd.
// This software is released under the MIT License.

using DeNA.Anjin.Reporters;
Expand All @@ -14,6 +14,11 @@ namespace DeNA.Anjin.Editor.UI.Reporters
[CustomEditor(typeof(CompositeReporter))]
public class CompositeReporterEditor : UnityEditor.Editor
{
private static readonly string s_description = L10n.Tr("Description");
private static readonly string s_descriptionTooltip = L10n.Tr("Description about this logger instance");
private SerializedProperty _descriptionProp;
private GUIContent _descriptionGUIContent;

private SerializedProperty _reportersProp;
private ReorderableList _reorderableList;
private static readonly string s_reporters = L10n.Tr("Reporters");
Expand All @@ -30,6 +35,9 @@ private void OnEnable()

private void Initialize()
{
_descriptionProp = serializedObject.FindProperty(nameof(SlackReporter.description));
_descriptionGUIContent = new GUIContent(s_description, s_descriptionTooltip);

_reportersProp = serializedObject.FindProperty(nameof(CompositeReporter.reporters));
_reportersGUIContent = new GUIContent(s_reporters);
_reporterGUIContent = new GUIContent(s_reporter);
Expand All @@ -52,7 +60,8 @@ private void Initialize()
public override void OnInspectorGUI()
{
serializedObject.Update();


EditorGUILayout.PropertyField(_descriptionProp, _descriptionGUIContent);
_reorderableList.DoLayoutList();

serializedObject.ApplyModifiedProperties();
Expand Down
13 changes: 12 additions & 1 deletion Editor/UI/Reporters/SlackReporterEditor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023 DeNA Co., Ltd.
// Copyright (c) 2023-2024 DeNA Co., Ltd.
// This software is released under the MIT License.

using DeNA.Anjin.Reporters;
Expand All @@ -16,6 +16,11 @@ public class SlackReporterEditor : UnityEditor.Editor
private const float SpacerPixels = 10f;
private const float SpacerPixelsUnderHeader = 4f;

private static readonly string s_description = L10n.Tr("Description");
private static readonly string s_descriptionTooltip = L10n.Tr("Description about this logger instance");
private SerializedProperty _descriptionProp;
private GUIContent _descriptionGUIContent;

private static readonly string s_slackToken = L10n.Tr("Slack Token");
private static readonly string s_slackTokenTooltip = L10n.Tr("Slack API token");
private SerializedProperty _slackTokenProp;
Expand Down Expand Up @@ -47,6 +52,9 @@ private void OnEnable()

private void Initialize()
{
_descriptionProp = serializedObject.FindProperty(nameof(SlackReporter.description));
_descriptionGUIContent = new GUIContent(s_description, s_descriptionTooltip);

_slackTokenProp = serializedObject.FindProperty(nameof(SlackReporter.slackToken));
_slackTokenGUIContent = new GUIContent(s_slackToken, s_slackTokenTooltip);

Expand All @@ -65,6 +73,9 @@ public override void OnInspectorGUI()
{
serializedObject.Update();

EditorGUILayout.PropertyField(_descriptionProp, _descriptionGUIContent);
GUILayout.Space(SpacerPixels);

EditorGUILayout.PropertyField(_slackTokenProp, _slackTokenGUIContent);
EditorGUILayout.PropertyField(_slackChannelsProp, _slackChannelsGUIContent);

Expand Down
28 changes: 1 addition & 27 deletions Editor/UI/Settings/AutopilotSettingsEditor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023 DeNA Co., Ltd.
// Copyright (c) 2023-2024 DeNA Co., Ltd.
// This software is released under the MIT License.

using System.Diagnostics.CodeAnalysis;
Expand Down Expand Up @@ -49,17 +49,6 @@ public class AutopilotSettingsEditor : UnityEditor.Editor
private static readonly string s_reporter = L10n.Tr("Reporter");
private static readonly string s_reporterTooltip = L10n.Tr("Reporter that called when some errors occurred in target application");

private static readonly string s_slackToken = L10n.Tr("Slack Token");
private static readonly string s_slackTokenTooltip = L10n.Tr("Slack API token");
private static readonly string s_slackChannels = L10n.Tr("Slack Channels");
private static readonly string s_slackChannelsTooltip = L10n.Tr("Slack channels to send notification");

private static readonly string s_slackMentionSettingsHeader = L10n.Tr("Slack Mention Settings");
private static readonly string s_mentionSubTeamIDs = L10n.Tr("Sub Team IDs to Mention");
private static readonly string s_mentionSubTeamIDsTooltip = L10n.Tr("Sub team IDs to mention (comma separates)");
private static readonly string s_addHereInSlackMessage = L10n.Tr("Add @here Into Slack Message");
private static readonly string s_addHereInSlackMessageTooltip = L10n.Tr("Whether adding @here into Slack messages or not");

private static readonly string s_errorHandlingSettingsHeader = L10n.Tr("Error Handling Settings");
private static readonly string s_handleException = L10n.Tr("Handle Exception");
private static readonly string s_handleExceptionTooltip = L10n.Tr("Notify when Exception detected in log");
Expand All @@ -71,9 +60,6 @@ public class AutopilotSettingsEditor : UnityEditor.Editor
private static readonly string s_handleWarningTooltip = L10n.Tr("Notify when Warning detected in log");
private static readonly string s_ignoreMessages = L10n.Tr("Ignore Messages");

private static readonly string s_obsoletedSlackParamsHelpBox =
L10n.Tr("Slack settings will be moved to SlackReporter");

private static readonly string s_ignoreMessagesTooltip =
L10n.Tr("Do not send notifications when log messages contain this string");

Expand Down Expand Up @@ -119,18 +105,6 @@ public override void OnInspectorGUI()
new GUIContent(s_logger, s_loggerTooltip));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AutopilotSettings.reporter)),
new GUIContent(s_reporter, s_reporterTooltip));
EditorGUILayout.HelpBox(s_obsoletedSlackParamsHelpBox, MessageType.Warning);
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AutopilotSettings.slackToken)),
new GUIContent(s_slackToken, s_slackTokenTooltip));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AutopilotSettings.slackChannels)),
new GUIContent(s_slackChannels, s_slackChannelsTooltip));

DrawHeader(s_slackMentionSettingsHeader);
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AutopilotSettings.mentionSubTeamIDs)),
new GUIContent(s_mentionSubTeamIDs, s_mentionSubTeamIDsTooltip));
EditorGUILayout.PropertyField(
serializedObject.FindProperty(nameof(AutopilotSettings.addHereInSlackMessage)),
new GUIContent(s_addHereInSlackMessage, s_addHereInSlackMessageTooltip));

DrawHeader(s_errorHandlingSettingsHeader);
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AutopilotSettings.handleException)),
Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ Therefore, please be careful to record in units of Scenes.

A screenshot of the operation by Automated QA is stored under `Application.persistentDataPath/Anjin`.
The `Application.persistentDataPath` for each platform can be found in the Unity manual at
[Application.persistentDataPath](https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html).
[Scripting API: Application.persistentDataPath](https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html).


### DoNothingAgent
Expand Down Expand Up @@ -541,7 +541,7 @@ Open it in the inspector and click the **Reset** button.
If this does not solve the problem, try deleting `AutopilotState.asset`.


### [CompilerError] Argument 1: Cannot convert to 'System.Threading.CancellationToken'
### \[CompilerError\] Argument 1: Cannot convert to 'System.Threading.CancellationToken'

The following compilation error has been reported in some cases:

Expand All @@ -560,6 +560,22 @@ 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 obsoleted" when running autopilot

For example, the following warning message may be output log.

```
Slack settings in AutopilotSettings has been obsoleted.
Please delete the value using Debug Mode in the Inspector window. And create a SlackReporter asset file.
```

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)



## License

Expand Down
21 changes: 19 additions & 2 deletions README_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ Automated QAによる操作のレコーディングは、Unityエディターの

また、Automated QAによる操作のスクリーンショットを`Application.persistentDataPath/Anjin`下に保存しています。
各プラットフォームの`Application.persistentDataPath`はUnityマニュアルの
[Application.persistentDataPath](https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html)
[Scripting API: Application.persistentDataPath](https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html)
を参照してください。


Expand Down Expand Up @@ -544,7 +544,7 @@ Anjinの実行状態を永続化している `AutopilotState.asset` が不正な
それでも解決しない場合、 `AutopilotState.asset` を削除してみてください。


### [CompilerError] Argument 1: Cannot convert to 'System.Threading.CancellationToken'
### \[CompilerError\] Argument 1: Cannot convert to 'System.Threading.CancellationToken'

次のコンパイルエラーが発生するケースが報告されています。

Expand All @@ -562,6 +562,23 @@ Compiler Error at Library\PackageCache\[email protected]\Runtime\Reporters\Sl
Unityエディターが生成するPackages/packages-lock.jsonの中身を確認するか、お使いのIDEのコード定義ジャンプ機能で `UniTask.WaitForEndOfFrame()` のソースファイルがどこにあるかを確認するなどして、古いUniTaskがインストールされている原因を突き止められます。


### 実行中に "settings has been obsoleted" 警告が出る

たとえば次のような警告メッセージが出力されることがあります。

```
Slack settings in AutopilotSettings has been obsoleted.
Please delete the value using Debug Mode in the Inspector window. And create a SlackReporter asset file.
```

すでに新しい設定方法(上例では `SlackReporter` )に移行済みであっても、廃止されたフィールドに値が残っていることを警告されています。
設定ファイルをInspectorウィンドウで開き、**Debug Mode** に切り替えることで廃止されたフィールドを編集できます。

Inspectorウィンドウの操作については、Unityマニュアルの
[Inspector の使用 - Unity マニュアル](https://docs.unity3d.com/ja/current/Manual/InspectorOptions.html)
を参照してください。



## ライセンス

Expand Down
25 changes: 25 additions & 0 deletions Runtime/Autopilot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading;
using Cysharp.Threading.Tasks;
using DeNA.Anjin.Loggers;
using DeNA.Anjin.Reporters;
using DeNA.Anjin.Settings;
using DeNA.Anjin.Utilities;
using UnityEngine;
Expand Down Expand Up @@ -37,6 +38,8 @@ private void Start()
_loggerAsset = _settings.loggerAsset;
_logger = _loggerAsset != null ? _loggerAsset.Logger : CreateDefaultLogger();

ConvertSlackReporterFromObsoleteSlackSettings(_settings, _logger);

if (!int.TryParse(_settings.randomSeed, out var seed))
{
seed = Environment.TickCount;
Expand Down Expand Up @@ -77,6 +80,28 @@ private static ILogger CreateDefaultLogger()
return Debug.unityLogger;
}

[Obsolete("Remove this method when bump major version")]
internal static void ConvertSlackReporterFromObsoleteSlackSettings(AutopilotSettings settings, ILogger logger)
{
if (string.IsNullOrEmpty(settings.slackToken) || string.IsNullOrEmpty(settings.slackChannels) ||
settings.reporter != null)
// TODO: This condition will change when the AutopilotSettings.reporter is changed to a List<AbstractReporter>.
{
return;
}

logger.Log(LogType.Warning, @"Slack settings in AutopilotSettings has been obsoleted.
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.");

var reporter = ScriptableObject.CreateInstance<SlackReporter>();
reporter.slackToken = settings.slackToken;
reporter.slackChannels = settings.slackChannels;
reporter.mentionSubTeamIDs = settings.mentionSubTeamIDs;
reporter.addHereInSlackMessage = settings.addHereInSlackMessage;
settings.reporter = reporter;
}

/// <summary>
/// Terminate when ran specified time.
/// </summary>
Expand Down
9 changes: 8 additions & 1 deletion Runtime/Reporters/AbstractReporter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023 DeNA Co., Ltd.
// Copyright (c) 2023-2024 DeNA Co., Ltd.
// This software is released under the MIT License.

using System.Threading;
Expand All @@ -12,6 +12,13 @@ namespace DeNA.Anjin.Reporters
/// </summary>
public abstract class AbstractReporter : ScriptableObject
{
#if UNITY_EDITOR
/// <summary>
/// Description about this agent instance.
/// </summary>
[Multiline] public string description;
#endif

/// <summary>
/// Post report log message, stacktrace and screenshot
/// </summary>
Expand Down
10 changes: 0 additions & 10 deletions Runtime/Settings/AutopilotSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,6 @@ public void OverrideByCommandLineArguments(Arguments args)
{
handleWarning = args.HandleWarning.Value();
}

if (args.SlackToken.IsCaptured())
{
slackToken = args.SlackToken.Value();
}

if (args.SlackChannels.IsCaptured())
{
slackChannels = args.SlackChannels.Value();
}
}
}
}
Loading

0 comments on commit 88b6016

Please sign in to comment.