MaxEventSystemChecker.cs 991 B

12345678910111213141516171819202122232425262728293031323334353637
  1. //
  2. // EventSystemChecker.cs
  3. // AppLovin MAX Unity Plugin
  4. //
  5. // Created by Jonathan Liu on 10/23/2022.
  6. // Copyright © 2022 AppLovin. All rights reserved.
  7. //
  8. #if UNITY_EDITOR
  9. using UnityEngine;
  10. using UnityEngine.EventSystems;
  11. namespace AppLovinMax.Scripts
  12. {
  13. /// <summary>
  14. /// A script to check and enable event system as needed for the AppLovin MAX ad prefabs.
  15. /// </summary>
  16. [RequireComponent(typeof(EventSystem))]
  17. public class MaxEventSystemChecker : MonoBehaviour
  18. {
  19. private void Awake()
  20. {
  21. // Enable the EventSystem if there is no other EventSystem in the scene
  22. var eventSystem = GetComponent<EventSystem>();
  23. var currentSystem = EventSystem.current;
  24. if (currentSystem == null || currentSystem == eventSystem)
  25. {
  26. eventSystem.enabled = true;
  27. }
  28. else
  29. {
  30. eventSystem.enabled = false;
  31. }
  32. }
  33. }
  34. }
  35. #endif