diff --git a/com.adsbynimbus.nimbus/Editor/AndroidBuildDependencies.cs b/com.adsbynimbus.nimbus/Editor/AndroidBuildDependencies.cs index ff2dec86..f06f6e84 100644 --- a/com.adsbynimbus.nimbus/Editor/AndroidBuildDependencies.cs +++ b/com.adsbynimbus.nimbus/Editor/AndroidBuildDependencies.cs @@ -13,5 +13,15 @@ public static string APSBuildDependencies() { builder.AppendLine("}"); return builder.ToString(); } + + public static string VungleBuildDependencies() { + var builder = new StringBuilder(); + + builder.AppendLine(""); + builder.AppendLine("dependencies {"); + builder.AppendLine($@"implementation ""com.adsbynimbus.android:extension-vungle:{SdkVersion}"""); + builder.AppendLine("}"); + return builder.ToString(); + } } } \ No newline at end of file diff --git a/com.adsbynimbus.nimbus/Editor/AndroidPostBuildProcessor.cs b/com.adsbynimbus.nimbus/Editor/AndroidPostBuildProcessor.cs index c424de3e..28487386 100644 --- a/com.adsbynimbus.nimbus/Editor/AndroidPostBuildProcessor.cs +++ b/com.adsbynimbus.nimbus/Editor/AndroidPostBuildProcessor.cs @@ -44,10 +44,18 @@ public void OnPostGenerateGradleAndroidProject(string path) { #if NIMBUS_ENABLE_APS var apsDependencies = AndroidBuildDependencies.APSBuildDependencies(); - var buildWriter = File.AppendText(path + "/build.gradle"); - buildWriter.WriteLine(apsDependencies); - buildWriter.Flush(); - buildWriter.Close(); + var apsBuildWriter = File.AppendText(path + "/build.gradle"); + apsBuildWriter.WriteLine(apsDependencies); + apsBuildWriter.Flush(); + apsBuildWriter.Close(); + #endif + + #if NIMBUS_ENABLE_VUNGLE + var vungleDependencies = AndroidBuildDependencies.VungleBuildDependencies(); + var vunlgeBuildWriter = File.AppendText(path + "/build.gradle"); + vunlgeBuildWriter.WriteLine(vungleDependencies); + vunlgeBuildWriter.Flush(); + vunlgeBuildWriter.Close(); #endif } diff --git a/com.adsbynimbus.nimbus/Editor/IOSPostBuildProcessor.cs b/com.adsbynimbus.nimbus/Editor/IOSPostBuildProcessor.cs index 93d394e6..056b87bc 100644 --- a/com.adsbynimbus.nimbus/Editor/IOSPostBuildProcessor.cs +++ b/com.adsbynimbus.nimbus/Editor/IOSPostBuildProcessor.cs @@ -26,22 +26,20 @@ private static void PostProcessBuild_iOS(BuildTarget target, string buildPath) #if NIMBUS_ENABLE_APS Dependencies.Add("'NimbusRequestAPSKit'"); #endif + #if NIMBUS_ENABLE_VUNGLE + Dependencies.Add("'NimbusVungleKit'"); + #endif var path = buildPath + "/Podfile"; - FileStream fileStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); using (StreamReader sr = new StreamReader(fileStream)) + var lines = File.ReadAllLines(path); + for(int i = 0 ; i < lines.Length ; i++) { - using (StreamWriter sw = new StreamWriter(fileStream)) + if (lines[i].ToLower().Contains("nimbus")) { - var line = ""; - while ((line = sr.ReadLine()) != null) - { - if (line.ToLower().Contains("nimbus")) - { - sw.WriteLine($"{line}, subspecs: [{string.Join(", ", Dependencies)}]"); - } - } + lines[i] = ($"{lines[i]}, subspecs: [{string.Join(", ", Dependencies)}]"); } } + File.WriteAllLines(path, lines); } } } @@ -62,6 +60,14 @@ public static void OnPostprocessBuild(BuildTarget target, string path) { // Enable MACRO for C++ code pbx.SetBuildProperty(projectGuid, "GCC_PREPROCESSOR_DEFINITIONS", "NIMBUS_ENABLE_APS"); #endif + + #if NIMBUS_ENABLE_VUNGLE + var projectGuid = pbx.ProjectGuid(); + // Enable MACRO for Swift code + pbx.SetBuildProperty(projectGuid, "SWIFT_ACTIVE_COMPILATION_CONDITIONS", "NIMBUS_ENABLE_VUNGLE"); + // Enable MACRO for C++ code + pbx.SetBuildProperty(projectGuid, "GCC_PREPROCESSOR_DEFINITIONS", "NIMBUS_ENABLE_VUNGLE"); + #endif // Unity-IPhone var targetGuid = pbx.GetUnityMainTargetGuid(); diff --git a/com.adsbynimbus.nimbus/Editor/NimbusManagerCreator.cs b/com.adsbynimbus.nimbus/Editor/NimbusManagerCreator.cs index 0c4fbb13..d71526f9 100644 --- a/com.adsbynimbus.nimbus/Editor/NimbusManagerCreator.cs +++ b/com.adsbynimbus.nimbus/Editor/NimbusManagerCreator.cs @@ -32,8 +32,12 @@ public class NimbusManagerCreator : EditorWindow { private SerializedProperty _iosAppId; private ReorderableList _iosApsSlotIdList = null; private SerializedProperty _iosApsSlots = null; - - + + // Vungle + private SerializedProperty _androidVungleAppId; + + private SerializedProperty _iosVungleAppId; + [MenuItem("Nimbus/Create New NimbusAdsManager")] public static void CreateNewNimbusGameManager() { GetWindow("NimbusAdsManager Creator"); @@ -73,6 +77,13 @@ private void OnEnable() { _iosApsSlotIdList.elementHeight = 10 * EditorGUIUtility.singleLineHeight; _iosApsSlotIdList.headerHeight = 0f; _iosApsSlotIdList.drawElementCallback += OnDrawElementIosApsSlotData; + + // Vungle + // Android Vungle UI + _androidVungleAppId = serializedObject.FindProperty("androidVungleAppID"); + + // IOS Vungle UI + _iosVungleAppId = serializedObject.FindProperty("iosVungleAppID"); } @@ -132,9 +143,12 @@ private void OnGUI() { var headerStyle = EditorStyles.largeLabel; headerStyle.fontStyle = FontStyle.Bold; + + #if NIMBUS_ENABLE_APS || NIMBUS_ENABLE_VUNGLE + EditorGUILayout.LabelField("Third Party SDK Support", headerStyle); + #endif #if NIMBUS_ENABLE_APS - EditorGUILayout.LabelField("Third Party SDK Support", headerStyle); EditorDrawUtility.DrawEditorLayoutHorizontalLine(Color.gray, 2); GUILayout.Space(10); EditorGUILayout.LabelField("APS Configuration", headerStyle); @@ -154,6 +168,25 @@ private void OnGUI() { EditorGUILayout.HelpBox("In build settings select Android or IOS to enter APS data", MessageType.Warning); #endif #endif + + #if NIMBUS_ENABLE_VUNGLE + EditorDrawUtility.DrawEditorLayoutHorizontalLine(Color.gray, 2); + GUILayout.Space(10); + EditorGUILayout.LabelField("Vungle Configuration", headerStyle); + #if UNITY_ANDROID + EditorGUILayout.PropertyField((_androidVungleAppId)); + EditorDrawUtility.DrawEditorLayoutHorizontalLine(Color.gray); + #endif + + #if UNITY_IOS + EditorGUILayout.PropertyField((_iosVungleAppId)); + EditorDrawUtility.DrawEditorLayoutHorizontalLine(Color.gray); + #endif + + #if !UNITY_ANDROID && !UNITY_IOS + EditorGUILayout.HelpBox("In build settings select Android or IOS to enter Vungle data", MessageType.Warning); + #endif + #endif // ReSharper disable InvertIf if (GUILayout.Button("Create")) { @@ -184,6 +217,12 @@ private void OnGUI() { return; } #endif + + #if NIMBUS_ENABLE_VUNGLE + if (!ValidateVungleData()) { + return; + } + #endif AssetDatabase.CreateAsset(_asset, "Packages/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.ScriptableObjects/NimbusSDKConfiguration.asset"); @@ -289,6 +328,23 @@ private bool ValidateApsData() { } return true; } + + private bool ValidateVungleData() { + string appId = null; + #if UNITY_ANDROID + appId = _androidVungleAppId.stringValue; + #elif UNITY_IOS + appId = _iosVungleAppId.stringValue; + #endif + + if (appId.IsNullOrEmpty()) { + Debug.unityLogger.LogError("Nimbus", + "Vungle SDK has been included, the Vungle App ID cannot be empty, object NimbusAdsManager not created"); + return false; + } + ApsSlotData[] slotData = null; + return true; + } } } #endif \ No newline at end of file diff --git a/com.adsbynimbus.nimbus/Editor/ThirdPartyMacros.cs b/com.adsbynimbus.nimbus/Editor/ThirdPartyMacros.cs index 1fe538b2..9022363f 100644 --- a/com.adsbynimbus.nimbus/Editor/ThirdPartyMacros.cs +++ b/com.adsbynimbus.nimbus/Editor/ThirdPartyMacros.cs @@ -9,11 +9,15 @@ namespace Nimbus.Editor { public class ThirdPartyMacros : EditorWindow { private bool _androidApsIsEnabled; private bool _iosApsIsEnabled; - + private bool _androidVungleIsEnabled; + private bool _iosVungleIsEnabled; private const string ApsMacro = "NIMBUS_ENABLE_APS"; + private const string VungleMacro = "NIMBUS_ENABLE_VUNGLE"; private const string Enabled = "Enabled"; private const string Disabled = "Disabled"; private const string ButtonMessageTemplate = @"{0} {1} Build Macro For {2}?"; + private const string ApsPartnerStr = "APS"; + private const string VunglePartnerStr = "Vungle"; private void OnEnable() { UpdateSettings(); @@ -52,7 +56,7 @@ private void OnGUI() { SetBuildMacroForGroup(BuildTargetGroup.Android, ApsMacro); EditorUtil.LogWithHelpBox("Don't Forget To Add your Android APS App Ids and APS Slot Ids to the " + "NimbusSDKConfiguration Scriptable object attached to your NimbusAdManager game object", MessageType.Warning); - FocusOnGameManager(); + FocusOnGameManager(ApsPartnerStr); } } @@ -72,10 +76,58 @@ private void OnGUI() { SetBuildMacroForGroup(BuildTargetGroup.iOS, ApsMacro); EditorUtil.LogWithHelpBox("Don't Forget To Add your IOS APS App Ids and APS Slot Ids to the " + "NimbusSDKConfiguration Scriptable object attached to your NimbusAdManager game object", MessageType.Warning); - FocusOnGameManager(); + FocusOnGameManager(ApsPartnerStr); } } // END OF APS + + GUILayout.Space(10); + EditorDrawUtility.DrawEditorLayoutHorizontalLine(Color.gray, 2); + + // START OF VUNGLE + EditorGUILayout.LabelField("Vungle Build Macro Settings:", headerStyle); + EditorDrawUtility.DrawEditorLayoutHorizontalLine(Color.gray, 2); + GUILayout.Space(10); + + var vungleAndroidStatus = _androidVungleIsEnabled ? Enabled : Disabled; + EditorGUILayout.LabelField($"Macro is set for Android is: {vungleAndroidStatus}", headerStyle); + GUILayout.Space(2); + var androidVunglebuttonText = _androidVungleIsEnabled + ? string.Format(ButtonMessageTemplate, "Remove", "Vungle", "Android") + : string.Format(ButtonMessageTemplate, "Enable", "Vungle", "Android"); + if (GUILayout.Button(androidVunglebuttonText)) { + if (_androidVungleIsEnabled) { + RemoveBuildMacroForGroup(BuildTargetGroup.Android, VungleMacro); + } + else { + SetBuildMacroForGroup(BuildTargetGroup.Android, VungleMacro); + EditorUtil.LogWithHelpBox("Don't Forget To Add your Android Vungle App Id to the " + + "NimbusSDKConfiguration Scriptable object attached to your NimbusAdManager game object", MessageType.Warning); + FocusOnGameManager(VunglePartnerStr); + } + } + + GUILayout.Space(5); + + var vungleIosStatus = _iosVungleIsEnabled ? Enabled : Disabled; + EditorGUILayout.LabelField($"Macro is set for Ios is: {vungleIosStatus}", headerStyle); + GUILayout.Space(2); + var vungleAndroidButtonText = _iosVungleIsEnabled + ? string.Format(ButtonMessageTemplate, "Remove", "Vungle", "Ios") + : string.Format(ButtonMessageTemplate, "Enable", "Vungle", "Ios"); + if (GUILayout.Button(vungleAndroidButtonText)) { + if (_iosVungleIsEnabled) { + RemoveBuildMacroForGroup(BuildTargetGroup.iOS, VungleMacro); + } + else { + SetBuildMacroForGroup(BuildTargetGroup.iOS, VungleMacro); + EditorUtil.LogWithHelpBox("Don't Forget To Add your IOS Vungle App Id to the " + + "NimbusSDKConfiguration Scriptable object attached to your NimbusAdManager game object", MessageType.Warning); + FocusOnGameManager(VunglePartnerStr); + } + } + // END OF VUNGLE + GUILayout.Space(10); EditorDrawUtility.DrawEditorLayoutHorizontalLine(Color.gray, 2); } @@ -87,6 +139,8 @@ private void OnInspectorUpdate() { private void UpdateSettings() { _androidApsIsEnabled = IsBuildMacroSet(BuildTargetGroup.Android, ApsMacro); _iosApsIsEnabled = IsBuildMacroSet(BuildTargetGroup.iOS, ApsMacro); + _androidVungleIsEnabled = IsBuildMacroSet(BuildTargetGroup.Android, VungleMacro); + _iosVungleIsEnabled = IsBuildMacroSet(BuildTargetGroup.iOS, VungleMacro); } @@ -111,13 +165,13 @@ private static void RemoveBuildMacroForGroup(BuildTargetGroup group, string buil PlayerSettings.SetScriptingDefineSymbolsForGroup(group, macros.ToArray()); } - private static void FocusOnGameManager() { + private static void FocusOnGameManager(string partner) { var manager = FindObjectOfType(); if (manager != null) { Selection.activeGameObject = manager.gameObject; } else { - EditorUtil.LogWithHelpBox("APS was enabled however there is no NimbusAdManager located in your scene, " + + EditorUtil.LogWithHelpBox($"{partner} was enabled however there is no NimbusAdManager located in your scene, " + "please add a NimbusGameManager to you scene. In the ToolBar Go to Nimbus -> Create New NimbusAdManager", MessageType.Error); } diff --git a/com.adsbynimbus.nimbus/Runtime/Plugins/RTB/Request/User.cs b/com.adsbynimbus.nimbus/Runtime/Plugins/RTB/Request/User.cs index 3600bb3b..cecea075 100644 --- a/com.adsbynimbus.nimbus/Runtime/Plugins/RTB/Request/User.cs +++ b/com.adsbynimbus.nimbus/Runtime/Plugins/RTB/Request/User.cs @@ -33,5 +33,8 @@ public class UserExt { [JsonProperty("eids", DefaultValueHandling = DefaultValueHandling.Ignore)] public Eid[] Eids; + + [JsonProperty("vungle_buyeruid", DefaultValueHandling = DefaultValueHandling.Ignore)] + public string VungleBuyerId; } } diff --git a/com.adsbynimbus.nimbus/Runtime/Plugins/RTB/Response/BidResponse.cs b/com.adsbynimbus.nimbus/Runtime/Plugins/RTB/Response/BidResponse.cs index 4404eb99..598cbfd7 100644 --- a/com.adsbynimbus.nimbus/Runtime/Plugins/RTB/Response/BidResponse.cs +++ b/com.adsbynimbus.nimbus/Runtime/Plugins/RTB/Response/BidResponse.cs @@ -32,6 +32,9 @@ public struct BidResponse { [JsonProperty("placement_id", DefaultValueHandling = DefaultValueHandling.Ignore)] public string PlacementId; + + [JsonProperty("exp", DefaultValueHandling = DefaultValueHandling.Ignore)] + public int Exp; [JsonProperty("duration", DefaultValueHandling = DefaultValueHandling.Ignore)] public int Duration; diff --git a/com.adsbynimbus.nimbus/Runtime/Plugins/iOS/NimbusBinding.mm b/com.adsbynimbus.nimbus/Runtime/Plugins/iOS/NimbusBinding.mm index 383ce52b..11e84adb 100644 --- a/com.adsbynimbus.nimbus/Runtime/Plugins/iOS/NimbusBinding.mm +++ b/com.adsbynimbus.nimbus/Runtime/Plugins/iOS/NimbusBinding.mm @@ -108,4 +108,15 @@ void _addAPSSlot(const char* slotUUID, int width, int height, bool isVideo) { return strdup([[NimbusManager fetchAPSParamsWithWidth: width height:height includeVideo:includeVideo] UTF8String]); } #endif + +#if NIMBUS_ENABLE_VUNGLE + void _initializeVungle(const char* appKey) { + [NimbusManager initializeVungleWithAppKey: GetStringParam(appKey)]; + } + + const char* _fetchVungleBuyerId() { + return strdup([[NimbusManager fetchVungleBuyerId] UTF8String]); + } + +#endif } \ No newline at end of file diff --git a/com.adsbynimbus.nimbus/Runtime/Plugins/iOS/NimbusManager.swift b/com.adsbynimbus.nimbus/Runtime/Plugins/iOS/NimbusManager.swift index 15739642..86643558 100644 --- a/com.adsbynimbus.nimbus/Runtime/Plugins/iOS/NimbusManager.swift +++ b/com.adsbynimbus.nimbus/Runtime/Plugins/iOS/NimbusManager.swift @@ -13,6 +13,10 @@ import NimbusKit #if NIMBUS_ENABLE_APS import NimbusRequestAPSKit #endif +#if NIMBUS_ENABLE_VUNGLE +import VungleAdsSDK +import NimbusSDK +#endif @objc public class NimbusManager: NSObject { @@ -23,6 +27,8 @@ import NimbusRequestAPSKit private var adController: AdController? private var adView: NimbusAdView? private var nimbusAdVC: NimbusAdViewController? + private lazy var thirdPartyInterstitialAdManager = ThirdPartyInterstitialAdManager() + private var thirdPartyInterstitialAdController: AdController? #if NIMBUS_ENABLE_APS private static var apsRequestHelper: NimbusAPSRequestHelper? @@ -72,6 +78,19 @@ import NimbusRequestAPSKit } #endif + #if NIMBUS_ENABLE_VUNGLE + @objc public class func initializeVungle(appKey: String) { + print("appkey is: \(appKey)") + let vungleRequestInterceptor = NimbusVungleRequestInterceptor(appId: "65eb251c96ec25b72d8e09f7") + NimbusRequestManager.requestInterceptors?.append(vungleRequestInterceptor) + Nimbus.shared.renderers = [.forNetwork("vungle"): NimbusVungleAdRenderer()] + } + + @objc public class func fetchVungleBuyerId() -> String { + return VungleAds.getBiddingToken() + } + #endif + // MARK: - Private Functions private init(adUnitInstanceId: Int) { @@ -112,23 +131,38 @@ import NimbusRequestAPSKit companionAd = NimbusCompanionAd(width: 320, height: 480, renderMode: .endCard) } - nimbusAdVC = NimbusAdViewController( - adView: adView, - ad: nimbusAd, - companionAd: companionAd, - closeButtonDelay: closeButtonDelay, - isRewardedAd: isRewarded - ) - guard let nimbusAdVC = nimbusAdVC else { return } - - // Instead of the VC sent in by the publisher, we are creating the blocking VC here - adView.adPresentingViewController = nimbusAdVC - nimbusAdVC.modalPresentationStyle = .fullScreen - nimbusAdVC.delegate = self - - viewController.present(nimbusAdVC, animated: true) - - nimbusAdVC.renderAndStart() + if ThirdPartyDemandNetwork.exists(for: nimbusAd) { + thirdPartyInterstitialAdController = try? thirdPartyInterstitialAdManager.render( + ad: nimbusAd, + adPresentingViewController: viewController, + companionAd: companionAd + ) + guard let thirdPartyInterstitialAdController else { + Nimbus.shared.logger.log("Unable to render ad for network: \(nimbusAd.network)", level: .error) + return + } + + thirdPartyInterstitialAdController.delegate = self + thirdPartyInterstitialAdController.start() + } else { + nimbusAdVC = NimbusAdViewController( + adView: adView, + ad: nimbusAd, + companionAd: companionAd, + closeButtonDelay: closeButtonDelay, + isRewardedAd: isRewarded + ) + guard let nimbusAdVC = nimbusAdVC else { return } + + // Instead of the VC sent in by the publisher, we are creating the blocking VC here + adView.adPresentingViewController = nimbusAdVC + nimbusAdVC.modalPresentationStyle = .fullScreen + nimbusAdVC.delegate = self + + viewController.present(nimbusAdVC, animated: true) + + nimbusAdVC.renderAndStart() + } UnityBinding.sendMessage(methodName: "OnAdRendered", params: ["adUnitInstanceID": adUnitInstanceId]) } else { diff --git a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Android.cs b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Android.cs index d42f1143..be27502d 100644 --- a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Android.cs +++ b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Android.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using Nimbus.Internal.Interceptor; using Nimbus.Internal.Interceptor.ThirdPartyDemand; +using Nimbus.Internal.Interceptor.ThirdPartyDemand.Vungle; using Nimbus.Internal.Utility; using Nimbus.ScriptableObjects; using OpenRTB.Enumerations; @@ -60,6 +61,15 @@ internal override void InitializeSDK(NimbusSDKConfiguration configuration) { aps.InitializeNativeSDK(); _interceptors.Add(aps); #endif + + #if NIMBUS_ENABLE_VUNGLE + var vungleAppId = configuration.GetVungleData(); + var applicationContext = _currentActivity.Call("getApplicationContext"); + Debug.unityLogger.Log(vungleAppId); + var vungle = new VungleAndroid(applicationContext, vungleAppId); + vungle.InitializeNativeSDK(); + _interceptors.Add(vungle); + #endif } diff --git a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/IOS.cs b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/IOS.cs index 2c970030..b3dba423 100644 --- a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/IOS.cs +++ b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/IOS.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using Nimbus.Internal.Interceptor; -using Nimbus.Internal.Interceptor.ThirdPartyDemand; +using Nimbus.Internal.Interceptor.ThirdPartyDemand.Vungle; using Nimbus.ScriptableObjects; using OpenRTB.Enumerations; using OpenRTB.Request; @@ -102,6 +102,13 @@ internal override void InitializeSDK(NimbusSDKConfiguration configuration) { aps.InitializeNativeSDK(); _interceptors.Add(aps); #endif + #if NIMBUS_ENABLE_VUNGLE + Debug.unityLogger.Log("Initializing iOS Vungle SDK"); + var appID = configuration.GetVungleData(); + var vungle = new VungleIOS(appID); + vungle.InitializeNativeSDK(); + _interceptors.Add(vungle); + #endif } internal override void ShowAd(NimbusAdUnit nimbusAdUnit) { diff --git a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/ApsAndroid.cs b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/APS/ApsAndroid.cs similarity index 100% rename from com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/ApsAndroid.cs rename to com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/APS/ApsAndroid.cs diff --git a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/ApsIOS.cs b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/APS/ApsIOS.cs similarity index 98% rename from com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/ApsIOS.cs rename to com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/APS/ApsIOS.cs index 95b614f9..2ae85d3b 100644 --- a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/ApsIOS.cs +++ b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/APS/ApsIOS.cs @@ -7,7 +7,7 @@ using UnityEngine; [assembly: InternalsVisibleTo("nimbus.test")] -namespace Nimbus.Internal.Interceptor.ThirdPartyDemand { +namespace Nimbus.Internal.Interceptor.ThirdPartyDemand.APS { #if UNITY_IOS && NIMBUS_ENABLE_APS internal class ApsIOS : IInterceptor, IProvider { private readonly string _appID; diff --git a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/ApsSlotData.cs b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/APS/ApsSlotData.cs similarity index 100% rename from com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/ApsSlotData.cs rename to com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/APS/ApsSlotData.cs diff --git a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/ApsAndroid.cs.meta b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/ApsAndroid.cs.meta deleted file mode 100644 index e169fc7e..00000000 --- a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/ApsAndroid.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 49ea1496335f40278d1d5208d133aa8b -timeCreated: 1662131727 \ No newline at end of file diff --git a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/ApsIOS.cs.meta b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/ApsIOS.cs.meta deleted file mode 100644 index cbc981b9..00000000 --- a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/ApsIOS.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: d77d3880807744b949a706ffd94f0e30 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/ApsSlotData.cs.meta b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/ApsSlotData.cs.meta deleted file mode 100644 index 63bfc4c5..00000000 --- a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/ApsSlotData.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: f6ad133a277542d2821539cecc7c96d3 -timeCreated: 1662132156 \ No newline at end of file diff --git a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/Vungle/VungleAndroid.cs b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/Vungle/VungleAndroid.cs new file mode 100644 index 00000000..d3ccbcd3 --- /dev/null +++ b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/Vungle/VungleAndroid.cs @@ -0,0 +1,51 @@ +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using Newtonsoft.Json; +using Nimbus.Internal.Utility; +using OpenRTB.Request; +using UnityEngine; + +[assembly: InternalsVisibleTo("nimbus.test")] +namespace Nimbus.Internal.Interceptor.ThirdPartyDemand.Vungle { + internal class VungleAndroid : IInterceptor, IProvider { + private const string NimbusVunglePackage = "com.adsbynimbus.request.VungleDemandProvider"; + private const string VunglePackage = "com.vungle.ads.VungleAds"; + private readonly string _appID; + private readonly AndroidJavaObject _applicationContext; + + public VungleAndroid(string appID) { + _appID = appID; + } + + public VungleAndroid(AndroidJavaObject applicationContext, string appID) { + _applicationContext = applicationContext; + _appID = appID; + } + + public BidRequest ModifyRequest(BidRequest bidRequest, string data) { + if (data.IsNullOrEmpty()) { + return bidRequest; + } + if (bidRequest.User.Ext == null) { + bidRequest.User.Ext = new UserExt(); + } + bidRequest.User.Ext.VungleBuyerId = data; + + + return bidRequest; + } + + public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen) + { + var vungle = new AndroidJavaClass(VunglePackage); + var buyerId = vungle.CallStatic("getBiddingToken", _applicationContext); + return buyerId; + } + + public void InitializeNativeSDK() { + var vungle = new AndroidJavaClass(NimbusVunglePackage); + vungle.CallStatic("initialize", _appID); + } + } +} \ No newline at end of file diff --git a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/Vungle/VungleIOS.cs b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/Vungle/VungleIOS.cs new file mode 100644 index 00000000..c009e7bc --- /dev/null +++ b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Interceptor/ThirdPartyDemand/Vungle/VungleIOS.cs @@ -0,0 +1,51 @@ +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using Newtonsoft.Json; +using Nimbus.Internal.Utility; +using OpenRTB.Request; +using UnityEngine; + +[assembly: InternalsVisibleTo("nimbus.test")] +namespace Nimbus.Internal.Interceptor.ThirdPartyDemand.Vungle { + #if UNITY_IOS && NIMBUS_ENABLE_VUNGLE + internal class VungleIOS : IInterceptor, IProvider { + private readonly string _appID; + + [DllImport("__Internal")] + private static extern void _initializeVungle(string appKey); + + [DllImport("__Internal")] + private static extern string _fetchVungleBuyerId(); + + public VungleIOS(string appID) { + _appID = appID; + } + + public void InitializeNativeSDK() { + _initializeVungle(_appID); + } + + public BidRequest ModifyRequest(BidRequest bidRequest, string data) { + if (data.IsNullOrEmpty()) { + return bidRequest; + } + if (bidRequest.User.Ext == null) { + bidRequest.User.Ext = new UserExt(); + } + bidRequest.User.Ext.VungleBuyerId = data; + + + return bidRequest; + } + + public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen) + { + var buyerId = _fetchVungleBuyerId(); + Debug.unityLogger.Log("VUNGLEBUYER", buyerId); + return buyerId; + } + + } +#endif +} \ No newline at end of file diff --git a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Utility/StaticMethod.cs b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Utility/StaticMethod.cs index 49f11d7b..14b5ff21 100644 --- a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Utility/StaticMethod.cs +++ b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.Internal/Utility/StaticMethod.cs @@ -1,7 +1,7 @@ namespace Nimbus.Internal.Utility { public static class StaticMethod { public static bool InitializeInterceptor() { -#if NIMBUS_ENABLE_APS +#if NIMBUS_ENABLE_APS || NIMBUS_ENABLE_VUNGLE return true; #endif #pragma warning disable CS0162 diff --git a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.ScriptableObjects/NimbusSDKConfiguration.cs b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.ScriptableObjects/NimbusSDKConfiguration.cs index 3408cda1..9530b0e2 100644 --- a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.ScriptableObjects/NimbusSDKConfiguration.cs +++ b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.ScriptableObjects/NimbusSDKConfiguration.cs @@ -16,6 +16,10 @@ public class NimbusSDKConfiguration : ScriptableObject { [HideInInspector] public string iosAppID; [HideInInspector] public ApsSlotData[] iosApsSlotData; + + // Vungle Data + [HideInInspector] public string androidVungleAppID; + [HideInInspector] public string iosVungleAppID; private void OnValidate() { Sanitize(); @@ -42,6 +46,11 @@ public void Sanitize() { } } #endif + + #if NIMBUS_ENABLE_VUNGLE + androidVungleAppID = androidVungleAppID?.Trim(); + iosVungleAppID = iosVungleAppID?.Trim(); + #endif } @@ -54,5 +63,14 @@ public Tuple GetApsData() { #endif return new Tuple(appID, slots); } + + public string GetVungleData() + { + var appID = androidVungleAppID; + #if UNITY_IOS + appID = iosVungleAppID; + #endif + return appID; + } } } \ No newline at end of file diff --git a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.ScriptableObjects/NimbusSDKConfigurationPropertiesEditor.cs b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.ScriptableObjects/NimbusSDKConfigurationPropertiesEditor.cs index e3bedeea..7656c359 100644 --- a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.ScriptableObjects/NimbusSDKConfigurationPropertiesEditor.cs +++ b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.ScriptableObjects/NimbusSDKConfigurationPropertiesEditor.cs @@ -21,6 +21,11 @@ public class NimbusSDKConfigurationPropertiesEditor : Editor { private SerializedProperty _iosAppId; private ReorderableList _iosApsSlotIdList = null; private SerializedProperty _iosApsSlots = null; + + // Vungle + private SerializedProperty _androidVungleAppId; + + private SerializedProperty _iosVungleAppId; private void OnEnable() { _publisherKey = serializedObject.FindProperty("publisherKey"); @@ -42,7 +47,7 @@ private void OnEnable() { _androidApsSlots.isExpanded = true; _androidApsSlotIdList.elementHeight = 10 * EditorGUIUtility.singleLineHeight; _androidApsSlotIdList.headerHeight = 0f; - _androidApsSlotIdList.drawElementCallback += OnDrawElementAndroidApsSlotData; + _androidApsSlotIdList.drawElementCallback += OnDrawElementApsSlotData; // IOS APS UI _iosAppId = serializedObject.FindProperty("iosAppID"); @@ -57,12 +62,19 @@ private void OnEnable() { _iosApsSlots.isExpanded = true; _iosApsSlotIdList.elementHeight = 10 * EditorGUIUtility.singleLineHeight; _iosApsSlotIdList.headerHeight = 0f; - _iosApsSlotIdList.drawElementCallback += OnDrawElementIosApsSlotData; + _iosApsSlotIdList.drawElementCallback += OnDrawElementApsSlotData; + + // Vungle + // Android Vungle UI + _androidVungleAppId = serializedObject.FindProperty("androidVungleAppID"); + + // IOS Vungle UI + _iosVungleAppId = serializedObject.FindProperty("iosVungleAppID"); } private void OnDisable() { - _androidApsSlotIdList.drawElementCallback -= OnDrawElementAndroidApsSlotData; - _iosApsSlotIdList.drawElementCallback -= OnDrawElementIosApsSlotData; + _androidApsSlotIdList.drawElementCallback -= OnDrawElementApsSlotData; + _iosApsSlotIdList.drawElementCallback -= OnDrawElementApsSlotData; var config = target as NimbusSDKConfiguration; if (config == null) return; @@ -73,11 +85,15 @@ private void OnDisable() { } - private void OnDrawElementAndroidApsSlotData(Rect rect, int index, bool isActive, bool isFocused) { + private void OnDrawElementApsSlotData(Rect rect, int index, bool isActive, bool isFocused) { var fieldRect = rect; fieldRect.height = EditorGUIUtility.singleLineHeight; - - var item = _androidApsSlots.GetArrayElementAtIndex(index); + #if UNITY_ANDROID + var item = _androidApsSlots.GetArrayElementAtIndex(index); + #endif + #if UNITY_IOS + var item = _iosApsSlots.GetArrayElementAtIndex(index); + #endif item.isExpanded = true; var itr = item.Copy(); @@ -92,27 +108,6 @@ private void OnDrawElementAndroidApsSlotData(Rect rect, int index, bool isActive fieldRect.y += fieldRect.height; } } - - private void OnDrawElementIosApsSlotData(Rect rect, int index, bool isActive, bool isFocused) { - var fieldRect = rect; - fieldRect.height = EditorGUIUtility.singleLineHeight; - - var item = _iosApsSlots.GetArrayElementAtIndex(index); - item.isExpanded = true; - var itr = item.Copy(); - - itr.Next(true); - fieldRect.y += 1.5f * fieldRect.height; - EditorGUI.PropertyField(fieldRect, itr, false); - - var children = item.CountInProperty() - 1; - for (var i = 0; i < children; i++) { - EditorGUI.PropertyField(fieldRect, itr, false); - itr.Next(false); - fieldRect.y += fieldRect.height; - } - } - public override void OnInspectorGUI() { serializedObject.Update(); @@ -139,9 +134,12 @@ public override void OnInspectorGUI() { EditorGUILayout.PropertyField((_enableUnityLogs)); GUILayout.Space(10); EditorDrawUtility.DrawEditorLayoutHorizontalLine(Color.gray, 5); - - #if NIMBUS_ENABLE_APS + + #if NIMBUS_ENABLE_APS || NIMBUS_ENABLE_VUNGLE EditorGUILayout.LabelField("Third Party SDK Support", headerStyle); + #endif + + #if NIMBUS_ENABLE_APS EditorDrawUtility.DrawEditorLayoutHorizontalLine(Color.gray, 2); GUILayout.Space(10); EditorGUILayout.LabelField("APS Configuration", headerStyle); @@ -160,7 +158,27 @@ public override void OnInspectorGUI() { #if !UNITY_ANDROID && !UNITY_IOS EditorGUILayout.HelpBox("In build settings select Android or IOS to enter APS data", MessageType.Warning); #endif - #endif + GUILayout.Space(10); + #endif + + #if NIMBUS_ENABLE_VUNGLE + EditorDrawUtility.DrawEditorLayoutHorizontalLine(Color.gray, 2); + GUILayout.Space(10); + EditorGUILayout.LabelField("Vungle Configuration", headerStyle); + #if UNITY_ANDROID + EditorGUILayout.PropertyField((_androidVungleAppId)); + EditorDrawUtility.DrawEditorLayoutHorizontalLine(Color.gray); + #endif + + #if UNITY_IOS + EditorGUILayout.PropertyField((_iosVungleAppId)); + EditorDrawUtility.DrawEditorLayoutHorizontalLine(Color.gray); + #endif + + #if !UNITY_ANDROID && !UNITY_IOS + EditorGUILayout.HelpBox("In build settings select Android or IOS to enter Vungle data", MessageType.Warning); + #endif + #endif serializedObject.ApplyModifiedProperties(); } diff --git a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.ScriptableObjects/NimbusSDKDevExample.asset b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.ScriptableObjects/NimbusSDKDevExample.asset index 4ec4416e..c56db2f6 100644 --- a/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.ScriptableObjects/NimbusSDKDevExample.asset +++ b/com.adsbynimbus.nimbus/Runtime/Scripts/Nimbus.ScriptableObjects/NimbusSDKDevExample.asset @@ -32,3 +32,5 @@ MonoBehaviour: AdUnitType: 1 - SlotId: 4acc26e6-3ada-4ee8-bae0-753c1e0ad278 AdUnitType: 3 + androidVungleAppID: + iosVungleAppID: