Skip to content

Commit

Permalink
The embedded EventSystem is activated only when needed to avoid dupli…
Browse files Browse the repository at this point in the history
…cate EventSystem warnings in the Console
  • Loading branch information
yasirkula committed Jul 25, 2022
1 parent fdcb28a commit d0bb5ed
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 3 deletions.
24 changes: 22 additions & 2 deletions Plugins/IngameDebugConsole/IngameDebugConsole.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!1 &110786
GameObject:
m_ObjectHideFlags: 1
Expand Down Expand Up @@ -135,6 +135,7 @@ GameObject:
- component: {fileID: 11440770}
- component: {fileID: 11490438}
- component: {fileID: 11452418}
- component: {fileID: 114573443145823088}
m_Layer: 5
m_Name: IngameDebugConsole
m_TagString: Untagged
Expand Down Expand Up @@ -1266,6 +1267,14 @@ MonoBehaviour:
toggleKey: 96
enableSearchbar: 1
topSearchbarMinWidth: 360
receiveLogsWhileInactive: 0
receiveInfoLogs: 1
receiveWarningLogs: 1
receiveErrorLogs: 1
receiveExceptionLogs: 1
captureLogTimestamps: 0
alwaysDisplayTimestamps: 0
queuedLogLimit: 256
clearCommandAfterExecution: 1
commandHistorySize: 15
showCommandSuggestions: 1
Expand Down Expand Up @@ -1325,7 +1334,6 @@ MonoBehaviour:
m_EditorClassIdentifier:
transformComponent: {fileID: 22400762}
viewportTransform: {fileID: 22485076}
debugManager: {fileID: 11452418}
logItemNormalColor1: {r: 0.23529412, g: 0.23529412, b: 0.23529412, a: 0.697}
logItemNormalColor2: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 0.697}
logItemSelectedColor: {r: 0.32941177, g: 0.4862745, b: 0.7058824, a: 0.697}
Expand Down Expand Up @@ -3258,6 +3266,18 @@ MonoBehaviour:
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
--- !u!114 &114573443145823088
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 132536}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c3cc1b407f337e641ad32a2e91d5b478, type: 3}
m_Name:
m_EditorClassIdentifier:
embeddedEventSystem: {fileID: 109254}
--- !u!114 &114575087663981696
MonoBehaviour:
m_ObjectHideFlags: 1
Expand Down
57 changes: 57 additions & 0 deletions Plugins/IngameDebugConsole/Scripts/EventSystemHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;

namespace IngameDebugConsole
{
// Avoid multiple EventSystems in the scene by activating the embedded EventSystem only if one doesn't already exist in the scene
[DefaultExecutionOrder( 1000 )]
public class EventSystemHandler : MonoBehaviour
{
#pragma warning disable 0649
[SerializeField]
private GameObject embeddedEventSystem;
#pragma warning restore 0649

private void OnEnable()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
SceneManager.sceneLoaded += OnSceneLoaded;
SceneManager.sceneUnloaded -= OnSceneUnloaded;
SceneManager.sceneUnloaded += OnSceneUnloaded;

ActivateEventSystemIfNeeded();
}

private void OnDisable()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
SceneManager.sceneUnloaded -= OnSceneUnloaded;

DeactivateEventSystem();
}

private void OnSceneLoaded( Scene scene, LoadSceneMode mode )
{
ActivateEventSystemIfNeeded();
}

private void OnSceneUnloaded( Scene current )
{
// Deactivate the embedded EventSystem before changing scenes because the new scene might have its own EventSystem
DeactivateEventSystem();
}

private void ActivateEventSystemIfNeeded()
{
if( embeddedEventSystem && !EventSystem.current )
embeddedEventSystem.SetActive( true );
}

private void DeactivateEventSystem()
{
if( embeddedEventSystem )
embeddedEventSystem.SetActive( false );
}
}
}
12 changes: 12 additions & 0 deletions Plugins/IngameDebugConsole/Scripts/EventSystemHandler.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.yasirkula.ingamedebugconsole",
"displayName": "In-game Debug Console",
"version": "1.5.6",
"version": "1.5.7",
"documentationUrl": "https://github.com/yasirkula/UnityIngameDebugConsole",
"changelogUrl": "https://github.com/yasirkula/UnityIngameDebugConsole/releases",
"licensesUrl": "https://github.com/yasirkula/UnityIngameDebugConsole/blob/master/LICENSE.txt",
Expand Down

0 comments on commit d0bb5ed

Please sign in to comment.