Skip to content

Commit

Permalink
HMSDispatcher and bug fixes. (#146)
Browse files Browse the repository at this point in the history
* Removed banner being shown on load. Instead, we added this as a checkbox in Ads Editor.
* PriceType values are revamped into a class.
* ObtainOwnedPurchases reworked in order to get all types of product types.
* Fixed scripts not reloading after creating constant classes.
* HMSPluginUpdater bug fix.
* Fixed HMS SDK callbacks are not being called from Unity's main thread.

Co-authored-by: Samet Güzel <[email protected]>
  • Loading branch information
sametguzeldev and sametguzeldev authored May 29, 2021
1 parent 45bcf81 commit 0539a82
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 14 deletions.
Binary file modified Assets/Huawei/Dlls/HuaweiMobileServices.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Assets/Huawei/Editor/Utils/HMSPluginUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal static void Request(bool ignoreSession = false)
Task.Delay(2000).ContinueWith(t =>
{
GameObject obj = new GameObject();
obj.hideFlags = HideFlags.HideAndDontSave;
request = obj.AddComponent<HMSPluginUpdateRequest>();
request.StartRequest(ignoreSession);
Expand Down
9 changes: 8 additions & 1 deletion Assets/Huawei/Editor/View/AdsTab/HMSAdsSettingsDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal class HMSAdsSettingsDrawer : VerticalSequenceDrawer

private Toggle.Toggle _enableBannerAdsToggle;
private TextField.TextFieldWithAccept _bannerAdsTextField;
private Toggle.Toggle _enableBannerAdLoadToggle;
private DisabledDrawer _bannerAdsDisabledDrawer;

private Toggle.Toggle _enableInterstitialAdsToggle;
Expand All @@ -34,7 +35,8 @@ public HMSAdsSettingsDrawer()
_settings = HMSAdsKitSettings.Instance.Settings;
_enableBannerAdsToggle = new Toggle.Toggle("Enable Banner Ads", _settings.GetBool(HMSAdsKitSettings.EnableBannerAd), OnBannerAdsToggleChanged, false);
_bannerAdsTextField = new TextFieldWithAccept("Banner Ad ID", _settings.Get(HMSAdsKitSettings.BannerAdID), "Save", OnBannerAdIDSaveButtonClick).SetLabelWidth(0).SetButtonWidth(100);
_bannerAdsDisabledDrawer = new DisabledDrawer(_bannerAdsTextField).SetEnabled(!_enableBannerAdsToggle.IsChecked());
_enableBannerAdLoadToggle = new Toggle.Toggle("Show Banner on Load*", _settings.GetBool(HMSAdsKitSettings.ShowBannerOnLoad), OnShowBannerOnLoadChanged, false).SetTooltip("Enabling this will make the banner to be shown right after it finishes loading.");
_bannerAdsDisabledDrawer = new DisabledDrawer(new VerticalSequenceDrawer(_bannerAdsTextField, _enableBannerAdLoadToggle)).SetEnabled(!_enableBannerAdsToggle.IsChecked());

_enableInterstitialAdsToggle = new Toggle.Toggle("Enable Interstitial Ads", _settings.GetBool(HMSAdsKitSettings.EnableInterstitialAd), OnInterstitialAdsToggleChanged, false);
_interstitialAdsTextField = new TextFieldWithAccept("Interstitial Ad ID", _settings.Get(HMSAdsKitSettings.InterstitialAdID), "Save", OnInterstitialAdIDSaveButtonClick).SetLabelWidth(0).SetButtonWidth(100);
Expand Down Expand Up @@ -87,6 +89,11 @@ private void OnTestAdsToggleChanged(bool value)
_settings.SetBool(HMSAdsKitSettings.UseTestAds, value);
}

private void OnShowBannerOnLoadChanged(bool value)
{
_settings.SetBool(HMSAdsKitSettings.ShowBannerOnLoad, value);
}

private void SetupSequence()
{
AddDrawer(new HorizontalSequenceDrawer(new HorizontalLine(), new Label.Label("Banner").SetBold(true), new HorizontalLine()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ private void CreateAchievementsConstants()
}
file.WriteLine("}");
}
AssetDatabase.Refresh();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ private void CreateIAPConstants()
}
file.WriteLine("}");
}
AssetDatabase.Refresh();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;

namespace HmsPlugin
Expand Down Expand Up @@ -87,6 +88,7 @@ private void CreateRemoteConfigConstants()
}
file.WriteLine("}");
}
AssetDatabase.Refresh();
}
}

Expand Down
4 changes: 2 additions & 2 deletions Assets/Huawei/Scripts/Ads/HMSAdsKitManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void SetTestAdStatus(bool value)

#region PUBLIC METHODS

public void LoadBannerAd(UnityBannerAdPositionCodeType position, bool show = true, string bannerSize = UnityBannerAdSize.BANNER_SIZE_320_50)
public void LoadBannerAd(UnityBannerAdPositionCodeType position, string bannerSize = UnityBannerAdSize.BANNER_SIZE_320_50)
{
if (!isInitialized || !adsKitSettings.GetBool(HMSAdsKitSettings.EnableBannerAd)) return;

Expand All @@ -85,7 +85,7 @@ public void LoadBannerAd(UnityBannerAdPositionCodeType position, bool show = tru
bannerView.SizeType = bannerSize;
bannerView.AdStatusListener = bannerAdStatusListener;
bannerView.LoadBanner(new AdParam.Builder().Build());
if (show)
if (adsKitSettings.GetBool(HMSAdsKitSettings.ShowBannerOnLoad))
bannerView.ShowBanner();
else
bannerView.HideBanner();
Expand Down
26 changes: 17 additions & 9 deletions Assets/Huawei/Scripts/IAP/HMSIAPManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,19 @@ public void ObtainProductInfo(List<string> productIdConsumablesList, List<string

if (!IsNullOrEmpty(productIdConsumablesList))
{
ObtainProductInfo(new List<string>(productIdConsumablesList), 0);
ObtainProductInfo(new List<string>(productIdConsumablesList), PriceType.IN_APP_CONSUMABLE);
}
if (!IsNullOrEmpty(productIdNonConsumablesList))
{
ObtainProductInfo(new List<string>(productIdNonConsumablesList), 1);
ObtainProductInfo(new List<string>(productIdNonConsumablesList), PriceType.IN_APP_NONCONSUMABLE);
}
if (!IsNullOrEmpty(productIdSubscriptionList))
{
ObtainProductInfo(new List<string>(productIdSubscriptionList), 2);
ObtainProductInfo(new List<string>(productIdSubscriptionList), PriceType.IN_APP_SUBSCRIPTION);
}
}

private void ObtainProductInfo(IList<string> productIdNonConsumablesList, int priceType)
private void ObtainProductInfo(IList<string> productIdNonConsumablesList, PriceType priceType)
{

if (iapAvailable != true)
Expand All @@ -123,11 +123,12 @@ private void ObtainProductInfo(IList<string> productIdNonConsumablesList, int pr
{
Debug.Log("[HMSPlugin]:" + type.ErrMsg + type.ReturnCode.ToString());
Debug.Log("[HMSPlugin]: {0=Consumable} {1=Non-Consumable} {2=Subscription}");
Debug.Log("[HMSPlugin]: Found " + type.ProductInfoList.Count + " type of " + priceType + " products");
Debug.Log("[HMSPlugin]: Found " + type.ProductInfoList.Count + " type of " + priceType.Value + " products");
foreach (var productInfo in type.ProductInfoList)
{
if (!productInfoList.Exists(c => c.ProductId == productInfo.ProductId))
productInfoList.Add(productInfo);
Debug.Log("[HMSPlugin]: ProductId: " + productInfo.ProductId + ", ProductName: " + productInfo.ProductName + ", Price: " + productInfo.Price);
}
OnObtainProductInfoSuccess?.Invoke(new List<ProductInfoResult> { type });
Expand Down Expand Up @@ -304,16 +305,23 @@ public void ObtainOwnedPurchases()
return;
}


Debug.Log("HMSP: ObtainOwnedPurchaseRequest");
OwnedPurchasesReq ownedPurchasesReq = new OwnedPurchasesReq
{
PriceType = 1
};
ObtainOwnedPurchases(new OwnedPurchasesReq() { PriceType = PriceType.IN_APP_CONSUMABLE });
ObtainOwnedPurchases(new OwnedPurchasesReq() { PriceType = PriceType.IN_APP_NONCONSUMABLE });
ObtainOwnedPurchases(new OwnedPurchasesReq() { PriceType = PriceType.IN_APP_SUBSCRIPTION });
}

private void ObtainOwnedPurchases(OwnedPurchasesReq ownedPurchasesReq)
{
ITask<OwnedPurchasesResult> task = iapClient.ObtainOwnedPurchases(ownedPurchasesReq);
task.AddOnSuccessListener((result) =>
{
Debug.Log("HMSP: ObtainOwnedPurchases");
foreach (var item in result.InAppPurchaseDataList)
{
Debug.Log("[HMSPlugin]: ProductId: " + item.ProductId + ", ProductName: " + item.ProductName + ", Price: " + item.Price);
}
OnObtainOwnedPurchasesSuccess?.Invoke(result);
}).AddOnFailureListener((exception) =>
Expand Down
1 change: 1 addition & 0 deletions Assets/Huawei/Scripts/Settings/HMSAdsKitSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class HMSAdsKitSettings : HMSEditorSingleton<HMSAdsKitSettings>
private const string SettingsFilename = "HMSAdsKitSettings";
public const string EnableBannerAd = "EnableBannerAd";
public const string BannerAdID = "BannerAdID";
public const string ShowBannerOnLoad = "ShowBannerOnLoad";
public const string EnableInterstitialAd = "EnableInterstitialAd";
public const string InterstitialAdID = "InterstitialAdID";
public const string EnableRewardedAd = "EnableRewardedAd";
Expand Down
2 changes: 1 addition & 1 deletion Assets/Huawei/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.5
2.0.6

0 comments on commit 0539a82

Please sign in to comment.