diff --git a/Assets/Scripts/Common/SDK/BFIronSourceSDKManager.cs b/Assets/Scripts/Common/SDK/BFIronSourceSDKManager.cs index 95f76bc94..f310845b7 100644 --- a/Assets/Scripts/Common/SDK/BFIronSourceSDKManager.cs +++ b/Assets/Scripts/Common/SDK/BFIronSourceSDKManager.cs @@ -33,8 +33,10 @@ namespace BF BFLog.Log("unity-script: IronSource.Agent.init"); IronSource.Agent.init(appKey); IronSource.Agent.setManualLoadRewardedVideo(true); + IronSourceAdQuality.Initialize(appKey); #elif UNITY_IPHONE // string appKey = "8545d445"; + // IronSourceAdQuality.Initialize(appKey); #else // string appKey = "unexpected_platform"; #endif diff --git a/Assets/ThirdParty/IronSourceAdQuality.meta b/Assets/ThirdParty/IronSourceAdQuality.meta new file mode 100644 index 000000000..ec98210ed --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: cd642f9c5d7126f47898e5dc9520a8ff +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Editor.meta b/Assets/ThirdParty/IronSourceAdQuality/Editor.meta new file mode 100644 index 000000000..a6ad52ddf --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6ee27eb8be2558e4482bcaa12bbd4781 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Editor/IronSourceAdQualityDependencies.xml b/Assets/ThirdParty/IronSourceAdQuality/Editor/IronSourceAdQualityDependencies.xml new file mode 100644 index 000000000..f8ac959ac --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Editor/IronSourceAdQualityDependencies.xml @@ -0,0 +1,36 @@ + + 7.13.0 + + + + + https://android-sdk.is.com/ + + + + + + + + https://android-sdk.is.com/ + + + + + + + diff --git a/Assets/ThirdParty/IronSourceAdQuality/Editor/IronSourceAdQualityDependencies.xml.meta b/Assets/ThirdParty/IronSourceAdQuality/Editor/IronSourceAdQualityDependencies.xml.meta new file mode 100644 index 000000000..2f3127d38 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Editor/IronSourceAdQualityDependencies.xml.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 0caf106b327a046c5b374834523d4477 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts.meta new file mode 100644 index 000000000..f24ec6fc2 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c104a6ee5617fb048acdd3b2f1cbc512 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality.meta new file mode 100644 index 000000000..5d1a0e574 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ae460004d99634df8a86e07e1a01faa5 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISADQualityDeviceIdType.cs b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISADQualityDeviceIdType.cs new file mode 100644 index 000000000..440d98b9b --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISADQualityDeviceIdType.cs @@ -0,0 +1,6 @@ +using System; +public enum ISAdQualityDeviceIdType { + NONE = 0, + GAID = 1, + IDFA = 2 +}; \ No newline at end of file diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISADQualityDeviceIdType.cs.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISADQualityDeviceIdType.cs.meta new file mode 100644 index 000000000..85e540337 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISADQualityDeviceIdType.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 92d1c3826af024ff1a77c6c7d7983c7d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityAdType.cs b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityAdType.cs new file mode 100644 index 000000000..5c409a88b --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityAdType.cs @@ -0,0 +1,16 @@ +using System; +public enum ISAdQualityAdType { + UNKNOWN = -1, + RICH_MEDIA = 0, + INTERSTITIAL = 1, + APP_WALL = 2, + VIDEO = 3, + REWARDED_VIDEO = 4, + NATIVE = 5, + BANNER = 6, + OFFER_WALL = 7, + NATIVE_HTML = 8, + EXTERNAL = 9, + REWARDED = 10, + INTERACTIVE = 11 +}; \ No newline at end of file diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityAdType.cs.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityAdType.cs.meta new file mode 100644 index 000000000..4b33fe796 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityAdType.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 08e1a7bef35354a1883fab85829a4273 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityAndroidInitHandler.cs b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityAndroidInitHandler.cs new file mode 100644 index 000000000..c5a78fd8c --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityAndroidInitHandler.cs @@ -0,0 +1,53 @@ +#if UNITY_ANDROID +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Scripting; + +[Preserve] +public class ISAdQualityAndroidInitHandler : AndroidJavaProxy +{ + private const string IRON_SOURCE_AD_QUALITY_CLASS = "com.ironsource.adqualitysdk.sdk.unity.IronSourceAdQuality"; + private const string UNITY_IS_AD_QUALITY_INIT_LISTENER = "com.ironsource.adqualitysdk.sdk.unity.UnityISAdQualityInitListener"; + + public event Action OnAdQualitySdkInitSuccess = delegate { }; + public event Action OnAdQualitySdkInitFailed = delegate { }; + + //implements UnityISAdQualityInitListener java interface + public ISAdQualityAndroidInitHandler(): base(UNITY_IS_AD_QUALITY_INIT_LISTENER) + { +#if !UNITY_EDITOR + try + { + using (var jniAdQualityClass = new AndroidJavaClass(IRON_SOURCE_AD_QUALITY_CLASS)) + { + jniAdQualityClass.CallStatic("setUnityISAdQualityInitListener", this); + } + } + catch(Exception e) + { + Debug.LogError("setUnityISAdQualityInitListener method doesn't exist, error: " + e.Message); + } +#endif + } + + [Preserve] + public void adQualitySdkInitSuccess() + { + if (this.OnAdQualitySdkInitSuccess != null) + { + this.OnAdQualitySdkInitSuccess(); + } + + } + + [Preserve] + public void adQualitySdkInitFailed(int adQualitySdkInitError, string errorMessage) + { + if (this.OnAdQualitySdkInitFailed != null) + { + this.OnAdQualitySdkInitFailed((ISAdQualityInitError)adQualitySdkInitError, errorMessage); + } + } +} +#endif \ No newline at end of file diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityAndroidInitHandler.cs.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityAndroidInitHandler.cs.meta new file mode 100644 index 000000000..91fe16490 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityAndroidInitHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c70eb41427c4848d391fa9e66f60daf3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityConfig.cs b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityConfig.cs new file mode 100644 index 000000000..ae3272ec8 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityConfig.cs @@ -0,0 +1,118 @@ +using System; +using UnityEngine; + +public class ISAdQualityConfig +{ + private String userId; + private bool userIdSet; + private bool testMode; + private ISAdQualityInitCallback adQualityInitCallback; + private ISAdQualityLogLevel logLevel; + private String initializationSource; + private bool coppa; + private ISAdQualityDeviceIdType deviceIdType; + + public ISAdQualityConfig() + { + userId = null; + testMode = false; + userIdSet = false; + logLevel = ISAdQualityLogLevel.INFO; + coppa = false; + deviceIdType = ISAdQualityDeviceIdType.NONE; + initializationSource = null; + } + + public String UserId + { + get + { + return userId; + } + set + { + userIdSet = true; + userId = value; + } + } + + internal bool UserIdSet + { + get + { + return userIdSet; + } + } + + public bool TestMode + { + get + { + return testMode; + } + set + { + testMode = value; + } + } + + public ISAdQualityLogLevel LogLevel + { + get + { + return logLevel; + } + set + { + logLevel = value; + } + } + + public ISAdQualityInitCallback AdQualityInitCallback + { + get + { + return adQualityInitCallback; + } + set + { + adQualityInitCallback = value; + } + } + + public String InitializationSource + { + get + { + return initializationSource; + } + set + { + initializationSource = value; + } + } + + public bool Coppa + { + get + { + return coppa; + } + set + { + coppa = value; + } + } + + public ISAdQualityDeviceIdType DeviceIdType + { + get + { + return deviceIdType; + } + set + { + deviceIdType = value; + } + } +} \ No newline at end of file diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityConfig.cs.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityConfig.cs.meta new file mode 100644 index 000000000..41950121c --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityConfig.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6ee3acefb6d46481191afc81fb1e4865 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityCustomMediationRevenue.cs b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityCustomMediationRevenue.cs new file mode 100644 index 000000000..39c399c3e --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityCustomMediationRevenue.cs @@ -0,0 +1,66 @@ +using System; +using UnityEngine; + +public class ISAdQualityCustomMediationRevenue +{ + private ISAdQualityMediationNetwork mediationNetwork; + private ISAdQualityAdType adType; + private double revenue; + private String placement; + + public ISAdQualityCustomMediationRevenue() + { + mediationNetwork = ISAdQualityMediationNetwork.UNKNOWN; + adType = ISAdQualityAdType.UNKNOWN; + revenue = 0; + placement = null; + } + + public ISAdQualityMediationNetwork MediationNetwork + { + get + { + return mediationNetwork; + } + set + { + mediationNetwork = value; + } + } + + public ISAdQualityAdType AdType + { + get + { + return adType; + } + set + { + adType = value; + } + } + + public double Revenue + { + get + { + return revenue; + } + set + { + revenue = value; + } + } + + public String Placement + { + get + { + return placement; + } + set + { + placement = value; + } + } +} \ No newline at end of file diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityCustomMediationRevenue.cs.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityCustomMediationRevenue.cs.meta new file mode 100644 index 000000000..fb691684c --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityCustomMediationRevenue.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8bb7937cdf9c640cf8ee92ed1fa34227 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityInitCallback.cs b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityInitCallback.cs new file mode 100644 index 000000000..a953c9995 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityInitCallback.cs @@ -0,0 +1,8 @@ +using System; +using UnityEngine; + +public interface ISAdQualityInitCallback +{ + void adQualitySdkInitSuccess(); + void adQualitySdkInitFailed(ISAdQualityInitError adQualityInitError, string errorMessage); +} \ No newline at end of file diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityInitCallback.cs.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityInitCallback.cs.meta new file mode 100644 index 000000000..7b30f4ce9 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityInitCallback.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 894fc956cbe6c43e385333baa4651e56 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityInitCallbackWrapper.cs b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityInitCallbackWrapper.cs new file mode 100644 index 000000000..566a72c63 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityInitCallbackWrapper.cs @@ -0,0 +1,88 @@ +using UnityEngine; +using System; + +public class ISAdQualityInitCallbackWrapper : MonoBehaviour +{ + private ISAdQualityInitCallback mCallback; + +#if UNITY_ANDROID + private ISAdQualityAndroidInitHandler adQualityAndroidInitHandler; +#endif + +#if UNITY_IPHONE || UNITY_IOS + private ISAdQualityiOSInitHandler adQualityiOSInitHandler; +#endif + + public ISAdQualityInitCallback AdQualityInitCallback + { + set + { + mCallback = value; + } + get + { + return mCallback; + } + } + + void Awake () + { +#if UNITY_ANDROID + adQualityAndroidInitHandler = new ISAdQualityAndroidInitHandler(); //sets this.adQualityAndroidInitHandler as listener for init events on the bridge + registerAdQualityAndroidInitEvents(); +#endif + +#if UNITY_IPHONE || UNITY_IOS + registerAdQualityiOSInitEvents(); + adQualityiOSInitHandler = new ISAdQualityiOSInitHandler(); //sets this.adQualityiOSInit as listener for init events on the bridge +#endif + DontDestroyOnLoad(gameObject); //Makes the object not be destroyed automatically when loading a new scene. + } + + private void adQualitySdkInitSuccess() + { + if (mCallback != null) + { + mCallback.adQualitySdkInitSuccess(); + } + } + + private void onAdQualitySdkInitFailed(ISAdQualityInitError sdkInitError, string errorMsg) + { + if (mCallback != null) + { + mCallback.adQualitySdkInitFailed(sdkInitError, errorMsg); + } + } + +#if UNITY_ANDROID + //subscribe to ISAdQualityAndroidInitHandler events + private void registerAdQualityAndroidInitEvents() { + adQualityAndroidInitHandler.OnAdQualitySdkInitSuccess += () => + { + adQualitySdkInitSuccess(); + }; + + adQualityAndroidInitHandler.OnAdQualitySdkInitFailed += (sdkInitError, errorMsg) => + { + onAdQualitySdkInitFailed(sdkInitError, errorMsg); + }; + } +#endif + +#if UNITY_IPHONE || UNITY_IOS + //subscribe to ISAdQualityiOSInitHandler events + private void registerAdQualityiOSInitEvents() { + ISAdQualityiOSInitHandler.OnAdQualitySdkInitSuccess += () => + { + adQualitySdkInitSuccess(); + }; + + ISAdQualityiOSInitHandler.OnAdQualitySdkInitFailed += (sdkInitError, errorMsg) => + { + onAdQualitySdkInitFailed(sdkInitError, errorMsg); + }; + } +#endif + +} \ No newline at end of file diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityInitCallbackWrapper.cs.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityInitCallbackWrapper.cs.meta new file mode 100644 index 000000000..b1a998fbb --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityInitCallbackWrapper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1f5c838c5a8ff40529569d29728deec4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityInitError.cs b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityInitError.cs new file mode 100644 index 000000000..d8d1ef423 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityInitError.cs @@ -0,0 +1,14 @@ +using System; + +public enum ISAdQualityInitError { + AD_QUALITY_SDK_WAS_SHUTDOWN = 0, + ILLEGAL_USER_ID = 1, + ILLEGAL_APP_KEY = 2, + EXCEPTION_ON_INIT = 3, + NO_NETWORK_CONNECTION = 4, + CONFIG_LOAD_TIMEOUT = 5, + CONNECTOR_LOAD_TIMEOUT = 6, + AD_NETWORK_VERSION_NOT_SUPPORTED_YET = 7, + AD_NETWORK_SDK_REQUIRES_NEWER_AD_QUALITY_SDK = 8, + AD_QUALITY_ALREADY_INITIALIZED = 9 +}; \ No newline at end of file diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityInitError.cs.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityInitError.cs.meta new file mode 100644 index 000000000..88213d265 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityInitError.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6da8d8e07e45042f197fc5f6304a9d62 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityJSON.cs b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityJSON.cs new file mode 100644 index 000000000..265f875c8 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityJSON.cs @@ -0,0 +1,495 @@ +/* + * Based on the miniJSON by Calvin Rien + */ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Text; + +namespace ISAdQualityJSON +{ + public static class Json + { + public static object Deserialize (string json) + { + if (json == null) { + return null; + } + return Parser.Parse (json); + } + + sealed class Parser : IDisposable + { + const string WHITE_SPACE = " \t\n\r"; + const string WORD_BREAK = " \t\n\r{}[],:\""; + + enum TOKEN + { + NONE, + CURLY_OPEN, + CURLY_CLOSE, + SQUARED_OPEN, + SQUARED_CLOSE, + COLON, + COMMA, + STRING, + NUMBER, + TRUE, + FALSE, + NULL + } + ; + + StringReader json; + + Parser (string jsonString) + { + json = new StringReader (jsonString); + } + + public static object Parse (string jsonString) + { + using (var instance = new Parser(jsonString)) { + return instance.ParseValue (); + } + } + + public void Dispose () + { + json.Dispose (); + json = null; + } + + Dictionary ParseObject () + { + Dictionary table = new Dictionary (); + + // ditch opening brace + json.Read (); + + // { + while (true) { + switch (NextToken) { + case TOKEN.NONE: + return null; + case TOKEN.COMMA: + continue; + case TOKEN.CURLY_CLOSE: + return table; + default: + // name + string name = ParseString (); + if (name == null) { + return null; + } + + // : + if (NextToken != TOKEN.COLON) { + return null; + } + // ditch the colon + json.Read (); + + // value + table [name] = ParseValue (); + break; + } + } + } + + List ParseArray () + { + List array = new List (); + + // ditch opening bracket + json.Read (); + + // [ + var parsing = true; + while (parsing) { + TOKEN nextToken = NextToken; + + switch (nextToken) { + case TOKEN.NONE: + return null; + case TOKEN.COMMA: + continue; + case TOKEN.SQUARED_CLOSE: + parsing = false; + break; + default: + object value = ParseByToken (nextToken); + + array.Add (value); + break; + } + } + + return array; + } + + object ParseValue () + { + TOKEN nextToken = NextToken; + return ParseByToken (nextToken); + } + + object ParseByToken (TOKEN token) + { + switch (token) { + case TOKEN.STRING: + return ParseString (); + case TOKEN.NUMBER: + return ParseNumber (); + case TOKEN.CURLY_OPEN: + return ParseObject (); + case TOKEN.SQUARED_OPEN: + return ParseArray (); + case TOKEN.TRUE: + return true; + case TOKEN.FALSE: + return false; + case TOKEN.NULL: + return null; + default: + return null; + } + } + + string ParseString () + { + StringBuilder s = new StringBuilder (); + char c; + + // ditch opening quote + json.Read (); + + bool parsing = true; + while (parsing) { + + if (json.Peek () == -1) { + parsing = false; + break; + } + + c = NextChar; + switch (c) { + case '"': + parsing = false; + break; + case '\\': + if (json.Peek () == -1) { + parsing = false; + break; + } + + c = NextChar; + switch (c) { + case '"': + case '\\': + case '/': + s.Append (c); + break; + case 'b': + s.Append ('\b'); + break; + case 'f': + s.Append ('\f'); + break; + case 'n': + s.Append ('\n'); + break; + case 'r': + s.Append ('\r'); + break; + case 't': + s.Append ('\t'); + break; + case 'u': + var hex = new StringBuilder (); + + for (int i=0; i< 4; i++) { + hex.Append (NextChar); + } + + s.Append ((char)Convert.ToInt32 (hex.ToString (), 16)); + break; + } + break; + default: + s.Append (c); + break; + } + } + + return s.ToString (); + } + + object ParseNumber () + { + string number = NextWord; + + if (number.IndexOf ('.') == -1) { + long parsedInt; + Int64.TryParse (number, NumberStyles.Any, CultureInfo.InvariantCulture, out parsedInt); + return parsedInt; + } + + double parsedDouble; + Double.TryParse (number, NumberStyles.Any, CultureInfo.InvariantCulture, out parsedDouble); + return parsedDouble; + } + + void EatWhitespace () + { + while (WHITE_SPACE.IndexOf(PeekChar) != -1) { + json.Read (); + + if (json.Peek () == -1) { + break; + } + } + } + + char PeekChar { + get { + return Convert.ToChar (json.Peek ()); + } + } + + char NextChar { + get { + return Convert.ToChar (json.Read ()); + } + } + + string NextWord { + get { + StringBuilder word = new StringBuilder (); + + while (WORD_BREAK.IndexOf(PeekChar) == -1) { + word.Append (NextChar); + + if (json.Peek () == -1) { + break; + } + } + + return word.ToString (); + } + } + + TOKEN NextToken { + get { + EatWhitespace (); + + if (json.Peek () == -1) { + return TOKEN.NONE; + } + + char c = PeekChar; + switch (c) { + case '{': + return TOKEN.CURLY_OPEN; + case '}': + json.Read (); + return TOKEN.CURLY_CLOSE; + case '[': + return TOKEN.SQUARED_OPEN; + case ']': + json.Read (); + return TOKEN.SQUARED_CLOSE; + case ',': + json.Read (); + return TOKEN.COMMA; + case '"': + return TOKEN.STRING; + case ':': + return TOKEN.COLON; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '-': + return TOKEN.NUMBER; + } + + string word = NextWord; + + switch (word) { + case "false": + return TOKEN.FALSE; + case "true": + return TOKEN.TRUE; + case "null": + return TOKEN.NULL; + } + + return TOKEN.NONE; + } + } + } + + /// + /// Converts a IDictionary / IList object or a simple type (string, int, etc.) into a JSON string + /// + /// A Dictionary<string, object> / List<object> + /// A JSON encoded string, or null if object 'json' is not serializable + public static string Serialize (object obj) + { + return Serializer.Serialize (obj); + } + + sealed class Serializer + { + StringBuilder builder; + + Serializer () + { + builder = new StringBuilder (); + } + + public static string Serialize (object obj) + { + var instance = new Serializer (); + + instance.SerializeValue (obj); + + return instance.builder.ToString (); + } + + void SerializeValue (object value) + { + IList asList; + IDictionary asDict; + string asStr; + + if (value == null) { + builder.Append ("null"); + } else if ((asStr = value as string) != null) { + SerializeString (asStr); + } else if (value is bool) { + builder.Append (value.ToString ().ToLower ()); + } else if ((asList = value as IList) != null) { + SerializeArray (asList); + } else if ((asDict = value as IDictionary) != null) { + SerializeObject (asDict); + } else if (value is char) { + SerializeString (value.ToString ()); + } else { + SerializeOther (value); + } + } + + void SerializeObject (IDictionary obj) + { + bool first = true; + + builder.Append ('{'); + + foreach (object e in obj.Keys) { + if (!first) { + builder.Append (','); + } + + SerializeString (e.ToString ()); + builder.Append (':'); + + SerializeValue (obj [e]); + + first = false; + } + + builder.Append ('}'); + } + + void SerializeArray (IList anArray) + { + builder.Append ('['); + + bool first = true; + + foreach (object obj in anArray) { + if (!first) { + builder.Append (','); + } + + SerializeValue (obj); + + first = false; + } + + builder.Append (']'); + } + + void SerializeString (string str) + { + builder.Append ('\"'); + + char[] charArray = str.ToCharArray (); + foreach (var c in charArray) { + switch (c) { + case '"': + builder.Append ("\\\""); + break; + case '\\': + builder.Append ("\\\\"); + break; + case '\b': + builder.Append ("\\b"); + break; + case '\f': + builder.Append ("\\f"); + break; + case '\n': + builder.Append ("\\n"); + break; + case '\r': + builder.Append ("\\r"); + break; + case '\t': + builder.Append ("\\t"); + break; + default: + int codepoint = Convert.ToInt32 (c); + if ((codepoint >= 32) && (codepoint <= 126)) { + builder.Append (c); + } else { + builder.Append ("\\u" + Convert.ToString (codepoint, 16).PadLeft (4, '0')); + } + break; + } + } + + builder.Append ('\"'); + } + + void SerializeOther (object value) + { + if (value is float + || value is int + || value is uint + || value is long + || value is double + || value is sbyte + || value is byte + || value is short + || value is ushort + || value is ulong + || value is decimal) { + builder.Append (value.ToString ()); + } else { + SerializeString (value.ToString ()); + } + } + } + } +} \ No newline at end of file diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityJSON.cs.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityJSON.cs.meta new file mode 100644 index 000000000..e2a4a3d96 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityJSON.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a80f212ad97ca4136b919689ba6ad522 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityLogLevel.cs b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityLogLevel.cs new file mode 100644 index 000000000..890bf089c --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityLogLevel.cs @@ -0,0 +1,9 @@ +using System; +public enum ISAdQualityLogLevel { + NONE = 0, + ERROR = 1, + WARNING = 2, + INFO = 3, + DEBUG = 4, + VERBOSE = 5 +}; \ No newline at end of file diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityLogLevel.cs.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityLogLevel.cs.meta new file mode 100644 index 000000000..398e03247 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityLogLevel.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c958a1a9721494cefb50a4fad4b6bb8b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityMediationNetwork.cs b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityMediationNetwork.cs new file mode 100644 index 000000000..ddd9340ae --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityMediationNetwork.cs @@ -0,0 +1,12 @@ +using System; +public enum ISAdQualityMediationNetwork { + UNKNOWN = -1, + ADMOB = 0, + DT_FAIR_BID = 1, + HELIUM = 2, + LEVEL_PLAY = 3, + MAX = 4, + UNITY = 5, + SELF_MEDIATED = 6, + OTHER = 7 +}; \ No newline at end of file diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityMediationNetwork.cs.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityMediationNetwork.cs.meta new file mode 100644 index 000000000..9fdcfb25b --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityMediationNetwork.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b1c44dbefc86f46d7a84660f64b9ba47 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualitySegment.cs b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualitySegment.cs new file mode 100644 index 000000000..79711ee42 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualitySegment.cs @@ -0,0 +1,66 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using System.Linq; + +public class ISAdQualitySegment +{ + public string name = null; + public int age; + public string gender = null; + public int level; + public int isPaying; + public double inAppPurchasesTotal; + public long userCreationDate; + public Dictionary customs; + + public ISAdQualitySegment () + { + age = -1; + level = -1; + isPaying = -1; + inAppPurchasesTotal = -1; + userCreationDate = -1; + customs = new Dictionary (); + } + + public void setCustom(string key, string value){ + customs.Add (key, value); + } + + public Dictionary getSegmentAsDict () + { + Dictionary dict = new Dictionary (); + if (!string.IsNullOrEmpty(name)) + { + dict.Add ("name", name); + } + if (age != -1) + { + dict.Add ("age", age + ""); + } + if (!string.IsNullOrEmpty(gender)) + { + dict.Add ("gender", gender); + } + if (level != -1) + { + dict.Add ("level", level + ""); + } + if (isPaying > -1 && isPaying < 2) + { + dict.Add ("isPaying", isPaying + ""); + } + if (inAppPurchasesTotal > -1) + { + dict.Add ("iapt", inAppPurchasesTotal + ""); + } + if (userCreationDate != -1) + { + dict.Add ("userCreationDate", userCreationDate + ""); + } + Dictionary result = dict.Concat(customs).GroupBy(d => d.Key).ToDictionary(d => d.Key, d => d.First().Value); + return result; + } + +} diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualitySegment.cs.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualitySegment.cs.meta new file mode 100644 index 000000000..ee6168beb --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualitySegment.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bbf07b143b428454a85a0dccbb3bd7b0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityUtils.cs b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityUtils.cs new file mode 100644 index 000000000..505c7f915 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityUtils.cs @@ -0,0 +1,57 @@ +using UnityEngine; +using System.Collections.Generic; +using System; + +public static class ISAdQualityUtils { + + private static bool isDebugBuild = false; + private static bool isDebugBuildSet = false; + /// + /// Creates Log Debug message according to given tag and message. + /// + /// The name of the class whose instance called this function. + /// Debug message to output to log. + public static void LogDebug(string tag, string message) + { + if (!isDebugBuildSet) + { + try //Debug.isDebugBuild can fail on WP8 if it is not called from the Main Thread + { + isDebugBuild = Debug.isDebugBuild; + } + catch (Exception e) + { + isDebugBuild = true; + Debug.Log(string.Format("{0} {1}", tag, e.Message)); + } + isDebugBuildSet = true; + } + if (isDebugBuild) + { + Debug.Log(string.Format("{0} {1}", tag, message)); + } + } + + /// + /// Creates Log Error message according to given tag and message. + /// + /// The name of the class whose instance called this function.. + /// Error message to output to log. + public static void LogError(string tag, string message) { + Debug.LogError(string.Format("{0} {1}", tag, message)); + } + + public static void LogWarning(string tag, string message) { + Debug.LogWarning(string.Format("{0} {1}", tag, message)); + } + + /// + /// Returns the class name to be used in serialization/deserialization process + /// + /// The target to get class name for + /// The class name of the provided instance + public static string GetClassName(object target) { + return target.GetType().Name; + } +} + diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityUtils.cs.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityUtils.cs.meta new file mode 100644 index 000000000..8d97db2c5 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityUtils.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ae84ef4134f7e4290bd18d994cd71a5b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityiOSInitHandler.cs b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityiOSInitHandler.cs new file mode 100644 index 000000000..aece31066 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityiOSInitHandler.cs @@ -0,0 +1,67 @@ +#if UNITY_IPHONE || UNITY_IOS +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using UnityEngine; + +public class ISAdQualityiOSInitHandler : MonoBehaviour +{ + public static event Action OnAdQualitySdkInitSuccess = delegate { }; + public static event Action OnAdQualitySdkInitFailed = delegate { }; + + +#if UNITY_IOS && !UNITY_EDITOR + delegate void ISAdQualityUnityInitSuccessCallback(string args); + [DllImport("__Internal")] + private static extern int ironSourceAdQuality_registerInitSuccessCallback(ISAdQualityUnityInitSuccessCallback func); + + delegate void ISAdQualityUnityInitFailedCallback(string args); + [DllImport("__Internal")] + private static extern void ironSourceAdQuality_registerInitFailedCallback(ISAdQualityUnityInitFailedCallback func); + + public ISAdQualityiOSInitHandler() + { + ironSourceAdQuality_registerInitSuccessCallback(fireInitSuccessCallback); + ironSourceAdQuality_registerInitFailedCallback(fireInitFailedCallback); + } + + [AOT.MonoPInvokeCallback(typeof(ISAdQualityUnityInitSuccessCallback))] + public static void fireInitSuccessCallback(string message) + { + if (OnAdQualitySdkInitSuccess != null) + { + OnAdQualitySdkInitSuccess(); + } + } + + [AOT.MonoPInvokeCallback(typeof(ISAdQualityUnityInitFailedCallback))] + public static void fireInitFailedCallback(string message) + { + if (OnAdQualitySdkInitFailed != null) + { + ISAdQualityInitError sdkInitError = ISAdQualityInitError.EXCEPTION_ON_INIT; + string errorMsg = String.Empty; + try + { + if (!String.IsNullOrEmpty(message)) + { + string[] separators = { "Unity:" }; + string[] splitArray = message.Split(separators, System.StringSplitOptions.RemoveEmptyEntries); + if (splitArray.Length > 1) + { + sdkInitError = (ISAdQualityInitError)Enum.Parse(typeof(ISAdQualityInitError), splitArray[0]); + errorMsg = splitArray[1]; + } + } + } + catch (Exception e) + { + errorMsg = e.Message; + } + OnAdQualitySdkInitFailed(sdkInitError, errorMsg); + } + } + #endif +} + +#endif \ No newline at end of file diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityiOSInitHandler.cs.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityiOSInitHandler.cs.meta new file mode 100644 index 000000000..8bf90f7c8 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/ISAdQualityiOSInitHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a21b72b3702244ccaa9227784e3fc6f3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/IronSourceAdQuality.cs b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/IronSourceAdQuality.cs new file mode 100644 index 000000000..113193fcb --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/IronSourceAdQuality.cs @@ -0,0 +1,157 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using UnityEngine; +using ISAdQualityJSON; + +public class IronSourceAdQuality : CodeGeneratedSingleton +{ + private static GameObject adQualityGameObject = new GameObject("IronSourceAdQuality"); + +#if UNITY_IOS && !UNITY_EDITOR + + [DllImport ("__Internal")] + private static extern int ironSourceAdQuality_initialize(string appKey, string userId, bool userIdSet, bool testMode, + bool debug, int logLevel, string initializationSource, bool coppa, + int deviceIdType, bool isInitCallbackSet); + [DllImport ("__Internal")] + private static extern int ironSourceAdQuality_changeUserId(string userId); + [DllImport ("__Internal")] + private static extern int ironSourceAdQuality_setUserConsent(bool userConsent); + [DllImport ("__Internal")] + private static extern int ironSourceAdQuality_sendCustomMediationRevenue(int mediationNetwork, int adType, string placement, double revenue); + [DllImport ("__Internal")] + private static extern int ironSourceAdQuality_setSegment(string jsonString); + +#endif + + protected override bool DontDestroySingleton { get { return true; } } + + protected override void InitAfterRegisteringAsSingleInstance() { + base.InitAfterRegisteringAsSingleInstance(); + } + + public static void Initialize(string appKey) { + Initialize(appKey, new ISAdQualityConfig()); + } + + public static void Initialize(string appKey, ISAdQualityConfig adQualityConfig) { + if (adQualityConfig == null) { + adQualityConfig = new ISAdQualityConfig(); + } + Initialize(appKey, + adQualityConfig.UserId, + adQualityConfig.UserIdSet, + adQualityConfig.TestMode, + adQualityConfig.LogLevel, + adQualityConfig.InitializationSource, + adQualityConfig.Coppa, + adQualityConfig.DeviceIdType, + adQualityConfig.AdQualityInitCallback); + } + + private static void Initialize(string appKey, + string userId, + bool userIdSet, + bool testMode, + ISAdQualityLogLevel logLevel, + string initializationSource, + bool coppa, + ISAdQualityDeviceIdType deviceIdType, + ISAdQualityInitCallback adQualityInitCallback) { + + #if !UNITY_EDITOR + GetSynchronousCodeGeneratedInstance(); + ISAdQualityInitCallbackWrapper initCallbackWrapper = adQualityGameObject.GetComponent(); + if (initCallbackWrapper == null) { + initCallbackWrapper = adQualityGameObject.AddComponent(); + } + initCallbackWrapper.AdQualityInitCallback = adQualityInitCallback; + bool isInitCallbackSet = (adQualityInitCallback != null); + + #if UNITY_ANDROID + AndroidJNI.PushLocalFrame(100); + + AndroidJNI.PopLocalFrame(IntPtr.Zero); + #endif + + #if UNITY_ANDROID + AndroidJNI.PushLocalFrame(100); + using(AndroidJavaClass jniAdQualityClass = new AndroidJavaClass("com.ironsource.adqualitysdk.sdk.unity.IronSourceAdQuality")) { + AndroidJavaClass jLogLevelEnum = new AndroidJavaClass("com.ironsource.adqualitysdk.sdk.ISAdQualityLogLevel"); + AndroidJavaObject jLogLevel = jLogLevelEnum.CallStatic("fromInt", (int)logLevel); + AndroidJavaClass jDeviceIdTypeEnum = new AndroidJavaClass("com.ironsource.adqualitysdk.sdk.ISAdQualityDeviceIdType"); + AndroidJavaObject jDeviceIdType = jDeviceIdTypeEnum.CallStatic("fromInt", (int)deviceIdType); + jniAdQualityClass.CallStatic("initialize", appKey, userId, userIdSet, testMode, jLogLevel, initializationSource, coppa, jDeviceIdType, isInitCallbackSet); + } + AndroidJNI.PopLocalFrame(IntPtr.Zero); + #elif UNITY_IOS + ironSourceAdQuality_initialize(appKey, userId, userIdSet ,testMode, DEBUG, (int)logLevel, initializationSource, coppa, (int)deviceIdType, isInitCallbackSet); + #endif + #else + ISAdQualityUtils.LogWarning(TAG, "Ad Quality SDK works only on Android or iOS devices."); + #endif + } + + public static void ChangeUserId(String userId) { + #if UNITY_ANDROID && !UNITY_EDITOR + AndroidJNI.PushLocalFrame(100); + using(AndroidJavaClass jniAdQualityClass = new AndroidJavaClass("com.ironsource.adqualitysdk.sdk.unity.IronSourceAdQuality")) { + jniAdQualityClass.CallStatic("changeUserId", userId); + } + AndroidJNI.PopLocalFrame(IntPtr.Zero); + #elif UNITY_IOS && !UNITY_EDITOR + ironSourceAdQuality_changeUserId(userId); + #endif + } + + [Obsolete("This method has been deprecated and will be removed soon")] + public static void SetUserConsent(bool userConsent) { + #if UNITY_ANDROID && !UNITY_EDITOR + AndroidJNI.PushLocalFrame(100); + using(AndroidJavaClass jniAdQualityClass = new AndroidJavaClass("com.ironsource.adqualitysdk.sdk.unity.IronSourceAdQuality")) { + jniAdQualityClass.CallStatic("setUserConsent", userConsent); + } + AndroidJNI.PopLocalFrame(IntPtr.Zero); + #elif UNITY_IOS && !UNITY_EDITOR + ironSourceAdQuality_setUserConsent(userConsent); + #endif + } + + public static void SendCustomMediationRevenue(ISAdQualityCustomMediationRevenue customMediationRevenue) { + #if UNITY_ANDROID && !UNITY_EDITOR + AndroidJNI.PushLocalFrame(100); + using(AndroidJavaClass jniAdQualityClass = new AndroidJavaClass("com.ironsource.adqualitysdk.sdk.unity.IronSourceAdQuality")) { + jniAdQualityClass.CallStatic("sendCustomMediationRevenue", + (int) customMediationRevenue.MediationNetwork, + (int) customMediationRevenue.AdType, + customMediationRevenue.Placement, + customMediationRevenue.Revenue); + } + AndroidJNI.PopLocalFrame(IntPtr.Zero); + #elif UNITY_IOS && !UNITY_EDITOR + ironSourceAdQuality_sendCustomMediationRevenue((int) customMediationRevenue.MediationNetwork, + (int) customMediationRevenue.AdType, + customMediationRevenue.Placement, + customMediationRevenue.Revenue); + #endif + } + + public static void setSegment(ISAdQualitySegment segment) { + Dictionary dict = segment.getSegmentAsDict(); + string jsonString = ISAdQualityJSON.Json.Serialize(dict); + #if UNITY_ANDROID && !UNITY_EDITOR + AndroidJNI.PushLocalFrame(100); + using(AndroidJavaClass jniAdQualityClass = new AndroidJavaClass("com.ironsource.adqualitysdk.sdk.unity.IronSourceAdQuality")) { + jniAdQualityClass.CallStatic("setSegment", jsonString); + } + AndroidJNI.PopLocalFrame(IntPtr.Zero); + #elif UNITY_IOS && !UNITY_EDITOR + ironSourceAdQuality_setSegment(jsonString); + #endif + } + + private const string TAG = "IronSource AdQuality"; + private const bool DEBUG = false; + +} diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/IronSourceAdQuality.cs.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/IronSourceAdQuality.cs.meta new file mode 100644 index 000000000..f67e6a1bf --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/AdQuality/IronSourceAdQuality.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9316531db81604347bb41857c8e7ea43 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config.meta new file mode 100644 index 000000000..8a41f0e1c --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4338140da312a4c6fb1614cd4725933a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/ISAdQualityEditorScript.cs b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/ISAdQualityEditorScript.cs new file mode 100644 index 000000000..7784221c5 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/ISAdQualityEditorScript.cs @@ -0,0 +1,22 @@ +using UnityEngine; +using System.IO; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +#if UNITY_EDITOR +using UnityEditor; +#endif + + +/// +/// This class holds the store's configurations. +/// +public class ISAdQualityEditorScript : ScriptableObject +{ + +#if UNITY_EDITOR + + static string currentModuleVersion = "7.13.0"; + +#endif +} diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/ISAdQualityEditorScript.cs.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/ISAdQualityEditorScript.cs.meta new file mode 100644 index 000000000..4f63d013f --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/ISAdQualityEditorScript.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5e0d3ac0c6a1f4767826e6a49833d7c3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/IronSourceAdQualityManifestTools.cs b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/IronSourceAdQualityManifestTools.cs new file mode 100644 index 000000000..4ea505aca --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/IronSourceAdQualityManifestTools.cs @@ -0,0 +1,208 @@ +using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif +using System.IO; +using System.Xml; +using System.Text; +using System.Linq; +using System.Collections.Generic; + +public class IronSourceAdQualityManifestTools +{ +#if UNITY_EDITOR +static string outputFile = Path.Combine(Application.dataPath, "Plugins/Android/AndroidManifest.xml"); + public static void GenerateManifest() + { + // only copy over a fresh copy of the AndroidManifest if one does not exist + if (!File.Exists(outputFile)) + { +#if UNITY_4_5 || UNITY_4_6 || UNITY_5_0 || UNITY_5_1 + var inputFile = Path.Combine(EditorApplication.applicationContentsPath, "PlaybackEngines/androidplayer/AndroidManifest.xml"); +#elif UNITY_5_2 + var inputFile = Path.Combine(EditorApplication.applicationContentsPath, "PlaybackEngines/androidplayer/Apk/AndroidManifest.xml"); +#else + var inputFile = Path.Combine(EditorApplication.applicationPath, "../PlaybackEngines/androidplayer/Apk/AndroidManifest.xml"); +#endif + File.Copy(inputFile, outputFile); + } + UpdateManifest(); + } + + private static string _namespace = ""; + private static XmlDocument _document = null; + private static XmlNode _manifestNode = null; + private static XmlNode _applicationNode = null; + + private static void LoadManifest(){ + _document = new XmlDocument(); + _document.Load(outputFile); + + if (_document == null) + { + Debug.LogError("Couldn't load " + outputFile); + return; + } + + _manifestNode = FindChildNode(_document, "manifest"); + _namespace = _manifestNode.GetNamespaceOfPrefix("android"); + _applicationNode = FindChildNode(_manifestNode, "application"); + + if (_applicationNode == null) { + Debug.LogError("Error parsing " + outputFile); + return; + } + } + + private static void SaveManifest(){ + _document.Save(outputFile); + } + + public static void UpdateManifest() { + LoadManifest (); + + SetPermission("android.permission.INTERNET"); + SetPermission("android.permission.ACCESS_NETWORK_STATE"); + + SaveManifest (); + } + + public static void AddActivity(string activityName, Dictionary attributes) { + AppendApplicationElement("activity", activityName, attributes); + } + + public static void RemoveActivity(string activityName) { + RemoveApplicationElement("activity", activityName); + } + + public static void SetPermission(string permissionName) { + PrependManifestElement("uses-permission", permissionName); + } + + public static void RemovePermission(string permissionName) { + RemoveManifestElement("uses-permission", permissionName); + } + + public static XmlElement AppendApplicationElement(string tagName, string name, Dictionary attributes) { + return AppendElementIfMissing(tagName, name, attributes, _applicationNode); + } + + public static void RemoveApplicationElement(string tagName, string name) { + RemoveElement(tagName, name, _applicationNode); + } + + public static XmlElement PrependManifestElement(string tagName, string name) { + return PrependElementIfMissing(tagName, name, null, _manifestNode); + } + + public static void RemoveManifestElement(string tagName, string name) { + RemoveElement(tagName, name, _manifestNode); + } + + public static XmlElement AddMetaDataTag(string mdName, string mdValue) { + return AppendApplicationElement("meta-data", mdName, new Dictionary() { + { "value", mdValue } + }); + } + + public static XmlElement AppendElementIfMissing(string tagName, string name, Dictionary otherAttributes, XmlNode parent) { + XmlElement e = null; + if (!string.IsNullOrEmpty(name)) { + e = FindElementWithTagAndName(tagName, name, parent); + } + + if (e == null) + { + e = _document.CreateElement(tagName); + if (!string.IsNullOrEmpty(name)) { + e.SetAttribute("name", _namespace, name); + } + + parent.AppendChild(e); + } + + if (otherAttributes != null) { + foreach(string key in otherAttributes.Keys) { + e.SetAttribute(key, _namespace, otherAttributes[key]); + } + } + + return e; + } + + public static XmlElement PrependElementIfMissing(string tagName, string name, Dictionary otherAttributes, XmlNode parent) { + XmlElement e = null; + if (!string.IsNullOrEmpty(name)) { + e = FindElementWithTagAndName(tagName, name, parent); + } + + if (e == null) + { + e = _document.CreateElement(tagName); + if (!string.IsNullOrEmpty(name)) { + e.SetAttribute("name", _namespace, name); + } + + parent.PrependChild(e); + } + + if (otherAttributes != null) { + foreach(string key in otherAttributes.Keys) { + e.SetAttribute(key, _namespace, otherAttributes[key]); + } + } + + return e; + } + + public static void RemoveElement(string tagName, string name, XmlNode parent) { + XmlElement e = FindElementWithTagAndName(tagName, name, parent); + if (e != null) + { + parent.RemoveChild(e); + } + } + + public static XmlNode FindChildNode(XmlNode parent, string tagName) + { + XmlNode curr = parent.FirstChild; + while (curr != null) + { + if (curr.Name.Equals(tagName)) + { + return curr; + } + curr = curr.NextSibling; + } + return null; + } + + public static XmlElement FindChildElement(XmlNode parent, string tagName) + { + XmlNode curr = parent.FirstChild; + while (curr != null) + { + if (curr.Name.Equals(tagName)) + { + return curr as XmlElement; + } + curr = curr.NextSibling; + } + return null; + } + + public static XmlElement FindElementWithTagAndName(string tagName, string name, XmlNode parent) + { + var curr = parent.FirstChild; + while (curr != null) + { + if (curr.Name.Equals(tagName) && curr is XmlElement && ((XmlElement)curr).GetAttribute("name", _namespace) == name) + { + return curr as XmlElement; + } + curr = curr.NextSibling; + } + return null; + } +#endif +} \ No newline at end of file diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/IronSourceAdQualityManifestTools.cs.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/IronSourceAdQualityManifestTools.cs.meta new file mode 100644 index 000000000..5ee9fd248 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/IronSourceAdQualityManifestTools.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 62494cb2550224675873046db8776006 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/ObjectDictionary.cs b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/ObjectDictionary.cs new file mode 100644 index 000000000..5fdda0535 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/ObjectDictionary.cs @@ -0,0 +1,95 @@ +// Copyright (c) 2012 Calvin Rien +// http://the.darktable.com +// +// This software is provided 'as-is', without any express or implied warranty. In +// no event will the authors be held liable for any damages arising from the use +// of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not claim +// that you wrote the original software. If you use this software in a product, +// an acknowledgment in the product documentation would be appreciated but is not +// required. +// +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. + +using UnityEngine; +using System.Collections.Generic; +using System; + +[System.Serializable] +public sealed class ObjectKvp : UnityNameValuePair { + public string value = null; + + override public string Value { + get { return this.value; } + set { this.value = value; } + } + + public ObjectKvp(string key, string value) : base(key, value) { + } +} + +[System.Serializable] +public class ObjectDictionary : UnityDictionary { + public List values; + + override protected List> KeyValuePairs { + get { + if (values == null) { + values = new List(); + } + + List> valuesConverted = new List>(); + foreach (ObjectKvp okvp in values) + { + valuesConverted.Add(ConvertOkvp(okvp)); + } + + return valuesConverted; + } + set { + if (value == null) { + values = new List(); + return; + } + + foreach(UnityKeyValuePair ukvp in value) + { + values.Add(ConvertUkvp(ukvp)); + } + } + } + + public new ObjectKvp ConvertUkvp(UnityKeyValuePair ukvp) + { + return new ObjectKvp(ukvp.Key, ukvp.Value); + + } + public UnityKeyValuePair ConvertOkvp(ObjectKvp okvp) + { + return new UnityKeyValuePair(okvp.Key,okvp.Value); + } + override protected void SetKeyValuePair(string k, string v) { + var index = values.FindIndex(x => { + return x.Key == k;}); + + if (index != -1) { + if (v == null) { + values.RemoveAt(index); + return; + } + + values[index] = new ObjectKvp(k, v); + return; + } + + values.Add(new ObjectKvp(k, v)); + } +} diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/ObjectDictionary.cs.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/ObjectDictionary.cs.meta new file mode 100644 index 000000000..e885618c6 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/ObjectDictionary.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3d242fa04ee9a4fc79ae19ff5a74303d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/UnityDictionary.cs b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/UnityDictionary.cs new file mode 100644 index 000000000..5d36ef0e1 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/UnityDictionary.cs @@ -0,0 +1,317 @@ +// Copyright (c) 2012 Calvin Rien +// http://the.darktable.com +// +// This software is provided 'as-is', without any express or implied warranty. In +// no event will the authors be held liable for any damages arising from the use +// of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not claim +// that you wrote the original software. If you use this software in a product, +// an acknowledgment in the product documentation would be appreciated but is not +// required. +// +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. + +using System.Collections; +using System.Collections.Generic; + +public class UnityNameValuePair : UnityKeyValuePair { + public string name = null; + + override public string Key { + get { return name; } + set { name = value; } + } + + public UnityNameValuePair() : base() { + } + + public UnityNameValuePair(string key, V value) : base(key, value) { + } +} + +public class UnityKeyValuePair { + virtual public K Key { + get; + set; + } + + virtual public V Value { + get; + set; + } + + public UnityKeyValuePair() { + Key = default(K); + Value = default(V); + } + + public UnityKeyValuePair(K key, V value) { + Key = key; + Value = value; + } +} + +public abstract class UnityDictionary : IDictionary { + abstract protected List> KeyValuePairs { + get; + set; + } + + protected abstract void SetKeyValuePair(K k, V v); /* { + var index = Collection.FindIndex(x => {return x.Key == k;}); + + if (index != -1) { + if (v == null) { + Collection.RemoveAt(index); + return; + } + + values[index] = new UnityKeyValuePair(key, value); + return; + } + + values.Add(new UnityKeyValuePair(key, value)); +} */ + + virtual public V this[K key] { + get { + var result = KeyValuePairs.Find(x => { + return x.Key.Equals(key);}); + + if (result == null) { + return default(V); + } + + return result.Value; + } + set { + if (key == null) { + return; + } + + SetKeyValuePair(key, value); + } + } + + #region IDictionary interface + + public void Add(K key, V value) { + this[key] = value; + } + + public void Add(KeyValuePair kvp) { + this[kvp.Key] = kvp.Value; + } + + public bool TryGetValue(K key, out V value) { + if (!this.ContainsKey(key)) { + value = default(V); + return false; + } + + value = this[key]; + return true; + } + + public bool Remove(KeyValuePair item) { + return Remove(item.Key); + } + + public bool Remove(K key) { + var list = KeyValuePairs; + + var index = list.FindIndex(x => { + return x.Key.Equals(key);}); + + if (index == -1) { + return false; + } + + list.RemoveAt(index); + + KeyValuePairs = list; + + return true; + } + + public void Clear() { + var list = KeyValuePairs; + + list.Clear(); + + KeyValuePairs = list; + } + + public bool ContainsKey(K key) { + return KeyValuePairs.FindIndex(x => { + return x.Key.Equals(key);}) != -1; + } + + public bool Contains(KeyValuePair kvp) { + return this[kvp.Key].Equals(kvp.Value); + } + + public int Count { + get { + return KeyValuePairs.Count; + } + } + + public void CopyTo(KeyValuePair[] array, int index) { + List> copy = new List>(); + for (int i = 0; i < KeyValuePairs.Count;i++) + { + copy[i] = ConvertUkvp(KeyValuePairs[i]); + } + copy.CopyTo(array, index); + } + + public KeyValuePair ConvertUkvp(UnityKeyValuePair ukvp) + { + return new KeyValuePair(ukvp.Key,(V)ukvp.Value); + } + + IEnumerator IEnumerable.GetEnumerator() { + return GetEnumerator() as IEnumerator; + } + + public IEnumerator> GetEnumerator() { + return new UnityDictionaryEnumerator(this); + } + + public ICollection Keys { + get { + ICollection keys = new List(); + foreach(UnityKeyValuePair ukvp in KeyValuePairs) + { + keys.Add(ukvp.Key); + } + return keys; + } + } + + public ICollection Values { + get { + ICollection values = new List(); + foreach (UnityKeyValuePair ukvp in KeyValuePairs) + { + values.Add(ukvp.Value); + } + return values; + } + } + + public ICollection> Items { + get { + List> items = new List>(); + foreach(UnityKeyValuePair value in KeyValuePairs) + { + items.Add(new KeyValuePair(value.Key, value.Value)); + } + return items; + } + } + + public V SyncRoot { + get { return default(V); } + } + + public bool IsFixedSize { + get { return false; } + } + + public bool IsReadOnly { + get { return false; } + } + + public bool IsSynchronized { + get { return false; } + } + + internal sealed class UnityDictionaryEnumerator : IEnumerator> { + // A copy of the SimpleDictionary T's key/value pairs. + KeyValuePair[] items; + int index = -1; + + internal UnityDictionaryEnumerator() { + } + + internal UnityDictionaryEnumerator(UnityDictionary ud) { + // Make a copy of the dictionary entries currently in the SimpleDictionary T. + items = new KeyValuePair[ud.Count]; + + ud.CopyTo(items, 0); + } + + object IEnumerator.Current { + get { return Current; } + } + + public KeyValuePair Current { + get { + ValidateIndex(); + return items[index]; + } + } + + // Return the current dictionary entry. + public KeyValuePair Entry { + get { return (KeyValuePair) Current; } + } + + public void Dispose() { + index = -1; + items = null; + } + + // Return the key of the current item. + public K Key { + get { + ValidateIndex(); + return items[index].Key; + } + } + + // Return the value of the current item. + public V Value { + get { + ValidateIndex(); + return items[index].Value; + } + } + + // Advance to the next item. + public bool MoveNext() { + if (index < items.Length - 1) { + index++; + return true; + } + return false; + } + + // Validate the enumeration index and throw an exception if the index is out of range. + private void ValidateIndex() { + if (index < 0 || index >= items.Length) { + throw new System.InvalidOperationException("Enumerator is before or after the collection."); + } + } + + // Reset the index to restart the enumeration. + public void Reset() { + index = -1; + } + #endregion + } +} + +public abstract class UnityDictionary : UnityDictionary { + +} diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/UnityDictionary.cs.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/UnityDictionary.cs.meta new file mode 100644 index 000000000..aa9a1cf39 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Config/UnityDictionary.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2b3aeeb1755c04e6f80ffb1e982537f5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons.meta new file mode 100644 index 000000000..2c212f28b --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 221bee1d14f6b4afaa10e6a0915411ba +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/BaseBehaviour.cs b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/BaseBehaviour.cs new file mode 100644 index 000000000..9187b60d7 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/BaseBehaviour.cs @@ -0,0 +1,16 @@ +using UnityEngine; + +public abstract class BaseBehaviour : MonoBehaviour +{ + private Transform cashedTransform; + public Transform CachedTransform + { + get { return cashedTransform ?? (cashedTransform = transform); } + } + + protected virtual void Awake() { } + + protected virtual void Start() { } + + protected virtual void OnDestroy() { } +} \ No newline at end of file diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/BaseBehaviour.cs.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/BaseBehaviour.cs.meta new file mode 100644 index 000000000..9206c781f --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/BaseBehaviour.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 80937c3c4170b4ff59501e589794ddca +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/CodeGeneratedSingleton.cs b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/CodeGeneratedSingleton.cs new file mode 100644 index 000000000..7042d7a85 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/CodeGeneratedSingleton.cs @@ -0,0 +1,17 @@ +#pragma warning disable 618 +/// +/// A Singleton for use when your component needs to be accessed at any given (run)time and can be automagically created on demand. +/// To use, override and write your initialization logic. +/// If your singleton shouldn't be destroyed when moving between scenes (), +/// Override and return true. +/// Like this: +/// +/// protected override bool DontDestroySingleton +/// { +/// get { return true; } +/// } +/// +/// +public abstract class CodeGeneratedSingleton : UnitySingleton +{ +} \ No newline at end of file diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/CodeGeneratedSingleton.cs.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/CodeGeneratedSingleton.cs.meta new file mode 100644 index 000000000..ef9a1c1b2 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/CodeGeneratedSingleton.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1a0aa54a1a93447f6a59f4a1534ecbe7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/SceneSingleton.cs b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/SceneSingleton.cs new file mode 100644 index 000000000..f1ce535ed --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/SceneSingleton.cs @@ -0,0 +1,17 @@ +#pragma warning disable 618 +/// +/// A Singleton for use when your component needs to be blaced in a scene on design time. +/// To use, override and write your initialization logic. +/// If your singleton shouldn't be destroyed when moving between scenes (), +/// Override and return true. +/// Like this: +/// +/// protected override bool DontDestroySingleton +/// { +/// get { return true; } +/// } +/// +/// +public abstract class SceneSingleton : UnitySingleton +{ +} \ No newline at end of file diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/SceneSingleton.cs.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/SceneSingleton.cs.meta new file mode 100644 index 000000000..a1248f990 --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/SceneSingleton.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2b330e7d866904612b12283dfae41b84 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/UnitySingleton.cs b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/UnitySingleton.cs new file mode 100644 index 000000000..3e6111e9b --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/UnitySingleton.cs @@ -0,0 +1,271 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; + +public abstract class UnitySingleton : BaseBehaviour +{ + #region Private Variables + private static readonly Dictionary instances = new Dictionary(); + private static readonly Dictionary>> instanceListeners = + new Dictionary>>(); + #endregion + + #region Private Properties + protected bool IsInstanceReady { get; private set; } + #endregion + + #region Private Functions + private void RegisterAsSingleInstanceAndInit() + { + instances.Add(GetType(), this); + InnerInit(); + } + + private void InnerInit() + { + InitAfterRegisteringAsSingleInstance(); + + if (DontDestroySingleton) + { + DontDestroyOnLoad(gameObject); + } + } + + private static S GetOrCreateInstanceOnGameObject(Type type) where S : CodeGeneratedSingleton + { + S instance = null; + + var prefab = Resources.Load(type.Name); + + if (prefab) + { + var instantiatedObject = Instantiate(prefab) +#if !UNITY_5 + as GameObject +#endif + ; + + if (!instantiatedObject) + { + throw new Exception("Failed to instantiate prefab: " + type.Name); + } + + instance = instantiatedObject.GetComponent(); + + if (!instance) + { + instance = instantiatedObject.AddComponent(); + } + } + + if (!instance) + { + instance = new GameObject(type.Name).AddComponent(); + } + + return instance; + } + + private void NotifyInstanceListeners() + { + var type = GetType(); + + // Checks if there are any registered listeners for this type of singleton + if (instanceListeners.ContainsKey(type)) + { + foreach (var actionWithSender in instanceListeners[type].ToArray()) + { + // If the sender is alive and has listeners - run its actions + if (actionWithSender.Key && actionWithSender.Value != null) + { + actionWithSender.Value(this); + } + + // Either way - remove the sender + action from the collection + instanceListeners[type].Remove(actionWithSender.Key); + } + } + } + + protected void DeclareAsReady() + { + IsInstanceReady = true; + + NotifyInstanceListeners(); + } + #endregion + + #region Public Functions + protected static S GetSynchronousCodeGeneratedInstance() where S : CodeGeneratedSingleton + { + var type = typeof(S); + + S instance; + + // An instance of this type does not exist + if (!instances.ContainsKey(type)) + { + // Try to find an existing one in the scene + instance = FindObjectOfType(); + + if (!instance) + { + // Creating a new one + instance = GetOrCreateInstanceOnGameObject(type); + } + + instance.RegisterAsSingleInstanceAndInit(); + } + // An instance of this type already exists + else + { + instance = instances[type] as S; + } + + if (!instance) + { + throw new Exception("No instance was created: " + type.Name); + } + + instance.IsInstanceReady = true; + + return instance; + } + + public static void DoWithCodeGeneratedInstance(MonoBehaviour sender, Action whatToDoWithInstanceWhenItsReady) where C : CodeGeneratedSingleton + { + // Make sure an instance exists (creating it if it doesn't) + GetSynchronousCodeGeneratedInstance(); + + // Do the action with the existing instance or wait for it to be ready + DoWithExistingInstance(sender, whatToDoWithInstanceWhenItsReady); + } + + public static void DoWithSceneInstance(MonoBehaviour sender, Action whatToDoWithInstanceWhenItsReady) where S : SceneSingleton + { + DoWithExistingInstance(sender, whatToDoWithInstanceWhenItsReady); + } + + /// + /// Performs an action on an existing instance if and when it exists and ready + /// + /// + /// + /// + private static void DoWithExistingInstance(MonoBehaviour sender, Action whatToDoWithInstanceWhenItsReady) where S : UnitySingleton + { + var type = typeof(S); + + var isInstanceNotExistOrReady = true; + + // An instance of this type exists + if (instances.ContainsKey(type)) + { + var instance = instances[type] as S; + + if (instance && instance.IsInstanceReady) + { + isInstanceNotExistOrReady = false; + + // Call the action with the existing instance + whatToDoWithInstanceWhenItsReady(instance); + } + } + + // An instance of this type does not exist, we have to wait for it to initialize + if (isInstanceNotExistOrReady) + { + if (!instanceListeners.ContainsKey(type)) + { + instanceListeners.Add(type, new Dictionary>()); + } + + if (!instanceListeners[type].ContainsKey(sender)) + { + instanceListeners[type].Add(sender, null); + } + + instanceListeners[type][sender] += singleton => whatToDoWithInstanceWhenItsReady(singleton as S); + } + } + #endregion + + #region Unity Functions + protected sealed override void Start() + { + base.Start(); + + var type = GetType(); + + var needToDestroy = false; + + // There's already an instance of my type + if (instances.ContainsKey(type)) + { + // The existing instance is not this instance so we've got a conflict (There can only be one!) + if (instances[type] != this) + { + if (this is CodeGeneratedSingleton) + { + throw new Exception("There's already an instance for " + type.Name); + } + + if (this is SceneSingleton) + { + if (DontDestroySingleton) + { + // [this] is not the single instance (Singleton) so we actually DO need to destroy it + needToDestroy = true; + } + } + } + } + // There's no instance of my type and I'm a CodeGeneratedSingleton + // It should have been created via code so if I don't exist in the instance collection it means I was created on a scene + else if (this is CodeGeneratedSingleton) + { + throw new NotSupportedException(string.Format("{0} is a {1} and needs to be created via code, and not placed on a scene!", type.Name, typeof(CodeGeneratedSingleton).Name)); + } + + if (needToDestroy) + { + Debug.LogWarning(string.Format("There's already a {0} instance on the current scene, there's no point in staying.. goodbye.. I'm gonna go now :(", type.Name)); + + Destroy(this); + } + else if (this is SceneSingleton) + { + RegisterAsSingleInstanceAndInit(); + + SetReadyAndNotifyAfterRegistering(); + } + } + + /// + /// Override this if the singleton won't be ready immediately after registering as single instance + /// + protected virtual void SetReadyAndNotifyAfterRegistering() + { + DeclareAsReady(); + } + + protected override void OnDestroy() + { + base.OnDestroy(); + + var type = GetType(); + + // There's already an instance of my type but it's me - remove me + if (instances.ContainsKey(type) && instances[type] == this) + { + instances.Remove(type); + } + } + #endregion + + #region Virtuals + protected virtual void InitAfterRegisteringAsSingleInstance() { } + protected virtual bool DontDestroySingleton { get { return false; } } + #endregion +} \ No newline at end of file diff --git a/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/UnitySingleton.cs.meta b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/UnitySingleton.cs.meta new file mode 100644 index 000000000..14328736f --- /dev/null +++ b/Assets/ThirdParty/IronSourceAdQuality/Scripts/Singletons/UnitySingleton.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ac12af7b0ebf6409c935fad7857982be +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: