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
YandexRequestOptions.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using UnityEngine;
5using YandexMobileAds.Base;
6
7namespace SCG.SpaceAdMobile
8{
14 [Serializable]
16 {
18 [Tooltip("User age passed to Yandex ad targeting.")]
19 public string Age;
20
22 [Tooltip("User gender passed to Yandex ad targeting.")]
23 public string Gender;
24
26 [Tooltip("Context query passed to Yandex ad targeting.")]
27 public string ContextQuery;
28
30 [Tooltip("User location passed to Yandex ad targeting.")]
32
34 [Tooltip("Context tags passed to Yandex ad targeting.")]
35 public List<string> ContextTags = new();
36
37#if !LEGACY_YANDEX_MOBILE_ADS
39 [Tooltip("Preferred ad theme passed to Yandex ad requests.")]
40 public AdTheme AdTheme = AdTheme.None;
41#endif
42
44 [Tooltip("Additional ad request parameters passed as key-value pairs.")]
45 public List<YandexRequestParameter> Parameters = new();
46
47#if !LEGACY_YANDEX_MOBILE_ADS
54 public AdTargeting CreateTargeting()
55 {
56 var hasContextTags = ContextTags is { Count: > 0 };
57 return string.IsNullOrEmpty(Age) &&
58 string.IsNullOrEmpty(Gender) &&
59 string.IsNullOrEmpty(ContextQuery) &&
60 Location?.Enabled != true &&
61 !hasContextTags
62 ? null
63 : new AdTargeting(
64 age: string.IsNullOrEmpty(Age) ? null : Age,
65 gender: string.IsNullOrEmpty(Gender) ? null : Gender,
66 location: Location?.Enabled == true ? Location.CreateLocation() : null,
67 contextQuery: string.IsNullOrEmpty(ContextQuery) ? null : ContextQuery,
68 contextTags: hasContextTags ? new List<string>(ContextTags) : null);
69 }
70#endif
71
78 public Dictionary<string, string> CreateParameters()
79 {
80 if (Parameters == null || Parameters.Count == 0)
81 return null;
82
83 var parameters = new Dictionary<string, string>();
84 foreach (var parameter in Parameters.Where(parameter => parameter != null && !string.IsNullOrEmpty(parameter.Key)))
85 {
86 parameters[parameter.Key] = parameter.Value ?? string.Empty;
87 }
88
89 return parameters.Count > 0 ? parameters : null;
90 }
91 }
92
98 [Serializable]
100 {
102 [Tooltip("Controls whether location targeting is added to ad requests.")]
103 public bool Enabled;
104
106 [Tooltip("User latitude passed to Yandex ad targeting.")]
107 public float Latitude;
108
110 [Tooltip("User longitude passed to Yandex ad targeting.")]
111 public float Longitude;
112
114 [Tooltip("User horizontal accuracy passed to Yandex ad targeting.")]
115 public float HorizontalAccuracy;
116
117#if !LEGACY_YANDEX_MOBILE_ADS
124 public Location CreateLocation() =>
125 new Location.Builder()
126 .SetLatitude(Latitude)
127 .SetLongitude(Longitude)
128 .SetHorizontalAccuracy(HorizontalAccuracy)
129 .Build();
130#endif
131 }
132
138 [Serializable]
140 {
142 [Tooltip("Request parameter key.")]
143 public string Key;
144
146 [Tooltip("Request parameter value.")]
147 public string Value;
148 }
149}
bool Enabled
Controls whether location targeting is added to ad requests.
Location CreateLocation()
Creates an SDK Location object from the configured inspector values. The method is called only when l...
Inspector-friendly Yandex user location options. The SDK Location type is immutable and created throu...
AdTargeting CreateTargeting()
Builds SDK targeting data from the configured fields. Empty targeting fields are skipped so requests ...
List< YandexRequestParameter > Parameters
Specifies the parameters.
AdTheme AdTheme
Preferred ad theme passed to Yandex ad requests.
Dictionary< string, string > CreateParameters()
Builds SDK request parameters from the inspector list. Empty keys are ignored and later duplicate key...
Stores common Yandex request settings for ad loading. Inspector values are converted to targeting,...
Inspector-friendly key-value pair for Yandex request parameters. Unity does not serialize dictionarie...