console subscribes to log event before any other script executes

This commit is contained in:
in0finite 2021-03-01 02:53:03 +01:00
parent 04153d6cc0
commit 2c4521200d
4 changed files with 58 additions and 6 deletions

View file

@ -518,6 +518,7 @@ GameObject:
- component: {fileID: 114473132252556806}
- component: {fileID: 821925318372548346}
- component: {fileID: 5292052593724244546}
- component: {fileID: 4052078131376788595}
m_Layer: 0
m_Name: UI
m_TagString: UI
@ -591,6 +592,18 @@ MonoBehaviour:
m_changeFontSizeInEditor: 0
m_scrollbarSizeMultiplierOnMobile: 2
m_changeScrollbarSizeInEditor: 0
--- !u!114 &4052078131376788595
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1611271869868126}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d95990750fbd4b9478e6b04bb976af8b, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1627404700688260
GameObject:
m_ObjectHideFlags: 0

View file

@ -69,6 +69,24 @@ namespace SanAndreasUnity.UI
this.useScrollView = false;
}
internal static void OnEventSubscriberAwake()
{
var console = FindObjectOfType<Console>();
if (null == console)
{
Debug.LogError("Failed to find console object");
return;
}
console.OnEventSubscriberAwakeNonStatic();
}
void OnEventSubscriberAwakeNonStatic()
{
Application.logMessageReceivedThreaded += HandleLogThreaded;
}
#region MonoBehaviour Messages
@ -78,12 +96,6 @@ namespace SanAndreasUnity.UI
base.OnDisable();
}
protected override void OnEnable()
{
base.OnEnable();
Application.logMessageReceivedThreaded += HandleLogThreaded;
}
void Start ()
{

View file

@ -0,0 +1,16 @@
using UnityEngine;
namespace SanAndreasUnity.UI
{
/// <summary>
/// This script should have lowest possible script execution order so that the <see cref="Console"/> is subscribed to
/// log events before any other script executes.
/// </summary>
public class ConsoleLogEventSubscriber : MonoBehaviour
{
void Awake()
{
Console.OnEventSubscriberAwake();
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d95990750fbd4b9478e6b04bb976af8b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: -32000
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: