diff options
Diffstat (limited to 'Runtime/Export/iOS')
-rw-r--r-- | Runtime/Export/iOS/CocoaIntegration.cs | 89 | ||||
-rw-r--r-- | Runtime/Export/iOS/iAD.cs | 187 | ||||
-rw-r--r-- | Runtime/Export/iOS/iAD.txt | 91 |
3 files changed, 367 insertions, 0 deletions
diff --git a/Runtime/Export/iOS/CocoaIntegration.cs b/Runtime/Export/iOS/CocoaIntegration.cs new file mode 100644 index 0000000..dea1431 --- /dev/null +++ b/Runtime/Export/iOS/CocoaIntegration.cs @@ -0,0 +1,89 @@ +#if UNITY_IPHONE_API + +using System; +using System.Collections; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace UnityEngine +{ +public sealed partial class iPhone +{ + [System.Runtime.InteropServices.DllImport("__Internal")] + internal static extern void UnityNSObject_RetainObject(IntPtr obj); + + [System.Runtime.InteropServices.DllImport("__Internal")] + internal static extern void UnityNSObject_ReleaseObject(IntPtr obj); + + public sealed partial class NSError + { + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern int UnityNSError_Code(IntPtr errorObj); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern IntPtr UnityNSError_Description(IntPtr errorObj); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern IntPtr UnityNSError_Reason(IntPtr errorObj); + + + private IntPtr _nativeError; + private NSError(IntPtr nativeError) + { + _nativeError = nativeError; + UnityNSObject_RetainObject(_nativeError); + } + ~NSError() + { + UnityNSObject_ReleaseObject(_nativeError); + } + + public static NSError CreateNSError(IntPtr nativeError) + { + return nativeError == IntPtr.Zero ? null : new NSError(nativeError); + } + + public int code + { + get { return UnityNSError_Code(_nativeError); } + } + public string description + { + get { return Marshal.PtrToStringAnsi(UnityNSError_Description(_nativeError)); } + } + public string reason + { + get { return Marshal.PtrToStringAnsi(UnityNSError_Reason(_nativeError)); } + } + } + + public sealed partial class NSNotification + { + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern IntPtr UnityNSNotification_Name(IntPtr notificationObj); + + private IntPtr _nativeNotification; + private NSNotification(IntPtr nativeNotification) + { + _nativeNotification = nativeNotification; + UnityNSObject_RetainObject(_nativeNotification); + } + ~NSNotification() + { + UnityNSObject_ReleaseObject(_nativeNotification); + } + + public static NSNotification CreateNSNotification(IntPtr nativeNotification) + { + return nativeNotification == IntPtr.Zero ? null : new NSNotification(nativeNotification); + } + + public string name + { + get { return Marshal.PtrToStringAnsi(UnityNSNotification_Name(_nativeNotification)); } + } + } +} +} + +#endif 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 diff --git a/Runtime/Export/iOS/iAD.txt b/Runtime/Export/iOS/iAD.txt new file mode 100644 index 0000000..725e4e6 --- /dev/null +++ b/Runtime/Export/iOS/iAD.txt @@ -0,0 +1,91 @@ +C++RAW + +#include "UnityPrefix.h" +#include "Runtime/Math/Vector2.h" +#include "Runtime/Scripting/ScriptingUtility.h" + +using namespace Unity; + +CSRAW +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Collections; + +namespace UnityEngine +{ + +CONDITIONAL UNITY_IPHONE_API +CLASS ADBannerView + + C++RAW extern void* UnityAD_CreateBanner(int, int); + C++RAW extern void UnityAD_DestroyBanner(void*); + C++RAW extern void UnityAD_ShowBanner(void*, bool); + C++RAW extern void UnityAD_MoveBanner(void*, float, float); + C++RAW extern void UnityAD_LayoutBanner(void*, int); + C++RAW extern bool UnityAD_BannerTypeAvailable(int); + C++RAW extern void UnityAD_BannerPosition(void*, float*, float*); + C++RAW extern void UnityAD_BannerSize(void*, float*, float*); + C++RAW extern bool UnityAD_BannerAdLoaded(void*); + C++RAW extern bool UnityAD_BannerAdVisible(void*); + + + CUSTOM private static IntPtr Native_CreateBanner(int type, int layout) { return UnityAD_CreateBanner(type, layout); } + CUSTOM private static void Native_ShowBanner(IntPtr view, bool show) { UnityAD_ShowBanner(view, show); } + CUSTOM private static void Native_MoveBanner(IntPtr view, Vector2 pos) { UnityAD_MoveBanner(view, pos.x, pos.y); } + CUSTOM private static void Native_LayoutBanner(IntPtr view, int layout) { UnityAD_LayoutBanner(view, layout); } + CUSTOM private static bool Native_BannerTypeAvailable(int type) { return UnityAD_BannerTypeAvailable(type); } + CUSTOM private static void Native_BannerPosition(IntPtr view, out Vector2 pos){ UnityAD_BannerPosition(view, &pos->x, &pos->y); } + CUSTOM private static void Native_BannerSize(IntPtr view, out Vector2 pos) { UnityAD_BannerSize(view, &pos->x, &pos->y); } + CUSTOM private static bool Native_BannerAdLoaded(IntPtr view) { return UnityAD_BannerAdLoaded(view); } + CUSTOM private static bool Native_BannerAdVisible(IntPtr view) { return UnityAD_BannerAdVisible(view); } + + + THREAD_SAFE CUSTOM private static void Native_DestroyBanner(IntPtr view) { UnityAD_DestroyBanner(view); } + +END + +CONDITIONAL UNITY_IPHONE_API +CLASS ADInterstitialAd + + C++RAW extern void* UnityAD_CreateInterstitial(bool); + C++RAW extern void UnityAD_DestroyInterstitial(void*); + C++RAW extern void UnityAD_ShowInterstitial(void*); + C++RAW extern void UnityAD_ReloadInterstitial(void*); + C++RAW extern bool UnityAD_InterstitialAvailable(); + C++RAW extern bool UnityAD_InterstitialAdLoaded(void*); + + + CUSTOM private static IntPtr Native_CreateInterstitial(bool autoReload) { return UnityAD_CreateInterstitial(autoReload); } + CUSTOM private static void Native_ShowInterstitial(IntPtr view) { UnityAD_ShowInterstitial(view); } + CUSTOM private static void Native_ReloadInterstitial(IntPtr view) { UnityAD_ReloadInterstitial(view); } + CUSTOM private static bool Native_InterstitialAdLoaded(IntPtr view) { return UnityAD_InterstitialAdLoaded(view); } + CUSTOM private static bool Native_InterstitialAvailable() { return UnityAD_InterstitialAvailable(); } + + + THREAD_SAFE CUSTOM private static void Native_DestroyInterstitial(IntPtr view) { UnityAD_DestroyInterstitial(view); } +END + + +CSRAW +} + +C++RAW +#if !UNITY_IPHONE + void* UnityAD_CreateBanner(int, int) { return 0; } + void UnityAD_DestroyBanner(void*) {} + void UnityAD_ShowBanner(void*, bool) {} + void UnityAD_MoveBanner(void*, float, float) {} + void UnityAD_LayoutBanner(void*, int) {} + bool UnityAD_BannerTypeAvailable(int) { return false; } + void UnityAD_BannerPosition(void*, float*, float*) {} + void UnityAD_BannerSize(void*, float*, float*) {} + bool UnityAD_BannerAdLoaded(void*) { return false; } + bool UnityAD_BannerAdVisible(void*) { return false; } + void* UnityAD_CreateInterstitial(bool) { return 0; } + void UnityAD_DestroyInterstitial(void*) {} + void UnityAD_ShowInterstitial(void*) {} + void UnityAD_ReloadInterstitial(void*) {} + bool UnityAD_InterstitialAvailable() { return false; } + bool UnityAD_InterstitialAdLoaded(void*) { return false; } +#endif |