Added Rewarded Ads

dev
Hazim Bin Ijaz 2 months ago
parent afb9909a22
commit bda64c2830

@ -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

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

@ -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

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

@ -14,8 +14,26 @@ PluginImporter:
isPreloaded: 0 isPreloaded: 0
isOverridable: 0 isOverridable: 0
isExplicitlyReferenced: 0 isExplicitlyReferenced: 0
validateReferences: 1 validateReferences: 0
platformData: 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: - first:
Any: Any:
second: second:
@ -26,7 +44,33 @@ PluginImporter:
second: second:
enabled: 1 enabled: 1
settings: settings:
CPU: AnyCPU
DefaultValueInitialized: true 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: - first:
Windows Store Apps: WindowsStoreApps Windows Store Apps: WindowsStoreApps
second: second:

@ -3067,6 +3067,53 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1336803836} m_GameObject: {fileID: 1336803836}
m_CullTransparentMesh: 1 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 --- !u!114 &1371660699
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -16385,7 +16432,7 @@ MonoBehaviour:
m_HorizontalOverflow: 0 m_HorizontalOverflow: 0
m_VerticalOverflow: 0 m_VerticalOverflow: 0
m_LineSpacing: 1 m_LineSpacing: 1
m_Text: 7 / 50 m_Text: 1 / 50
--- !u!114 &1790415148045805483 --- !u!114 &1790415148045805483
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -17975,7 +18022,7 @@ MonoBehaviour:
m_HorizontalOverflow: 0 m_HorizontalOverflow: 0
m_VerticalOverflow: 0 m_VerticalOverflow: 0
m_LineSpacing: 1 m_LineSpacing: 1
m_Text: '00 : 24' m_Text: '00 : 30'
--- !u!114 &1790415148045805529 --- !u!114 &1790415148045805529
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -18293,7 +18340,7 @@ MonoBehaviour:
m_HorizontalOverflow: 0 m_HorizontalOverflow: 0
m_VerticalOverflow: 0 m_VerticalOverflow: 0
m_LineSpacing: 1 m_LineSpacing: 1
m_Text: 7 / 50 m_Text: 1 / 50
--- !u!114 &1790415148045805539 --- !u!114 &1790415148045805539
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -24545,3 +24592,4 @@ SceneRoots:
- {fileID: 1790415148045805085} - {fileID: 1790415148045805085}
- {fileID: 1790415148045805084} - {fileID: 1790415148045805084}
- {fileID: 2116257506} - {fileID: 2116257506}
- {fileID: 1341897758}

@ -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

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
</component>
</project>

@ -31,7 +31,7 @@ public class AdsManager : MonoBehaviour
private bool loadingrAd = false; private bool loadingrAd = false;
private RewardedTypes rewardType; private RewardedTypes rewardType;
private bool isRewardAvailable = false; private bool isRewardAvailable = false;
public bool isRewardedAdAvailable = false;
public static AdsManager Instance; public static AdsManager Instance;
public Action<RewardedTypes> OnUserEarnedReward; public Action<RewardedTypes> OnUserEarnedReward;
public Action OnAdmobInitializedEvent; public Action OnAdmobInitializedEvent;
@ -41,13 +41,21 @@ public class AdsManager : MonoBehaviour
public Action<bool> OnrAdLoaded; public Action<bool> OnrAdLoaded;
private void Awake() private void Awake()
{
if (Instance != null && Instance != this)
{
Destroy(this);
}
else
{ {
Instance = this; Instance = this;
} }
DontDestroyOnLoad(gameObject);
}
private void Start() private void Start()
{ {
//InitializeAdmob(); InitializeAdmob();
} }
private void FixedUpdate() private void FixedUpdate()
@ -269,6 +277,7 @@ public class AdsManager : MonoBehaviour
if (error != null || ad == null) if (error != null || ad == null)
{ {
OnrAdLoaded?.Invoke(false); OnrAdLoaded?.Invoke(false);
isRewardedAdAvailable = false;
rewardedRetryAttempt++; rewardedRetryAttempt++;
//load ad again //load ad again
LoadRewardedAdWithDelay(); LoadRewardedAdWithDelay();
@ -281,6 +290,7 @@ public class AdsManager : MonoBehaviour
Debug.Log("rewarded ad loaded with response : " Debug.Log("rewarded ad loaded with response : "
+ ad.GetResponseInfo()); + ad.GetResponseInfo());
isRewardedAdAvailable = true;
OnrAdLoaded?.Invoke(true); OnrAdLoaded?.Invoke(true);
_rewardedAd = ad; _rewardedAd = ad;
RegisterEventHandlers(_rewardedAd); RegisterEventHandlers(_rewardedAd);
@ -373,5 +383,6 @@ public enum RewardedTypes
Color, Color,
Animation, Animation,
InventoryPurchase, InventoryPurchase,
Hint Hint,
Coins
} }

@ -27,24 +27,18 @@ public class RewardedVideoButton : MonoBehaviour
Timer.Schedule(this, 0.1f, AddEvents); Timer.Schedule(this, 0.1f, AddEvents);
} }
private void AddEvents()
{
IronSourceRewardedVideoEvents.onAdRewardedEvent += HandleRewardBasedVideoRewarded;
//if (AdmobController.instance.rewardBasedVideo != null) private void AddEvents()
//{ {
// AdmobController.instance.rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded; AdsManager.Instance.OnUserEarnedReward += OnRewardAdComplete;
//}
} }
public void OnClick() public void OnClick()
{ {
if (IsAdAvailable()) if (AdsManager.Instance.isRewardedAdAvailable)
{ {
IronSource.Agent.showRewardedVideo(); AdsManager.Instance.ShowRewardedAd(RewardedTypes.Coins);
} }
else else
{ {
@ -55,7 +49,7 @@ public class RewardedVideoButton : MonoBehaviour
public void HandleRewardBasedVideoRewarded(IronSourcePlacement ironSourcePlacement, IronSourceAdInfo ironSourceAdInfo) public void HandleRewardBasedVideoRewarded(IronSourcePlacement ironSourcePlacement, IronSourceAdInfo ironSourceAdInfo)
{ {
onRewarded.Invoke();
} }
//public void HandleRewardBasedVideoRewarded(object sender, Reward args) //public void HandleRewardBasedVideoRewarded(object sender, Reward args)
@ -73,10 +67,15 @@ public class RewardedVideoButton : MonoBehaviour
{ {
IronSourceRewardedVideoEvents.onAdRewardedEvent -= HandleRewardBasedVideoRewarded; IronSourceRewardedVideoEvents.onAdRewardedEvent -= HandleRewardBasedVideoRewarded;
AdsManager.Instance.OnUserEarnedReward -= OnRewardAdComplete;
//if (AdmobController.instance.rewardBasedVideo != null) //if (AdmobController.instance.rewardBasedVideo != null)
//{ //{
// AdmobController.instance.rewardBasedVideo.OnAdRewarded -= HandleRewardBasedVideoRewarded; // AdmobController.instance.rewardBasedVideo.OnAdRewarded -= HandleRewardBasedVideoRewarded;
//} //}
} }
private void OnRewardAdComplete(RewardedTypes obj)
{
onRewarded.Invoke();
}
} }

@ -1,6 +1,7 @@
{ {
"dependencies": { "dependencies": {
"com.unity.2d.sprite": "1.0.0", "com.unity.2d.sprite": "1.0.0",
"com.unity.ide.rider": "3.0.31",
"com.unity.textmeshpro": "3.0.9", "com.unity.textmeshpro": "3.0.9",
"com.unity.modules.ai": "1.0.0", "com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0", "com.unity.modules.androidjni": "1.0.0",

@ -6,6 +6,22 @@
"source": "builtin", "source": "builtin",
"dependencies": {} "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": { "com.unity.textmeshpro": {
"version": "3.0.9", "version": "3.0.9",
"depth": 0, "depth": 0,

Loading…
Cancel
Save