/
DebugLogManager.cs
731 lines (601 loc) · 21.3 KB
/
DebugLogManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections.Generic;
using System.IO;
// Receives debug entries and custom events (e.g. Clear, Collapse, Filter by Type)
// and notifies the recycled list view of changes to the list of debug entries
//
// - Vocabulary -
// Debug/Log entry: a Debug.Log/LogError/LogWarning/LogException/LogAssertion request made by
// the client and intercepted by this manager object
// Debug/Log item: a visual (uGUI) representation of a debug entry
//
// There can be a lot of debug entries in the system but there will only be a handful of log items
// to show their properties on screen (these log items are recycled as the list is scrolled)
// An enum to represent filtered log types
namespace IngameDebugConsole
{
public enum DebugLogFilter
{
None = 0,
Info = 1,
Warning = 2,
Error = 4,
All = 7
}
public class DebugLogManager : MonoBehaviour
{
private static DebugLogManager instance = null;
// Debug console will persist between scenes
[Header( "Properties" )]
[SerializeField]
private bool singleton = true;
// Minimum height of the console window
[SerializeField]
private float minimumHeight = 200f;
// Should command input field be cleared after pressing Enter
[SerializeField]
private bool startInPopupMode = true;
[SerializeField]
private bool clearCommandAfterExecution = true;
[SerializeField]
private int commandHistorySize = 15;
[SerializeField]
private bool receiveLogcatLogsInAndroid = false;
[SerializeField]
private string logcatArguments;
[Header( "Visuals" )]
[SerializeField]
private DebugLogItem logItemPrefab;
// Visuals for different log types
[SerializeField]
private Sprite infoLog;
[SerializeField]
private Sprite warningLog;
[SerializeField]
private Sprite errorLog;
private Dictionary<LogType, Sprite> logSpriteRepresentations;
[SerializeField]
private Color collapseButtonNormalColor;
[SerializeField]
private Color collapseButtonSelectedColor;
[SerializeField]
private Color filterButtonsNormalColor;
[SerializeField]
private Color filterButtonsSelectedColor;
[Header( "Internal References" )]
[SerializeField]
private RectTransform logWindowTR;
private RectTransform canvasTR;
[SerializeField]
private RectTransform logItemsContainer;
[SerializeField]
private InputField commandInputField;
[SerializeField]
private Image collapseButton;
[SerializeField]
private Image filterInfoButton;
[SerializeField]
private Image filterWarningButton;
[SerializeField]
private Image filterErrorButton;
[SerializeField]
private Text infoEntryCountText;
[SerializeField]
private Text warningEntryCountText;
[SerializeField]
private Text errorEntryCountText;
[SerializeField]
private GameObject snapToBottomButton;
// Number of entries filtered by their types
private int infoEntryCount = 0, warningEntryCount = 0, errorEntryCount = 0;
// Canvas group to modify visibility of the log window
[SerializeField]
private CanvasGroup logWindowCanvasGroup;
private bool isLogWindowVisible = true;
private bool screenDimensionsChanged = false;
[SerializeField]
private DebugLogPopup popupManager;
[SerializeField]
private ScrollRect logItemsScrollRect;
// Recycled list view to handle the log items efficiently
[SerializeField]
private DebugLogRecycledListView recycledListView;
// Filters to apply to the list of debug entries to show
private bool isCollapseOn = false;
private DebugLogFilter logFilter = DebugLogFilter.All;
// If the last log item is completely visible (scrollbar is at the bottom),
// scrollbar will remain at the bottom when new debug entries are received
private bool snapToBottom = true;
// List of unique debug entries (duplicates of entries are not kept)
private List<DebugLogEntry> collapsedLogEntries;
// Dictionary to quickly find if a log already exists in collapsedLogEntries
private Dictionary<DebugLogEntry, int> collapsedLogEntriesMap;
// The order the collapsedLogEntries are received
// (duplicate entries have the same index (value))
private DebugLogIndexList uncollapsedLogEntriesIndices;
// Filtered list of debug entries to show
private DebugLogIndexList indicesOfListEntriesToShow;
private List<DebugLogItem> pooledLogItems;
// History of the previously entered commands
private CircularBuffer<string> commandHistory;
private int commandHistoryIndex = -1;
// Required in ValidateScrollPosition() function
private PointerEventData nullPointerEventData;
#if !UNITY_EDITOR && UNITY_ANDROID
private DebugLogLogcatListener logcatListener;
#endif
private void OnEnable()
{
// Only one instance of debug console is allowed
if( instance == null )
{
instance = this;
pooledLogItems = new List<DebugLogItem>();
commandHistory = new CircularBuffer<string>( commandHistorySize );
canvasTR = (RectTransform) transform;
// Associate sprites with log types
logSpriteRepresentations = new Dictionary<LogType, Sprite>
{
{ LogType.Log, infoLog },
{ LogType.Warning, warningLog },
{ LogType.Error, errorLog },
{ LogType.Exception, errorLog },
{ LogType.Assert, errorLog }
};
// Initially, all log types are visible
filterInfoButton.color = filterButtonsSelectedColor;
filterWarningButton.color = filterButtonsSelectedColor;
filterErrorButton.color = filterButtonsSelectedColor;
collapsedLogEntries = new List<DebugLogEntry>( 128 );
collapsedLogEntriesMap = new Dictionary<DebugLogEntry, int>( 128 );
uncollapsedLogEntriesIndices = new DebugLogIndexList();
indicesOfListEntriesToShow = new DebugLogIndexList();
recycledListView.Initialize( this, collapsedLogEntries, indicesOfListEntriesToShow, logItemPrefab.Transform.sizeDelta.y );
recycledListView.UpdateItemsInTheList( true );
nullPointerEventData = new PointerEventData( null );
// If it is a singleton object, don't destroy it between scene changes
if( singleton )
DontDestroyOnLoad( gameObject );
}
else if( this != instance )
{
Destroy( gameObject );
return;
}
// Intercept debug entries
Application.logMessageReceived -= ReceivedLog;
Application.logMessageReceived += ReceivedLog;
if( receiveLogcatLogsInAndroid )
{
#if !UNITY_EDITOR && UNITY_ANDROID
if( logcatListener == null )
logcatListener = new DebugLogLogcatListener();
logcatListener.Start( logcatArguments );
#endif
}
// Listen for entered commands
commandInputField.onValidateInput -= OnValidateCommand;
commandInputField.onValidateInput += OnValidateCommand;
if( minimumHeight < 200f )
minimumHeight = 200f;
DebugLogConsole.AddCommandInstance( "save_logs", "Saves logs to a file", "SaveLogsToFile", this );
//Debug.LogAssertion( "assert" );
//Debug.LogError( "error" );
//Debug.LogException( new System.IO.EndOfStreamException() );
//Debug.LogWarning( "warning" );
//Debug.Log( "log" );
}
private void OnDisable()
{
if( instance != this )
return;
// Stop receiving debug entries
Application.logMessageReceived -= ReceivedLog;
#if !UNITY_EDITOR && UNITY_ANDROID
if( logcatListener != null )
logcatListener.Stop();
#endif
// Stop receiving commands
commandInputField.onValidateInput -= OnValidateCommand;
DebugLogConsole.RemoveCommand( "save_logs" );
}
// Launch in popup mode
private void Start()
{
if( startInPopupMode )
HideButtonPressed();
else
popupManager.OnPointerClick( null );
}
// Window is resized, update the list
private void OnRectTransformDimensionsChange()
{
screenDimensionsChanged = true;
}
// If snapToBottom is enabled, force the scrollbar to the bottom
private void LateUpdate()
{
if( screenDimensionsChanged )
{
// Update the recycled list view
if( isLogWindowVisible )
recycledListView.OnViewportDimensionsChanged();
else
popupManager.OnViewportDimensionsChanged();
screenDimensionsChanged = false;
}
if( snapToBottom )
{
logItemsScrollRect.verticalNormalizedPosition = 0f;
if( snapToBottomButton.activeSelf )
snapToBottomButton.SetActive( false );
}
else
{
float scrollPos = logItemsScrollRect.verticalNormalizedPosition;
if( snapToBottomButton.activeSelf != ( scrollPos > 1E-6f && scrollPos < 0.9999f ) )
snapToBottomButton.SetActive( !snapToBottomButton.activeSelf );
}
if( isLogWindowVisible && commandInputField.isFocused )
{
if( Input.GetKeyDown( KeyCode.UpArrow ) )
{
if( commandHistoryIndex == -1 )
commandHistoryIndex = commandHistory.Count - 1;
else if( --commandHistoryIndex < 0 )
commandHistoryIndex = 0;
if( commandHistoryIndex >= 0 && commandHistoryIndex < commandHistory.Count )
{
commandInputField.text = commandHistory[commandHistoryIndex];
commandInputField.caretPosition = commandInputField.text.Length;
}
}
else if( Input.GetKeyDown( KeyCode.DownArrow ) )
{
if( commandHistoryIndex == -1 )
commandHistoryIndex = commandHistory.Count - 1;
else if( ++commandHistoryIndex >= commandHistory.Count )
commandHistoryIndex = commandHistory.Count - 1;
if( commandHistoryIndex >= 0 && commandHistoryIndex < commandHistory.Count )
commandInputField.text = commandHistory[commandHistoryIndex];
}
}
#if !UNITY_EDITOR && UNITY_ANDROID
if( logcatListener != null )
{
string log;
while( ( log = logcatListener.GetLog() ) != null )
ReceivedLog( "LOGCAT: " + log, string.Empty, LogType.Log );
}
#endif
}
// Command field input is changed, check if command is submitted
public char OnValidateCommand( string text, int charIndex, char addedChar )
{
if( addedChar == '\t' ) // Autocomplete attempt
{
if( !string.IsNullOrEmpty( text ) )
{
string autoCompletedCommand = DebugLogConsole.GetAutoCompleteCommand( text );
if( !string.IsNullOrEmpty( autoCompletedCommand ) )
commandInputField.text = autoCompletedCommand;
}
return '\0';
}
else if( addedChar == '\n' ) // Command is submitted
{
// Clear the command field
if( clearCommandAfterExecution )
commandInputField.text = "";
if( text.Length > 0 )
{
if( commandHistory.Count == 0 || commandHistory[commandHistory.Count - 1] != text )
commandHistory.Add( text );
commandHistoryIndex = -1;
// Execute the command
DebugLogConsole.ExecuteCommand( text );
// Snap to bottom and select the latest entry
SetSnapToBottom( true );
}
return '\0';
}
return addedChar;
}
// A debug entry is received
private void ReceivedLog( string logString, string stackTrace, LogType logType )
{
DebugLogEntry logEntry = new DebugLogEntry( logString, stackTrace, null );
// Check if this entry is a duplicate (i.e. has been received before)
int logEntryIndex;
bool isEntryInCollapsedEntryList = collapsedLogEntriesMap.TryGetValue( logEntry, out logEntryIndex );
if( !isEntryInCollapsedEntryList )
{
// It is not a duplicate,
// add it to the list of unique debug entries
logEntry.logTypeSpriteRepresentation = logSpriteRepresentations[logType];
logEntryIndex = collapsedLogEntries.Count;
collapsedLogEntries.Add( logEntry );
collapsedLogEntriesMap[logEntry] = logEntryIndex;
}
else
{
// It is a duplicate,
// increment the original debug item's collapsed count
logEntry = collapsedLogEntries[logEntryIndex];
logEntry.count++;
}
// Add the index of the unique debug entry to the list
// that stores the order the debug entries are received
uncollapsedLogEntriesIndices.Add( logEntryIndex );
// If this debug entry matches the current filters,
// add it to the list of debug entries to show
Sprite logTypeSpriteRepresentation = logEntry.logTypeSpriteRepresentation;
if( isCollapseOn && isEntryInCollapsedEntryList )
{
if( isLogWindowVisible )
recycledListView.OnCollapsedLogEntryAtIndexUpdated( logEntryIndex );
}
else if( logFilter == DebugLogFilter.All ||
( logTypeSpriteRepresentation == infoLog && ( ( logFilter & DebugLogFilter.Info ) == DebugLogFilter.Info ) ) ||
( logTypeSpriteRepresentation == warningLog && ( ( logFilter & DebugLogFilter.Warning ) == DebugLogFilter.Warning ) ) ||
( logTypeSpriteRepresentation == errorLog && ( ( logFilter & DebugLogFilter.Error ) == DebugLogFilter.Error ) ) )
{
indicesOfListEntriesToShow.Add( logEntryIndex );
if( isLogWindowVisible )
recycledListView.OnLogEntriesUpdated( false );
}
if( logType == LogType.Log )
{
infoEntryCount++;
infoEntryCountText.text = infoEntryCount.ToString();
// If debug popup is visible, notify it of the new debug entry
if( !isLogWindowVisible )
popupManager.NewInfoLogArrived();
}
else if( logType == LogType.Warning )
{
warningEntryCount++;
warningEntryCountText.text = warningEntryCount.ToString();
// If debug popup is visible, notify it of the new debug entry
if( !isLogWindowVisible )
popupManager.NewWarningLogArrived();
}
else
{
errorEntryCount++;
errorEntryCountText.text = errorEntryCount.ToString();
// If debug popup is visible, notify it of the new debug entry
if( !isLogWindowVisible )
popupManager.NewErrorLogArrived();
}
}
// Value of snapToBottom is changed (user scrolled the list manually)
public void SetSnapToBottom( bool snapToBottom )
{
this.snapToBottom = snapToBottom;
}
// Make sure the scroll bar of the scroll rect is adjusted properly
public void ValidateScrollPosition()
{
logItemsScrollRect.OnScroll( nullPointerEventData );
}
// Show the log window
public void Show()
{
// Update the recycled list view (in case new entries were
// intercepted while log window was hidden)
recycledListView.OnLogEntriesUpdated( true );
logWindowCanvasGroup.interactable = true;
logWindowCanvasGroup.blocksRaycasts = true;
logWindowCanvasGroup.alpha = 1f;
isLogWindowVisible = true;
}
// Hide the log window
public void Hide()
{
logWindowCanvasGroup.interactable = false;
logWindowCanvasGroup.blocksRaycasts = false;
logWindowCanvasGroup.alpha = 0f;
commandHistoryIndex = -1;
isLogWindowVisible = false;
}
// Hide button is clicked
public void HideButtonPressed()
{
Hide();
popupManager.Show();
}
// Clear button is clicked
public void ClearButtonPressed()
{
snapToBottom = true;
infoEntryCount = 0;
warningEntryCount = 0;
errorEntryCount = 0;
infoEntryCountText.text = "0";
warningEntryCountText.text = "0";
errorEntryCountText.text = "0";
collapsedLogEntries.Clear();
collapsedLogEntriesMap.Clear();
uncollapsedLogEntriesIndices.Clear();
indicesOfListEntriesToShow.Clear();
recycledListView.DeselectSelectedLogItem();
recycledListView.OnLogEntriesUpdated( true );
}
// Collapse button is clicked
public void CollapseButtonPressed()
{
// Swap the value of collapse mode
isCollapseOn = !isCollapseOn;
snapToBottom = true;
collapseButton.color = isCollapseOn ? collapseButtonSelectedColor : collapseButtonNormalColor;
recycledListView.SetCollapseMode( isCollapseOn );
// Determine the new list of debug entries to show
FilterLogs();
}
// Filtering mode of info logs has been changed
public void FilterLogButtonPressed()
{
logFilter = logFilter ^ DebugLogFilter.Info;
if( ( logFilter & DebugLogFilter.Info ) == DebugLogFilter.Info )
filterInfoButton.color = filterButtonsSelectedColor;
else
filterInfoButton.color = filterButtonsNormalColor;
FilterLogs();
}
// Filtering mode of warning logs has been changed
public void FilterWarningButtonPressed()
{
logFilter = logFilter ^ DebugLogFilter.Warning;
if( ( logFilter & DebugLogFilter.Warning ) == DebugLogFilter.Warning )
filterWarningButton.color = filterButtonsSelectedColor;
else
filterWarningButton.color = filterButtonsNormalColor;
FilterLogs();
}
// Filtering mode of error logs has been changed
public void FilterErrorButtonPressed()
{
logFilter = logFilter ^ DebugLogFilter.Error;
if( ( logFilter & DebugLogFilter.Error ) == DebugLogFilter.Error )
filterErrorButton.color = filterButtonsSelectedColor;
else
filterErrorButton.color = filterButtonsNormalColor;
FilterLogs();
}
// Debug window is being resized,
// Set the sizeDelta property of the window accordingly while
// preventing window dimensions from going below the minimum dimensions
public void Resize( BaseEventData dat )
{
PointerEventData eventData = (PointerEventData) dat;
// Grab the resize button from top; 36f is the height of the resize button
float newHeight = ( eventData.position.y - logWindowTR.position.y ) / -canvasTR.localScale.y + 36f;
if( newHeight < minimumHeight )
newHeight = minimumHeight;
Vector2 anchorMin = logWindowTR.anchorMin;
anchorMin.y = Mathf.Max( 0f, 1f - newHeight / canvasTR.sizeDelta.y );
logWindowTR.anchorMin = anchorMin;
// Update the recycled list view
recycledListView.OnViewportDimensionsChanged();
}
// Determine the filtered list of debug entries to show on screen
private void FilterLogs()
{
if( logFilter == DebugLogFilter.None )
{
// Show no entry
indicesOfListEntriesToShow.Clear();
}
else if( logFilter == DebugLogFilter.All )
{
if( isCollapseOn )
{
// All the unique debug entries will be listed just once.
// So, list of debug entries to show is the same as the
// order these unique debug entries are added to collapsedLogEntries
indicesOfListEntriesToShow.Clear();
for( int i = 0; i < collapsedLogEntries.Count; i++ )
indicesOfListEntriesToShow.Add( i );
}
else
{
indicesOfListEntriesToShow.Clear();
for( int i = 0; i < uncollapsedLogEntriesIndices.Count; i++ )
indicesOfListEntriesToShow.Add( uncollapsedLogEntriesIndices[i] );
}
}
else
{
// Show only the debug entries that match the current filter
bool isInfoEnabled = ( logFilter & DebugLogFilter.Info ) == DebugLogFilter.Info;
bool isWarningEnabled = ( logFilter & DebugLogFilter.Warning ) == DebugLogFilter.Warning;
bool isErrorEnabled = ( logFilter & DebugLogFilter.Error ) == DebugLogFilter.Error;
if( isCollapseOn )
{
indicesOfListEntriesToShow.Clear();
for( int i = 0; i < collapsedLogEntries.Count; i++ )
{
DebugLogEntry logEntry = collapsedLogEntries[i];
if( logEntry.logTypeSpriteRepresentation == infoLog && isInfoEnabled )
indicesOfListEntriesToShow.Add( i );
else if( logEntry.logTypeSpriteRepresentation == warningLog && isWarningEnabled )
indicesOfListEntriesToShow.Add( i );
else if( logEntry.logTypeSpriteRepresentation == errorLog && isErrorEnabled )
indicesOfListEntriesToShow.Add( i );
}
}
else
{
indicesOfListEntriesToShow.Clear();
for( int i = 0; i < uncollapsedLogEntriesIndices.Count; i++ )
{
DebugLogEntry logEntry = collapsedLogEntries[uncollapsedLogEntriesIndices[i]];
if( logEntry.logTypeSpriteRepresentation == infoLog && isInfoEnabled )
indicesOfListEntriesToShow.Add( uncollapsedLogEntriesIndices[i] );
else if( logEntry.logTypeSpriteRepresentation == warningLog && isWarningEnabled )
indicesOfListEntriesToShow.Add( uncollapsedLogEntriesIndices[i] );
else if( logEntry.logTypeSpriteRepresentation == errorLog && isErrorEnabled )
indicesOfListEntriesToShow.Add( uncollapsedLogEntriesIndices[i] );
}
}
}
// Update the recycled list view
recycledListView.DeselectSelectedLogItem();
recycledListView.OnLogEntriesUpdated( true );
ValidateScrollPosition();
}
public string GetAllLogs()
{
int count = uncollapsedLogEntriesIndices.Count;
int length = 0;
int newLineLength = System.Environment.NewLine.Length;
for( int i = 0; i < count; i++ )
{
DebugLogEntry entry = collapsedLogEntries[uncollapsedLogEntriesIndices[i]];
length += entry.logString.Length + entry.stackTrace.Length + newLineLength * 3;
}
length += 100; // Just in case...
System.Text.StringBuilder sb = new System.Text.StringBuilder( length );
for( int i = 0; i < count; i++ )
{
DebugLogEntry entry = collapsedLogEntries[uncollapsedLogEntriesIndices[i]];
sb.AppendLine( entry.logString ).AppendLine( entry.stackTrace ).AppendLine();
}
return sb.ToString();
}
private void SaveLogsToFile()
{
string path = Path.Combine( Application.persistentDataPath, System.DateTime.Now.ToString( "dd-MM-yyyy--HH-mm-ss" ) + ".txt" );
File.WriteAllText( path, instance.GetAllLogs() );
Debug.Log( "Logs saved to: " + path );
}
// Pool an unused log item
public void PoolLogItem( DebugLogItem logItem )
{
logItem.gameObject.SetActive( false );
pooledLogItems.Add( logItem );
}
// Fetch a log item from the pool
public DebugLogItem PopLogItem()
{
DebugLogItem newLogItem;
// If pool is not empty, fetch a log item from the pool,
// create a new log item otherwise
if( pooledLogItems.Count > 0 )
{
newLogItem = pooledLogItems[pooledLogItems.Count - 1];
pooledLogItems.RemoveAt( pooledLogItems.Count - 1 );
newLogItem.gameObject.SetActive( true );
}
else
{
newLogItem = (DebugLogItem) Instantiate( logItemPrefab, logItemsContainer, false );
newLogItem.Initialize( recycledListView );
}
return newLogItem;
}
}
}