Skip to content

Commit 7714289

Browse files
committed
fix crash report
1 parent c563d39 commit 7714289

File tree

1 file changed

+40
-16
lines changed

1 file changed

+40
-16
lines changed

app/Assets/UniDebugMenu/Example/Scripts/iOSCrashReportListCreator.cs

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using UnityEngine;
5+
using UnityEngine.Diagnostics;
56

67
namespace UniDebugMenu.Example
78
{
@@ -11,6 +12,33 @@ namespace UniDebugMenu.Example
1112
[Serializable]
1213
public sealed class iOSCrashReportListCreator : ListCreatorBase<ActionData>
1314
{
15+
//==============================================================================
16+
// 定数(static readonly)
17+
//==============================================================================
18+
private static readonly string NL = Environment.NewLine;
19+
private static readonly string TIME_FORMAT = "yyyy/MM/dd HH:mm:ss";
20+
21+
//==============================================================================
22+
// クラス
23+
//==============================================================================
24+
private sealed class CrashData
25+
{
26+
public readonly string m_time;
27+
public readonly string m_summary;
28+
public readonly string m_text;
29+
public readonly string m_listText;
30+
public readonly string m_detailText;
31+
32+
public CrashData( CrashReport report )
33+
{
34+
m_time = report.time.ToString( TIME_FORMAT );
35+
m_summary = report.text.Split( new [] { NL }, StringSplitOptions.None ).FirstOrDefault();
36+
m_text = report.text;
37+
m_listText = $"{m_time}: {m_summary}";
38+
m_detailText = $"{m_time}{NL}{NL}{NL}{m_text}";
39+
}
40+
}
41+
1442
//==============================================================================
1543
// 変数
1644
//==============================================================================
@@ -21,6 +49,12 @@ public sealed class iOSCrashReportListCreator : ListCreatorBase<ActionData>
2149
//==============================================================================
2250
public override int Count => m_list.Count;
2351

52+
public override ActionData[] OptionActionList => new[]
53+
{
54+
new ActionData( "テスト", () => Utils.ForceCrash( ForcedCrashCategory.AccessViolation ) ),
55+
new ActionData( "削除", () => { CrashReport.RemoveAll(); UpdateDisp(); } ),
56+
};
57+
2458
//==============================================================================
2559
// 関数
2660
//==============================================================================
@@ -29,10 +63,12 @@ public sealed class iOSCrashReportListCreator : ListCreatorBase<ActionData>
2963
/// </summary>
3064
protected override void DoCreate( ListCreateData data )
3165
{
32-
m_list = ToText()
33-
.Split( '\n' )
34-
.Where( c => data.IsMatch( c ) )
35-
.Select( c => new ActionData( c ) )
66+
m_list = CrashReport.reports
67+
.Take( CrashReport.reports.Length - 1 ) // 末尾のレポートが重複していたので無視
68+
.OrderByDescending( c => c.time )
69+
.Select( c => new CrashData( c ) )
70+
.Where( c => data.IsMatch( c.m_time, c.m_summary ) )
71+
.Select( c => new ActionData( c.m_listText, () => OpenAdd( DMType.TEXT_TAB_6, new SimpleTextListDataCreator( c.m_detailText ) ) ) )
3672
.ToArray()
3773
.ReverseIf( data.IsReverse )
3874
;
@@ -42,17 +78,5 @@ protected override void DoCreate( ListCreateData data )
4278
/// 指定されたインデックスの要素の表示に使用するデータを返します
4379
/// </summary>
4480
protected override ActionData DoGetElemData( int index ) => m_list.ElementAtOrDefault( index );
45-
46-
/// <summary>
47-
/// テキストを整形して返します
48-
/// </summary>
49-
private static string ToText()
50-
{
51-
var reports = CrashReport.reports;
52-
var texts = reports.Select( c => $"{c.time.ToString()}: {c.text}" );
53-
var result = string.Join( "\n", texts );
54-
55-
return result;
56-
}
5781
}
5882
}

0 commit comments

Comments
 (0)