summaryrefslogtreecommitdiff
path: root/Runtime/Export/iOS/iAD.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Runtime/Export/iOS/iAD.cs')
-rw-r--r--Runtime/Export/iOS/iAD.cs187
1 files changed, 187 insertions, 0 deletions
diff --git a/Runtime/Export/iOS/iAD.cs b/Runtime/Export/iOS/iAD.cs
new file mode 100644
index 0000000..c8fc80f
--- /dev/null
+++ b/Runtime/Export/iOS/iAD.cs
@@ -0,0 +1,187 @@
+#if UNITY_IPHONE_API
+
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Collections;
+
+namespace UnityEngine
+{
+public sealed partial class ADBannerView
+{
+ public enum
+ Layout
+ {
+ // banner
+ Top = 0,
+ Bottom = 1,
+
+ // rect
+ TopLeft = 0,
+ TopRight = 4,
+ TopCenter = 8,
+ BottomLeft = 1,
+ BottomRight = 5,
+ BottomCenter= 9,
+ CenterLeft = 2,
+ CenterRight = 6,
+ Center = 10,
+
+ Manual = -1
+ };
+
+ public enum
+ Type
+ {
+ Banner = 0,
+ MediumRect = 1
+ };
+
+ private Layout _layout;
+ private IntPtr _bannerView;
+
+ public static bool IsAvailable(Type type)
+ {
+ return Native_BannerTypeAvailable((int)type);
+ }
+
+ // some naughty magic to make sure we can properly strip class
+ // if ctor is ever called, static func will be forcibly generated
+ private static bool _AlwaysFalseDummy = false;
+ public ADBannerView(Type type, Layout layout)
+ {
+ if(_AlwaysFalseDummy)
+ {
+ FireBannerWasClicked();
+ FireBannerWasLoaded();
+ }
+
+ _bannerView = Native_CreateBanner((int)type, (int)layout);
+ }
+ ~ADBannerView()
+ {
+ Native_DestroyBanner(_bannerView);
+ }
+
+ public bool loaded
+ {
+ get { return Native_BannerAdLoaded(_bannerView); }
+ }
+ public bool visible
+ {
+ get { return Native_BannerAdVisible(_bannerView); }
+ set { Native_ShowBanner(_bannerView, value); }
+ }
+ public Layout layout
+ {
+ // TODO: should we query native side?
+ get { return _layout; }
+ set { _layout = value; Native_LayoutBanner(_bannerView, (int)_layout); }
+ }
+
+ public Vector2 position
+ {
+ get
+ {
+ Vector2 ret; Native_BannerPosition(_bannerView, out ret);
+ return OSToScreenCoords(ret);
+ }
+ set
+ {
+ Vector2 pos = new Vector2(value.x/Screen.width, value.y/Screen.height);
+ Native_MoveBanner(_bannerView, pos);
+ }
+ }
+
+ public Vector2 size
+ {
+ get
+ {
+ Vector2 ret; Native_BannerSize(_bannerView, out ret);
+ return OSToScreenCoords(ret);
+ }
+ }
+
+ public delegate void BannerWasClickedDelegate();
+ public static event BannerWasClickedDelegate onBannerWasClicked = null;
+
+ public delegate void BannerWasLoadedDelegate();
+ public static event BannerWasLoadedDelegate onBannerWasLoaded = null;
+
+ private Vector2 OSToScreenCoords(Vector2 v)
+ {
+ return new Vector2(v.x * Screen.width, v.y * Screen.height);
+ }
+
+ private static void FireBannerWasClicked()
+ {
+ if(onBannerWasClicked != null)
+ onBannerWasClicked();
+ }
+
+ private static void FireBannerWasLoaded()
+ {
+ if(onBannerWasLoaded != null)
+ onBannerWasLoaded();
+ }
+}
+
+public sealed partial class ADInterstitialAd
+{
+ private IntPtr interstitialView;
+
+ public static bool isAvailable
+ {
+ get { return Native_InterstitialAvailable(); }
+ }
+
+ // some naughty magic to make sure we can properly strip class
+ // if ctor is ever called, static func will be forcibly generated
+ private static bool _AlwaysFalseDummy = false;
+ private void CtorImpl(bool autoReload)
+ {
+ if(_AlwaysFalseDummy)
+ FireInterstitialWasLoaded();
+
+ interstitialView = Native_CreateInterstitial(autoReload);
+ }
+ public ADInterstitialAd(bool autoReload)
+ {
+ CtorImpl(autoReload);
+ }
+ public ADInterstitialAd()
+ {
+ CtorImpl(false);
+ }
+ ~ADInterstitialAd()
+ {
+ Native_DestroyInterstitial(interstitialView);
+ }
+
+
+ public void Show()
+ {
+ Native_ShowInterstitial(interstitialView);
+ }
+ public void ReloadAd()
+ {
+ Native_ReloadInterstitial(interstitialView);
+ }
+
+ public bool loaded
+ {
+ get { return Native_InterstitialAdLoaded(interstitialView); }
+ }
+
+ public delegate void InterstitialWasLoadedDelegate();
+ public static event InterstitialWasLoadedDelegate onInterstitialWasLoaded = null;
+
+ private static void FireInterstitialWasLoaded()
+ {
+ if(onInterstitialWasLoaded != null)
+ onInterstitialWasLoaded();
+ }
+}
+}
+
+#endif