Space Ad Mobile 9.5.1
Space Ad Mobile makes ads easy to add into your mobile game: one unified workflow for LevelPlay, AdMob, Yandex.Ads across banners, interstitials and rewarded.
Loading...
Searching...
No Matches
RequestOptions.cs
1using System;
2using GoogleMobileAds.Api;
3using UnityEngine;
4
5namespace SCG.SpaceAdMobile
6{
10 [Serializable]
11 public class RequestOptions : ISerializationCallbackReceiver
12 {
14 [Tooltip("Specifies the maximum allowed ad content rating, based on ESRB classifications.")]
16
18 [Tooltip("Specifies whether ad requests require child, teen, or unspecified age-restricted treatment.")]
20
25 Enum.GetName(typeof(ContentRating), ContentRating));
26
38 public void SetContentRatingBasedOnAge(int age)
39 => ContentRating = age switch
40 {
41 < 7 => ContentRating.G,
42 < 13 => ContentRating.PG,
43 < 17 => ContentRating.T,
44 _ => ContentRating.MA
45 };
46
47 #region Legacy age treatment migration // TODO: Remove this migration in the next major version
48
49 private const int CurrentSerializationVersion = 1;
50 private const int LegacyTreatmentTrue = 1;
51 private const int MissingLegacyTreatment = int.MinValue;
52
53 [SerializeField, HideInInspector]
54 [UnityEngine.Serialization.FormerlySerializedAs("TagForChildDirectedTreatment")]
55 private int legacyTagForChildDirectedTreatment = MissingLegacyTreatment;
56
57 [SerializeField, HideInInspector]
58 [UnityEngine.Serialization.FormerlySerializedAs("TagForUnderAgeOfConsent")]
59 private int legacyTagForUnderAgeOfConsent = MissingLegacyTreatment;
60
61 [SerializeField, HideInInspector]
62 private int serializationVersion = CurrentSerializationVersion;
63
65 public void OnBeforeSerialize() => MigrateLegacyAgeTreatment();
66
68 public void OnAfterDeserialize() => MigrateLegacyAgeTreatment();
69
70 private void MigrateLegacyAgeTreatment()
71 {
72 var hasLegacyTreatment = legacyTagForChildDirectedTreatment != MissingLegacyTreatment
73 || legacyTagForUnderAgeOfConsent != MissingLegacyTreatment;
74 if (serializationVersion >= CurrentSerializationVersion && !hasLegacyTreatment)
75 return;
76
77 if (hasLegacyTreatment)
78 {
79 // Google maps either legacy true signal to Child; Teen has no legacy equivalent
80 AgeRestrictedTreatment = legacyTagForChildDirectedTreatment == LegacyTreatmentTrue
81 || legacyTagForUnderAgeOfConsent == LegacyTreatmentTrue
82 ? AgeRestrictedTreatment.Child
83 : AgeRestrictedTreatment.Unspecified;
84 }
85
86 legacyTagForChildDirectedTreatment = MissingLegacyTreatment;
87 legacyTagForUnderAgeOfConsent = MissingLegacyTreatment;
88 serializationVersion = CurrentSerializationVersion;
89 }
90
91 #endregion
92 }
93
99 public enum ContentRating
100 {
101 [Tooltip("No specific maximum rating. Ensure your ad settings in AdMob are configured as desired.")]
102 Unspecified = 0,
103 [Tooltip("Content suitable for general audiences, including all ages.")]
104 G = 1,
105 [Tooltip("Content that may require parental guidance. Recommended for viewers aged 7 and above.")]
106 // ReSharper disable once InconsistentNaming
107 PG = 2,
108 [Tooltip("Content targeting teenagers, typically suitable for those aged 13 and above.")]
109 T =3,
110 [Tooltip("Content meant for mature audiences, usually requiring viewers to be at least 17 years old.")]
111 // ReSharper disable once InconsistentNaming
112 MA = 4
113 }
114}
AgeRestrictedTreatment AgeRestrictedTreatment
Specifies whether ad requests require child, teen, or unspecified age-restricted treatment.
MaxAdContentRating MaxAdContentRating
Converts the selected content rating to a format recognized by the ad service.
ContentRating ContentRating
Specifies the maximum allowed ad content rating, based on ESRB classifications.
void SetContentRatingBasedOnAge(int age)
Sets the ContentRating field based on the user's age.
Represents the options for customizing ad requests, including content ratings and regulatory complian...
ContentRating
Enumerates the possible maximum content ratings for ads, as classified by the ESRB....