惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
IT之家
IT之家
V
V2EX
Jina AI
Jina AI
V
Visual Studio Blog
有赞技术团队
有赞技术团队
博客园 - 司徒正美
博客园 - 叶小钗
The Cloudflare Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 三生石上(FineUI控件)
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
腾讯CDC
Google Online Security Blog
Google Online Security Blog
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
N
News and Events Feed by Topic
N
News and Events Feed by Topic
The Last Watchdog
The Last Watchdog
W
WeLiveSecurity
月光博客
月光博客
Security Archives - TechRepublic
Security Archives - TechRepublic
Webroot Blog
Webroot Blog
SecWiki News
SecWiki News
博客园_首页
罗磊的独立博客
量子位
Latest news
Latest news
I
Intezer
V
Vulnerabilities – Threatpost
A
Arctic Wolf
Last Week in AI
Last Week in AI
Recent Commits to openclaw:main
Recent Commits to openclaw:main
S
SegmentFault 最新的问题
S
Security Affairs
阮一峰的网络日志
阮一峰的网络日志
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
酷 壳 – CoolShell
酷 壳 – CoolShell
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
N
News | PayPal Newsroom

博客园 - 威少小二orz

团结引擎抖音小游戏一定要手动填缓存资源域名 团结引擎+Addressable+Instant Game打包抖音小游戏 团结引擎发布抖音小游戏(十万个坑已踩完) 团结引擎发布小游戏区分不同平台 团结引擎发布小游戏与js版本SDK的互相调用 Unity发布京东小游戏 LayerMask的使用规范 Unity RectTransform中使用stretch模式时代码动态控制Left、Top、Right、Bottom Unity使用https请求握手失败的处理方案 【MAUI开发】一、初识MAUI Android中使用GSON解析JSON数据 游戏软著渠道的用户协议和隐私协议方案(启动显示方案) C#文件夹复制 C#在Json序列化中动态忽略某些属性或字段 安卓多个Activity大退时自动重启的问题处理 C#中接收到的Json数据中key为数字的问题处理 对于UniWebView这种组件违规获取信息的处理 TapTap实名认证-Android Unity使用Get和Post传递json数据并转换成class对象 Unity获取手机本地应用以及调起apk安装、启动app、安装完成回调
Unity接入穿山甲GroMore广告——重构偏2(Banner广告)
威少小二orz · 2022-09-27 · via 博客园 - 威少小二orz

完成前一偏文章后,我们在com下创建一个adtools文件夹,再创建一个类名为BannerAd的BannerAd.java文件。

 Android模块:

1、写入Banner广告的单例和Unity接收消息的GameObject名字。

    private static volatile BannerAd instance;
    public static BannerAd Instance() {
        if (instance == null) {
            synchronized (BannerAd.class) {
                if (instance == null) {
                    instance = new BannerAd();
                }
            }
        }
        return instance;
    }

    //Unity接收消息的名字
    public static String AdGameObjectName = "CSJSDK_BannerAd";

2、加载广告和加载完成的回调。

广告加载出来后,如果展示,是需要放在一个View中的。

 public GMBannerAd mttBannerAd;//加载出来的广告放在这

 public ViewGroup bannerViewLayout;//创建出来的View存在这

public void LoadBannerAd(Activity context,String adUnitId)
    {
        Log.e("LoadBanner",adUnitId);
        mttBannerAd = new GMBannerAd(context, adUnitId);
        GMAdSlotBanner slotBanner = new GMAdSlotBanner.Builder()
                .setBannerSize(GMAdSize.BANNER_CUSTOME)
                .setImageAdSize(UIUtils.getScreenWidth(WXEntryActivity.app), 50)
                //.setImageAdSize(adSlot.getImgAcceptedWidth(), adSlot.getImgAcceptedHeight())// GMAdSize.BANNER_CUSTOME可以调用setImageAdSize设置大小
                .setRefreshTime(10)
                .setAllowShowCloseBtn(true)//如果广告本身允许展示关闭按钮,这里设置为true就是展示。注:目前只有mintegral支持。
                .build();
        mttBannerAd.setAdBannerListener(new GMBannerAdListener() {
            @Override
            public void onAdOpened() {

            }

            @Override
            public void onAdLeftApplication() {

            }

            @Override
            public void onAdClosed() {
                //OnAdDismiss
               //手动点击Banner的关闭按钮
            }

            @Override
            public void onAdClicked() {

            }

            @Override
            public void onAdShow() {
                WXEntryActivity.mUnityPlayer.UnitySendMessage(AdGameObjectName, "onAdShowCallBack","");
            }

            @Override
            public void onAdShowFail(@NonNull AdError adError) {

            }
        });
        Log.e("LoadBanner","onAdFailedToLoad");
        mttBannerAd.loadAd(slotBanner, new GMBannerAdLoadCallback() {
            @Override
            public void onAdFailedToLoad(@NonNull AdError adError) {
                Log.e("LoadBanner","onAdFailedToLoad___" + adError.code + "__" + adError.message);
            }

            @Override
            public void onAdLoaded() {
                Log.e("LoadBanner","onAdLoaded");
                context.runOnUiThread(new Runnable() {
                    public void run() {
                        try
                        {
                            removeViewFromRootView(context,bannerViewLayout);
                            bannerViewLayout  = getFrameLayoutForBanner(context);
                            Log.e("LoadBanner","bannerViewLayout");
                            View view = mttBannerAd.getBannerView();
                            Log.e("LoadBanner","getBannerView");
                            if(view != null)
                            {
                                Log.e("LoadBanner","xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1");
                                view.setBackgroundColor(Color.WHITE);

                            }

                            Log.e("LoadBanner","setBackgroundColor");
                            bannerViewLayout.addView(view);
                            Log.e("LoadBanner","bannerViewLayout.addView");
                        }
                        catch(Exception ex)
                        {
                            Log.e("LoadBanner","xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx2");
                        }

                    }
                });

            }
        });


    }

3、未完待续