com.azerion.bluestack 2.0.1 → 3.0.0-preview2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Editor/BlueStackDependencies.xml +1 -1
- package/Example/Azerion.BlueStack.Example.asmdef +16 -0
- package/Example/Azerion.BlueStack.Example.asmdef.meta +7 -0
- package/Example/Prefabs/NativeAd.prefab +908 -0
- package/Example/Prefabs/NativeAd.prefab.meta +7 -0
- package/Example/Prefabs/SmallNativeAd.prefab +739 -0
- package/Example/Prefabs/SmallNativeAd.prefab.meta +7 -0
- package/Example/Prefabs.meta +8 -0
- package/Example/Scripts/NativeAdManager.cs +208 -0
- package/Example/Scripts/NativeAdManager.cs.meta +11 -0
- package/Example/Scripts/SmallNativeAdManager.cs +181 -0
- package/Example/Scripts/SmallNativeAdManager.cs.meta +11 -0
- package/Example/Scripts.meta +8 -0
- package/Example.meta +8 -0
- package/Plugins/Android/{bluestack-unity-android-bridge-1.0.1.aar → bluestack-unity-android-bridge-2.0.0-preview1.aar} +0 -0
- package/Plugins/Android/{bluestack-unity-android-bridge-1.0.1.aar.meta → bluestack-unity-android-bridge-2.0.0-preview1.aar.meta} +1 -1
- package/Plugins/iOS/BSUInterface.h +14 -0
- package/Plugins/iOS/BSUInterface.m +83 -1
- package/Plugins/iOS/BSUNativeAd.h +32 -0
- package/Plugins/iOS/BSUNativeAd.h.meta +27 -0
- package/Plugins/iOS/BSUNativeAd.m +82 -0
- package/Plugins/iOS/BSUNativeAd.m.meta +37 -0
- package/Plugins/iOS/BSUTypes.h +12 -0
- package/Runtime/API/BlueStackAds.cs +4 -2
- package/Runtime/API/NativeAd/NativeAd.cs +182 -0
- package/Runtime/API/NativeAd/NativeAd.cs.meta +3 -0
- package/Runtime/API/NativeAd/NativeAdEventArgs.cs +14 -0
- package/Runtime/API/NativeAd/NativeAdEventArgs.cs.meta +11 -0
- package/Runtime/API/NativeAd/NativeAdInteractionHandler.cs +157 -0
- package/Runtime/API/NativeAd/NativeAdInteractionHandler.cs.meta +11 -0
- package/Runtime/API/NativeAd/NativeAdInteractionUtils.cs +122 -0
- package/Runtime/API/NativeAd/NativeAdInteractionUtils.cs.meta +11 -0
- package/Runtime/API/NativeAd/NativeAdLoader.cs +57 -0
- package/Runtime/API/NativeAd/NativeAdLoader.cs.meta +11 -0
- package/Runtime/API/NativeAd/NativeAdObject.cs +520 -0
- package/Runtime/API/NativeAd/NativeAdObject.cs.meta +11 -0
- package/Runtime/API/NativeAd/NativeAdType.cs +8 -0
- package/Runtime/API/NativeAd/NativeAdType.cs.meta +11 -0
- package/Runtime/API/NativeAd/NativeAssetID.cs +30 -0
- package/Runtime/API/NativeAd/NativeAssetID.cs.meta +11 -0
- package/Runtime/API/NativeAd/NativeClientFactoryManager.cs +32 -0
- package/Runtime/API/NativeAd/NativeClientFactoryManager.cs.meta +11 -0
- package/Runtime/API/NativeAd.meta +8 -0
- package/Runtime/Common/NativeAd/AdLoaderClientArgs.cs +16 -0
- package/Runtime/Common/NativeAd/AdLoaderClientArgs.cs.meta +11 -0
- package/Runtime/Common/NativeAd/AdsEventExecutor.cs +84 -0
- package/Runtime/Common/NativeAd/AdsEventExecutor.cs.meta +11 -0
- package/Runtime/Common/NativeAd/DummyNativeClient.cs +61 -0
- package/Runtime/Common/NativeAd/DummyNativeClient.cs.meta +11 -0
- package/Runtime/Common/NativeAd/NativeClientEventArgs.cs +10 -0
- package/Runtime/Common/NativeAd/NativeClientEventArgs.cs.meta +11 -0
- package/Runtime/Common/NativeAd/NativeUtils.cs +117 -0
- package/Runtime/Common/NativeAd/NativeUtils.cs.meta +11 -0
- package/Runtime/Internal/IClientsFactory.cs +5 -2
- package/Runtime/Internal/NativeAd/IAdLoaderClient.cs +24 -0
- package/Runtime/Internal/NativeAd/IAdLoaderClient.cs.meta +11 -0
- package/Runtime/Internal/NativeAd/INativeAdClient.cs +25 -0
- package/Runtime/Internal/NativeAd/INativeAdClient.cs.meta +3 -0
- package/Runtime/Internal/NativeAd/INativeAdInteractionHandlerClient.cs +15 -0
- package/Runtime/Internal/NativeAd/INativeAdInteractionHandlerClient.cs.meta +11 -0
- package/Runtime/Internal/NativeAd/INativeClientFactory.cs +9 -0
- package/Runtime/Internal/NativeAd/INativeClientFactory.cs.meta +11 -0
- package/Runtime/Internal/NativeAd.meta +8 -0
- package/Runtime/Platforms/Android/AndroidJavaObjectFactory.cs +9 -1
- package/Runtime/Platforms/Android/BannerAdClient.cs +1 -1
- package/Runtime/Platforms/Android/BlueStackClient.cs +1 -1
- package/Runtime/Platforms/Android/BlueStackErrorUtils.cs +1 -1
- package/Runtime/Platforms/Android/BlueStackNativeClassNames.cs +4 -1
- package/Runtime/Platforms/Android/ClientsFactory.cs +12 -1
- package/Runtime/Platforms/Android/InitializationStatusClient.cs +1 -1
- package/Runtime/Platforms/Android/InterstitialAdClient.cs +1 -1
- package/Runtime/Platforms/Android/NativeAdClient.cs +108 -0
- package/Runtime/Platforms/Android/NativeAdClient.cs.meta +3 -0
- package/Runtime/Platforms/Android/PreferenceClient.cs +1 -1
- package/Runtime/Platforms/Android/RewardedVideoAdClient.cs +1 -1
- package/Runtime/Platforms/Unity/BannerAdClient.cs +1 -0
- package/Runtime/Platforms/Unity/ClientsFactory.cs +6 -1
- package/Runtime/Platforms/Unity/NativeAdClient.cs +101 -0
- package/Runtime/Platforms/Unity/NativeAdClient.cs.meta +3 -0
- package/Runtime/Platforms/Unity/RewardedTimer.cs +2 -2
- package/Runtime/Platforms/Unity/Utils.cs +73 -0
- package/Runtime/Platforms/Unity/Utils.cs.meta +11 -0
- package/Runtime/Platforms/iOS/BannerAdClient.cs +1 -1
- package/Runtime/Platforms/iOS/BlueStackClient.cs +1 -1
- package/Runtime/Platforms/iOS/BlueStackErrorUtils.cs +1 -1
- package/Runtime/Platforms/iOS/ClientsFactory.cs +13 -1
- package/Runtime/Platforms/iOS/Externs.cs +49 -1
- package/Runtime/Platforms/iOS/InitializationStatusClient.cs +1 -1
- package/Runtime/Platforms/iOS/InterstitialAdClient.cs +1 -1
- package/Runtime/Platforms/iOS/NativeAdClient.cs +156 -0
- package/Runtime/Platforms/iOS/NativeAdClient.cs.meta +3 -0
- package/Runtime/Platforms/iOS/PreferenceClient.cs +1 -1
- package/Runtime/Platforms/iOS/RewardedVideoAdClient.cs +1 -1
- package/Runtime/Platforms/iOS/Utils.cs +1 -1
- package/Runtime/Utilities/MiniJSON.cs +581 -0
- package/Runtime/Utilities/MiniJSON.cs.meta +11 -0
- package/Runtime/Utilities.meta +8 -0
- package/package.json +1 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using System.Runtime.CompilerServices;
|
|
4
|
+
using System.Threading;
|
|
5
|
+
using Azerion.BlueStack.Common;
|
|
6
|
+
using Azerion.BlueStack.Internal;
|
|
7
|
+
using UnityEngine;
|
|
8
|
+
|
|
9
|
+
// WIP
|
|
10
|
+
namespace Azerion.BlueStack.API
|
|
11
|
+
{
|
|
12
|
+
public class NativeAdLoader
|
|
13
|
+
{
|
|
14
|
+
private IAdLoaderClient _adLoaderClient;
|
|
15
|
+
public event EventHandler<BlueStackError> OnNativeAdFailedToLoad;
|
|
16
|
+
public event EventHandler<NativeAdEventArgs> OnNativeAdLoaded;
|
|
17
|
+
|
|
18
|
+
internal bool IsAdLoaded;
|
|
19
|
+
internal GameObject AdGameObject;
|
|
20
|
+
private NativeAd _nativeAd;
|
|
21
|
+
|
|
22
|
+
public NativeAdLoader(string adUnitId)
|
|
23
|
+
{
|
|
24
|
+
AdUnitId = adUnitId;
|
|
25
|
+
|
|
26
|
+
NativeUtils.CheckInitialization();
|
|
27
|
+
|
|
28
|
+
_nativeAd = new NativeAd(AdUnitId);
|
|
29
|
+
|
|
30
|
+
_nativeAd.OnNativeAdDidFail += (sender, args) =>
|
|
31
|
+
{
|
|
32
|
+
OnNativeAdFailedToLoad?.Invoke(this, args);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
_nativeAd.OnNativeAdDidLoad +=(_sender, _args) =>
|
|
36
|
+
{
|
|
37
|
+
NativeAdEventArgs nativeAdEventArgs = new NativeAdEventArgs
|
|
38
|
+
{
|
|
39
|
+
nativeAd = _nativeAd
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
this.OnNativeAdLoaded?.Invoke(this, nativeAdEventArgs);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public string AdUnitId { get; private set; }
|
|
48
|
+
public HashSet<NativeAdType> AdTypes { get; private set; }
|
|
49
|
+
public HashSet<string> FormatIds { get; private set; }
|
|
50
|
+
internal int NumberOfAdsToLoad { get; private set; }
|
|
51
|
+
|
|
52
|
+
public void Load() => this._nativeAd.Load();
|
|
53
|
+
public void Load(Preference preference) => this._nativeAd.Load(preference);
|
|
54
|
+
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
}
|
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
using Azerion.BlueStack.Common;
|
|
2
|
+
using System;
|
|
3
|
+
using System.Collections.Generic;
|
|
4
|
+
using System.Threading;
|
|
5
|
+
using UnityEngine;
|
|
6
|
+
using UnityEngine.EventSystems;
|
|
7
|
+
using UnityEngine.UI;
|
|
8
|
+
|
|
9
|
+
namespace Azerion.BlueStack.API
|
|
10
|
+
{
|
|
11
|
+
// Struct to store screen space bounds
|
|
12
|
+
internal struct VisibilityInfo
|
|
13
|
+
{
|
|
14
|
+
public float PercentageOfVisibleArea; // Percentage of visible area
|
|
15
|
+
public float PercentageOfScreenSpace; // Percentage of screen space
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
internal struct ClickInfo
|
|
19
|
+
{
|
|
20
|
+
public Vector3 clickPosition;
|
|
21
|
+
public float clickTime;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
internal class ClickEventArgs : EventArgs
|
|
25
|
+
{
|
|
26
|
+
public ClickInfo startClick { get; set; }
|
|
27
|
+
public ClickInfo endClick { get; set; }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
internal enum HitStatus
|
|
31
|
+
{
|
|
32
|
+
Miss,
|
|
33
|
+
ObstructedHit,
|
|
34
|
+
UnobstructedHit,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
[AddComponentMenu(""), DisallowMultipleComponent, HideInInspector]
|
|
38
|
+
internal sealed class NativeAdObject : MonoBehaviour
|
|
39
|
+
{
|
|
40
|
+
private const float _timeInterval = 0.1f;
|
|
41
|
+
private const int _iterations = 5;
|
|
42
|
+
private float _interactionTime;
|
|
43
|
+
private float _lastInteractionTime;
|
|
44
|
+
private bool _isVisible;
|
|
45
|
+
private ClickInfo _clickInfo;
|
|
46
|
+
private string _objectTag;
|
|
47
|
+
private bool _is2DColliderPresent;
|
|
48
|
+
private bool _isRectTransPresent;
|
|
49
|
+
private bool _isInteractionStarted;
|
|
50
|
+
internal event EventHandler<EventArgs> OnAdDisplay;
|
|
51
|
+
internal event EventHandler<ClickEventArgs> OnAdClick;
|
|
52
|
+
internal float InteractionTime
|
|
53
|
+
{
|
|
54
|
+
get
|
|
55
|
+
{
|
|
56
|
+
return this._interactionTime;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
internal string ObjectTag
|
|
61
|
+
{
|
|
62
|
+
get
|
|
63
|
+
{
|
|
64
|
+
return this._objectTag;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public void Start()
|
|
69
|
+
{
|
|
70
|
+
this._lastInteractionTime = 0f;
|
|
71
|
+
this._isVisible = false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public void Initialize(string tag, bool isClickable = false)
|
|
75
|
+
{
|
|
76
|
+
_objectTag = tag;
|
|
77
|
+
string exMessage;
|
|
78
|
+
|
|
79
|
+
// Check if the GameObject has a Renderer component.
|
|
80
|
+
Renderer rendererComponent = GetComponent<Renderer>();
|
|
81
|
+
if (rendererComponent != null)
|
|
82
|
+
{
|
|
83
|
+
_isVisible = rendererComponent.isVisible;
|
|
84
|
+
|
|
85
|
+
if (GetComponent<Collider>() == null)
|
|
86
|
+
{
|
|
87
|
+
if (GetComponent<Collider2D>() == null)
|
|
88
|
+
{
|
|
89
|
+
throw new InvalidOperationException(" No Collider or Collider2D component found.");
|
|
90
|
+
}
|
|
91
|
+
else
|
|
92
|
+
{
|
|
93
|
+
_is2DColliderPresent = true;
|
|
94
|
+
Debug.Log("2D Collider Present!!!");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else
|
|
98
|
+
{
|
|
99
|
+
Debug.Log("Collider Present!!!");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else if (IsValidUIObject())
|
|
103
|
+
{
|
|
104
|
+
_isVisible = true;
|
|
105
|
+
_isRectTransPresent = true;
|
|
106
|
+
}
|
|
107
|
+
else
|
|
108
|
+
{
|
|
109
|
+
throw new InvalidOperationException(" Not a valid Ad Object.");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!_isVisible)
|
|
113
|
+
{
|
|
114
|
+
throw new InvalidOperationException(" Object is not visible.");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
InvokeRepeating("CheckForImpression", 0f, this.TimeInterval());
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
ClickInfo _startClick;
|
|
121
|
+
ClickInfo _endClick;
|
|
122
|
+
|
|
123
|
+
public void Update()
|
|
124
|
+
{
|
|
125
|
+
this._lastInteractionTime += (Time.deltaTime - this._lastInteractionTime) * 0.1f;
|
|
126
|
+
|
|
127
|
+
if (Input.GetMouseButtonDown(0))
|
|
128
|
+
{
|
|
129
|
+
this._isInteractionStarted = true;
|
|
130
|
+
_startClick.clickPosition = Input.mousePosition;
|
|
131
|
+
_startClick.clickTime = Time.time * 1000f;
|
|
132
|
+
}
|
|
133
|
+
else if (this._isInteractionStarted && Input.GetMouseButtonUp(0))
|
|
134
|
+
{
|
|
135
|
+
this._isInteractionStarted = false;
|
|
136
|
+
_endClick.clickPosition = Input.mousePosition;
|
|
137
|
+
_endClick.clickTime = Time.time * 1000f;
|
|
138
|
+
|
|
139
|
+
HitStatus hitStatus;
|
|
140
|
+
|
|
141
|
+
if (!_is2DColliderPresent)
|
|
142
|
+
{
|
|
143
|
+
hitStatus = CheckHitStatus3D(Input.mousePosition);
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
else
|
|
147
|
+
{
|
|
148
|
+
hitStatus = CheckHitStatus2D(Input.mousePosition);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// hitStatus = CheckHitStatusCanvas(Input.mousePosition);
|
|
152
|
+
// Debug.Log("Hit Status::::::: " + hitStatus.ToString());
|
|
153
|
+
if (hitStatus == HitStatus.UnobstructedHit)
|
|
154
|
+
{
|
|
155
|
+
OnAdClick?.Invoke(this, new ClickEventArgs { startClick = _startClick, endClick = _endClick });
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Method to get screen space bounds
|
|
161
|
+
internal VisibilityInfo GetVisibilityInfo()
|
|
162
|
+
{
|
|
163
|
+
// Get camera component
|
|
164
|
+
Camera mainCamera = NativeUtils.GetCamera();
|
|
165
|
+
VisibilityInfo visibilityInfo = new VisibilityInfo(); // Create a new struct
|
|
166
|
+
// Get gameobject to check bounds for
|
|
167
|
+
GameObject currentGameObject = this.gameObject;
|
|
168
|
+
// Get world space bounds
|
|
169
|
+
Bounds worldSpaceBounds;
|
|
170
|
+
if (!_is2DColliderPresent) // Check if 3D object
|
|
171
|
+
{
|
|
172
|
+
worldSpaceBounds = currentGameObject.GetComponent<Collider>().bounds;
|
|
173
|
+
}
|
|
174
|
+
else
|
|
175
|
+
{
|
|
176
|
+
worldSpaceBounds = currentGameObject.GetComponent<Collider2D>().bounds;
|
|
177
|
+
}
|
|
178
|
+
// Get max bounds
|
|
179
|
+
Vector3 maxBounds = NativeUtils.GetBoundsMax(currentGameObject, mainCamera, worldSpaceBounds);
|
|
180
|
+
// Get min bounds
|
|
181
|
+
Vector3 minBounds = NativeUtils.GetBoundsMin(currentGameObject, mainCamera, worldSpaceBounds);
|
|
182
|
+
|
|
183
|
+
// Calculate screen space bounds
|
|
184
|
+
float minX = Math.Max(0.0f, minBounds.x);
|
|
185
|
+
float minY = Math.Max(0.0f, minBounds.y);
|
|
186
|
+
float maxX = Math.Min(Screen.width, maxBounds.x);
|
|
187
|
+
float maxY = Math.Min(Screen.height, maxBounds.y);
|
|
188
|
+
|
|
189
|
+
// Increment amounts
|
|
190
|
+
int xDivisions = (int) ((maxX - minX) / 5.0);
|
|
191
|
+
int yDivisions = (int) ((maxY - minY) / 5.0);
|
|
192
|
+
|
|
193
|
+
// Check if center is visible
|
|
194
|
+
if (xDivisions <= 0 || yDivisions <= 0)
|
|
195
|
+
{
|
|
196
|
+
return visibilityInfo;
|
|
197
|
+
}
|
|
198
|
+
// Calculate screen space area
|
|
199
|
+
float width = maxX - minX;
|
|
200
|
+
float height = maxY - minY;
|
|
201
|
+
|
|
202
|
+
// Check if height, width are neg
|
|
203
|
+
if (width <= 0.0f || height <= 0.0f)
|
|
204
|
+
{
|
|
205
|
+
return visibilityInfo;
|
|
206
|
+
}
|
|
207
|
+
float area = width * height;
|
|
208
|
+
|
|
209
|
+
// Set values in Visibility Info
|
|
210
|
+
// visibilityInfo.PercentageOfVisibleArea = !this._is2DColliderPresent ? this.CalculatePercentageOfVisibleArea3D(minX, maxX, minY, maxY, xDivisions, yDivisions)
|
|
211
|
+
// : this.CalculatePercentageOfVisibleArea3D(minX, maxX, minY, maxY, xDivisions, yDivisions);
|
|
212
|
+
|
|
213
|
+
visibilityInfo.PercentageOfVisibleArea = CalculatePercentageOfVisibleArea(minX, maxX, minY, maxY, xDivisions, yDivisions);
|
|
214
|
+
visibilityInfo.PercentageOfScreenSpace = area / (Screen.width * Screen.height);
|
|
215
|
+
return visibilityInfo;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Methods to check if the given input vector is obstructed or unobstructed v
|
|
219
|
+
|
|
220
|
+
public HitStatus CheckHitStatus2D(Vector3 position)
|
|
221
|
+
{
|
|
222
|
+
// Create a ray from the camera to the specified screen point
|
|
223
|
+
Ray ray = NativeUtils.GetCamera().ScreenPointToRay(position);
|
|
224
|
+
|
|
225
|
+
// Perform a 2D raycast and store the result
|
|
226
|
+
var rayIntersection = Physics2D.GetRayIntersection(ray);
|
|
227
|
+
// Check if the raycast hit is obstructed by a Collider component
|
|
228
|
+
if (rayIntersection.collider != null)
|
|
229
|
+
{
|
|
230
|
+
if (rayIntersection.collider == GetComponent<Collider2D>())
|
|
231
|
+
{
|
|
232
|
+
// Perform a 3D raycast and store the result
|
|
233
|
+
if (Physics.Raycast(ray, out var hitInfo, float.PositiveInfinity))
|
|
234
|
+
{
|
|
235
|
+
// Check if the 3D raycast hit is closer than the 2D raycast hit
|
|
236
|
+
if (rayIntersection.distance >= hitInfo.distance)
|
|
237
|
+
{
|
|
238
|
+
return HitStatus.ObstructedHit;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// Return unobstructed hit if no obstructions were found
|
|
242
|
+
return HitStatus.UnobstructedHit;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Perform a 2D raycast and store the results in an array
|
|
247
|
+
RaycastHit2D[] rayIntersectionAll = Physics2D.GetRayIntersectionAll(ray);
|
|
248
|
+
// Loop through the raycast hits
|
|
249
|
+
foreach (var raycastHit2D in rayIntersectionAll)
|
|
250
|
+
{
|
|
251
|
+
// Check if the raycast hit is obstructed by the Collider2D component
|
|
252
|
+
if (raycastHit2D.collider == GetComponent<Collider2D>())
|
|
253
|
+
{
|
|
254
|
+
return HitStatus.ObstructedHit;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return this.CheckHitStatusCanvas(position);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
private HitStatus CheckHitStatusCanvas(Vector3 position)
|
|
261
|
+
{
|
|
262
|
+
GraphicRaycaster parentGraphicRaycaster = GetComponentInParent<GraphicRaycaster>();
|
|
263
|
+
if(parentGraphicRaycaster == null)
|
|
264
|
+
{
|
|
265
|
+
return HitStatus.Miss;
|
|
266
|
+
}
|
|
267
|
+
EventSystem currentEventSystem = EventSystem.current;
|
|
268
|
+
if(currentEventSystem == null)
|
|
269
|
+
{
|
|
270
|
+
return HitStatus.Miss;
|
|
271
|
+
}
|
|
272
|
+
PointerEventData pointerEventData = new PointerEventData(currentEventSystem);
|
|
273
|
+
pointerEventData.position = position;
|
|
274
|
+
List<RaycastResult> raycastResults = new List<RaycastResult>();
|
|
275
|
+
parentGraphicRaycaster.Raycast(pointerEventData, raycastResults);
|
|
276
|
+
GameObject hitGameObject = null;
|
|
277
|
+
bool isHit = false;
|
|
278
|
+
int maxDepth = 0;
|
|
279
|
+
foreach(RaycastResult result in raycastResults)
|
|
280
|
+
{
|
|
281
|
+
if(result.gameObject == gameObject)
|
|
282
|
+
{
|
|
283
|
+
isHit = true;
|
|
284
|
+
}
|
|
285
|
+
if(result.depth > maxDepth)
|
|
286
|
+
{
|
|
287
|
+
maxDepth = result.depth;
|
|
288
|
+
hitGameObject = result.gameObject;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if(!isHit)
|
|
292
|
+
{
|
|
293
|
+
return HitStatus.Miss;
|
|
294
|
+
}
|
|
295
|
+
if(hitGameObject == gameObject)
|
|
296
|
+
{
|
|
297
|
+
return HitStatus.UnobstructedHit;
|
|
298
|
+
}
|
|
299
|
+
else
|
|
300
|
+
{
|
|
301
|
+
return HitStatus.ObstructedHit;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
private HitStatus CheckHitStatus3D(Vector3 position)
|
|
306
|
+
{
|
|
307
|
+
// Create a ray from the camera to the input vector
|
|
308
|
+
Ray ray = NativeUtils.GetCamera().ScreenPointToRay(position);
|
|
309
|
+
// Initialize variables for raycast hits
|
|
310
|
+
RaycastHit hitInfo;
|
|
311
|
+
RaycastHit2D rayIntersection;
|
|
312
|
+
// bool isHit = GetComponent<Collider>().Raycast(ray, out hitInfo, float.PositiveInfinity);
|
|
313
|
+
|
|
314
|
+
// Check for 3D raycast hit
|
|
315
|
+
if (Physics.Raycast(ray, out hitInfo, float.PositiveInfinity))
|
|
316
|
+
{
|
|
317
|
+
// Check if the hit object is the current object
|
|
318
|
+
if (hitInfo.collider == GetComponent<Collider>())
|
|
319
|
+
{
|
|
320
|
+
return HitStatus.UnobstructedHit;
|
|
321
|
+
}
|
|
322
|
+
else
|
|
323
|
+
{
|
|
324
|
+
// Check for 2D raycast hit
|
|
325
|
+
rayIntersection = Physics2D.GetRayIntersection(ray);
|
|
326
|
+
if ((UnityEngine.Object)rayIntersection.collider != (UnityEngine.Object)null &&
|
|
327
|
+
(double)rayIntersection.distance <= (double)hitInfo.distance)
|
|
328
|
+
{
|
|
329
|
+
return HitStatus.UnobstructedHit;
|
|
330
|
+
}
|
|
331
|
+
else
|
|
332
|
+
{
|
|
333
|
+
return HitStatus.ObstructedHit;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return this.CheckHitStatusCanvas(position);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// Method to check for Visible Area in screen space
|
|
341
|
+
private float CalculatePercentageOfVisibleArea(float minX, float maxX, float minY, float maxY, int xDivisions, int yDivisions)
|
|
342
|
+
{
|
|
343
|
+
// Initialize variables
|
|
344
|
+
float numUnobstructedPoints = 0.0f;
|
|
345
|
+
float totalPoints = 0.0f;
|
|
346
|
+
float currentX = minX;
|
|
347
|
+
float currentY = minY;
|
|
348
|
+
// Increment through screen space
|
|
349
|
+
while (currentX <= maxX)
|
|
350
|
+
{
|
|
351
|
+
while (currentY <= maxY)
|
|
352
|
+
{
|
|
353
|
+
// Check if point is unobstructed
|
|
354
|
+
HitStatus obstructionCheckResult = !_is2DColliderPresent
|
|
355
|
+
? CheckHitStatus3D(new Vector3(currentX, currentY, 0.0f))
|
|
356
|
+
: CheckHitStatus2D(new Vector3(currentX, currentY, 0.0f));
|
|
357
|
+
if (obstructionCheckResult == HitStatus.UnobstructedHit)
|
|
358
|
+
{
|
|
359
|
+
numUnobstructedPoints++;
|
|
360
|
+
totalPoints++;
|
|
361
|
+
}
|
|
362
|
+
else if (obstructionCheckResult == HitStatus.ObstructedHit)
|
|
363
|
+
{
|
|
364
|
+
totalPoints++;
|
|
365
|
+
}
|
|
366
|
+
currentY += yDivisions;
|
|
367
|
+
}
|
|
368
|
+
currentX += xDivisions;
|
|
369
|
+
currentY = minY;
|
|
370
|
+
}
|
|
371
|
+
return numUnobstructedPoints / totalPoints;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
public void OnDestroy()
|
|
375
|
+
{
|
|
376
|
+
base.CancelInvoke();
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
public void OnBecameVisible()
|
|
380
|
+
{
|
|
381
|
+
if (!this._isVisible)
|
|
382
|
+
{
|
|
383
|
+
InvokeRepeating("CheckForImpression", 0f, this.TimeInterval());
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
public void OnBecameInvisible() => CancelInvoke();
|
|
388
|
+
|
|
389
|
+
public void StopImpressionCheck()
|
|
390
|
+
{
|
|
391
|
+
base.CancelInvoke();
|
|
392
|
+
this._isVisible = true;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// Method to check if a UI element overlaps with the screen
|
|
396
|
+
private bool DoesUIElementOverlapScreen()
|
|
397
|
+
{
|
|
398
|
+
// Get the RectTransform component
|
|
399
|
+
RectTransform rectTransform = this.GetComponent<RectTransform>();
|
|
400
|
+
// Create a rect for the screen size
|
|
401
|
+
Rect screenRect = new Rect(0.0f, 0.0f, Screen.width, Screen.height);
|
|
402
|
+
// Get the anchored position of the UI element
|
|
403
|
+
float x = rectTransform.anchoredPosition.x + rectTransform.position.x;
|
|
404
|
+
float y = Screen.height - rectTransform.position.y - rectTransform.anchoredPosition.y;
|
|
405
|
+
// Get the size of the UI element
|
|
406
|
+
Vector2 elementSize = Vector2.Scale(rectTransform.rect.size, rectTransform.lossyScale);
|
|
407
|
+
// Create a rect for the UI element
|
|
408
|
+
Rect elementRect = new Rect(x, y, elementSize.x, elementSize.y);
|
|
409
|
+
// Check if the UI element rect overlaps with the screen rect
|
|
410
|
+
if (screenRect.Overlaps(elementRect, false))
|
|
411
|
+
{
|
|
412
|
+
return true;
|
|
413
|
+
}
|
|
414
|
+
return false;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// Method to check if a gameobject is in the camera's view frustum
|
|
418
|
+
private bool IsInViewFrustum()
|
|
419
|
+
{
|
|
420
|
+
// Check if the gameobject is rendered in the screen space overlay canvas
|
|
421
|
+
if (!NativeUtils.IsRenderedInScreenSpaceOverlayCanvas(gameObject))
|
|
422
|
+
{
|
|
423
|
+
// Get the camera component
|
|
424
|
+
Camera mainCamera = NativeUtils.GetCamera();
|
|
425
|
+
// Get the bounds of the gameobject
|
|
426
|
+
Bounds bounds;
|
|
427
|
+
if (_is2DColliderPresent)
|
|
428
|
+
{
|
|
429
|
+
bounds = this.GetComponent<Collider2D>().bounds;
|
|
430
|
+
}
|
|
431
|
+
else
|
|
432
|
+
{
|
|
433
|
+
bounds = this.GetComponent<Collider>().bounds;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// Get the view frustum planes
|
|
437
|
+
Plane[] frustumPlanes = GeometryUtility.CalculateFrustumPlanes(mainCamera);
|
|
438
|
+
|
|
439
|
+
// Check if the gameobject bounds intersect with the view frustum planes
|
|
440
|
+
if (!GeometryUtility.TestPlanesAABB(frustumPlanes, bounds))
|
|
441
|
+
{
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// Get the max bounds of the gameobject
|
|
446
|
+
Vector3 maxBounds = NativeUtils.GetBoundsMax(this.gameObject, mainCamera, bounds);
|
|
447
|
+
// Get the min bounds of the gameobject
|
|
448
|
+
Vector3 minBounds = NativeUtils.GetBoundsMin(this.gameObject, mainCamera, bounds);
|
|
449
|
+
|
|
450
|
+
float height = Math.Min(Screen.height, maxBounds.y) - Math.Max(0.0f, minBounds.y);
|
|
451
|
+
float width = Math.Min(Screen.width, maxBounds.x) - Math.Max(0.0f, minBounds.x);
|
|
452
|
+
|
|
453
|
+
// Check if the gameobject bounds are too small to be visible
|
|
454
|
+
if (height <= 0.01f * Screen.height || width <= 0.01f * Screen.width)
|
|
455
|
+
{
|
|
456
|
+
return false;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
else // When rendered in the screen space overlay canvas
|
|
460
|
+
{
|
|
461
|
+
// Check if the UI element overlaps with the screen
|
|
462
|
+
if (!DoesUIElementOverlapScreen())
|
|
463
|
+
{
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
return true;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
private void CheckForImpression()
|
|
472
|
+
{
|
|
473
|
+
if (_isVisible && IsInViewFrustum())
|
|
474
|
+
{
|
|
475
|
+
OnAdDisplay?.Invoke(this, EventArgs.Empty);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
private float TimeInterval()
|
|
479
|
+
{
|
|
480
|
+
return 0.1f;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// TODO: BSSDK-401 : Move viewability to container level
|
|
484
|
+
private bool IsValidUIObject()
|
|
485
|
+
{
|
|
486
|
+
Canvas canvas = GetComponentInParent<Canvas>();
|
|
487
|
+
if (canvas == null)
|
|
488
|
+
{
|
|
489
|
+
Debug.Log("GetComponentInParent<Canvas>()");
|
|
490
|
+
return false;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
RectTransform rectTransform = GetComponent<RectTransform>();
|
|
494
|
+
if (rectTransform == null)
|
|
495
|
+
{
|
|
496
|
+
Debug.Log("uiObject.GetComponent<RectTransform>()");
|
|
497
|
+
return false;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
Rect rect = rectTransform.rect;
|
|
501
|
+
|
|
502
|
+
// Get the center position of the RectTransform in its local coordinates
|
|
503
|
+
Vector2 centerLocalPosition = new Vector2(rect.center.x, rect.center.y);
|
|
504
|
+
|
|
505
|
+
// Convert the local center position to world position
|
|
506
|
+
Vector3 centerWorldPosition = rectTransform.TransformPoint(centerLocalPosition);
|
|
507
|
+
// Debug.Log("centerWorldPosition: " + centerWorldPosition);
|
|
508
|
+
|
|
509
|
+
Vector3 viewportPoint = NativeUtils.GetCamera().WorldToViewportPoint(centerWorldPosition);
|
|
510
|
+
// Debug.Log("viewportPoints: " + viewportPoint);
|
|
511
|
+
if (viewportPoint.x >= 0 && viewportPoint.x <= 1 && viewportPoint.y >= 0 && viewportPoint.y <= 1 && viewportPoint.z > 0)
|
|
512
|
+
{
|
|
513
|
+
return true;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
Debug.Log("Object Not visible!");
|
|
517
|
+
return false;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
namespace Azerion.BlueStack.API
|
|
2
|
+
{
|
|
3
|
+
public class NativeAssetID
|
|
4
|
+
{
|
|
5
|
+
public string Value { get; set; }
|
|
6
|
+
|
|
7
|
+
public static NativeAssetID Image => new NativeAssetID("Image");
|
|
8
|
+
|
|
9
|
+
public static NativeAssetID Icon => new NativeAssetID("Icon");
|
|
10
|
+
|
|
11
|
+
public static NativeAssetID AdChoices => new NativeAssetID("AdChoices");
|
|
12
|
+
|
|
13
|
+
public static NativeAssetID Headline => new NativeAssetID("Headline");
|
|
14
|
+
|
|
15
|
+
public static NativeAssetID Body => new NativeAssetID("Body");
|
|
16
|
+
|
|
17
|
+
public static NativeAssetID CallToAction => new NativeAssetID("CallToAction");
|
|
18
|
+
|
|
19
|
+
public static NativeAssetID Advertiser => new NativeAssetID("Advertiser");
|
|
20
|
+
|
|
21
|
+
public static NativeAssetID Price => new NativeAssetID("Price");
|
|
22
|
+
|
|
23
|
+
public static NativeAssetID Store => new NativeAssetID("Store");
|
|
24
|
+
|
|
25
|
+
private NativeAssetID(string value)
|
|
26
|
+
{
|
|
27
|
+
Value = value;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using Azerion.BlueStack.Common;
|
|
3
|
+
using Azerion.BlueStack.Internal;
|
|
4
|
+
using UnityEngine;
|
|
5
|
+
|
|
6
|
+
internal class NativeClientFactoryManager
|
|
7
|
+
{
|
|
8
|
+
private static INativeClientFactory _nativeClientFactory;
|
|
9
|
+
internal static INativeClientFactory GetNativeClientFactory()
|
|
10
|
+
{
|
|
11
|
+
if (NativeClientFactoryManager._nativeClientFactory == null)
|
|
12
|
+
{
|
|
13
|
+
string typeName;
|
|
14
|
+
switch (Application.platform)
|
|
15
|
+
{
|
|
16
|
+
case RuntimePlatform.IPhonePlayer:
|
|
17
|
+
typeName = "Azerion.BlueStack.Platforms.Android.ClientsFactory";
|
|
18
|
+
break;
|
|
19
|
+
case RuntimePlatform.Android:
|
|
20
|
+
typeName = "Azerion.BlueStack.Platforms.iOS.ClientsFactory";
|
|
21
|
+
break;
|
|
22
|
+
default:
|
|
23
|
+
typeName = "Azerion.BlueStack.Platforms.UnityEditor.ClientsFactory";
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
NativeClientFactoryManager._nativeClientFactory = (INativeClientFactory) Activator.CreateInstance(System.Type.GetType(typeName));
|
|
27
|
+
}
|
|
28
|
+
return NativeClientFactoryManager._nativeClientFactory;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
internal static IAdLoaderClient CreateAdLoaderClient(AdLoaderClientArgs args) => NativeClientFactoryManager.GetNativeClientFactory().BuildAdLoaderClient(args);
|
|
32
|
+
}
|