googleads / googleads-mobile-unity

Official Unity Plugin for the Google Mobile Ads SDK
https://developers.google.com/admob/unity
Apache License 2.0
1.36k stars 1.08k forks source link

[UMP] Release the User Messaging Platform SDK as a separate unity package #3181

Closed KarahanOnarlar closed 6 months ago

KarahanOnarlar commented 7 months ago

[REQUIRED] Step 1: Describe your environment

[REQUIRED] Step 2: Describe the problem

Release the User Messaging Platform sdk as a separate unity package for those using other mediation platforms such as Ironsource. It will make things easier for those who want to install UMP without installing the Admob SDK. It will make things easier for those who want to install UMP without installing the Admob SDK. It's frustrating to deal with this since Ironsource hasn't yet integrated ump into its sdk like Applovin.

Here are just the dependencies to speed things up if you want to do it.

Files:

  1. GoogleUmpDependencies.xml
  2. Editor/Resources/Ump

A copy of MobileAds.RaiseAction(Action action) code should be created for ump like this:

Note: RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad) is the right place to set the SynchronizationContext. It is called immediately after Awake and OnEnable.

public class MainThreadEventExecuter
{
    private static SynchronizationContext _synchronizationContext;
    private static int? _unityMainThreadId;

    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
    public static void Initialize()
    {
        _synchronizationContext ??= SynchronizationContext.Current;
        _unityMainThreadId ??= Thread.CurrentThread.ManagedThreadId;
    }
    public static void RaiseAction(Action action)
    {
        if (action == null) return;
        if (_synchronizationContext == null || Thread.CurrentThread.ManagedThreadId == _unityMainThreadId)
        {
            action();
            return;
        }
        _synchronizationContext.Post(state => action(), action);
    }

For Android:

Only two files are available at. They just need to be placed in the Plugins folder.

  1. UnityConsentForm.java
  2. UnityConsentFormCallback.java

For iOS:

Apart from these, extra dependencies on the Admob SDK are as follows.

I write with the codes I have parsed to help others. It is enough to create the GADUObjectCache.m & GADUObjectCache.h file as it is and the others as code files and put them in the plugins folder. If the Admob SDK is not removed along with the files in the plugins folder, conflicts will occur.

  1. GADUObjectCache.m & GADUObjectCache.h => Dependency: All
  2. GADUTypes.h => Dependency: Only the following code
    
    #import <Foundation/Foundation.h>

/// Base type representing a GADU pointer. typedef const void GADUTypeRef;

3. [GADUInterface.m](https://github.com/googleads/googleads-mobile-unity/blob/main/source/plugin/Assets/Plugins/iOS/GADUInterface.m) => Dependency: Only the following code

// Copyright 2014 Google Inc. All Rights Reserved.

import "GADUObjectCache.h"

import "GADUTypes.h"

pragma mark - Other methods

/// Removes an object from the cache. void GADURelease(GADUTypeRef ref) { if (ref) { GADUObjectCache cache = GADUObjectCache.sharedInstance; [cache removeObjectForKey:[(__bridge NSObject )ref gadu_referenceKey]]; } }

4. [GADUPluginUtil.h](https://github.com/googleads/googleads-mobile-unity/blob/main/source/plugin/Assets/Plugins/iOS/GADUPluginUtil.h) => Dependency: Only the following code

// Copyright 2016 Google Inc. All Rights Reserved.

import <Foundation/Foundation.h>

@interface GADUPluginUtil : NSObject

/// Returns the Unity view controller.

@end

5. [GADUPluginUtil.m](https://github.com/googleads/googleads-mobile-unity/blob/main/source/plugin/Assets/Plugins/iOS/GADUPluginUtil.m) => Dependency: Only the following code

// Copyright 2016 Google Inc. All Rights Reserved.

import "GADUPluginUtil.h"

@implementation GADUPluginUtil

@end

NVentimiglia commented 6 months ago

Thanks @KarahanOnarlar

He have considered releasing the UMP SDK on its own in the past. I will submit this feature request to engineering for consideration.

NVentimiglia commented 6 months ago

Submitted this feature request to Engineering, they are considering it. Closing the issue here.