Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vungle Support for Unity #56

Merged
merged 14 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions com.adsbynimbus.nimbus/Editor/AndroidBuildDependencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,15 @@ public static string APSBuildDependencies() {
builder.AppendLine("}");
return builder.ToString();
}

public static string VungleBuildDependencies() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is minor and can be done at a later time but ideally all of the extensions would be contained within a single dependencies block which would require changing the functionality of this class to take in a list of required extensions instead of writing a new dependencies block for each extension. The output would look like the following

dependencies {
    implementation "com.adsbynimbus.android:extension-aps:{SdkVersion}"
    implementation "com.adsbynimbus.android:extension-vungle:{SdkVersion}"
}

var builder = new StringBuilder();

builder.AppendLine("");
builder.AppendLine("dependencies {");
builder.AppendLine($@"implementation ""com.adsbynimbus.android:extension-vungle:{SdkVersion}""");
builder.AppendLine("}");
return builder.ToString();
}
}
}
16 changes: 12 additions & 4 deletions com.adsbynimbus.nimbus/Editor/AndroidPostBuildProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
Expand Down
26 changes: 16 additions & 10 deletions com.adsbynimbus.nimbus/Editor/IOSPostBuildProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(", ", Dependencies)}]");
}
}
lines[i] = ($"{lines[i]}, subspecs: [{string.Join<string>(", ", Dependencies)}]");
}
}
File.WriteAllLines(path, lines);
}
}
}
Expand All @@ -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();
Expand Down
64 changes: 61 additions & 3 deletions com.adsbynimbus.nimbus/Editor/NimbusManagerCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<NimbusManagerCreator>("NimbusAdsManager Creator");
Expand Down Expand Up @@ -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");
}


Expand Down Expand Up @@ -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);
Expand All @@ -154,6 +168,27 @@ 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("Liftoff Monetize Configuration", headerStyle);
#if UNITY_ANDROID
var label = new GUIContent("Android Liftoff Monetize App ID");
EditorGUILayout.PropertyField(_androidVungleAppId, label);
EditorDrawUtility.DrawEditorLayoutHorizontalLine(Color.gray);
#endif

#if UNITY_IOS
var label = new GUIContent("iOS Liftoff Monetize App ID");
EditorGUILayout.PropertyField(_iosVungleAppId, label);
EditorDrawUtility.DrawEditorLayoutHorizontalLine(Color.gray);
#endif

#if !UNITY_ANDROID && !UNITY_IOS
EditorGUILayout.HelpBox("In build settings select Android or IOS to enter Liftoff Monetize data", MessageType.Warning);
#endif
#endif

// ReSharper disable InvertIf
if (GUILayout.Button("Create")) {
Expand Down Expand Up @@ -184,6 +219,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");
Expand Down Expand Up @@ -289,6 +330,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",
"Liftoff Monetize SDK has been included, the Liftoff Monetize App ID cannot be empty, object NimbusAdsManager not created");
return false;
}
ApsSlotData[] slotData = null;
return true;
}
}
}
#endif
64 changes: 59 additions & 5 deletions com.adsbynimbus.nimbus/Editor/ThirdPartyMacros.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "Liftoff Monetize";

private void OnEnable() {
UpdateSettings();
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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("Liftoff Monetize 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", "Liftoff Monetize", "Android")
: string.Format(ButtonMessageTemplate, "Enable", "Liftoff Monetize", "Android");
if (GUILayout.Button(androidVunglebuttonText)) {
if (_androidVungleIsEnabled) {
RemoveBuildMacroForGroup(BuildTargetGroup.Android, VungleMacro);
}
else {
SetBuildMacroForGroup(BuildTargetGroup.Android, VungleMacro);
EditorUtil.LogWithHelpBox("Don't Forget To Add your Liftoff Monetize Android 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", "Liftoff Monetize", "Ios")
: string.Format(ButtonMessageTemplate, "Enable", "Liftoff Monetize", "Ios");
if (GUILayout.Button(vungleAndroidButtonText)) {
if (_iosVungleIsEnabled) {
RemoveBuildMacroForGroup(BuildTargetGroup.iOS, VungleMacro);
}
else {
SetBuildMacroForGroup(BuildTargetGroup.iOS, VungleMacro);
EditorUtil.LogWithHelpBox("Don't Forget To Add your Liftoff Monetize IOS 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);
}
Expand All @@ -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);
}


Expand All @@ -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<NimbusManager>();
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);
}
Expand Down
3 changes: 3 additions & 0 deletions com.adsbynimbus.nimbus/Runtime/Plugins/RTB/Request/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@ public class UserExt {

[JsonProperty("eids", DefaultValueHandling = DefaultValueHandling.Ignore)]
public Eid[] Eids;

[JsonProperty("vungle_buyeruid", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string VungleBuyerId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions com.adsbynimbus.nimbus/Runtime/Plugins/iOS/NimbusBinding.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading