bingo 项目提交

This commit is contained in:
2026-04-20 13:49:36 +08:00
commit ad5920ac6a
5585 changed files with 1216243 additions and 0 deletions
@@ -0,0 +1,37 @@
//
// Copyright 2020
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("Unity.Advertisement.IosSupport.Editor")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Unity Technologies")]
[assembly: AssemblyProduct("Monetization")]
[assembly: AssemblyCopyright("Copyright © Unity Technologies 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("0.1.0")]
[assembly: InternalsVisibleTo("Unity.Advertisement.IosSupport.Editor.Tests")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fe609725aa1304d10bd0232f8a727830
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7c12ab5a1ea52495bbfe2f28879f608e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using UnityEngine;
namespace Unity.Advertisement.IosSupport.Editor
{
internal interface ISkAdNetworkParser
{
string GetExtension();
HashSet<string> ParseSource(ISkAdNetworkSource source);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 97e0c61e3aa704af086868b25f08f85a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,9 @@
namespace Unity.Advertisement.IosSupport.Editor
{
public static class SkAdNetworkFileExtension
{
public const string XML = "xml";
public const string JSON = "json";
public const string NONE = "";
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e496c38bf001040ecbe70e444a0542fb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
namespace Unity.Advertisement.IosSupport.Editor
{
internal class SkAdNetworkJsonParser : ISkAdNetworkParser
{
[Serializable]
public class SkAdNetworkIdArray
{
public List<SkAdNetworkInfo> skadnetwork_ids;
}
[Serializable]
public class SkAdNetworkInfo
{
public string skadnetwork_id;
}
public string GetExtension()
{
return SkAdNetworkFileExtension.JSON;
}
public HashSet<string> ParseSource(ISkAdNetworkSource source)
{
var foundIds = new HashSet<string>();
try
{
string jsonData;
using (var stream = source.Open())
{
if (stream == null)
{
Debug.LogWarning($"[Unity SKAdNetwork Parser] Unable to parse SKAdNetwork file: {source.Path}");
return foundIds;
}
jsonData = new StreamReader(stream).ReadToEnd();
}
SkAdNetworkIdArray skAdNetworkCompanyInfo = null;
try
{
skAdNetworkCompanyInfo = JsonUtility.FromJson<SkAdNetworkIdArray>(jsonData);
}
catch (Exception) {}
//Fallback to try and see if this is a JSONObject which contains an array element called skadnetwork_ids instead of the expected JSONArray
if (skAdNetworkCompanyInfo?.skadnetwork_ids == null || skAdNetworkCompanyInfo.skadnetwork_ids.Count == 0)
{
var updatedJson = "{\"skadnetwork_ids\":" + jsonData + "}";
skAdNetworkCompanyInfo = JsonUtility.FromJson<SkAdNetworkIdArray>(updatedJson);
}
if (skAdNetworkCompanyInfo?.skadnetwork_ids == null)
{
Debug.LogWarning($"[Unity SKAdNetwork Parser] Unable to parse SKAdNetwork file: {source.Path}");
return foundIds;
}
foundIds.UnionWith(skAdNetworkCompanyInfo.skadnetwork_ids.Select(t => t.skadnetwork_id).Where(t => t != null));
}
catch (Exception)
{
Debug.LogWarning($"[Unity SKAdNetwork Parser] Unable to parse SKAdNetwork file: {source.Path}");
}
return foundIds;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9840479aaa6504c9ea96572abd23249c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
namespace Unity.Advertisement.IosSupport.Editor
{
internal static class SkAdNetworkParser
{
private static Dictionary<string, ISkAdNetworkParser> s_Parsers;
static SkAdNetworkParser()
{
s_Parsers = new Dictionary<string, ISkAdNetworkParser>
{
{ SkAdNetworkFileExtension.XML, new SkAdNetworkXmlParser() },
{ SkAdNetworkFileExtension.JSON, new SkAdNetworkJsonParser() },
{ SkAdNetworkFileExtension.NONE, new SkAdNetworkUrlParser() }
};
}
public static ISkAdNetworkParser GetParser(string parserType)
{
try
{
s_Parsers.TryGetValue(parserType, out var parser);
return parser;
}
catch (Exception) {}
return null;
}
public static IEnumerable<ISkAdNetworkParser> GetAllParsers()
{
return s_Parsers.Values;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f70ff3726241b4d2b8d0ea012c80e706
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
namespace Unity.Advertisement.IosSupport.Editor
{
internal class SkAdNetworkUrlParser : ISkAdNetworkParser
{
public string GetExtension()
{
return SkAdNetworkFileExtension.NONE;
}
public HashSet<string> ParseSource(ISkAdNetworkSource source)
{
var foundIds = new HashSet<string>();
try
{
string[] lines;
using (var reader = new StreamReader(source.Open()))
{
lines = reader.ReadToEnd().Split(Environment.NewLine.ToCharArray());
}
lines.Where(url => !string.IsNullOrEmpty(url))
.Where(url => Uri.IsWellFormedUriString(url, UriKind.Absolute))
.ToList().ForEach(url => {
ISkAdNetworkParser parser = null;
switch (GetExtensionFromPath(url))
{
case SkAdNetworkFileExtension.XML:
parser = SkAdNetworkParser.GetParser(SkAdNetworkFileExtension.XML);
break;
case SkAdNetworkFileExtension.JSON:
parser = SkAdNetworkParser.GetParser(SkAdNetworkFileExtension.JSON);
break;
}
if (parser == null)
{
Debug.LogWarning($"[Unity SKAdNetwork Parser] Unsupported file extension, No parser available to parse SKAdNetwork file: {source.Path} ");
return;
}
foundIds.UnionWith(parser.ParseSource(new SkAdNetworkRemoteSource(url)));
});
}
catch (Exception)
{
Debug.LogWarning($"[Unity SKAdNetwork Parser] Unable to parse SKAdNetwork file: {source.Path}");
}
return foundIds;
}
/// <summary>
/// Gets the extension for a filepath string
/// </summary>
private static string GetExtensionFromPath(string filepath)
{
var extension = Path.GetExtension(filepath);
return string.IsNullOrEmpty(extension) ? "" : extension.Substring(1).ToLower();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 95e1f9f2b229246a08a2354f8c702ae9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Xml;
using UnityEngine;
namespace Unity.Advertisement.IosSupport.Editor
{
internal class SkAdNetworkXmlParser : ISkAdNetworkParser
{
private const string k_SkAdNetworkIdentifier = "SKAdNetworkIdentifier";
public string GetExtension()
{
return SkAdNetworkFileExtension.XML;
}
public HashSet<string> ParseSource(ISkAdNetworkSource source)
{
var foundIds = new HashSet<string>();
try
{
var xmlDocument = new XmlDocument();
using (var stream = source.Open())
{
if (stream == null)
{
Debug.LogWarning("[Unity SKAdNetwork Parser] Unable to parse SKAdNetwork file: {source.Path}");
return foundIds;
}
xmlDocument.Load(stream);
}
var items = xmlDocument.GetElementsByTagName("key");
for (var x = 0; x < items.Count; x++)
{
if (items[x].InnerText == k_SkAdNetworkIdentifier)
{
var nextSibling = items[x]?.NextSibling;
if (nextSibling != null)
{
foundIds.Add(nextSibling.InnerText);
}
}
}
}
catch (Exception)
{
Debug.LogWarning($"[Unity SKAdNetwork Parser] Unable to parse SKAdNetwork file: {source.Path}");
}
return foundIds;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b62c9c75b6cf84b3db11f5bb9f036169
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,118 @@
#if UNITY_2018_1_OR_NEWER && UNITY_IOS
using System;
using System.IO;
using UnityEngine;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.iOS.Xcode;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Build.Reporting;
namespace Unity.Advertisement.IosSupport.Editor
{
internal class PostProcessBuildPlist : IPostprocessBuildWithReport
{
public int callbackOrder => 0;
private const string k_SkAdNetworkIdentifier = "SKAdNetworkIdentifier";
private const string k_SkAdNetworkItems = "SKAdNetworkItems";
private const string k_SkAdNetworksFileName = "SKAdNetworks";
public void OnPostprocessBuild(BuildReport report)
{
if (report.summary.platform != BuildTarget.iOS)
{
return;
}
UpdateInfoPlistWithSkAdNetworkIds(report.summary.outputPath);
}
internal static void UpdateInfoPlistWithSkAdNetworkIds(string pathToPlistFile)
{
var provider = new SkAdNetworkLocalSourceProvider();
var ids = new HashSet<string>();
try
{
SkAdNetworkParser.GetAllParsers().ToList().ForEach(parser => {
provider.GetSources(k_SkAdNetworksFileName, parser.GetExtension()).ToList().ForEach(source => {
ids.UnionWith(parser.ParseSource(source));
});
});
}
catch (Exception e)
{
Debug.LogError($"Failed to parse SKAdNetwork files due to following reason: {e.Message}");
}
try
{
WriteSkAdNetworkIdsToInfoPlist(ids, pathToPlistFile);
}
catch (Exception e)
{
Debug.LogError($"Failed to update info.plist file due to following reason: {e.Message}");
}
}
/// <summary>
/// Write all plistValues to an existing Info.plist file
/// </summary>
internal static void WriteSkAdNetworkIdsToInfoPlist(HashSet<string> skAdNetworkIds, string outputPath)
{
var infoPlistPath = outputPath + "/Info.plist";
var plist = new PlistDocument();
plist.ReadFromString(File.ReadAllText(infoPlistPath));
var root = plist.root;
if (root == null)
{
Debug.LogWarning("[Unity SKAdNetwork Parser] Unable to parse info.plist. Unable to add SkAdNetwork Identifiers.");
return;
}
if (!root.values?.ContainsKey(k_SkAdNetworkItems) ?? false)
{
root.CreateArray(k_SkAdNetworkItems);
}
var adNetworkItems = root[k_SkAdNetworkItems].AsArray();
if (adNetworkItems == null)
{
Debug.LogWarning("[Unity SKAdNetwork Parser] Unable to modify existing info.plist. Unable to add SkAdNetwork Identifiers.");
return;
}
foreach (var adNetworkId in skAdNetworkIds)
{
if (!PlistContainsAdNetworkId(adNetworkItems, adNetworkId))
{
adNetworkItems.AddDict().SetString(k_SkAdNetworkIdentifier, adNetworkId);
}
}
File.WriteAllText(infoPlistPath, plist.WriteToString());
}
/// <summary>
/// Check if the value is already contained in the plist
/// </summary>
internal static bool PlistContainsAdNetworkId(PlistElementArray adNetworkItems, string adNetworkId)
{
foreach (var adNetworkItem in adNetworkItems.values)
{
var item = adNetworkItem.AsDict();
if (item.values.TryGetValue(k_SkAdNetworkIdentifier, out var value))
{
if (value.AsString() == adNetworkId)
{
return true;
}
}
}
return false;
}
}
}
#endif //UNITY_2018_1_OR_NEWER
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e7bc5a6e424ec49089ca10bdb43d4c42
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b2b15b7af045b42dabe70a3914e67cba
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,11 @@
using System.IO;
using UnityEngine;
namespace Unity.Advertisement.IosSupport.Editor
{
internal interface ISkAdNetworkSource
{
string Path { get; }
Stream Open();
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b3b688cb4385c4ed287404f01d47d2cf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,21 @@
using System;
using System.IO;
using UnityEngine;
namespace Unity.Advertisement.IosSupport.Editor
{
internal class SkAdNetworkLocalSource : ISkAdNetworkSource
{
public string Path { get; }
public SkAdNetworkLocalSource(string path)
{
Path = path;
}
public Stream Open()
{
return new FileStream(Path, FileMode.Open);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bc26fb3115fcd455f8d1d7b9739bc0f5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
namespace Unity.Advertisement.IosSupport.Editor
{
/// <summary>
/// Responsible for finding all SkAdNetwork files on the local filesystem by searching through the users project directory and all includes packages.
/// </summary>
internal class SkAdNetworkLocalSourceProvider
{
private const int k_MaxPackageLookupTimeoutInSeconds = 30;
private string[] m_PackagePaths;
public SkAdNetworkLocalSourceProvider()
{
m_PackagePaths = GetAllPackagePaths();
}
public IEnumerable<SkAdNetworkLocalSource> GetSources(string filename, string extension)
{
return GetLocalFilePaths(filename, extension).Select(x => new SkAdNetworkLocalSource(x)).ToArray();
}
/// <summary>
/// Finds a file on the local filesystem by looking the project directory, and all package directories
/// </summary>
/// <param name="filename">the filename to look for</param>
/// <param name="fileExtension">the filename extension to look for</param>
/// <returns>a full path to the file</returns>
private IEnumerable<string> GetLocalFilePaths(string filename, string fileExtension)
{
return m_PackagePaths
.Prepend(Directory.GetCurrentDirectory())
.SelectMany(path => Directory.GetFiles(path, string.IsNullOrEmpty(fileExtension) ? filename : $"{filename}.{fileExtension}" , SearchOption.AllDirectories))
.ToList();
}
/// <summary>
/// Returns a list of paths to the root folder of each package included in the users project.
/// These may be in different locations on disk depending on where the package is being stored/cached.
/// </summary>
private static string[] GetAllPackagePaths(bool offlineMode = true)
{
var list = UnityEditor.PackageManager.Client.List(offlineMode);
if (list == null)
{
return Array.Empty<string>();
}
var timeSpan = TimeSpan.FromSeconds(k_MaxPackageLookupTimeoutInSeconds);
var startTime = DateTime.Now;
while (!list.IsCompleted && (DateTime.Now - startTime) < timeSpan)
{
Thread.Sleep(10);
}
if (list.Error != null)
{
return Array.Empty<string>();
}
return list.Result.Select(packageInfo => packageInfo.assetPath).ToArray();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5d925f4b6523544bbbfa58d11df1ac49
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,21 @@
using System.IO;
using System.Net;
using UnityEngine;
namespace Unity.Advertisement.IosSupport.Editor
{
internal class SkAdNetworkRemoteSource : ISkAdNetworkSource
{
public string Path { get; }
public SkAdNetworkRemoteSource(string path)
{
Path = path;
}
public Stream Open()
{
return new WebClient().OpenRead(Path);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fc886aae4a1fc42b48e8b6deccb67ab5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,15 @@
{
"name": "Unity.Advertisement.IosSupport.Editor",
"references": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 782c39a29bdf44a569029c0fc1c6d458
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: