Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


onConfigurationChanged

A callback to detect the device configuration changes when the application is running.
Read time 1 minuteLast updated 6 days ago

Definition

public static event Action<AndroidConfiguration> onConfigurationChanged

Remarks

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.

Examples

using UnityEngine;using UnityEngine.Android;public class MyApplication : MonoBehaviour{ AndroidConfiguration m_PrevConfig; public void Start() { m_PrevConfig = new AndroidConfiguration(AndroidApplication.currentConfiguration); AndroidApplication.onConfigurationChanged += OnConfigurationChanged; } public void OnDisable() { AndroidApplication.onConfigurationChanged -= OnConfigurationChanged; } private void OnConfigurationChanged(AndroidConfiguration newConfig) { if (m_PrevConfig.orientation != newConfig.orientation || m_PrevConfig.screenLayoutSize != newConfig.screenLayoutSize) { ApplyUIChanges(newConfig.orientation, newConfig.screenLayoutSize); } if (m_PrevConfig.uiModeNight != newConfig.uiModeNight) { ApplyUINightMode(newConfig.uiModeNight); } if (m_PrevConfig.screenHeightDp != newConfig.screenHeightDp || m_PrevConfig.screenWidthDp != newConfig.screenWidthDp) { ApplyScreenSizeChanges(); } m_PrevConfig.CopyFrom(newConfig); } private void ApplyUIChanges(AndroidOrientation orientation, AndroidScreenLayoutSize layoutSize) { } private void ApplyUINightMode(AndroidUIModeNight nightMode) { } private void ApplyScreenSizeChanges() { }}