Version: Unity 6 Preview (6000.0)
LanguageEnglish
  • C#

AndroidApplication.onConfigurationChanged

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

A callback to detect the device configuration changes when the application is running.

Unity invokes this callback for the configuration changes related to the following aspects.

  • Orientation
  • Keyboard visibility
  • Dark theme
  • Screen layout
  • Screen size

For more information on the configuration changes, refer to the Android developer documentation.

using UnityEngine;
using UnityEngine.Android;

public class MyApplication : MonoBehaviour { AndroidConfiguration m_CurrentConfig; AndroidConfiguration m_PrevConfig;

public void Start() { m_PrevConfig = m_CurrentConfig = AndroidApplication.currentConfiguration; AndroidApplication.onConfigurationChanged += OnConfigurationChanged; } public void OnDisable() { AndroidApplication.onConfigurationChanged -= OnConfigurationChanged; } private void OnConfigurationChanged(AndroidConfiguration newConfig) { m_PrevConfig = m_CurrentConfig; m_CurrentConfig = newConfig; if (m_PrevConfig.orientation != m_CurrentConfig.orientation || m_PrevConfig.screenLayoutSize != m_CurrentConfig.screenLayoutSize) { ApplyUIChanges(m_CurrentConfig.orientation, m_CurrentConfig.screenLayoutSize); }

if (m_PrevConfig.uiModeNight != m_CurrentConfig.uiModeNight) { ApplyUINightMode(m_CurrentConfig.uiModeNight); }

if (m_PrevConfig.screenHeightDp != m_CurrentConfig.screenHeightDp || m_PrevConfig.screenWidthDp != m_CurrentConfig.screenWidthDp) { ApplyScreenSizeChanges(); } }

private void ApplyUIChanges(AndroidOrientation orientation, AndroidScreenLayoutSize layoutSize) {

}

private void ApplyUINightMode(AndroidUIModeNight nightMode) {

}

private void ApplyScreenSizeChanges() {

} }