-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from DeNA/custom-reporters
Introduce customizable reporters
- Loading branch information
Showing
27 changed files
with
785 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) 2023 DeNA Co., Ltd. | ||
// This software is released under the MIT License. | ||
|
||
using DeNA.Anjin.Reporters; | ||
using UnityEditor; | ||
using UnityEditorInternal; | ||
using UnityEngine; | ||
|
||
namespace DeNA.Anjin.Editor.UI.Reporters | ||
{ | ||
/// <summary> | ||
/// Editor for <c cref="CompositeReporter" /> | ||
/// </summary> | ||
[CustomEditor(typeof(CompositeReporter))] | ||
public class CompositeReporterEditor : UnityEditor.Editor | ||
{ | ||
private SerializedProperty _reportersProp; | ||
private ReorderableList _reorderableList; | ||
private static readonly string s_reporters = L10n.Tr("Reporters"); | ||
private GUIContent _reportersGUIContent; | ||
private static readonly string s_reporter = L10n.Tr("Reporter"); | ||
private GUIContent _reporterGUIContent; | ||
|
||
|
||
private void OnEnable() | ||
{ | ||
Initialize(); | ||
} | ||
|
||
|
||
private void Initialize() | ||
{ | ||
_reportersProp = serializedObject.FindProperty(nameof(CompositeReporter.reporters)); | ||
_reportersGUIContent = new GUIContent(s_reporters); | ||
_reporterGUIContent = new GUIContent(s_reporter); | ||
_reorderableList = new ReorderableList(serializedObject, _reportersProp) | ||
{ | ||
drawHeaderCallback = rect => EditorGUI.LabelField(rect, _reportersGUIContent), | ||
elementHeightCallback = _ => EditorGUIUtility.singleLineHeight, | ||
// XXX: Dont use discarded parameter to treat Unity 2019.x | ||
// ReSharper disable UnusedParameter.Local | ||
drawElementCallback = (rect, index, active, focused) => | ||
// ReSharper restore UnusedParameter.Local | ||
{ | ||
var elemProp = _reportersProp.GetArrayElementAtIndex(index); | ||
EditorGUI.PropertyField(rect, elemProp, _reporterGUIContent); | ||
} | ||
}; | ||
} | ||
|
||
|
||
public override void OnInspectorGUI() | ||
{ | ||
serializedObject.Update(); | ||
|
||
_reorderableList.DoLayoutList(); | ||
|
||
serializedObject.ApplyModifiedProperties(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright (c) 2023 DeNA Co., Ltd. | ||
// This software is released under the MIT License. | ||
|
||
using DeNA.Anjin.Reporters; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace DeNA.Anjin.Editor.UI.Reporters | ||
{ | ||
/// <summary> | ||
/// Editor for <c cref="SlackReporter" /> | ||
/// </summary> | ||
[CustomEditor(typeof(SlackReporter))] | ||
public class SlackReporterEditor : UnityEditor.Editor | ||
{ | ||
private const float SpacerPixels = 10f; | ||
private const float SpacerPixelsUnderHeader = 4f; | ||
|
||
private static readonly string s_slackToken = L10n.Tr("Slack Token"); | ||
private static readonly string s_slackTokenTooltip = L10n.Tr("Slack API token"); | ||
private SerializedProperty _slackTokenProp; | ||
private GUIContent _slackTokenGUIContent; | ||
|
||
private static readonly string s_slackChannels = L10n.Tr("Slack Channels"); | ||
private static readonly string s_slackChannelsTooltip = L10n.Tr("Slack channels to send notification"); | ||
private SerializedProperty _slackChannelsProp; | ||
private GUIContent _slackChannelsGUIContent; | ||
|
||
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 SerializedProperty _mentionSubTeamIDsProp; | ||
private GUIContent _mentionSubTeamIDsGUIContent; | ||
|
||
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 SerializedProperty _addHereInSlackMessageProp; | ||
private GUIContent _addHereInSlackMessageGUIContent; | ||
|
||
|
||
private void OnEnable() | ||
{ | ||
Initialize(); | ||
} | ||
|
||
|
||
private void Initialize() | ||
{ | ||
_slackTokenProp = serializedObject.FindProperty(nameof(SlackReporter.slackToken)); | ||
_slackTokenGUIContent = new GUIContent(s_slackToken, s_slackTokenTooltip); | ||
|
||
_slackChannelsProp = serializedObject.FindProperty(nameof(SlackReporter.slackChannels)); | ||
_slackChannelsGUIContent = new GUIContent(s_slackChannels, s_slackChannelsTooltip); | ||
|
||
_mentionSubTeamIDsProp = serializedObject.FindProperty(nameof(SlackReporter.mentionSubTeamIDs)); | ||
_mentionSubTeamIDsGUIContent = new GUIContent(s_mentionSubTeamIDs, s_mentionSubTeamIDsTooltip); | ||
|
||
_addHereInSlackMessageProp = serializedObject.FindProperty(nameof(SlackReporter.addHereInSlackMessage)); | ||
_addHereInSlackMessageGUIContent = new GUIContent(s_addHereInSlackMessage, s_addHereInSlackMessageTooltip); | ||
} | ||
|
||
|
||
public override void OnInspectorGUI() | ||
{ | ||
serializedObject.Update(); | ||
|
||
EditorGUILayout.PropertyField(_slackTokenProp, _slackTokenGUIContent); | ||
EditorGUILayout.PropertyField(_slackChannelsProp, _slackChannelsGUIContent); | ||
|
||
GUILayout.Space(SpacerPixels); | ||
GUILayout.Label(s_slackMentionSettingsHeader); | ||
GUILayout.Space(SpacerPixelsUnderHeader); | ||
|
||
EditorGUILayout.PropertyField(_mentionSubTeamIDsProp, _mentionSubTeamIDsGUIContent); | ||
EditorGUILayout.PropertyField(_addHereInSlackMessageProp, _addHereInSlackMessageGUIContent); | ||
|
||
serializedObject.ApplyModifiedProperties(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 14 additions & 3 deletions
17
Runtime/Reporters/IReporter.cs → Runtime/Reporters/AbstractReporter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,35 @@ | ||
// Copyright (c) 2023 DeNA Co., Ltd. | ||
// This software is released under the MIT License. | ||
|
||
using System.Threading; | ||
using Cysharp.Threading.Tasks; | ||
using DeNA.Anjin.Settings; | ||
using UnityEngine; | ||
|
||
namespace DeNA.Anjin.Reporters | ||
{ | ||
/// <summary> | ||
/// Reporter interface | ||
/// Reporter base class | ||
/// </summary> | ||
public interface IReporter | ||
public abstract class AbstractReporter : ScriptableObject | ||
{ | ||
/// <summary> | ||
/// Post report log message, stacktrace and screenshot | ||
/// </summary> | ||
/// <param name="settings">Autopilot settings</param> | ||
/// <param name="logString">Log message</param> | ||
/// <param name="stackTrace">Stack trace</param> | ||
/// <param name="type">Log message type</param> | ||
/// <param name="withScreenshot">With screenshot</param> | ||
/// <param name="cancellationToken">Cancellation token</param> | ||
/// <returns></returns> | ||
UniTask PostReportAsync(string logString, string stackTrace, LogType type, bool withScreenshot); | ||
public abstract UniTask PostReportAsync( | ||
AutopilotSettings settings, | ||
string logString, | ||
string stackTrace, | ||
LogType type, | ||
bool withScreenshot, | ||
CancellationToken cancellationToken = default | ||
); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) 2023 DeNA Co., Ltd. | ||
// This software is released under the MIT License. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using Cysharp.Threading.Tasks; | ||
using DeNA.Anjin.Settings; | ||
using UnityEngine; | ||
|
||
namespace DeNA.Anjin.Reporters | ||
{ | ||
/// <summary> | ||
/// A class for reporters that delegate to multiple reporters | ||
/// </summary> | ||
[CreateAssetMenu(fileName = "New CompositeReporter", menuName = "Anjin/Composite Reporter", order = 51)] | ||
public class CompositeReporter : AbstractReporter | ||
{ | ||
/// <summary> | ||
/// Reporters to delegate | ||
/// </summary> | ||
public List<AbstractReporter> reporters = new List<AbstractReporter>(); | ||
|
||
|
||
/// <inheritdoc /> | ||
public override async UniTask PostReportAsync( | ||
AutopilotSettings settings, | ||
string logString, | ||
string stackTrace, | ||
LogType type, | ||
bool withScreenshot, | ||
CancellationToken cancellationToken = default | ||
) | ||
{ | ||
await UniTask.WhenAll( | ||
reporters | ||
.Where(r => r != this && r != null) | ||
.Select( | ||
r => r.PostReportAsync(settings, logString, stackTrace, type, withScreenshot, cancellationToken) | ||
) | ||
); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.