2using System.Collections.Generic;
7using Object = UnityEngine.Object;
18 #region Validation sync
20#if UNITY_6000_4_OR_NEWER
21 private static readonly HashSet<EntityId> pendingValidationInstanceIds =
new();
23 private static readonly HashSet<int> pendingValidationInstanceIds =
new();
25 private static bool isSynchronizingAggregators;
36 if (instance !=
null)
return instance;
64 [Tooltip(
"Controls whether enhanced Yandex editor dummies are generated and applied.")]
68 [Tooltip(
"Folder names to exclude when scanning for scripts (matched by path segments, case-insensitive).")]
72 "Democumentation",
"Demo",
"Documentation",
90#if !UPM_PACKAGE && UNITY_ASTOOLS_EXPERIMENTAL
95 if (EditorApplication.isUpdating || EditorApplication.isCompiling)
97#if UNITY_6000_4_OR_NEWER
98 ScheduleSynchronization(GetEntityId());
100 ScheduleSynchronization(GetInstanceID());
105 SynchronizeAggregators();
108#if LEGACY_YANDEX_MOBILE_ADS
118 #region Validation sync
120 private void SynchronizeAggregators()
122 if (isSynchronizingAggregators ||
Aggregators ==
null)
125 isSynchronizingAggregators =
true;
129 var anyChanged =
false;
134 var newPrefabs = CollectHelper.CollectPrefabsForAggregator(aggregator);
136 if (!CollectHelper.ArraysEqual(aggregator.Migrations, newList))
138 aggregator.Migrations = newList;
142 if (!CollectHelper.ArraysEqual(aggregator.Prefabs, newPrefabs))
144 aggregator.Prefabs = newPrefabs;
152 EditorUtility.SetDirty(
this);
153 AssetDatabase.SaveAssets();
157 isSynchronizingAggregators =
false;
161#if !UPM_PACKAGE && UNITY_ASTOOLS_EXPERIMENTAL
162#if UNITY_6000_4_OR_NEWER
163 private static void ScheduleSynchronization(EntityId entityId)
165 if (!pendingValidationInstanceIds.Add(entityId))
168 EditorApplication.delayCall += () =>
170 if (EditorApplication.isUpdating || EditorApplication.isCompiling)
172 pendingValidationInstanceIds.Remove(entityId);
173 ScheduleSynchronization(entityId);
177 pendingValidationInstanceIds.Remove(entityId);
179 var resource = EditorUtility.EntityIdToObject(entityId) as AdAggregatorResource;
183 resource.SynchronizeAggregators();
187 private static void ScheduleSynchronization(
int instanceId)
189 if (!pendingValidationInstanceIds.Add(instanceId))
192 EditorApplication.delayCall += () =>
194 if (EditorApplication.isUpdating || EditorApplication.isCompiling)
196 pendingValidationInstanceIds.Remove(instanceId);
197 ScheduleSynchronization(instanceId);
201 pendingValidationInstanceIds.Remove(instanceId);
203 var resource = EditorUtility.InstanceIDToObject(instanceId) as AdAggregatorResource;
207 resource.SynchronizeAggregators();
241 [Tooltip(
"Install configuration used by the selector to detect SDK presence and open install flows.")]
266 [Tooltip(
"Determines how the Install action is opened for this aggregator.")]
270 [Tooltip(
"External installation URL opened when InstallMode is ExternalUrl.")]
274 [Tooltip(
"Package IDs used for install checks and Package Manager deep links.")]
278 [Tooltip(
"Folder names used to detect installed SDK files in Assets or Packages.")]
282 [Tooltip(
"Assembly names used to detect installed SDK assemblies in the editor domain.")]
286 [Tooltip(
"Optional Package Manager filter or section label for the Install action.")]
315 ""name"": ""YandexMobileAds"",
316 ""rootNamespace"": ""YandexMobileAds"",
318 ""AppMetricaAdRevenueAdapter""
320 ""includePlatforms"": [],
321 ""excludePlatforms"": [],
322 ""allowUnsafeCode"": true,
323 ""overrideReferences"": false,
324 ""precompiledReferences"": [],
325 ""autoReferenced"": false,
326 ""defineConstraints"": [],
327 ""versionDefines"": [],
328 ""noEngineReferences"": false
335 ""name"": ""YandexMobileAds.Editor"",
336 ""rootNamespace"": """",
340 ""includePlatforms"": [
343 ""excludePlatforms"": [],
344 ""allowUnsafeCode"": false,
345 ""overrideReferences"": false,
346 ""precompiledReferences"": [],
347 ""autoReferenced"": true,
348 ""defineConstraints"": [
349 ""YANDEX_MOBILE_ADS""
351 ""versionDefines"": [],
352 ""noEngineReferences"": false
356 [Tooltip(
"C# source template for the enhanced rewarded ad editor dummy.")]
361 [Tooltip(
"C# source template for the enhanced interstitial ad editor dummy.")]
366 [Tooltip(
"C# source template for the enhanced app-open ad editor dummy.")]
371 [Tooltip(
"C# source template for the enhanced banner client editor dummy.")]
376 internal static class CollectHelper
378 private static readonly StringComparer pathComparer = StringComparer.OrdinalIgnoreCase;
384 public static MonoScript[] CollectScriptsForAggregator(
Aggregator aggregator, IList<string> excludedNames)
386 var scripts =
new List<MonoScript>();
388 if (aggregator?.Folder ==
null)
389 return scripts.ToArray();
391 var folderPath = AssetDatabase.GetAssetPath(aggregator.
Folder);
392 if (
string.IsNullOrEmpty(folderPath))
393 return scripts.ToArray();
396 if (!AssetDatabase.IsValidFolder(folderPath))
397 folderPath = Path.GetDirectoryName(folderPath)?.Replace(
'\\',
'/') ?? folderPath;
399 if (
string.IsNullOrEmpty(folderPath) || !AssetDatabase.IsValidFolder(folderPath))
400 return scripts.ToArray();
402 var guids = AssetDatabase.FindAssets(
"t:MonoScript",
new[] { folderPath });
406 select AssetDatabase.GUIDToAssetPath(guid)
408 where path.EndsWith(
".cs", StringComparison.OrdinalIgnoreCase)
409 where !IsPathExcluded(path, excludedNames)
410 select AssetDatabase.LoadAssetAtPath<MonoScript>(path)
417 .OrderBy(ms => Path.GetFileNameWithoutExtension(AssetDatabase.GetAssetPath(ms)), pathComparer)
418 .ThenBy(AssetDatabase.GetAssetPath, pathComparer)
426 public static GameObject[] CollectPrefabsForAggregator(Aggregator aggregator,
string prefabsFolderName =
"Prefabs")
429 if (aggregator?.Folder ==
null)
430 return Array.Empty<GameObject>();
433 var basePath = AssetDatabase.GetAssetPath(aggregator.Folder);
434 if (
string.IsNullOrEmpty(basePath))
435 return Array.Empty<GameObject>();
438 if (!AssetDatabase.IsValidFolder(basePath))
439 basePath = Path.GetDirectoryName(basePath)?.Replace(
'\\',
'/') ?? basePath;
441 if (
string.IsNullOrEmpty(basePath) || !AssetDatabase.IsValidFolder(basePath))
442 return Array.Empty<GameObject>();
445 var prefabsPath = $
"{basePath.TrimEnd('/')}/{prefabsFolderName}";
448 if (!AssetDatabase.IsValidFolder(prefabsPath))
451 var folderGuids = AssetDatabase.FindAssets(
"t:Folder",
new[] { basePath });
452 var match = folderGuids
453 .Select(AssetDatabase.GUIDToAssetPath)
454 .FirstOrDefault(p => pathComparer.Equals(Path.GetFileName(p.TrimEnd(
'/')), prefabsFolderName));
456 if (match ==
null || !AssetDatabase.IsValidFolder(match))
457 return Array.Empty<GameObject>();
463 var guids = AssetDatabase.FindAssets(
"t:Prefab",
new[] { prefabsPath });
465 var list =
new List<GameObject>(guids.Length);
469 select AssetDatabase.GUIDToAssetPath(guid)
471 where path.EndsWith(
".prefab", StringComparison.OrdinalIgnoreCase)
472 select AssetDatabase.LoadAssetAtPath<GameObject>(path)
479 .OrderBy(go => go.name, pathComparer)
480 .ThenBy(AssetDatabase.GetAssetPath, pathComparer)
487 private static bool IsPathExcluded(
string assetPath, IList<string> excludedNames)
489 if (excludedNames ==
null || excludedNames.Count == 0)
return false;
491 var normalized = assetPath.Replace(
'\\',
'/');
492 var segments = normalized.Split(
'/');
495 for (var i = 0; i < segments.Length - 1; i++)
497 var seg = segments[i];
498 if (excludedNames.Any(t => pathComparer.Equals(seg, t)))
506 public static bool ArraysEqual<T>(T[] a, T[] b) where T : Object
508 if (ReferenceEquals(a, b))
return true;
509 if (a ==
null || b ==
null)
return false;
510 if (a.Length != b.Length)
return false;
511 return !a.Where((t, i) => t != b[i]).Any();
const string KeyDeleteOtherFolders
Specifies the key delete other folders.
bool IsFreeVersion
Specifies the is free version.
void OnValidate()
Validates serialized configuration in the Unity Editor.
Aggregator[] Aggregators
Specifies the aggregators.
const string KeyDeleteDemo
Specifies the key delete demo.
string WelcomeText
Specifies the welcome text.
YandexData Yandex
Configuration used to prepare Yandex Mobile Ads assemblies.
bool UseEnhancedYandexEditorDummies
Controls whether enhanced Yandex editor dummies are generated and applied.
const string KeyUseEnhancedYandexEditorDummies
Specifies the key use enhanced yandex editor dummies.
bool DeleteOtherFolders
Controls whether folders for unselected ad aggregators are deleted.
virtual void OnDestroy()
Releases resources during Unity's destroy callback.
const string KeyDeleteDocumentation
Specifies the key delete documentation.
bool DeleteDocumentation
Controls whether documentation content is deleted during package preparation.
static AdAggregatorResource Instance
Singleton Resource instance.
string[] ExcludedFolderNames
Folder names to exclude when scanning for scripts (matched by path segments, case-insensitive).
bool DeleteDemo
Controls whether demo content is deleted during package preparation.
Provides ad aggregator resource functionality.
string Name
Specifies the name.
GameObject[] Prefabs
Specifies the prefabs.
string Define
Specifies the define.
AggregatorInstallResource Install
Install configuration used by the selector to detect SDK presence and open install flows.
string ShortName
Specifies the short name.
string DemoFolderName
Specifies the demo folder name.
Object Folder
Specifies the folder.
Texture2D Texture
Specifies the texture.
MonoScript[] Migrations
Specifies the migrations.
Provides aggregator functionality.
string[] InstallPackageIds
Package IDs used for install checks and Package Manager deep links.
string[] InstallFolderNames
Folder names used to detect installed SDK files in Assets or Packages.
InstallOpenMode InstallMode
Determines how the Install action is opened for this aggregator.
string[] InstallAssemblyNames
Assembly names used to detect installed SDK assemblies in the editor domain.
string PackageManagerFilter
Optional Package Manager filter or section label for the Install action.
string InstallUrl
External installation URL opened when InstallMode is ExternalUrl.
Provides aggregator install resource functionality.
Represents a mobile ad manager component specifically designed for integration with Google AdMob serv...
string AsmdefEditorTemplate
Specifies the asmdef editor template.
string MainAsmdefName
Specifies the main asmdef name.
string BannerDummyTemplate
C# source template for the enhanced banner client editor dummy.
string RewardedDummyTemplate
C# source template for the enhanced rewarded ad editor dummy.
string AssetPath
Specifies the asset path.
string AsmdefTemplate
Specifies the asmdef template.
string EditorPath
Specifies the editor path.
string EditorAsmdefName
Specifies the editor asmdef name.
string RemoveDefineConstraint
Specifies the remove define constraint.
Object Asmdef
Specifies the asmdef.
string AppOpenDummyTemplate
C# source template for the enhanced app-open ad editor dummy.
string InterstitialDummyTemplate
C# source template for the enhanced interstitial ad editor dummy.
Provides yandex data functionality.
InstallOpenMode
Defines the target destination for the Install action in the aggregator selector. External URL opens ...
@ PackageManager
Open Unity Package Manager and fallback to URL when unavailable.
@ ExternalUrl
Open the configured external URL in a browser.