initial commit
This commit is contained in:
parent
6715289efe
commit
788c3389af
37645 changed files with 2526849 additions and 80 deletions
|
@ -0,0 +1,14 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Unity.Services.Core.Registration")]
|
||||
|
||||
// Test assemblies
|
||||
#if UNITY_INCLUDE_TESTS
|
||||
[assembly: InternalsVisibleTo("Unity.Services.Core.Tests")]
|
||||
[assembly: InternalsVisibleTo("Unity.Services.Core.EditorTests")]
|
||||
[assembly: InternalsVisibleTo("Unity.Services.Core.TestUtils.Tests")]
|
||||
[assembly: InternalsVisibleTo("Unity.Services.Core.TestUtils.EditorTests")]
|
||||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
|
||||
|
||||
[assembly: InternalsVisibleTo("Unity.Services.Core.AdsIntegration.Tests")]
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4ccb088ac3dc549f8b9dd4c7fa79206f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,81 @@
|
|||
using System;
|
||||
using Unity.Services.Core.Device.Internal;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.Services.Core.Device
|
||||
{
|
||||
class InstallationId : IInstallationId
|
||||
{
|
||||
const string k_UnityInstallationIdKey = "UnityInstallationId";
|
||||
|
||||
internal string Identifier;
|
||||
|
||||
internal IUserIdentifierProvider UnityAdsIdentifierProvider;
|
||||
internal IUserIdentifierProvider UnityAnalyticsIdentifierProvider;
|
||||
|
||||
public InstallationId()
|
||||
{
|
||||
UnityAdsIdentifierProvider = new UnityAdsIdentifier();
|
||||
UnityAnalyticsIdentifierProvider = new UnityAnalyticsIdentifier();
|
||||
}
|
||||
|
||||
public string GetOrCreateIdentifier()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Identifier))
|
||||
CreateIdentifier();
|
||||
|
||||
return Identifier;
|
||||
}
|
||||
|
||||
public void CreateIdentifier()
|
||||
{
|
||||
Identifier = ReadIdentifierFromFile();
|
||||
if (!string.IsNullOrEmpty(Identifier))
|
||||
return;
|
||||
|
||||
var analyticsId = UnityAnalyticsIdentifierProvider.UserId;
|
||||
var adsId = UnityAdsIdentifierProvider.UserId;
|
||||
|
||||
if (!string.IsNullOrEmpty(analyticsId))
|
||||
{
|
||||
Identifier = analyticsId;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(adsId))
|
||||
{
|
||||
Identifier = adsId;
|
||||
}
|
||||
else
|
||||
{
|
||||
Identifier = GenerateGuid();
|
||||
}
|
||||
|
||||
WriteIdentifierToFile(Identifier);
|
||||
|
||||
if (string.IsNullOrEmpty(analyticsId))
|
||||
{
|
||||
UnityAnalyticsIdentifierProvider.UserId = Identifier;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(adsId))
|
||||
{
|
||||
UnityAdsIdentifierProvider.UserId = Identifier;
|
||||
}
|
||||
}
|
||||
|
||||
static string ReadIdentifierFromFile()
|
||||
{
|
||||
return PlayerPrefs.GetString(k_UnityInstallationIdKey);
|
||||
}
|
||||
|
||||
static void WriteIdentifierToFile(string identifier)
|
||||
{
|
||||
PlayerPrefs.SetString(k_UnityInstallationIdKey, identifier);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
static string GenerateGuid()
|
||||
{
|
||||
return Guid.NewGuid().ToString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c3788e7e3e2e94c38a2deace1fee410e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,3 @@
|
|||
// This file is generated. Do not modify by hand.
|
||||
// XML documentation file not found. To check if public methods have XML comments,
|
||||
// make sure the XML doc file is present and located next to the scraped dll
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9fd3161dccac3420aba623cc85241d0d
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"name": "Unity.Services.Core.Device",
|
||||
"references": [
|
||||
"Unity.Services.Core.Internal"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 614c328814c3e4cb89d08dcc15048513
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e12cdb285c9804571a21e551bdac8e68
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,77 @@
|
|||
#if UNITY_ANDROID
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.Services.Core.Device
|
||||
{
|
||||
static class AndroidUtils
|
||||
{
|
||||
const int k_ContextModePrivate = 0x0000;
|
||||
|
||||
public static AndroidJavaObject GetUnityActivity()
|
||||
{
|
||||
using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
|
||||
{
|
||||
return unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
|
||||
}
|
||||
}
|
||||
|
||||
public static AndroidJavaObject GetSharedPreferences(AndroidJavaObject context, string name, int mode = k_ContextModePrivate)
|
||||
{
|
||||
return context.Call<AndroidJavaObject>("getSharedPreferences", name, mode);
|
||||
}
|
||||
|
||||
public static AndroidJavaObject GetSharedPreferences(string name, int mode = k_ContextModePrivate)
|
||||
{
|
||||
using (var activity = GetUnityActivity())
|
||||
{
|
||||
return GetSharedPreferences(activity, name, mode);
|
||||
}
|
||||
}
|
||||
|
||||
public static string SharedPreferencesGetString(string name, string key, string defValue = "")
|
||||
{
|
||||
using (var preferences = GetSharedPreferences(name))
|
||||
{
|
||||
return SharedPreferencesGetString(preferences, key, defValue);
|
||||
}
|
||||
}
|
||||
|
||||
public static string SharedPreferencesGetString(AndroidJavaObject preferences, string key, string defValue = "")
|
||||
{
|
||||
if (preferences == null)
|
||||
return defValue;
|
||||
if (!preferences.Call<bool>("contains", key))
|
||||
return defValue;
|
||||
|
||||
try
|
||||
{
|
||||
return preferences.Call<string>("getString", key, defValue);
|
||||
}
|
||||
// throws ClassCastException
|
||||
catch (Exception)
|
||||
{
|
||||
return defValue;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SharedPreferencesPutString(string name, string key, string value)
|
||||
{
|
||||
using (var preferences = GetSharedPreferences(name))
|
||||
{
|
||||
SharedPreferencesPutString(preferences, key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SharedPreferencesPutString(AndroidJavaObject preferences, string key, string value)
|
||||
{
|
||||
if (preferences == null)
|
||||
return;
|
||||
|
||||
var editor = preferences.Call<AndroidJavaObject>("edit");
|
||||
editor.Call<AndroidJavaObject>("putString", key, value);
|
||||
editor.Call<bool>("commit");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 294f83b40dade45de80752da3ccfb793
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,7 @@
|
|||
namespace Unity.Services.Core.Device
|
||||
{
|
||||
interface IUserIdentifierProvider
|
||||
{
|
||||
string UserId { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 49757d9e69f214a659a1e5221912d21c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,34 @@
|
|||
#if UNITY_IOS
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Unity.Services.Core.Device
|
||||
{
|
||||
class NSUserDefaults
|
||||
{
|
||||
public static string GetString(string key)
|
||||
{
|
||||
if (string.IsNullOrEmpty(key))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(key));
|
||||
}
|
||||
return UserDefaultsGetString(key);
|
||||
}
|
||||
|
||||
public static void SetString(string key, string value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(key))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(key));
|
||||
}
|
||||
UserDefaultsSetString(key, value);
|
||||
}
|
||||
|
||||
[DllImport("__Internal", EntryPoint = "UOCPUserDefaultsGetString")]
|
||||
static extern string UserDefaultsGetString(string key);
|
||||
|
||||
[DllImport("__Internal", EntryPoint = "UOCPUserDefaultsSetString")]
|
||||
static extern void UserDefaultsSetString(string key, string value);
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e6a7022b5e3dc42b5b29a830722baea0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,36 @@
|
|||
#include <string>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
char* UOCPUserDefaultsGetString(const char *key) {
|
||||
if (!key) {
|
||||
return nil;
|
||||
}
|
||||
NSString* stringKey = [NSString stringWithUTF8String:key];
|
||||
NSString* stringValue = [[NSUserDefaults standardUserDefaults] stringForKey:stringKey];
|
||||
if (!stringValue) {
|
||||
return nil;
|
||||
}
|
||||
return strdup([stringValue UTF8String]);
|
||||
}
|
||||
|
||||
void UOCPUserDefaultsSetString(const char *key, const char *value) {
|
||||
if (!key) {
|
||||
return;
|
||||
}
|
||||
NSString* stringKey = [NSString stringWithUTF8String:key];
|
||||
if (!value)
|
||||
{
|
||||
[[NSUserDefaults standardUserDefaults] removeObjectForKey:stringKey];
|
||||
} else {
|
||||
NSString* stringValue = [NSString stringWithUTF8String:value];
|
||||
[[NSUserDefaults standardUserDefaults] setValue:stringValue forKey:stringKey];
|
||||
}
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,37 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 24f488a631d59471fac9f6afb99df333
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 1
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
tvOS: tvOS
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,49 @@
|
|||
namespace Unity.Services.Core.Device
|
||||
{
|
||||
class UnityAdsIdentifier : IUserIdentifierProvider
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
const string k_AndroidSettingsFile = "unityads-installinfo";
|
||||
#endif
|
||||
#if UNITY_ANDROID || UNITY_IOS
|
||||
const string k_IdfiKey = "unityads-idfi";
|
||||
#endif
|
||||
|
||||
public string UserId
|
||||
{
|
||||
get
|
||||
{
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
return IdentifierForInstallAndroid;
|
||||
#elif UNITY_IOS && !UNITY_EDITOR
|
||||
return IdentifierForInstallIos;
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
}
|
||||
set
|
||||
{
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
IdentifierForInstallAndroid = value;
|
||||
#elif UNITY_IOS && !UNITY_EDITOR
|
||||
IdentifierForInstallIos = value;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_ANDROID
|
||||
static string IdentifierForInstallAndroid
|
||||
{
|
||||
get => AndroidUtils.SharedPreferencesGetString(k_AndroidSettingsFile, k_IdfiKey);
|
||||
set => AndroidUtils.SharedPreferencesPutString(k_AndroidSettingsFile, k_IdfiKey, value);
|
||||
}
|
||||
#endif
|
||||
#if UNITY_IOS
|
||||
static string IdentifierForInstallIos
|
||||
{
|
||||
get => NSUserDefaults.GetString(k_IdfiKey);
|
||||
set => NSUserDefaults.SetString(k_IdfiKey, value);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5845494cae7434f98a56718a3f9eb802
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.Services.Core.Device
|
||||
{
|
||||
class UnityAnalyticsIdentifier : IUserIdentifierProvider
|
||||
{
|
||||
const string k_PlayerUserIdKey = "unity.cloud_userid";
|
||||
|
||||
public string UserId
|
||||
{
|
||||
get => PlayerPrefs.GetString(k_PlayerUserIdKey);
|
||||
set
|
||||
{
|
||||
try
|
||||
{
|
||||
PlayerPrefs.SetString(k_PlayerUserIdKey, value);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2dbae1a4e85854c5a9bbf5fbb99aa8c7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue