com.azerion.bluestack 3.1.7 → 3.1.9

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## [3.1.9] - 2024-11-07
4
+
5
+ ### fixed
6
+
7
+ - Removed unused namespaces and fixed assembly reference missing issue.
8
+
9
+ ## [3.1.8] - 2024-11-07
10
+
11
+ ### Changed
12
+
13
+ - BlueStackSettings Initialization on AssetPostProcess.
14
+
3
15
  ## [3.1.7] - 2024-10-23
4
16
 
5
17
  ### Changed
@@ -11,7 +23,7 @@
11
23
 
12
24
  ### Fixed
13
25
 
14
- - Rerestricted interaction with Native ad objects while any overlay view is on top.
26
+ - Restricted interaction with Native ad objects while any overlay view is on top.
15
27
 
16
28
  ## [3.1.6] - 2024-07-26
17
29
 
@@ -29,6 +29,7 @@ namespace Azerion.BlueStack.Editor.Android
29
29
  return;
30
30
  }
31
31
 
32
+ bool valueChanged = false;
32
33
  // Remove all networks from the packages node
33
34
  // androidPackages.RemoveAll();
34
35
 
@@ -41,16 +42,17 @@ namespace Azerion.BlueStack.Editor.Android
41
42
  if (packageNode != null)
42
43
  {
43
44
  // Remove inactive network
44
- if (!dependency.Active)
45
+ if (!dependency.IsActive)
45
46
  {
46
47
  androidPackages.RemoveChild(packageNode);
48
+ valueChanged = true;
47
49
  }
48
50
  // else keep it
49
51
  }
50
52
  else
51
53
  {
52
54
  // Add new active network
53
- if (dependency.Active)
55
+ if (dependency.IsActive)
54
56
  {
55
57
  XmlElement package = xmlDoc.CreateElement("androidPackage");
56
58
  package.SetAttribute("spec", dependency.Package);
@@ -60,54 +62,64 @@ namespace Azerion.BlueStack.Editor.Android
60
62
  package.AppendChild(repositories);
61
63
  }
62
64
  androidPackages.AppendChild(package);
65
+ valueChanged = true;
63
66
  }
64
67
  }
65
68
  }
66
69
 
67
70
  // Replace main dependency XML content with the updated XML
68
- System.IO.File.WriteAllText(xmlFilePath, xmlDoc.OuterXml);
69
- AssetDatabase.Refresh();
70
-
71
- // Debug.Log("Mediation Dependencies are updated successfully in Main Dependencies XML.");
71
+ if (valueChanged)
72
+ {
73
+ DependencyProvider.SaveDependenciesXMLFile(xmlDoc.OuterXml);
74
+ // Debug.Log("Android Mediation Dependencies are updated successfully in Main Dependencies XML.");
75
+ }
72
76
  }
73
77
 
74
78
  void IDependencyModifier.modifyMediationNetworkDependencies(string xmlFilePath,
75
79
  List<MediationNetworkDependency> dependencies)
76
80
  {
77
- XmlDocument mainDependencyXML = new XmlDocument();
81
+ XmlDocument mediationDependencyXML = new XmlDocument();
78
82
 
79
83
  try
80
84
  {
81
- mainDependencyXML.Load(xmlFilePath);
85
+ mediationDependencyXML.Load(xmlFilePath);
82
86
  }
83
87
  catch (IOException e)
84
88
  {
85
89
  throw new Exception("Unable to load xml, error: " + e.Message);
86
90
  }
87
91
 
92
+ bool valueChanged = false;
88
93
  foreach (MediationNetworkDependency dependency in dependencies)
89
94
  {
90
95
  XmlNode mainNode =
91
- mainDependencyXML.SelectSingleNode(
96
+ mediationDependencyXML.SelectSingleNode(
92
97
  $"//networkList/androidNetworks/network[@name='{dependency.Name}']");
93
98
 
94
- if (mainNode != null)
99
+ if (mainNode is { Attributes: not null })
95
100
  {
96
- mainNode.Attributes["active"].Value = dependency.Active.ToString();
101
+ if (mainNode.Attributes["active"].Value != dependency.IsActive.ToString())
102
+ {
103
+ mainNode.Attributes["active"].Value = dependency.IsActive.ToString();
104
+ valueChanged = true;
105
+ }
97
106
  }
98
107
  else
99
108
  {
100
109
  // Node doesn't exists in Mediation Dependency XML
101
110
  Debug.LogError(
102
- $"Something went wrong: Node '{dependency.Name}' doesn't exists in Mediation Dependency XML! " +
111
+ "Something went wrong: " +
112
+ $"Node '{dependency.Name}' doesn't exists in Mediation Dependency XML! " +
103
113
  "Please check if you have manually changed the xml");
104
114
  }
105
115
  }
106
116
 
107
- // Save the modified XML
108
- DependencyProvider.SaveMainXMLFile(mainDependencyXML.OuterXml);
109
-
110
- Debug.Log("Mediation Dependency XML files merged and updated successfully.");
117
+ // if changed, Save the modified XML
118
+ if (valueChanged)
119
+ {
120
+ DependencyProvider.SaveMediationDependenciesXMLFile(mediationDependencyXML.OuterXml);
121
+ // Debug.Log("Android Mediation Dependency XML files merged and updated successfully.");
122
+ }
111
123
  }
112
124
  }
113
125
  }
@@ -1,8 +1,5 @@
1
1
  using System;
2
2
  using System.IO;
3
- using Azerion.BlueStack.Editor;
4
- using Azerion.BlueStack.Editor.Android;
5
- using Azerion.BlueStack.Editor.iOS;
6
3
 
7
4
  namespace Azerion.BlueStack.Editor.Android.Gradle
8
5
  {
@@ -3,9 +3,6 @@ using System.IO;
3
3
  using System.Linq;
4
4
  using System.Xml.Linq;
5
5
  using UnityEditor;
6
- using UnityEditor.Build;
7
- using UnityEditor.Build.Reporting;
8
- using UnityEngine;
9
6
 
10
7
  namespace Azerion.BlueStack.Editor.Android
11
8
  {
@@ -0,0 +1,15 @@
1
+ using UnityEditor;
2
+
3
+ namespace Azerion.BlueStack.Editor
4
+ {
5
+ public class BlueStackAssetPostProcessor : AssetPostprocessor
6
+ {
7
+ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets,
8
+ string[] movedFromAssetPaths, bool didDomainReload)
9
+ {
10
+ // This is Required when updating the SDK.
11
+ // Initialize and Sync dependencies when project loaded in Unity Editor.
12
+ BlueStackSettingsEditor.Initialize();
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 7c805618c65b145c4bb90a8023c35d37
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -1,8 +1,5 @@
1
- using System;
2
1
  using System.Collections.Generic;
3
2
  using UnityEngine;
4
- using UnityEngine.Events;
5
- using UnityEngine.Serialization;
6
3
 
7
4
  namespace Azerion.BlueStack.Editor
8
5
  {
@@ -1,10 +1,8 @@
1
1
  using System;
2
2
  using System.Collections.Generic;
3
3
  using System.IO;
4
- using System.Linq;
5
4
  using UnityEditor;
6
5
  using UnityEngine;
7
- using System.Xml;
8
6
  using Azerion.BlueStack.Editor.Android;
9
7
  using Azerion.BlueStack.Editor.iOS;
10
8
 
@@ -40,6 +38,7 @@ namespace Azerion.BlueStack.Editor
40
38
  {
41
39
  if (BlueStackSettings.Instance == null)
42
40
  {
41
+ Debug.LogWarning("BlueStackSettings Instance is not available!");
43
42
  try
44
43
  {
45
44
  Directory.CreateDirectory(BlueStackSettingsResDir);
@@ -69,18 +68,19 @@ namespace Azerion.BlueStack.Editor
69
68
 
70
69
  // This is Required when updating the SDK.
71
70
  // Initialize and Sync dependencies when project loaded in Unity Editor.
72
- [InitializeOnLoadMethod]
73
- static void OnProjectLoadedInEditor()
74
- {
75
- Initialize();
76
- }
71
+ // This logic is now moved to OnPostprocessAllAssets of BlueStackAssetPostProcessor
72
+ // [InitializeOnLoadMethod]
73
+ // static void OnProjectLoadedInEditor()
74
+ // {
75
+ // Initialize();
76
+ // }
77
77
 
78
78
  void OnEnable()
79
79
  {
80
80
  Initialize();
81
81
  }
82
82
 
83
- static void Initialize()
83
+ public static void Initialize()
84
84
  {
85
85
  if (!DoesBlueStackSettingsExist()) return;
86
86
 
@@ -121,10 +121,10 @@ namespace Azerion.BlueStack.Editor
121
121
  foreach (var dependency in BlueStackSettings.Instance.AndroidMediationNetworks)
122
122
  {
123
123
  // dependency.Print();
124
- bool newAutomaticConfigurationFilesUpdate = GUILayout.Toggle(dependency.Active, dependency.Name);
125
- if (newAutomaticConfigurationFilesUpdate != dependency.Active)
124
+ bool newAutomaticConfigurationFilesUpdate = GUILayout.Toggle(dependency.IsActive, dependency.Name);
125
+ if (newAutomaticConfigurationFilesUpdate != dependency.IsActive)
126
126
  {
127
- dependency.Active = newAutomaticConfigurationFilesUpdate;
127
+ dependency.IsActive = newAutomaticConfigurationFilesUpdate;
128
128
  }
129
129
  }
130
130
 
@@ -135,10 +135,10 @@ namespace Azerion.BlueStack.Editor
135
135
  foreach (var dependency in BlueStackSettings.Instance.IOSMediationNetworks)
136
136
  {
137
137
  // dependency.Print();
138
- bool newAutomaticConfigurationFilesUpdate = GUILayout.Toggle(dependency.Active, dependency.Name);
139
- if (newAutomaticConfigurationFilesUpdate != dependency.Active)
138
+ bool newAutomaticConfigurationFilesUpdate = GUILayout.Toggle(dependency.IsActive, dependency.Name);
139
+ if (newAutomaticConfigurationFilesUpdate != dependency.IsActive)
140
140
  {
141
- dependency.Active = newAutomaticConfigurationFilesUpdate;
141
+ dependency.IsActive = newAutomaticConfigurationFilesUpdate;
142
142
  }
143
143
  }
144
144
 
@@ -1,6 +1,3 @@
1
- using System;
2
- using System.Collections.Generic;
3
-
4
1
  namespace Azerion.BlueStack.Editor
5
2
  {
6
3
  public class Constants
@@ -1,3 +1,4 @@
1
+ using System;
1
2
  using System.Collections.Generic;
2
3
  using System.IO;
3
4
  using System.Xml;
@@ -67,9 +68,9 @@ namespace Azerion.BlueStack.Editor
67
68
  public static void SyncDependenciesXMLs()
68
69
  {
69
70
  // Copy from the source
70
- CopyDependenciesXMLFileToAssets();
71
- if (CopyMediationDependenciesXMLFileToAssets())
71
+ if (CopyDependenciesXMLFileToAssets() & CopyMediationDependenciesXMLFileToAssets())
72
72
  {
73
+ Debug.LogWarning("XML Files Copied from package to To Assets.");
73
74
  return;
74
75
  }
75
76
 
@@ -82,7 +83,7 @@ namespace Azerion.BlueStack.Editor
82
83
  if (!XMLStructuresMatch(mainDependencyXML, updateDependencyXML))
83
84
  {
84
85
  Debug.LogWarning("XML structures do not match. replacing main with update.");
85
- SaveMainXMLFile(updateDependencyXML.OuterXml);
86
+ SaveMediationDependenciesXMLFile(updateDependencyXML.OuterXml);
86
87
  return;
87
88
  }
88
89
 
@@ -119,9 +120,7 @@ namespace Azerion.BlueStack.Editor
119
120
  }
120
121
 
121
122
  // Save the modified main XML
122
- SaveMainXMLFile(mainDependencyXML.OuterXml);
123
-
124
- // Debug.Log("Mediation Dependency XML files merged and updated successfully.");
123
+ SaveMediationDependenciesXMLFile(mainDependencyXML.OuterXml);
125
124
  }
126
125
 
127
126
  private static bool XMLStructuresMatch(XmlDocument mainDoc, XmlDocument updateDoc)
@@ -141,21 +140,40 @@ namespace Azerion.BlueStack.Editor
141
140
  return true;
142
141
  }
143
142
  }
143
+
144
+ public static void SaveDependenciesXMLFile(string updatedXML)
145
+ {
146
+ // Replace main mediation dependency XML content with the updated XML
147
+ System.IO.File.WriteAllText(_dependencyPathInAssets, updatedXML);
148
+ AssetDatabase.Refresh();
149
+ }
144
150
 
145
- public static void SaveMainXMLFile(string updatedXML)
151
+ public static void SaveMediationDependenciesXMLFile(string updatedXML)
146
152
  {
147
153
  // Replace main mediation dependency XML content with the updated XML
148
154
  System.IO.File.WriteAllText(_mediationDependencyPathInAssets, updatedXML);
149
155
  AssetDatabase.Refresh();
150
156
  }
151
-
152
- private static void CopyDependenciesXMLFileToAssets()
157
+
158
+ public static void SaveMainXMLFile(string updatedXML, string path)
153
159
  {
154
- Directory.CreateDirectory(_editorPathInAssets);
155
- FileUtil.ReplaceFile(_dependencyPathInPackage, _dependencyPathInAssets);
160
+ // Replace main XML content with the updated XML
161
+ System.IO.File.WriteAllText(path, updatedXML);
156
162
  AssetDatabase.Refresh();
157
163
  }
158
164
 
165
+ private static bool CopyDependenciesXMLFileToAssets()
166
+ {
167
+ if (!File.Exists(_dependencyPathInAssets))
168
+ {
169
+ Directory.CreateDirectory(_editorPathInAssets);
170
+ FileUtil.ReplaceFile(_dependencyPathInPackage, _dependencyPathInAssets);
171
+ AssetDatabase.Refresh();
172
+ return true;
173
+ }
174
+ return false;
175
+ }
176
+
159
177
  private static bool CopyMediationDependenciesXMLFileToAssets()
160
178
  {
161
179
  // Delete previous BlueStackMediationDependencies.xml file - TODO: remove in future
@@ -180,7 +198,7 @@ namespace Azerion.BlueStack.Editor
180
198
  Debug.Log($"====================={dependencies.Count}=====================>");
181
199
  foreach (MediationNetworkDependency dependency in dependencies)
182
200
  {
183
- Debug.Log($"Network Name: {dependency.Name}, Package: {dependency.Package}, Status: {dependency.Active}");
201
+ Debug.Log($"Network Name: {dependency.Name}, Package: {dependency.Package}, Status: {dependency.IsActive}");
184
202
  }
185
203
  Debug.Log("<==========================================");
186
204
  }
@@ -7,22 +7,22 @@ namespace Azerion.BlueStack.Editor
7
7
  [Serializable]
8
8
  public class MediationNetworkDependency
9
9
  {
10
- public MediationNetworkDependency(string name, string package, bool active, XmlNode repositories = null)
10
+ public MediationNetworkDependency(string name, string package, bool isActive, XmlNode repositories = null)
11
11
  {
12
12
  Name = name;
13
13
  Package = package;
14
- Active = active;
14
+ IsActive = isActive;
15
15
  Repositories = repositories;
16
16
  }
17
17
 
18
18
  public string Name { get; set; }
19
19
  public string Package { get; set; }
20
- public bool Active { get; set; }
20
+ public bool IsActive { get; set; }
21
21
  public XmlNode Repositories { get; set; }
22
22
 
23
23
  public void Print()
24
24
  {
25
- Debug.Log("Name: " + Name + "Package: " + Package + "Active: " + Active + "\nRepositories: " + Repositories.ToString());
25
+ Debug.Log("Name: " + Name + "Package: " + Package + "Active: " + IsActive + "\nRepositories: " + Repositories.ToString());
26
26
  }
27
27
  }
28
28
  }
@@ -6,7 +6,6 @@ using UnityEditor.Callbacks;
6
6
  using System.IO;
7
7
  using Azerion.BlueStack.Editor.iOS.PodDependency;
8
8
  using UnityEditor.iOS.Xcode;
9
- using UnityEngine;
10
9
 
11
10
  namespace Azerion.BlueStack.Editor.iOS
12
11
  {
@@ -1,9 +1,7 @@
1
1
  using System;
2
2
  using System.Collections.Generic;
3
3
  using System.IO;
4
- using System.Linq;
5
4
  using System.Xml;
6
- using UnityEditor;
7
5
  using UnityEngine;
8
6
 
9
7
  namespace Azerion.BlueStack.Editor.iOS
@@ -24,14 +22,13 @@ namespace Azerion.BlueStack.Editor.iOS
24
22
  }
25
23
 
26
24
  XmlNode mainNode = xmlDoc.SelectSingleNode($"//dependencies/iosPods/iosPod[@name='BlueStack-SDK']");
27
- if (mainNode == null || mainNode.Attributes == null)
25
+ if (mainNode?.Attributes == null)
28
26
  {
29
27
  Debug.LogError("No node with the name 'BlueStack-SDK' found in the xml");
30
28
  return;
31
29
  }
32
30
 
33
- var subspecsAttribute = mainNode.Attributes["subspecs"];
34
- if (subspecsAttribute == null)
31
+ if (mainNode.Attributes["subspecs"] == null)
35
32
  {
36
33
  Debug.LogError("No 'subspecs' Attribute found in the node 'BlueStack-SDK'");
37
34
  return;
@@ -39,67 +36,72 @@ namespace Azerion.BlueStack.Editor.iOS
39
36
 
40
37
  // remove all inactive networks from the list
41
38
  // dependencies.RemoveAll(a => dependencies.Any(b => !b.Active));
42
-
43
- mainNode.Attributes["subspecs"].Value = "[";
39
+
40
+ string subspecsValue;
41
+ subspecsValue = "[";
44
42
  foreach (MediationNetworkDependency dependency in dependencies)
45
43
  {
46
- if (dependency.Active)
44
+ if (dependency.IsActive)
47
45
  {
48
- mainNode.Attributes["subspecs"].Value += $"'{dependency.Package}', ";
46
+ subspecsValue += $"'{dependency.Package}', ";
49
47
  }
50
48
  }
51
- mainNode.Attributes["subspecs"].Value += "]";
49
+ subspecsValue += "]";
52
50
 
53
- // Replace main dependency XML content with the updated XML
54
- System.IO.File.WriteAllText(xmlFilePath, xmlDoc.OuterXml);
55
- AssetDatabase.Refresh();
56
-
57
- // Debug.Log("Mediation Dependencies are updated successfully in Main Dependencies XML.");
51
+ if (subspecsValue != mainNode.Attributes["subspecs"].Value)
52
+ {
53
+ mainNode.Attributes["subspecs"].Value = subspecsValue;
54
+
55
+ // Replace main dependency XML content with the updated XML
56
+ DependencyProvider.SaveDependenciesXMLFile(xmlDoc.OuterXml);
57
+ // Debug.Log("iOS Mediation Dependencies are updated successfully in Main Dependencies XML.");
58
+ }
58
59
  }
59
60
 
60
61
  void IDependencyModifier.modifyMediationNetworkDependencies(string xmlFilePath,
61
62
  List<MediationNetworkDependency> dependencies)
62
63
  {
63
- XmlDocument xmlDoc = new XmlDocument();
64
+ XmlDocument mediationDependencyXML = new XmlDocument();
64
65
 
65
66
  try
66
67
  {
67
- xmlDoc.Load(xmlFilePath);
68
+ mediationDependencyXML.Load(xmlFilePath);
68
69
  }
69
70
  catch (IOException e)
70
71
  {
71
72
  throw new Exception("Unable to load xml, error: " + e.Message);
72
73
  }
73
74
 
75
+ bool valueChanged = false;
74
76
  foreach (MediationNetworkDependency dependency in dependencies)
75
77
  {
76
78
  XmlNode mainNode =
77
- xmlDoc.SelectSingleNode($"//networkList/iosNetworks/network[@name='{dependency.Name}']");
79
+ mediationDependencyXML.SelectSingleNode($"//networkList/iosNetworks/network[@name='{dependency.Name}']");
78
80
 
79
- if (mainNode != null)
81
+ if (mainNode is { Attributes: not null })
80
82
  {
81
- mainNode.Attributes["active"].Value = dependency.Active.ToString();
83
+ if (mainNode.Attributes["active"].Value != dependency.IsActive.ToString())
84
+ {
85
+ mainNode.Attributes["active"].Value = dependency.IsActive.ToString();
86
+ valueChanged = true;
87
+ }
82
88
  }
83
89
  else
84
90
  {
85
91
  // Node doesn't exists in Mediation Dependency XML
86
92
  Debug.LogError(
87
- $"Something went wrong: Node '{dependency.Name}' doesn't exists in Mediation Dependency XML! " +
93
+ $"Something went wrong: " +
94
+ $"Node '{dependency.Name}' doesn't exists in Mediation Dependency XML! " +
88
95
  "Please check if you have manually changed the xml");
89
96
  }
90
97
  }
91
-
98
+
92
99
  // Replace main mediation dependency XML content with the modified XML
93
- System.IO.File.WriteAllText(xmlFilePath, xmlDoc.OuterXml);
94
- AssetDatabase.Refresh();
95
- // Debug.Log("Mediation Network Dependencies XML file updated successfully.");
96
- }
97
-
98
- private static void SaveMainXMLFile(string updatedXML, string path)
99
- {
100
- // Replace main mediation dependency XML content with the updated XML
101
- System.IO.File.WriteAllText(path, updatedXML);
102
- AssetDatabase.Refresh();
100
+ if (valueChanged)
101
+ {
102
+ DependencyProvider.SaveMediationDependenciesXMLFile(mediationDependencyXML.OuterXml);
103
+ // Debug.Log("iOS Mediation Network Dependencies XML file updated successfully.");
104
+ }
103
105
  }
104
106
  }
105
107
  }
@@ -1,6 +1,5 @@
1
1
  using System.Collections.Generic;
2
2
  using System.Xml;
3
- using UnityEngine;
4
3
 
5
4
  namespace Azerion.BlueStack.Editor.iOS
6
5
  {
@@ -1,11 +1,7 @@
1
1
  using System;
2
- using System.Collections;
3
- using System.Collections.Generic;
4
2
  using UnityEngine;
5
3
  using Azerion.BlueStack.API;
6
4
  using UnityEngine.UI;
7
- using System.Linq;
8
- using UnityEngine.Serialization;
9
5
 
10
6
  namespace Azerion.BlueStack.Example
11
7
  {
@@ -1,11 +1,7 @@
1
1
  using System;
2
- using System.Collections;
3
- using System.Collections.Generic;
4
2
  using UnityEngine;
5
3
  using Azerion.BlueStack.API;
6
4
  using UnityEngine.UI;
7
- using System.Linq;
8
- using UnityEngine.Serialization;
9
5
 
10
6
  namespace Azerion.BlueStack.Example
11
7
  {
@@ -1,6 +1,4 @@
1
1
  using System;
2
- using Azerion.BlueStack;
3
- using Azerion.BlueStack.API;
4
2
  using Azerion.BlueStack.Internal;
5
3
 
6
4
  namespace Azerion.BlueStack.API.Banner
@@ -2,7 +2,6 @@ using System;
2
2
  using Azerion.BlueStack.Internal;
3
3
  using Azerion.BlueStack.Common;
4
4
  using UnityEngine;
5
- using UnityEngine.UI;
6
5
 
7
6
  namespace Azerion.BlueStack.API
8
7
  {
@@ -87,7 +87,7 @@ namespace Azerion.BlueStack.API
87
87
  {
88
88
  nativeAdObject.Initialize(assetID, isImpressive, isClickable);
89
89
  }
90
- catch (InvalidOperationException ex)
90
+ catch (SystemException ex)
91
91
  {
92
92
  Debug.LogWarning("Unable to initialize nativeAdObject!");
93
93
  Debug.LogException(ex);
@@ -1,7 +1,5 @@
1
1
  using System;
2
2
  using System.Collections.Generic;
3
- using System.Runtime.CompilerServices;
4
- using System.Threading;
5
3
  using Azerion.BlueStack.Common;
6
4
  using Azerion.BlueStack.Internal;
7
5
  using UnityEngine;
@@ -1,10 +1,8 @@
1
1
  using Azerion.BlueStack.Common;
2
2
  using System;
3
3
  using System.Collections.Generic;
4
- using System.Threading;
5
4
  using UnityEngine;
6
5
  using UnityEngine.EventSystems;
7
- using UnityEngine.Serialization;
8
6
  using UnityEngine.UI;
9
7
 
10
8
  namespace Azerion.BlueStack.API
@@ -34,7 +32,7 @@ namespace Azerion.BlueStack.API
34
32
  ObstructedHit,
35
33
  UnobstructedHit,
36
34
  }
37
-
35
+
38
36
  [AddComponentMenu(""), DisallowMultipleComponent, HideInInspector]
39
37
  internal sealed class NativeAdObject : MonoBehaviour
40
38
  {
@@ -51,11 +49,46 @@ namespace Azerion.BlueStack.API
51
49
  internal bool HasMadeImpression;
52
50
  internal bool IsImpressive;
53
51
  internal bool IsClickable;
54
-
52
+ internal bool IsUIObject;
53
+
54
+
55
55
  internal float InteractionTime { get; private set; }
56
56
 
57
57
  internal string ObjectTag { get; private set; }
58
58
 
59
+ private Canvas _canvas;
60
+ private Canvas CanvasComponent
61
+ {
62
+ get
63
+ {
64
+ if (_canvas == null)
65
+ {
66
+ _canvas = GetComponent<Canvas>();
67
+
68
+ if (_canvas == null)
69
+ {
70
+ _canvas = GetComponentInParent<Canvas>();
71
+ }
72
+ }
73
+ return _canvas;
74
+ }
75
+ }
76
+
77
+ private CanvasRenderer _canvasRenderer;
78
+ private CanvasRenderer CanvasRendererComponent => _canvasRenderer ??= GetComponent<CanvasRenderer>();
79
+
80
+ private RectTransform _rectTransform;
81
+ private RectTransform RectTransformComponent => _rectTransform ??= GetComponent<RectTransform>();
82
+
83
+ private Renderer _renderer;
84
+ private Renderer RendererComponent => _renderer ??= GetComponent<Renderer>();
85
+
86
+ private Collider2D _collider2D;
87
+ private Collider2D Collider2DComponent => _collider2D ??= GetComponent<Collider2D>();
88
+
89
+ private Collider _collider;
90
+ private Collider ColliderComponent => _collider ??= GetComponent<Collider>();
91
+
59
92
  public void Start()
60
93
  {
61
94
  _lastInteractionTime = 0f;
@@ -69,7 +102,7 @@ namespace Azerion.BlueStack.API
69
102
  IsClickable = isClickable;
70
103
 
71
104
  // Check for Collider or Collider2D
72
- if (!ValidateColliders())
105
+ if (!HasCollider())
73
106
  {
74
107
  throw new MissingComponentException("No Collider or Collider2D component found.");
75
108
  }
@@ -77,7 +110,7 @@ namespace Azerion.BlueStack.API
77
110
  // Check if the GameObject has a Renderer or is a valid UI object
78
111
  if (!ValidateRendererOrUIObject(nativeAssetID))
79
112
  {
80
- throw new MissingComponentException("Not a valid Ad Object, No Renderer or UI components found.");
113
+ throw new InvalidOperationException("Not a valid Ad Object.");
81
114
  }
82
115
 
83
116
  if (IsImpressive)
@@ -135,11 +168,11 @@ namespace Azerion.BlueStack.API
135
168
  Bounds worldSpaceBounds;
136
169
  if (!_is2DColliderPresent) // Check if 3D object
137
170
  {
138
- worldSpaceBounds = GetComponent<Collider>().bounds;
171
+ worldSpaceBounds = ColliderComponent.bounds;
139
172
  }
140
173
  else
141
174
  {
142
- worldSpaceBounds = GetComponent<Collider2D>().bounds;
175
+ worldSpaceBounds = Collider2DComponent.bounds;
143
176
  }
144
177
 
145
178
  // Get max bounds
@@ -208,7 +241,7 @@ namespace Azerion.BlueStack.API
208
241
  // Check if the raycast hit is obstructed by a Collider component
209
242
  if (rayIntersection2D.collider != null)
210
243
  {
211
- if (rayIntersection2D.collider == GetComponent<Collider2D>())
244
+ if (rayIntersection2D.collider == Collider2DComponent)
212
245
  {
213
246
  // Perform a 3D raycast and store the result
214
247
  if (Physics.Raycast(ray, out var hitInfo3D, float.PositiveInfinity))
@@ -220,7 +253,7 @@ namespace Azerion.BlueStack.API
220
253
  }
221
254
  }
222
255
 
223
- if (IsValidUIObject())
256
+ if (IsUIObject)
224
257
  {
225
258
  return CheckHitStatusCanvas(position);
226
259
  }
@@ -230,13 +263,13 @@ namespace Azerion.BlueStack.API
230
263
  }
231
264
 
232
265
  // Check if the 2D raycast is hit but Obstructed
233
- if(NativeUtils.CheckRayHits2DCollider(ray, GetComponent<Collider2D>()))
266
+ if(NativeUtils.CheckRayHits2DCollider(ray, Collider2DComponent))
234
267
  {
235
268
  return HitStatus.ObstructedHit;
236
269
  }
237
270
  }
238
271
  // Check if the gameobject is rendered in the screen space overlay canvas and valid UI Object
239
- // else if (NativeUtils.IsRenderedInScreenSpaceOverlayCanvas(gameObject) && IsValidUIObject())
272
+ // else if (NativeUtils.IsRenderedInScreenSpaceOverlayCanvas(gameObject) && IsUIObject)
240
273
  // {
241
274
  // return CheckHitStatusCanvas(position);
242
275
  // }
@@ -301,13 +334,13 @@ namespace Azerion.BlueStack.API
301
334
  // Initialize variables for raycast hits
302
335
  RaycastHit hitInfo3D;
303
336
  RaycastHit2D rayIntersection2D;
304
- // bool isHit = GetComponent<Collider>().Raycast(ray, out hitInfo3D, float.PositiveInfinity);
337
+ // bool isHit = AdObjCollider.Raycast(ray, out hitInfo3D, float.PositiveInfinity);
305
338
 
306
339
  // Check for 3D raycast hit
307
340
  if (Physics.Raycast(ray, out hitInfo3D, float.PositiveInfinity))
308
341
  {
309
342
  // Check if the hit object is the current object
310
- if (hitInfo3D.collider == GetComponent<Collider>())
343
+ if (hitInfo3D.collider == ColliderComponent)
311
344
  {
312
345
  rayIntersection2D = Physics2D.GetRayIntersection(ray);
313
346
  if (rayIntersection2D.collider != null)
@@ -319,7 +352,7 @@ namespace Azerion.BlueStack.API
319
352
  }
320
353
  }
321
354
 
322
- if (IsValidUIObject())
355
+ if (IsUIObject)
323
356
  {
324
357
  return CheckHitStatusCanvas(position);
325
358
  }
@@ -329,13 +362,13 @@ namespace Azerion.BlueStack.API
329
362
  }
330
363
 
331
364
  // Check if the 3D raycast is hit but Obstructed
332
- if(NativeUtils.CheckRayHits3DCollider(ray, GetComponent<Collider>()))
365
+ if(NativeUtils.CheckRayHits3DCollider(ray, ColliderComponent))
333
366
  {
334
367
  return HitStatus.ObstructedHit;
335
368
  }
336
369
  }
337
370
  // Check if the gameobject is rendered in the screen space overlay canvas and valid UI Object
338
- // else if (NativeUtils.IsRenderedInScreenSpaceOverlayCanvas(gameObject) && IsValidUIObject())
371
+ // else if (NativeUtils.IsRenderedInScreenSpaceOverlayCanvas(gameObject) && IsUIObject)
339
372
  // {
340
373
  // return CheckHitStatusCanvas(position);
341
374
  // }
@@ -407,18 +440,21 @@ namespace Azerion.BlueStack.API
407
440
  // Method to check if a UI element overlaps with the screen
408
441
  private bool DoesUIElementOverlapScreen()
409
442
  {
410
- // Get the RectTransform component
411
- RectTransform rectTransform = GetComponent<RectTransform>();
443
+ if (RectTransformComponent == null)
444
+ {
445
+ Debug.LogWarning(ObjectTag + ": RectTransform component is missing.");
446
+ return false;
447
+ }
412
448
 
413
449
  // Create a rect for the screen size
414
450
  Rect screenRect = new Rect(0.0f, 0.0f, Screen.width, Screen.height);
415
451
 
416
452
  // Get the anchored position of the UI element
417
- float x = rectTransform.anchoredPosition.x + rectTransform.position.x;
418
- float y = Screen.height - rectTransform.position.y - rectTransform.anchoredPosition.y;
453
+ float x = RectTransformComponent.anchoredPosition.x + RectTransformComponent.position.x;
454
+ float y = Screen.height - RectTransformComponent.position.y - RectTransformComponent.anchoredPosition.y;
419
455
 
420
456
  // Get the size of the UI element
421
- Vector2 elementSize = Vector2.Scale(rectTransform.rect.size, rectTransform.lossyScale);
457
+ Vector2 elementSize = Vector2.Scale(RectTransformComponent.rect.size, RectTransformComponent.lossyScale);
422
458
 
423
459
  // Create a rect for the UI element
424
460
  Rect elementRect = new Rect(x, y, elementSize.x, elementSize.y);
@@ -445,11 +481,11 @@ namespace Azerion.BlueStack.API
445
481
  Bounds bounds;
446
482
  if (_is2DColliderPresent)
447
483
  {
448
- bounds = GetComponent<Collider2D>().bounds;
484
+ bounds = Collider2DComponent.bounds;
449
485
  }
450
486
  else
451
487
  {
452
- bounds = GetComponent<Collider>().bounds;
488
+ bounds = ColliderComponent.bounds;
453
489
  }
454
490
  // Debug.LogWarning("bounds: " + bounds);
455
491
 
@@ -514,15 +550,16 @@ namespace Azerion.BlueStack.API
514
550
  return 1.0f;
515
551
  }
516
552
 
517
- private bool ValidateColliders()
553
+ private bool HasCollider()
518
554
  {
519
555
  // Check for the presence of a Collider or Collider2D component
520
- if (GetComponent<Collider>() != null)
556
+ if (ColliderComponent != null)
521
557
  {
522
558
  // Regular 3D collider found, no issues
523
559
  return true;
524
560
  }
525
- else if (GetComponent<Collider2D>() != null)
561
+
562
+ if (Collider2DComponent != null)
526
563
  {
527
564
  // 2D collider found, set the flag for later use
528
565
  _is2DColliderPresent = true;
@@ -536,15 +573,14 @@ namespace Azerion.BlueStack.API
536
573
  private bool ValidateRendererOrUIObject(string nativeAssetID)
537
574
  {
538
575
  // Check for Renderer component on the GameObject
539
- Renderer rendererComponent = GetComponent<Renderer>();
540
-
541
- if (rendererComponent != null)
576
+ if (RendererComponent != null)
542
577
  {
543
- Debug.Log($"RendererComponent.isVisible: {nativeAssetID} : {rendererComponent.isVisible}");
578
+ Debug.Log($"RendererComponent.isVisible: {nativeAssetID} : {RendererComponent.isVisible}");
544
579
 
545
580
  // Throw an exception if the object is not visible
546
- if (!rendererComponent.isVisible)
581
+ if (!RendererComponent.isVisible)
547
582
  {
583
+ Debug.Log("Renderer Component not visible!!");
548
584
  throw new InvalidOperationException("Object is not visible.");
549
585
  }
550
586
 
@@ -553,9 +589,9 @@ namespace Azerion.BlueStack.API
553
589
  }
554
590
 
555
591
  // If no Renderer, check if the GameObject is a valid UI object
556
- if (IsValidUIObject())
592
+ IsUIObject = IsValidUIObject();
593
+ if (IsUIObject)
557
594
  {
558
- // Valid UI Object
559
595
  return true;
560
596
  }
561
597
 
@@ -563,42 +599,47 @@ namespace Azerion.BlueStack.API
563
599
  return false;
564
600
  }
565
601
 
566
- // TODO: More testing and Improvement required
567
- // TODO: BSSDK-401 : Move viewability to container level - may not have a container
568
602
  private bool IsValidUIObject()
569
603
  {
570
- Canvas canvas = GetComponentInParent<Canvas>();
571
- if (canvas == null)
604
+ if (CanvasComponent == null)
572
605
  {
573
- // Debug.LogWarning(ObjectTag + ": Unable to find Canvas component in parents.");
606
+ // throw new MissingComponentException("Unable to find Canvas component in parents.");
607
+ Debug.LogWarning(ObjectTag + ": Unable to find Canvas component in parents.");
574
608
  return false;
575
609
  }
576
610
 
577
- RectTransform rectTransform = GetComponent<RectTransform>();
578
- if (rectTransform == null)
611
+ if (RectTransformComponent == null)
579
612
  {
580
- // Debug.LogWarning(ObjectTag + ": RectTransform component is missing.");
613
+ // throw new MissingComponentException("RectTransform component is missing.");
614
+ Debug.LogWarning(ObjectTag + ": RectTransform component is missing.");
581
615
  return false;
582
616
  }
583
617
 
584
- CanvasRenderer canvasRenderer = GetComponent<CanvasRenderer>();
585
- if (canvasRenderer == null)
618
+ if (CanvasRendererComponent == null)
586
619
  {
587
- // Debug.LogWarning(ObjectTag + ": CanvasRenderer component is missing.");
620
+ // throw new MissingComponentException("CanvasRenderer component is missing.");
621
+ Debug.LogWarning(ObjectTag + ": CanvasRenderer component is missing.");
588
622
  return false;
589
623
  }
590
-
591
-
592
- /* // In future if want to check the center position or full object inside the viewport
593
-
594
- // Check if the center is inside the viewport
595
- Rect rect = rectTransform.rect;
624
+
625
+ return true;
626
+ }
627
+
628
+ // TODO: More testing and Improvement required
629
+ // TODO: BSSDK-401 : Move viewability to container level - may not have a container
630
+
631
+ // In future if want to check the center position or full object inside the viewport
632
+
633
+ // Check if the center is inside the viewport
634
+ private bool IsCenterInsideViewport()
635
+ {
636
+ Rect rect = RectTransformComponent.rect;
596
637
 
597
638
  // Get the center position of the RectTransform in its local coordinates
598
639
  Vector2 centerLocalPosition = new Vector2(rect.center.x, rect.center.y);
599
640
 
600
641
  // Convert the local center position to world position
601
- Vector3 centerWorldPosition = rectTransform.TransformPoint(centerLocalPosition);
642
+ Vector3 centerWorldPosition = RectTransformComponent.TransformPoint(centerLocalPosition);
602
643
  Debug.Log("centerWorldPosition: " + centerWorldPosition);
603
644
 
604
645
  Vector3 centerViewportPoint = NativeUtils.GetCamera().WorldToViewportPoint(centerWorldPosition);
@@ -610,9 +651,14 @@ namespace Azerion.BlueStack.API
610
651
  return true;
611
652
  }
612
653
 
613
- // Check if the object is completely inside the viewport
654
+ return false;
655
+ }
656
+
657
+ // Check if the object is completely inside the viewport
658
+ private bool IsCompletelyInsideViewport()
659
+ {
614
660
  Vector3[] corners = new Vector3[4];
615
- rectTransform.GetWorldCorners(corners);
661
+ RectTransformComponent.GetWorldCorners(corners);
616
662
  foreach (Vector3 corner in corners)
617
663
  {
618
664
  Vector3 cornerViewportPoint = NativeUtils.GetCamera().WorldToViewportPoint(corner);
@@ -623,10 +669,8 @@ namespace Azerion.BlueStack.API
623
669
  return true;
624
670
  }
625
671
  }
626
- */
627
- // Debug.Log("Not a Valid UI Object!");
628
-
629
- return true;
672
+
673
+ return false;
630
674
  }
631
675
 
632
676
  }
@@ -1,5 +1,4 @@
1
1
  using System;
2
- using Azerion.BlueStack;
3
2
  using Azerion.BlueStack.API.Banner;
4
3
  using Azerion.BlueStack.API;
5
4
 
@@ -1,5 +1,4 @@
1
1
  using System;
2
- using Azerion.BlueStack;
3
2
  using Azerion.BlueStack.API;
4
3
 
5
4
  namespace Azerion.BlueStack.Internal
@@ -1,5 +1,4 @@
1
1
  #if UNITY_EDITOR
2
- using System.Collections.Generic;
3
2
  using UnityEngine;
4
3
  using UnityEngine.UI;
5
4
  using UnityEditor;
@@ -1,6 +1,5 @@
1
1
  #if UNITY_EDITOR
2
2
  using System;
3
- using System.Collections.Generic;
4
3
  using Azerion.BlueStack.API;
5
4
  using Azerion.BlueStack.Internal;
6
5
 
@@ -2,9 +2,7 @@
2
2
  using System;
3
3
  using Azerion.BlueStack.API;
4
4
  using Azerion.BlueStack.Internal;
5
- using System.Collections.Generic;
6
5
  using UnityEngine;
7
- using UnityEngine.UI;
8
6
 
9
7
  namespace Azerion.BlueStack.Platforms.UnityEditor
10
8
  {
@@ -1,8 +1,5 @@
1
1
  #if UNITY_EDITOR
2
2
  using System;
3
- using System.Collections.Generic;
4
- using System.Runtime.InteropServices;
5
- using Azerion.BlueStack.API;
6
3
 
7
4
  namespace Azerion.BlueStack.Platforms.UnityEditor
8
5
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.azerion.bluestack",
3
- "version": "3.1.7",
3
+ "version": "3.1.9",
4
4
  "displayName": "BlueStack",
5
5
  "description": "BlueStack SDK has been designed to give developers options for showing Ads from different ad networks.",
6
6
  "unity": "2020.3",