15#if UNITY_6000_4_OR_NEWER
16 private static readonly HashSet<EntityId> pending =
new();
18 private static readonly HashSet<int> pending =
new();
22 [Tooltip(
"Automatically validates and adjusts the " + nameof(
MessageOptions) +
23 " based on the selected " + nameof(ValidateType) +
" policy.")]
26 protected virtual void OnValidate()
29 if (!ValidateScript())
return;
32#if UNITY_6000_4_OR_NEWER
33 ScheduleAfterEditorReady(GetEntityId());
35 ScheduleAfterEditorReady(GetInstanceID());
43 protected virtual void ValidateSafe()
45 if (!ValidateScript())
return;
47 if (!TryGetComponent<AdUnitBase>(out var adUnit) || !adUnit)
49 Debug.LogWarning($
"{nameof(AdUnitBase)} component not found on the GameObject '{name}'.",
this);
55 ValidateMessageOptions(adUnit);
58 protected virtual bool ValidateScript()
60 if (!
this || !gameObject)
return false;
61 var scn = gameObject.scene;
62 return scn.IsValid() && scn.isLoaded && !Application.isPlaying;
65#if UNITY_6000_4_OR_NEWER
66 private static void ScheduleAfterEditorReady(EntityId entityId)
68 if (!pending.Add(entityId))
return;
70 UnityEditor.EditorApplication.delayCall += () =>
72 if (UnityEditor.EditorApplication.isUpdating || UnityEditor.EditorApplication.isCompiling)
74 pending.Remove(entityId);
75 ScheduleAfterEditorReady(entityId);
79 pending.Remove(entityId);
82 if (!obj || !obj.gameObject)
return;
84 var scn = obj.gameObject.scene;
85 if (!scn.IsValid() || !scn.isLoaded)
return;
91 private static void ScheduleAfterEditorReady(
int instanceId)
94 if (!pending.Add(instanceId))
return;
96 UnityEditor.EditorApplication.delayCall += () =>
98 if (UnityEditor.EditorApplication.isUpdating || UnityEditor.EditorApplication.isCompiling)
100 pending.Remove(instanceId);
101 ScheduleAfterEditorReady(instanceId);
105 pending.Remove(instanceId);
108 if (!obj || !obj.gameObject)
return;
110 var scn = obj.gameObject.scene;
111 if (!scn.IsValid() || !scn.isLoaded)
return;
122 protected virtual void ValidateMessageOptions(
AdUnitBase adUnit)
141 protected bool CheckByType<T>(
bool value)
142 => ValidateType == MessageValidateType.Full ?
this is T :
this is T || value;