Commit d11d3714 authored by zhangzhe's avatar zhangzhe

修改广告

parent 76c3a59c
......@@ -665,7 +665,9 @@ public class AdManager
}
else
{
#if UNITY_ANDROID
LoadCacheFeedAd(slotName);
#endif
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "展示大图失败 缓存的信息为null");
}
}
......
......@@ -133,7 +133,9 @@ public class CSJSplshADUtils
}
public void onTimeout()
{
listener.onError("CSJ SplshAd timeout");
EventUtils.onEventPullFail(entity, "-1", "网络超时");
listener.onError("CSJ SplshAd code -1 message 网络超时");
Debug.Log("splash load Onerror: -1 : 网络超时");
callback(false);
}
......
......@@ -1699,6 +1699,10 @@ public sealed class Example : MonoBehaviour
#endif
}
public void onTimeout()
{
throw new System.NotImplementedException();
}
private sealed class SplashAdInteractionListener : ISplashAdInteractionListener
{
......@@ -1809,6 +1813,11 @@ public sealed class Example : MonoBehaviour
}
#endif
}
public void onTimeout()
{
throw new System.NotImplementedException();
}
}
private sealed class ExpressSplashAdInteractionListener : ISplashAdInteractionListener
......
......@@ -331,6 +331,12 @@ namespace ByteDance.Union
() => this.listener.OnError(code, message));
}
public void onTimeout()
{
UnityDispatcher.PostTask(
() => this.listener.onTimeout());
}
public void onSplashAdLoad(AndroidJavaObject handle)
{
var ad = new BUSplashAd(handle);
......
......@@ -17,6 +17,8 @@ namespace ByteDance.Union
/// </summary>
void OnError(int code, string message);
void onTimeout();
/// <summary>
/// Invoke when the Ad load success.
/// </summary>
......
......@@ -20,13 +20,14 @@ public class GDTFeedAdUtil
}
//FeedAd
private NativeExpressAdView feedAd;
private static NativeExpressAdView feedAd;
/// <summary>
/// 大图广告缓存队列
/// </summary>
private static Queue<NativeExpressAdView> feedAdCacheList = new Queue<NativeExpressAdView>();
public NativeExpressAd nativeExpressAd;
/// <summary>
......@@ -40,6 +41,7 @@ public class GDTFeedAdUtil
//string PosId = Constants.nativeExpressVideoPosId;//带视频的大图广告
NativeExpressAd ad = new NativeExpressAd(entity.codeId, GetAdSize());
nativeExpressAd = ad;
ad.SetListener(new FeedAdListener(entity,callback));
ad.LoadAd(1);
}
......@@ -62,16 +64,21 @@ public class GDTFeedAdUtil
/// <param name="entity"></param>
public void ShowCacheFeedAd(AdEntity entity,Action<bool> callback)
{
CloseFeedAd();
if (feedAdCacheList.Count > 0)
//CloseFeedAd();
#if UNITY_IOS
if (feedAd != null)
#else
if(feedAdCacheList.Count > 0)
#endif
{
feedAd = feedAdCacheList.Dequeue();
#if UNITY_IOS
// iOS 广告加载完毕即可展示
feedAd.Render();
IOSDemoUtils.ShowView(feedAd.GetIOSNativeView());
#else
// Android 可直接展示,代码如下
feedAd = feedAdCacheList.Dequeue();
feedAd.Render();
AndroidDemoUtils.ShowView(feedAd.GetAndroidNativeView(), true);
callback(true);
......@@ -101,7 +108,14 @@ public class GDTFeedAdUtil
{
#if UNITY_IOS
// iOS 暂不支持自适应宽高
return new AdSize(350, 200);
if (Screen.width > 1000)
{
return new AdSize(Screen.width / 3, (Screen.width / 3) * 9 / 16);
}
else
{
return new AdSize(Screen.width / 2, (Screen.width / 2) * 9 / 16);
}
#else
return new AdSize(AdSize.FULL_WIDTH, AdSize.AUTO_HEIGHT);
#endif
......@@ -140,7 +154,11 @@ public class GDTFeedAdUtil
view.PreloadVideo();
}
#endif
#if UNITY_IOS
feedAd = view;
#else
feedAdCacheList.Enqueue(view);
#endif
callback(true);
string msg1 = "OnAdLoaded";
Debug.unityLogger.Log(Constants.tagForLog, msg1);
......
......@@ -14,7 +14,39 @@ extern "C" {
#endif
void GDT_UnionPlatform_Ad_ShowAdView(UIView *adView) {
[GetAppController().rootViewController.view addSubview:adView];
static dispatch_source_t _timer;
if (_timer)
{
dispatch_source_cancel(_timer);
_timer = nil;
}
//设置时间间隔
NSTimeInterval period = 0.05f;
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
dispatch_source_set_timer(_timer, dispatch_walltime(NULL, 0), period * NSEC_PER_SEC, 0);
// 事件回调
dispatch_source_set_event_handler(_timer, ^{
dispatch_async(dispatch_get_main_queue(), ^{
CGFloat width = adView.frame.size.width;
CGFloat height = adView.frame.size.height;
CGFloat x = (GetAppController().rootViewController.view.frame.size.width - width) / 2.0f;
CGFloat y = GetAppController().rootViewController.view.frame.size.height - height;
if (adView.frame.origin.x != x || adView.frame.origin.y != y || adView.frame.size.width != width || adView.frame.size.height != height)
{
adView.frame = CGRectMake(x, y, width, height);
}
});
});
// 开启定时器
dispatch_resume(_timer);
}
#if defined (__cplusplus)
......
......@@ -9,6 +9,7 @@ PluginImporter:
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
......
......@@ -34,7 +34,6 @@ GraphicsSettings:
- {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16003, guid: 0000000000000000f000000000000000, type: 0}
m_PreloadedShaders: []
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
type: 0}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment