Commit d11d3714 authored by zhangzhe's avatar zhangzhe

修改广告

parent 76c3a59c
...@@ -665,7 +665,9 @@ public class AdManager ...@@ -665,7 +665,9 @@ public class AdManager
} }
else else
{ {
#if UNITY_ANDROID
LoadCacheFeedAd(slotName); LoadCacheFeedAd(slotName);
#endif
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "展示大图失败 缓存的信息为null"); Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "展示大图失败 缓存的信息为null");
} }
} }
......
...@@ -133,7 +133,9 @@ public class CSJSplshADUtils ...@@ -133,7 +133,9 @@ public class CSJSplshADUtils
} }
public void onTimeout() 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); callback(false);
} }
......
...@@ -1699,6 +1699,10 @@ public sealed class Example : MonoBehaviour ...@@ -1699,6 +1699,10 @@ public sealed class Example : MonoBehaviour
#endif #endif
} }
public void onTimeout()
{
throw new System.NotImplementedException();
}
private sealed class SplashAdInteractionListener : ISplashAdInteractionListener private sealed class SplashAdInteractionListener : ISplashAdInteractionListener
{ {
...@@ -1809,6 +1813,11 @@ public sealed class Example : MonoBehaviour ...@@ -1809,6 +1813,11 @@ public sealed class Example : MonoBehaviour
} }
#endif #endif
} }
public void onTimeout()
{
throw new System.NotImplementedException();
}
} }
private sealed class ExpressSplashAdInteractionListener : ISplashAdInteractionListener private sealed class ExpressSplashAdInteractionListener : ISplashAdInteractionListener
......
...@@ -331,6 +331,12 @@ namespace ByteDance.Union ...@@ -331,6 +331,12 @@ namespace ByteDance.Union
() => this.listener.OnError(code, message)); () => this.listener.OnError(code, message));
} }
public void onTimeout()
{
UnityDispatcher.PostTask(
() => this.listener.onTimeout());
}
public void onSplashAdLoad(AndroidJavaObject handle) public void onSplashAdLoad(AndroidJavaObject handle)
{ {
var ad = new BUSplashAd(handle); var ad = new BUSplashAd(handle);
......
...@@ -17,6 +17,8 @@ namespace ByteDance.Union ...@@ -17,6 +17,8 @@ namespace ByteDance.Union
/// </summary> /// </summary>
void OnError(int code, string message); void OnError(int code, string message);
void onTimeout();
/// <summary> /// <summary>
/// Invoke when the Ad load success. /// Invoke when the Ad load success.
/// </summary> /// </summary>
......
...@@ -20,13 +20,14 @@ public class GDTFeedAdUtil ...@@ -20,13 +20,14 @@ public class GDTFeedAdUtil
} }
//FeedAd //FeedAd
private NativeExpressAdView feedAd; private static NativeExpressAdView feedAd;
/// <summary> /// <summary>
/// 大图广告缓存队列 /// 大图广告缓存队列
/// </summary> /// </summary>
private static Queue<NativeExpressAdView> feedAdCacheList = new Queue<NativeExpressAdView>(); private static Queue<NativeExpressAdView> feedAdCacheList = new Queue<NativeExpressAdView>();
public NativeExpressAd nativeExpressAd;
/// <summary> /// <summary>
...@@ -40,6 +41,7 @@ public class GDTFeedAdUtil ...@@ -40,6 +41,7 @@ public class GDTFeedAdUtil
//string PosId = Constants.nativeExpressVideoPosId;//带视频的大图广告 //string PosId = Constants.nativeExpressVideoPosId;//带视频的大图广告
NativeExpressAd ad = new NativeExpressAd(entity.codeId, GetAdSize()); NativeExpressAd ad = new NativeExpressAd(entity.codeId, GetAdSize());
nativeExpressAd = ad;
ad.SetListener(new FeedAdListener(entity,callback)); ad.SetListener(new FeedAdListener(entity,callback));
ad.LoadAd(1); ad.LoadAd(1);
} }
...@@ -62,16 +64,21 @@ public class GDTFeedAdUtil ...@@ -62,16 +64,21 @@ public class GDTFeedAdUtil
/// <param name="entity"></param> /// <param name="entity"></param>
public void ShowCacheFeedAd(AdEntity entity,Action<bool> callback) public void ShowCacheFeedAd(AdEntity entity,Action<bool> callback)
{ {
CloseFeedAd(); //CloseFeedAd();
if (feedAdCacheList.Count > 0) #if UNITY_IOS
if (feedAd != null)
#else
if(feedAdCacheList.Count > 0)
#endif
{ {
feedAd = feedAdCacheList.Dequeue();
#if UNITY_IOS #if UNITY_IOS
// iOS 广告加载完毕即可展示 // iOS 广告加载完毕即可展示
feedAd.Render(); feedAd.Render();
IOSDemoUtils.ShowView(feedAd.GetIOSNativeView()); IOSDemoUtils.ShowView(feedAd.GetIOSNativeView());
#else #else
// Android 可直接展示,代码如下 // Android 可直接展示,代码如下
feedAd = feedAdCacheList.Dequeue();
feedAd.Render(); feedAd.Render();
AndroidDemoUtils.ShowView(feedAd.GetAndroidNativeView(), true); AndroidDemoUtils.ShowView(feedAd.GetAndroidNativeView(), true);
callback(true); callback(true);
...@@ -101,7 +108,14 @@ public class GDTFeedAdUtil ...@@ -101,7 +108,14 @@ public class GDTFeedAdUtil
{ {
#if UNITY_IOS #if UNITY_IOS
// 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 #else
return new AdSize(AdSize.FULL_WIDTH, AdSize.AUTO_HEIGHT); return new AdSize(AdSize.FULL_WIDTH, AdSize.AUTO_HEIGHT);
#endif #endif
...@@ -140,7 +154,11 @@ public class GDTFeedAdUtil ...@@ -140,7 +154,11 @@ public class GDTFeedAdUtil
view.PreloadVideo(); view.PreloadVideo();
} }
#endif #endif
#if UNITY_IOS
feedAd = view;
#else
feedAdCacheList.Enqueue(view); feedAdCacheList.Enqueue(view);
#endif
callback(true); callback(true);
string msg1 = "OnAdLoaded"; string msg1 = "OnAdLoaded";
Debug.unityLogger.Log(Constants.tagForLog, msg1); Debug.unityLogger.Log(Constants.tagForLog, msg1);
......
...@@ -14,7 +14,39 @@ extern "C" { ...@@ -14,7 +14,39 @@ extern "C" {
#endif #endif
void GDT_UnionPlatform_Ad_ShowAdView(UIView *adView) { void GDT_UnionPlatform_Ad_ShowAdView(UIView *adView) {
[GetAppController().rootViewController.view addSubview: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) #if defined (__cplusplus)
......
...@@ -9,6 +9,7 @@ PluginImporter: ...@@ -9,6 +9,7 @@ PluginImporter:
isPreloaded: 0 isPreloaded: 0
isOverridable: 0 isOverridable: 0
isExplicitlyReferenced: 0 isExplicitlyReferenced: 0
validateReferences: 1
platformData: platformData:
- first: - first:
Any: Any:
......
...@@ -34,7 +34,6 @@ GraphicsSettings: ...@@ -34,7 +34,6 @@ GraphicsSettings:
- {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16003, guid: 0000000000000000f000000000000000, type: 0}
m_PreloadedShaders: [] m_PreloadedShaders: []
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
type: 0} 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