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

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

@ -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 RewardedTypes rewardType;
private bool isRewardAvailable = false;
public bool isRewardedAdAvailable = false;
public static AdsManager Instance;
public Action<RewardedTypes> 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
}

@ -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;
//}
private void AddEvents()
{
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();
}
}

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

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

Loading…
Cancel
Save