initial commit
This commit is contained in:
parent
6715289efe
commit
788c3389af
37645 changed files with 2526849 additions and 80 deletions
|
|
@ -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