AllowAndroidAppToMakeHttpRequestsOption.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using UnityEditor;
  2. namespace SingularityGroup.HotReload.Editor {
  3. internal class AllowAndroidAppToMakeHttpRequestsOption : ProjectOptionBase {
  4. public override string ShortSummary {
  5. get {
  6. return "Allow app to make HTTP requests";
  7. }
  8. }
  9. public override string Summary => ShortSummary;
  10. public override bool GetValue(SerializedObject so) {
  11. #if UNITY_2022_1_OR_NEWER
  12. // use PlayerSettings as the source of truth
  13. return PlayerSettings.insecureHttpOption != InsecureHttpOption.NotAllowed;
  14. #else
  15. return GetProperty(so).boolValue;
  16. #endif
  17. }
  18. public override string ObjectPropertyName =>
  19. nameof(HotReloadSettingsObject.AllowAndroidAppToMakeHttpRequests);
  20. public override void SetValue(SerializedObject so, bool value) {
  21. base.SetValue(so, value);
  22. // Enabling on Unity 2022 or newer → set the Unity option to ‘Development Builds only’
  23. #if UNITY_2022_1_OR_NEWER
  24. var notAllowed = PlayerSettings.insecureHttpOption == InsecureHttpOption.NotAllowed;
  25. if (value) {
  26. // user chose to enable it
  27. if (notAllowed) {
  28. PlayerSettings.insecureHttpOption = InsecureHttpOption.DevelopmentOnly;
  29. }
  30. } else {
  31. // user chose to disable it
  32. PlayerSettings.insecureHttpOption = InsecureHttpOption.NotAllowed;
  33. }
  34. #endif
  35. }
  36. public override void InnerOnGUI(SerializedObject so) {
  37. var description = "For Hot Reload to work on-device, please allow HTTP requests";
  38. EditorGUILayout.LabelField(description, HotReloadWindowStyles.WrapStyle);
  39. }
  40. }
  41. }