From bda64c2830b95fa09caf737b62177376f004e4f8 Mon Sep 17 00:00:00 2001 From: Hazim Bin Ijaz Date: Mon, 7 Oct 2024 00:32:01 +0500 Subject: [PATCH] Added Rewarded Ads --- .../.idea/.gitignore | 13 +++++ .../.idea/encodings.xml | 4 ++ .../.idea/indexLayout.xml | 8 +++ .../.idea/vcs.xml | 6 +++ .../.idea.PlumberUltimateAds/.idea/.gitignore | 13 +++++ .../.idea/encodings.xml | 4 ++ .../.idea/indexLayout.xml | 8 +++ .idea/.idea.PlumberUltimateAds/.idea/vcs.xml | 6 +++ .../1.2.181/Google.IOSResolver.dll.meta | 46 +++++++++++++++- Assets/PipeOut/Scenes/HomeScene.unity | 54 +++++++++++++++++-- .../.idea.Ads Scripts.dir/.idea/.gitignore | 17 ++++++ .../.idea.Ads Scripts.dir/.idea/encodings.xml | 4 ++ .../.idea/indexLayout.xml | 8 +++ .../.idea/.idea.Ads Scripts.dir/.idea/vcs.xml | 6 +++ Assets/Scripts/Ads Scripts/AdsManager.cs | 29 ++++++---- Assets/Scripts/RewardedVideoButton.cs | 25 +++++---- Packages/manifest.json | 1 + Packages/packages-lock.json | 16 ++++++ 18 files changed, 242 insertions(+), 26 deletions(-) create mode 100644 .idea/.idea.PlumberUltimateAds.dir/.idea/.gitignore create mode 100644 .idea/.idea.PlumberUltimateAds.dir/.idea/encodings.xml create mode 100644 .idea/.idea.PlumberUltimateAds.dir/.idea/indexLayout.xml create mode 100644 .idea/.idea.PlumberUltimateAds.dir/.idea/vcs.xml create mode 100644 .idea/.idea.PlumberUltimateAds/.idea/.gitignore create mode 100644 .idea/.idea.PlumberUltimateAds/.idea/encodings.xml create mode 100644 .idea/.idea.PlumberUltimateAds/.idea/indexLayout.xml create mode 100644 .idea/.idea.PlumberUltimateAds/.idea/vcs.xml create mode 100644 Assets/Scripts/Ads Scripts/.idea/.idea.Ads Scripts.dir/.idea/.gitignore create mode 100644 Assets/Scripts/Ads Scripts/.idea/.idea.Ads Scripts.dir/.idea/encodings.xml create mode 100644 Assets/Scripts/Ads Scripts/.idea/.idea.Ads Scripts.dir/.idea/indexLayout.xml create mode 100644 Assets/Scripts/Ads Scripts/.idea/.idea.Ads Scripts.dir/.idea/vcs.xml diff --git a/.idea/.idea.PlumberUltimateAds.dir/.idea/.gitignore b/.idea/.idea.PlumberUltimateAds.dir/.idea/.gitignore new file mode 100644 index 00000000..fc67f05b --- /dev/null +++ b/.idea/.idea.PlumberUltimateAds.dir/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/modules.xml +/.idea.PlumberUltimateAds.iml +/contentModel.xml +/projectSettingsUpdater.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.idea.PlumberUltimateAds.dir/.idea/encodings.xml b/.idea/.idea.PlumberUltimateAds.dir/.idea/encodings.xml new file mode 100644 index 00000000..df87cf95 --- /dev/null +++ b/.idea/.idea.PlumberUltimateAds.dir/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.PlumberUltimateAds.dir/.idea/indexLayout.xml b/.idea/.idea.PlumberUltimateAds.dir/.idea/indexLayout.xml new file mode 100644 index 00000000..7b08163c --- /dev/null +++ b/.idea/.idea.PlumberUltimateAds.dir/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.PlumberUltimateAds.dir/.idea/vcs.xml b/.idea/.idea.PlumberUltimateAds.dir/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/.idea.PlumberUltimateAds.dir/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/.idea.PlumberUltimateAds/.idea/.gitignore b/.idea/.idea.PlumberUltimateAds/.idea/.gitignore new file mode 100644 index 00000000..fc67f05b --- /dev/null +++ b/.idea/.idea.PlumberUltimateAds/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/modules.xml +/.idea.PlumberUltimateAds.iml +/contentModel.xml +/projectSettingsUpdater.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.idea.PlumberUltimateAds/.idea/encodings.xml b/.idea/.idea.PlumberUltimateAds/.idea/encodings.xml new file mode 100644 index 00000000..df87cf95 --- /dev/null +++ b/.idea/.idea.PlumberUltimateAds/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.PlumberUltimateAds/.idea/indexLayout.xml b/.idea/.idea.PlumberUltimateAds/.idea/indexLayout.xml new file mode 100644 index 00000000..7b08163c --- /dev/null +++ b/.idea/.idea.PlumberUltimateAds/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.PlumberUltimateAds/.idea/vcs.xml b/.idea/.idea.PlumberUltimateAds/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/.idea.PlumberUltimateAds/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Assets/ExternalDependencyManager/Editor/1.2.181/Google.IOSResolver.dll.meta b/Assets/ExternalDependencyManager/Editor/1.2.181/Google.IOSResolver.dll.meta index 1eb09c51..d3429aab 100644 --- a/Assets/ExternalDependencyManager/Editor/1.2.181/Google.IOSResolver.dll.meta +++ b/Assets/ExternalDependencyManager/Editor/1.2.181/Google.IOSResolver.dll.meta @@ -14,8 +14,26 @@ PluginImporter: isPreloaded: 0 isOverridable: 0 isExplicitlyReferenced: 0 - validateReferences: 1 + validateReferences: 0 platformData: + - first: + : Any + second: + enabled: 0 + settings: + Exclude Android: 1 + Exclude Editor: 0 + Exclude Linux64: 1 + Exclude OSXUniversal: 1 + Exclude Win: 1 + Exclude Win64: 1 + - first: + Android: Android + second: + enabled: 0 + settings: + AndroidSharedLibraryType: Executable + CPU: ARMv7 - first: Any: second: @@ -26,7 +44,33 @@ PluginImporter: second: enabled: 1 settings: + CPU: AnyCPU DefaultValueInitialized: true + OS: AnyOS + - first: + Standalone: Linux64 + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Standalone: OSXUniversal + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Standalone: Win + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Standalone: Win64 + second: + enabled: 0 + settings: + CPU: AnyCPU - first: Windows Store Apps: WindowsStoreApps second: diff --git a/Assets/PipeOut/Scenes/HomeScene.unity b/Assets/PipeOut/Scenes/HomeScene.unity index 4a000241..f056dfa8 100644 --- a/Assets/PipeOut/Scenes/HomeScene.unity +++ b/Assets/PipeOut/Scenes/HomeScene.unity @@ -3067,6 +3067,53 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1336803836} m_CullTransparentMesh: 1 +--- !u!1 &1341897756 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1341897758} + - component: {fileID: 1341897757} + m_Layer: 0 + m_Name: AdsManager + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1341897757 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1341897756} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a853c83bcccfa14468a366e0290483a3, type: 3} + m_Name: + m_EditorClassIdentifier: + iAdUnit: ca-app-pub-3940256099942544/1033173712 + rAdUnit: ca-app-pub-3940256099942544/5224354917 + isRewardedAdAvailable: 0 +--- !u!4 &1341897758 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1341897756} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -0.03515625, y: -3.5898125, z: 90} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1371660699 MonoBehaviour: m_ObjectHideFlags: 0 @@ -16385,7 +16432,7 @@ MonoBehaviour: m_HorizontalOverflow: 0 m_VerticalOverflow: 0 m_LineSpacing: 1 - m_Text: 7 / 50 + m_Text: 1 / 50 --- !u!114 &1790415148045805483 MonoBehaviour: m_ObjectHideFlags: 0 @@ -17975,7 +18022,7 @@ MonoBehaviour: m_HorizontalOverflow: 0 m_VerticalOverflow: 0 m_LineSpacing: 1 - m_Text: '00 : 24' + m_Text: '00 : 30' --- !u!114 &1790415148045805529 MonoBehaviour: m_ObjectHideFlags: 0 @@ -18293,7 +18340,7 @@ MonoBehaviour: m_HorizontalOverflow: 0 m_VerticalOverflow: 0 m_LineSpacing: 1 - m_Text: 7 / 50 + m_Text: 1 / 50 --- !u!114 &1790415148045805539 MonoBehaviour: m_ObjectHideFlags: 0 @@ -24545,3 +24592,4 @@ SceneRoots: - {fileID: 1790415148045805085} - {fileID: 1790415148045805084} - {fileID: 2116257506} + - {fileID: 1341897758} diff --git a/Assets/Scripts/Ads Scripts/.idea/.idea.Ads Scripts.dir/.idea/.gitignore b/Assets/Scripts/Ads Scripts/.idea/.idea.Ads Scripts.dir/.idea/.gitignore new file mode 100644 index 00000000..d7a07aea --- /dev/null +++ b/Assets/Scripts/Ads Scripts/.idea/.idea.Ads Scripts.dir/.idea/.gitignore @@ -0,0 +1,17 @@ +# Default ignored files +/shelf/ +/workspace.xml + +# Rider ignored files +/.idea.Ads Scripts.iml +/contentModel.xml +/modules.xml +/projectSettingsUpdater.xml + +# Editor-based HTTP Client requests +/httpRequests/ + +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml + diff --git a/Assets/Scripts/Ads Scripts/.idea/.idea.Ads Scripts.dir/.idea/encodings.xml b/Assets/Scripts/Ads Scripts/.idea/.idea.Ads Scripts.dir/.idea/encodings.xml new file mode 100644 index 00000000..df87cf95 --- /dev/null +++ b/Assets/Scripts/Ads Scripts/.idea/.idea.Ads Scripts.dir/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Assets/Scripts/Ads Scripts/.idea/.idea.Ads Scripts.dir/.idea/indexLayout.xml b/Assets/Scripts/Ads Scripts/.idea/.idea.Ads Scripts.dir/.idea/indexLayout.xml new file mode 100644 index 00000000..7b08163c --- /dev/null +++ b/Assets/Scripts/Ads Scripts/.idea/.idea.Ads Scripts.dir/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Assets/Scripts/Ads Scripts/.idea/.idea.Ads Scripts.dir/.idea/vcs.xml b/Assets/Scripts/Ads Scripts/.idea/.idea.Ads Scripts.dir/.idea/vcs.xml new file mode 100644 index 00000000..c2365ab1 --- /dev/null +++ b/Assets/Scripts/Ads Scripts/.idea/.idea.Ads Scripts.dir/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Assets/Scripts/Ads Scripts/AdsManager.cs b/Assets/Scripts/Ads Scripts/AdsManager.cs index 225b6244..1b3e9e68 100644 --- a/Assets/Scripts/Ads Scripts/AdsManager.cs +++ b/Assets/Scripts/Ads Scripts/AdsManager.cs @@ -31,7 +31,7 @@ public class AdsManager : MonoBehaviour private bool loadingrAd = false; private RewardedTypes rewardType; private bool isRewardAvailable = false; - + public bool isRewardedAdAvailable = false; public static AdsManager Instance; public Action OnUserEarnedReward; public Action OnAdmobInitializedEvent; @@ -42,12 +42,20 @@ public class AdsManager : MonoBehaviour private void Awake() { - Instance = this; + if (Instance != null && Instance != this) + { + Destroy(this); + } + else + { + Instance = this; + } + DontDestroyOnLoad(gameObject); } private void Start() { - //InitializeAdmob(); + InitializeAdmob(); } private void FixedUpdate() @@ -88,8 +96,8 @@ public class AdsManager : MonoBehaviour private void OnAdPaid(AdValue adValue) { Debug.Log(String.Format("ad paid {0} {1}.", - adValue.Value, - adValue.CurrencyCode)); + adValue.Value, + adValue.CurrencyCode)); } private void PauseGame() @@ -210,7 +218,7 @@ public class AdsManager : MonoBehaviour MobileAdsEventExecutor.ExecuteInUpdate(() => { Debug.LogError("Interstitial ad failed to open full screen content " + - "with error : " + error); + "with error : " + error); LoadInterstitialAdWithDelay(); }); }; @@ -269,6 +277,7 @@ public class AdsManager : MonoBehaviour if (error != null || ad == null) { OnrAdLoaded?.Invoke(false); + isRewardedAdAvailable = false; rewardedRetryAttempt++; //load ad again LoadRewardedAdWithDelay(); @@ -281,6 +290,7 @@ public class AdsManager : MonoBehaviour Debug.Log("rewarded ad loaded with response : " + ad.GetResponseInfo()); + isRewardedAdAvailable = true; OnrAdLoaded?.Invoke(true); _rewardedAd = ad; RegisterEventHandlers(_rewardedAd); @@ -319,7 +329,7 @@ public class AdsManager : MonoBehaviour MobileAdsEventExecutor.ExecuteInUpdate(() => { Debug.LogError("Rewarded ad failed to open full screen content " + - "with error : " + error); + "with error : " + error); LoadRewardedAdWithDelay(); }); }; @@ -373,5 +383,6 @@ public enum RewardedTypes Color, Animation, InventoryPurchase, - Hint -} + Hint, + Coins +} \ No newline at end of file diff --git a/Assets/Scripts/RewardedVideoButton.cs b/Assets/Scripts/RewardedVideoButton.cs index 3621aa4b..2133163f 100644 --- a/Assets/Scripts/RewardedVideoButton.cs +++ b/Assets/Scripts/RewardedVideoButton.cs @@ -27,24 +27,18 @@ public class RewardedVideoButton : MonoBehaviour Timer.Schedule(this, 0.1f, AddEvents); } + + private void AddEvents() { - IronSourceRewardedVideoEvents.onAdRewardedEvent += HandleRewardBasedVideoRewarded; - - - - - //if (AdmobController.instance.rewardBasedVideo != null) - //{ - // AdmobController.instance.rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded; - //} + AdsManager.Instance.OnUserEarnedReward += OnRewardAdComplete; } public void OnClick() { - if (IsAdAvailable()) + if (AdsManager.Instance.isRewardedAdAvailable) { - IronSource.Agent.showRewardedVideo(); + AdsManager.Instance.ShowRewardedAd(RewardedTypes.Coins); } else { @@ -55,7 +49,7 @@ public class RewardedVideoButton : MonoBehaviour public void HandleRewardBasedVideoRewarded(IronSourcePlacement ironSourcePlacement, IronSourceAdInfo ironSourceAdInfo) { - onRewarded.Invoke(); + } //public void HandleRewardBasedVideoRewarded(object sender, Reward args) @@ -73,10 +67,15 @@ public class RewardedVideoButton : MonoBehaviour { IronSourceRewardedVideoEvents.onAdRewardedEvent -= HandleRewardBasedVideoRewarded; - + AdsManager.Instance.OnUserEarnedReward -= OnRewardAdComplete; //if (AdmobController.instance.rewardBasedVideo != null) //{ // AdmobController.instance.rewardBasedVideo.OnAdRewarded -= HandleRewardBasedVideoRewarded; //} } + + private void OnRewardAdComplete(RewardedTypes obj) + { + onRewarded.Invoke(); + } } diff --git a/Packages/manifest.json b/Packages/manifest.json index 83b6b275..903ee49b 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -1,6 +1,7 @@ { "dependencies": { "com.unity.2d.sprite": "1.0.0", + "com.unity.ide.rider": "3.0.31", "com.unity.textmeshpro": "3.0.9", "com.unity.modules.ai": "1.0.0", "com.unity.modules.androidjni": "1.0.0", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index be913aca..84a409c0 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -6,6 +6,22 @@ "source": "builtin", "dependencies": {} }, + "com.unity.ext.nunit": { + "version": "1.0.6", + "depth": 1, + "source": "registry", + "dependencies": {}, + "url": "https://packages.unity.com" + }, + "com.unity.ide.rider": { + "version": "3.0.31", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.ext.nunit": "1.0.6" + }, + "url": "https://packages.unity.com" + }, "com.unity.textmeshpro": { "version": "3.0.9", "depth": 0,