Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Tayx94/graphy
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Pane committed Apr 24, 2019
2 parents 59091cb + f5ccc16 commit cc8b658
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,15 @@ private void Update()
else if( m_audioListener == null
&& m_findAudioListenerInCameraIfNull == GraphyManager.LookForAudioListener.ALWAYS)
{
FindAudioListener();
m_audioListener = FindAudioListener();
}
}

private void OnDestroy()
{
UnityEngine.SceneManagement.SceneManager.sceneLoaded -= OnSceneLoaded;
}

#endregion

#region Methods -> Public
Expand All @@ -141,7 +146,7 @@ public void UpdateParameters()
if (m_audioListener == null
&& m_findAudioListenerInCameraIfNull != GraphyManager.LookForAudioListener.NEVER)
{
FindAudioListener();
m_audioListener = FindAudioListener();
}

m_spectrum = new float[m_spectrumSize];
Expand Down Expand Up @@ -175,9 +180,26 @@ public float dBNormalized(float db)
/// <summary>
/// Tries to find an audio listener in the main camera.
/// </summary>
private void FindAudioListener()
private AudioListener FindAudioListener()
{
Camera mainCamera = Camera.main;

if (mainCamera != null)
{
return mainCamera.GetComponent<AudioListener>();
}
else
{
return null;
}
}

private void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
{
m_audioListener = Camera.main.GetComponent<AudioListener>();
if (m_findAudioListenerInCameraIfNull == GraphyManager.LookForAudioListener.ON_SCENE_LOAD)
{
m_audioListener = FindAudioListener();
}
}

private void Init()
Expand All @@ -186,14 +208,7 @@ private void Init()

UpdateParameters();

SceneManager.sceneLoaded += (scene, loadMode) =>
{
if (m_audioListener == null
&& m_findAudioListenerInCameraIfNull == GraphyManager.LookForAudioListener.ON_SCENE_LOAD)
{
FindAudioListener();
}
};
UnityEngine.SceneManagement.SceneManager.sceneLoaded += OnSceneLoaded;
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,12 @@ public override void OnInspectorGUI()
value: m_enableOnStartup.boolValue
);

// This is a neat trick to hide Graphy in the Scene if it's going to be deactivated in play mode so that it doesn't use screen space.
if (!Application.isPlaying)
{
m_target.GetComponent<Canvas>().enabled = m_enableOnStartup.boolValue;
}

m_keepAlive.boolValue = EditorGUILayout.Toggle
(
new GUIContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,9 @@ private void Init()
if (!m_enableOnStartup)
{
ToggleActive();

// We need to enable this on startup because we disable it in GraphyManagerEditor
GetComponent<Canvas>().enabled = true;
}

m_initialized = true;
Expand Down

0 comments on commit cc8b658

Please sign in to comment.