1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
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
|