diff --git a/Assets/Plugins/Android/AndroidManifest.xml b/Assets/Plugins/Android/AndroidManifest.xml index 9892de5d..696f2741 100644 --- a/Assets/Plugins/Android/AndroidManifest.xml +++ b/Assets/Plugins/Android/AndroidManifest.xml @@ -1,7 +1,7 @@ - + diff --git a/Assets/Plugins/Android/Heyzap/AndroidManifest.xml b/Assets/Plugins/Android/Heyzap/AndroidManifest.xml new file mode 100644 index 00000000..18756f84 --- /dev/null +++ b/Assets/Plugins/Android/Heyzap/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/Assets/Plugins/Android/Heyzap/AndroidManifest.xml.meta b/Assets/Plugins/Android/Heyzap/AndroidManifest.xml.meta new file mode 100644 index 00000000..c44200a0 --- /dev/null +++ b/Assets/Plugins/Android/Heyzap/AndroidManifest.xml.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 713d28e117c28427db14295ce2107426 +timeCreated: 1527782868 +licenseType: Free +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/Heyzap/HZBannerAd.cs b/Assets/Plugins/Heyzap/HZBannerAd.cs index f65f6d9d..21824442 100644 --- a/Assets/Plugins/Heyzap/HZBannerAd.cs +++ b/Assets/Plugins/Heyzap/HZBannerAd.cs @@ -39,7 +39,7 @@ public class HZBannerAd : MonoBehaviour { public delegate void AdDisplayListener(string state, string tag); private static AdDisplayListener adDisplayListener; - private static HZBannerAd _instance = null; + private static HZBannerAd _instance; // these are reproduced here for convenience since they were here in old SDK versions /// diff --git a/Assets/Plugins/Heyzap/HZDemographics.cs b/Assets/Plugins/Heyzap/HZDemographics.cs index 1c96bbcb..c8706444 100644 --- a/Assets/Plugins/Heyzap/HZDemographics.cs +++ b/Assets/Plugins/Heyzap/HZDemographics.cs @@ -37,7 +37,7 @@ namespace Heyzap { /// public class HZDemographics : MonoBehaviour { - private static HZDemographics _instance = null; + private static HZDemographics _instance; public enum Gender { UNKNOWN, diff --git a/Assets/Plugins/Heyzap/HZIncentivizedAd.cs b/Assets/Plugins/Heyzap/HZIncentivizedAd.cs index 1cc8ed2e..86dab1aa 100644 --- a/Assets/Plugins/Heyzap/HZIncentivizedAd.cs +++ b/Assets/Plugins/Heyzap/HZIncentivizedAd.cs @@ -38,7 +38,7 @@ public class HZIncentivizedAd : MonoBehaviour { public delegate void AdDisplayListener(string state, string tag); private static AdDisplayListener adDisplayListener; - private static HZIncentivizedAd _instance = null; + private static HZIncentivizedAd _instance; //provided since JS can't use default parameters /// @@ -52,8 +52,6 @@ public static void Fetch() { /// /// The ad tag to fetch an ad for. public static void Fetch(string tag) { - tag = HeyzapAds.TagForString(tag); - #if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IPHONE) #if UNITY_ANDROID HZIncentivizedAdAndroid.Fetch(tag); @@ -107,8 +105,6 @@ public static bool IsAvailable() { /// /// true, if an ad is available, false otherwise. public static bool IsAvailable(string tag) { - tag = HeyzapAds.TagForString(tag); - #if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IPHONE) #if UNITY_ANDROID return HZIncentivizedAdAndroid.IsAvailable(tag); diff --git a/Assets/Plugins/Heyzap/HZInterstitialAd.cs b/Assets/Plugins/Heyzap/HZInterstitialAd.cs index e50c9e58..e998e913 100644 --- a/Assets/Plugins/Heyzap/HZInterstitialAd.cs +++ b/Assets/Plugins/Heyzap/HZInterstitialAd.cs @@ -37,7 +37,7 @@ public class HZInterstitialAd : MonoBehaviour { public delegate void AdDisplayListener(string state, string tag); private static AdDisplayListener adDisplayListener; - private static HZInterstitialAd _instance = null; + private static HZInterstitialAd _instance; //provided since JS can't use default parameters /// @@ -80,8 +80,6 @@ public static void Fetch() { /// /// The ad tag to fetch an ad for. public static void Fetch(string tag) { - tag = HeyzapAds.TagForString(tag); - #if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IPHONE) #if UNITY_ANDROID HZInterstitialAdAndroid.Fetch(tag); @@ -107,8 +105,6 @@ public static bool IsAvailable() { /// /// true, if an ad is available, false otherwise. public static bool IsAvailable(string tag) { - tag = HeyzapAds.TagForString(tag); - #if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IPHONE) #if UNITY_ANDROID return HZInterstitialAdAndroid.IsAvailable(tag); @@ -257,7 +253,7 @@ public static void ShowWithOptions(HZShowOptions showOptions) { } } - public static void Fetch(string tag="default") { + public static void Fetch(string tag) { if(Application.platform != RuntimePlatform.Android) return; AndroidJNIHelper.debug = false; @@ -266,7 +262,7 @@ public static void Fetch(string tag="default") { } } - public static Boolean IsAvailable(string tag="default") { + public static Boolean IsAvailable(string tag) { if(Application.platform != RuntimePlatform.Android) return false; AndroidJNIHelper.debug = false; diff --git a/Assets/Plugins/Heyzap/HZOfferwallAd.cs b/Assets/Plugins/Heyzap/HZOfferwallAd.cs index 5614d855..539531e4 100644 --- a/Assets/Plugins/Heyzap/HZOfferwallAd.cs +++ b/Assets/Plugins/Heyzap/HZOfferwallAd.cs @@ -46,7 +46,7 @@ public class HZOfferWallAd : MonoBehaviour { public delegate void VirtualCurrencyErrorListener(string errorMsg); private static VirtualCurrencyErrorListener virtualCurrencyErrorListener; - private static HZOfferWallAd _instance = null; + private static HZOfferWallAd _instance; //provided since JS can't use default parameters /// @@ -88,8 +88,6 @@ public static void Fetch() { /// /// The ad tag to fetch an ad for. public static void Fetch(string tag) { - tag = HeyzapAds.TagForString(tag); - #if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IPHONE) #if UNITY_ANDROID HZOfferWallAdAndroid.Fetch(tag); @@ -115,8 +113,6 @@ public static bool IsAvailable() { /// /// true, if an ad is available, false otherwise. public static bool IsAvailable(string tag) { - tag = HeyzapAds.TagForString(tag); - #if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IPHONE) #if UNITY_ANDROID return HZOfferWallAdAndroid.IsAvailable(tag); diff --git a/Assets/Plugins/Heyzap/HZShowOptions.cs b/Assets/Plugins/Heyzap/HZShowOptions.cs index 482e90d8..f3230894 100644 --- a/Assets/Plugins/Heyzap/HZShowOptions.cs +++ b/Assets/Plugins/Heyzap/HZShowOptions.cs @@ -8,8 +8,7 @@ namespace Heyzap { public class HZShowOptions { /// - /// An identifier for the location of the ad, which you can use to disable the ad from your dashboard. If not specified the tag "default" is always used. - /// Guaranteed to be non-null - will be set to the default value if the setter is called with `null`. + /// An identifier for the location of the ad, which you can use to disable the ad from your dashboard. /// /// The tag. public string Tag { @@ -17,14 +16,10 @@ public string Tag { return tag; } set { - if (value != null) { - tag = value; - } else { - tag = HeyzapAds.DEFAULT_TAG; - } + tag = value; } } - private string tag = HeyzapAds.DEFAULT_TAG; + private string tag; } /// @@ -36,7 +31,6 @@ public class HZIncentivizedShowOptions : HZShowOptions { /// /// When an incentivized video is completed, this string will be sent to your server via our server-to-server callbacks. Set it to anything you want to pass to your server regarding this incentivized video view (i.e.: a username, user ID, level name, etc.), or leave it empty if you don't need to use it / aren't using server callbacks for incentivized video. /// More information about using this feature can be found at https://developers.heyzap.com/docs/advanced-publishing . - /// Guaranteed to be non-null - will be set to the default value if the setter is called with `null`. /// public string IncentivizedInfo { get { @@ -96,7 +90,6 @@ public class HZOfferWallShowOptions : HZShowOptions { /// /// When an incentivized video is completed, this string will be sent to your server via our server-to-server callbacks. Set it to anything you want to pass to your server regarding this incentivized video view (i.e.: a username, user ID, level name, etc.), or leave it empty if you don't need to use it / aren't using server callbacks for incentivized video. /// More information about using this feature can be found at https://developers.heyzap.com/docs/advanced-publishing . - /// Guaranteed to be non-null - will be set to the default value if the setter is called with `null`. /// public bool ShouldCloseAfterFirstClick { get { @@ -108,4 +101,4 @@ public bool ShouldCloseAfterFirstClick { } private bool shouldCloseAfterFirstClick = HZOfferWallShowOptions.DEFAULT_SHOULD_CLOSE_AFTER_FIRST_CLICK; } -} \ No newline at end of file +} diff --git a/Assets/Plugins/Heyzap/HZVideoAd.cs b/Assets/Plugins/Heyzap/HZVideoAd.cs index 560c7bbd..8b1d22cf 100644 --- a/Assets/Plugins/Heyzap/HZVideoAd.cs +++ b/Assets/Plugins/Heyzap/HZVideoAd.cs @@ -39,7 +39,7 @@ public class HZVideoAd : MonoBehaviour { public delegate void AdDisplayListener(string state, string tag); private static AdDisplayListener adDisplayListener; - private static HZVideoAd _instance = null; + private static HZVideoAd _instance; //provided since JS can't use default parameters /// @@ -81,8 +81,6 @@ public static void Fetch() { /// /// The ad tag to fetch an ad for. public static void Fetch(string tag) { - tag = HeyzapAds.TagForString(tag); - #if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IPHONE) #if UNITY_ANDROID HZVideoAdAndroid.Fetch(tag); @@ -108,8 +106,6 @@ public static bool IsAvailable() { /// /// true, if an ad is available, false otherwise. public static bool IsAvailable(string tag) { - tag = HeyzapAds.TagForString(tag); - #if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IPHONE) #if UNITY_ANDROID return HZVideoAdAndroid.IsAvailable(tag); diff --git a/Assets/Plugins/Heyzap/HeyzapAds.cs b/Assets/Plugins/Heyzap/HeyzapAds.cs index 7f180e3d..b323d851 100644 --- a/Assets/Plugins/Heyzap/HeyzapAds.cs +++ b/Assets/Plugins/Heyzap/HeyzapAds.cs @@ -36,10 +36,11 @@ namespace Heyzap { /// Heyzap wrapper for iOS and Android via Unity. For more information, see https://developers.heyzap.com/docs/unity_sdk_setup_and_requirements . /// public class HeyzapAds : MonoBehaviour { + public const string Version = "9.51.0"; public delegate void NetworkCallbackListener(string network, string callback); private static NetworkCallbackListener networkCallbackListener; - private static HeyzapAds _instance = null; + private static HeyzapAds _instance; #region Flags for the call to HeyzapAds.StartWithOptions() /// @@ -77,8 +78,6 @@ public class HeyzapAds : MonoBehaviour { /// public const int FLAG_CHILD_DIRECTED_ADS = 1 << 6; // 64 #endregion - - public const string DEFAULT_TAG = "default"; #region String constants to expect in Ad Listener & network callbacks // `NetworkCallback` is a bit of a misnomer. The callback constants here are both for "network callbacks" and for ad listener callbacks. We should refactor these into two classes in the next major SDK. @@ -140,8 +139,10 @@ public static class Network { public static void Start(string publisher_id, int options) { #if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IPHONE) #if UNITY_ANDROID + HeyzapAdsAndroid.SetPluginVersion(Version); HeyzapAdsAndroid.Start(publisher_id, options); #elif UNITY_IPHONE + HeyzapAdsIOS.SetPluginVersion(Version); HeyzapAdsIOS.Start(publisher_id, options); #endif #else @@ -348,7 +349,7 @@ public static void HideDebugLogs() { /// public static void ShowThirdPartyDebugLogs() { #if UNITY_IPHONE && !UNITY_EDITOR - HeyzapAdsIOS.ShowThirdPartyDebugLogs(); + HeyzapAdsIOS.ShowThirdPartyDebugLogs(); #endif } @@ -358,7 +359,7 @@ public static void ShowThirdPartyDebugLogs() { /// public static void HideThirdPartyDebugLogs() { #if UNITY_IPHONE && !UNITY_EDITOR - HeyzapAdsIOS.HideThirdPartyDebugLogs(); + HeyzapAdsIOS.HideThirdPartyDebugLogs(); #endif } @@ -385,7 +386,7 @@ public static void SetBundleIdentifier(string bundleID) { /// The Device ID that FAN prints to the iOS console public static void AddFacebookTestDevice(string device_id) { #if UNITY_IPHONE && !UNITY_EDITOR - HeyzapAdsIOS.AddFacebookTestDevice(device_id); + HeyzapAdsIOS.AddFacebookTestDevice(device_id); #endif } #endregion @@ -402,7 +403,7 @@ protected static void SetNetworkCallback(string network, string callback) { } } - public static void InitReceiver(){ + public static void InitReceiver() { if (_instance == null) { GameObject receiverObject = new GameObject("HeyzapAds"); DontDestroyOnLoad(receiverObject); @@ -410,14 +411,6 @@ public static void InitReceiver(){ } } - public static string TagForString(string tag) { - if (tag == null) { - tag = HeyzapAds.DEFAULT_TAG; - } - - return tag; - } - // Within Unity's .NET framework we don't have a stock solution for converting objets to Json so we need to implement a custom solution static private string GetGdprConsentDataAsJsonString(Dictionary gdprConsentData) { @@ -433,6 +426,8 @@ static private string GetGdprConsentDataAsJsonString(Dictionary #if UNITY_IPHONE && !UNITY_EDITOR public class HeyzapAdsIOS : MonoBehaviour { + [DllImport ("__Internal")] + private static extern void hz_ads_set_plugin_version(string pluginVersion); [DllImport ("__Internal")] private static extern void hz_ads_start_app(string publisher_id, int flags); @@ -479,6 +474,10 @@ public class HeyzapAdsIOS : MonoBehaviour [DllImport ("__Internal")] private static extern void hz_add_facebook_test_device(string device_id); + public static void SetPluginVersion(string pluginVersion) { + hz_ads_set_plugin_version(pluginVersion); + } + public static void Start(string publisher_id, int options=0) { hz_ads_start_app(publisher_id, options); } @@ -548,6 +547,14 @@ public static void AddFacebookTestDevice(string device_id) { #if UNITY_ANDROID && !UNITY_EDITOR public class HeyzapAdsAndroid : MonoBehaviour { + public static void SetPluginVersion(string pluginVersion) { + if (Application.platform != RuntimePlatform.Android) return; + AndroidJNIHelper.debug = false; + using (AndroidJavaClass jc = new AndroidJavaClass("com.heyzap.sdk.extensions.unity3d.UnityHelper")) { + jc.CallStatic("addCustomParameter", "plugin_version", pluginVersion); + } + } + public static void Start(string publisher_id, int options=0) { if(Application.platform != RuntimePlatform.Android) return; diff --git a/Assets/Plugins/iOS/Heyzap/HeyzapUnityAds.mm b/Assets/Plugins/iOS/Heyzap/HeyzapUnityAds.mm index 860be910..9e092904 100644 --- a/Assets/Plugins/iOS/Heyzap/HeyzapUnityAds.mm +++ b/Assets/Plugins/iOS/Heyzap/HeyzapUnityAds.mm @@ -163,10 +163,19 @@ - (NSString *)jsonFromDict:(NSDictionary *)dict { #pragma mark - Starting the SDK + NSString* nil_or_string(const char *characters) { + return (characters == NULL) ? nil : [NSString stringWithUTF8String:characters]; + } + + void hz_ads_set_plugin_version(const char *pluginVersion) { + NSString *pluginVersionString = nil_or_string(pluginVersion); + [HeyzapAds setPluginVersion:pluginVersionString]; + } + void hz_ads_start_app(const char *publisher_id, HZAdOptions flags) { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - NSString *publisherID = [NSString stringWithUTF8String:publisher_id]; + NSString *publisherID = nil_or_string(publisher_id); [HeyzapAds startWithPublisherID:publisherID andOptions:flags andFramework:HZ_FRAMEWORK_NAME]; @@ -192,57 +201,57 @@ void hz_ads_start_app(const char *publisher_id, HZAdOptions flags) { }]; }); } - + #pragma mark - Interstitial Ads void hz_ads_show_interstitial(const char *tag) { - [HZInterstitialAd showForTag:[NSString stringWithUTF8String:tag]]; + [HZInterstitialAd showForTag:nil_or_string(tag)]; } void hz_ads_fetch_interstitial(const char *tag) { - [HZInterstitialAd fetchForTag:[NSString stringWithUTF8String:tag]]; + [HZInterstitialAd fetchForTag:nil_or_string(tag)]; } bool hz_ads_interstitial_is_available(const char *tag) { - return [HZInterstitialAd isAvailableForTag:[NSString stringWithUTF8String:tag]]; + return [HZInterstitialAd isAvailableForTag:nil_or_string(tag)]; } #pragma mark - Video Ads void hz_ads_show_video(const char *tag) { - [HZVideoAd showForTag:[NSString stringWithUTF8String:tag]]; + [HZVideoAd showForTag:nil_or_string(tag)]; } void hz_ads_fetch_video(const char *tag) { - [HZVideoAd fetchForTag:[NSString stringWithUTF8String:tag]]; + [HZVideoAd fetchForTag:nil_or_string(tag)]; } bool hz_ads_video_is_available(const char *tag) { - return [HZVideoAd isAvailableForTag:[NSString stringWithUTF8String:tag]]; + return [HZVideoAd isAvailableForTag:nil_or_string(tag)]; } #pragma mark - Incentivized Ads void hz_ads_show_incentivized(const char *tag) { - [HZIncentivizedAd showForTag:[NSString stringWithUTF8String: tag]]; + [HZIncentivizedAd showForTag:nil_or_string(tag)]; } void hz_ads_show_incentivized_with_custom_info(const char *tag, const char *customInfo) { HZShowOptions *showOptions = [HZShowOptions new]; - showOptions.tag = [NSString stringWithUTF8String:tag]; - showOptions.incentivizedInfo = [NSString stringWithUTF8String:customInfo]; + showOptions.tag = nil_or_string(tag); + showOptions.incentivizedInfo = nil_or_string(customInfo); [HZIncentivizedAd showWithOptions:showOptions]; } void hz_ads_fetch_incentivized(const char *tag) { - [HZIncentivizedAd fetchForTag:[NSString stringWithUTF8String:tag]]; + [HZIncentivizedAd fetchForTag:nil_or_string(tag)]; } bool hz_ads_incentivized_is_available(const char *tag) { - return [HZIncentivizedAd isAvailableForTag:[NSString stringWithUTF8String:tag]]; + return [HZIncentivizedAd isAvailableForTag:nil_or_string(tag)]; } @@ -251,13 +260,13 @@ bool hz_ads_incentivized_is_available(const char *tag) { void hz_ads_show_banner(const char *position, const char *tag) { if (!HZCurrentBannerAd) { HZBannerPosition pos = HZBannerPositionBottom; - NSString *positionStr = [NSString stringWithUTF8String:position]; + NSString *positionStr = nil_or_string(position); if ([positionStr isEqualToString:@"top"]) { pos = HZBannerPositionTop; } HZBannerAdOptions *options = [[HZBannerAdOptions alloc] init]; - options.tag = [NSString stringWithUTF8String:tag]; + options.tag = nil_or_string(tag); [HZBannerAd placeBannerInView:nil position:pos options:options success:^(HZBannerAd *banner) { if (!HZCurrentBannerAd) { @@ -282,7 +291,6 @@ void hz_ads_show_banner(const char *position, const char *tag) { void hz_ads_hide_banner(void) { if (HZCurrentBannerAd) { [HZCurrentBannerAd setHidden:YES]; - } else { NSLog(@"Can't hide banner, there is no banner ad currently loaded."); } @@ -320,23 +328,23 @@ void hz_ads_destroy_banner(void) { #pragma mark - Offerwall Ads void hz_ads_fetch_offerwall(const char *tag) { - [HZOfferWallAd fetchForTag:[NSString stringWithUTF8String:tag]]; + [HZOfferWallAd fetchForTag:nil_or_string(tag)]; } void hz_ads_show_offerwall(const char *tag, bool shouldCloseAfterFirstClick) { HZOfferWallShowOptions *offerwallOpts = [HZOfferWallShowOptions new]; offerwallOpts.shouldCloseAfterFirstClick = shouldCloseAfterFirstClick; offerwallOpts.animatePresentation = YES; - offerwallOpts.tag = [NSString stringWithUTF8String:tag]; + offerwallOpts.tag = nil_or_string(tag); [HZOfferWallAd showWithOptions:offerwallOpts]; } bool hz_ads_offerwall_is_available(const char *tag) { - return [HZOfferWallAd isAvailableForTag:[NSString stringWithUTF8String:tag]]; + return [HZOfferWallAd isAvailableForTag:nil_or_string(tag)]; } void hz_ads_virtual_currency_request(const char *currencyId) { - [[HZFyberVirtualCurrencyClient sharedClient] requestDeltaOfCurrency:(currencyId == NULL ? nil : [NSString stringWithUTF8String:currencyId])]; + [[HZFyberVirtualCurrencyClient sharedClient] requestDeltaOfCurrency:nil_or_string(currencyId)]; } @@ -383,7 +391,7 @@ void hz_ads_clear_gdpr_consent_data() { bool hz_ads_is_network_initialized(const char *network) { if (network == NULL) { return NO; } - return [HeyzapAds isNetworkInitialized:[NSString stringWithUTF8String:network]]; + return [HeyzapAds isNetworkInitialized:nil_or_string(network)]; } @@ -419,12 +427,12 @@ void hz_ads_hide_third_party_debug_logs(void) { void hz_ads_set_bundle_identifier(const char *bundle_id) { if (bundle_id == NULL) { return; } - NSString *bundleID = [NSString stringWithUTF8String:bundle_id]; + NSString *bundleID = nil_or_string(bundle_id); [HeyzapAds setBundleIdentifier:bundleID]; } void hz_add_facebook_test_device(const char *device_id) { - NSString *deviceID = [NSString stringWithUTF8String:device_id]; + NSString *deviceID = nil_or_string(device_id); Class fbAdSettings = NSClassFromString(@"FBAdSettings"); if ([fbAdSettings respondsToSelector:@selector(addTestDevice:)]) { @@ -438,7 +446,7 @@ void hz_add_facebook_test_device(const char *device_id) { #pragma mark - Demographics Setters void hz_demo_set_gender(const char * genderChar) { - NSString *gender = [NSString stringWithUTF8String:genderChar]; + NSString *gender = nil_or_string(genderChar); if ([gender isEqualToString:@"MALE"]) { [[HeyzapAds demographicInformation] setUserGender:HZUserGenderMale]; @@ -457,7 +465,7 @@ void hz_demo_set_location(float latitude, float longitude, float horizontalAccur } void hz_demo_set_postal_code(const char * postalCodeChar) { - NSString *postalCode = (postalCodeChar == NULL ? nil : [NSString stringWithUTF8String:postalCodeChar]); + NSString *postalCode = nil_or_string(postalCodeChar); [[HeyzapAds demographicInformation] setUserPostalCode:postalCode]; } @@ -466,7 +474,7 @@ void hz_demo_set_household_income(int householdIncome) { } void hz_demo_set_marital_status(const char * maritalStatusChar) { - NSString *maritalStatus = [NSString stringWithUTF8String:maritalStatusChar]; + NSString *maritalStatus = nil_or_string(maritalStatusChar); if ([maritalStatus isEqualToString:@"SINGLE"]) { [[HeyzapAds demographicInformation] setUserMaritalStatus:HZUserMaritalStatusSingle]; @@ -478,7 +486,7 @@ void hz_demo_set_marital_status(const char * maritalStatusChar) { } void hz_demo_set_education_level(const char * educationLevelChar) { - NSString *educationLevel = [NSString stringWithUTF8String:educationLevelChar]; + NSString *educationLevel = nil_or_string(educationLevelChar); if ([educationLevel isEqualToString:@"GRADE_SCHOOL"]) { [[HeyzapAds demographicInformation] setUserEducationLevel:HZUserEducationGradeSchool]; @@ -511,7 +519,7 @@ void hz_demo_set_birth_date(const char * yyyyMMdd_dateChar) { NSDate *parsedDate = nil; if (yyyyMMdd_dateChar != NULL) { - parsedDate = [dateFormat dateFromString:[NSString stringWithUTF8String:yyyyMMdd_dateChar]]; + parsedDate = [dateFormat dateFromString:nil_or_string(yyyyMMdd_dateChar)]; } [[HeyzapAds demographicInformation] setUserBirthDate:parsedDate]; @@ -539,12 +547,12 @@ void hz_fetch_chartboost_for_location_objc(NSString *location) { } void hz_fetch_chartboost_for_location(const char *location) { - NSString *nsLocation = [NSString stringWithUTF8String:location]; + NSString *nsLocation = nil_or_string(location); hz_fetch_chartboost_for_location_objc(nsLocation); } bool hz_chartboost_is_available_for_location(const char *location) { - NSString *nsLocation = [NSString stringWithUTF8String:location]; + NSString *nsLocation = nil_or_string(location); if (!hz_chartboost_enabled()) { HZDLog(@"Chartboost ad is not available because it is not enabled"); return NO; @@ -555,13 +563,13 @@ bool hz_chartboost_is_available_for_location(const char *location) { } void hz_show_chartboost_for_location(const char *location) { - NSString *nsLocation = [NSString stringWithUTF8String:location]; + NSString *nsLocation = nil_or_string(location); if (!hz_chartboost_enabled()) { HZDLog(@"Chartboost not enabled yet; not able to show ad."); return; } - HZDLog(@"Requesting Chartboost show interstitial for location: %@",nsLocation); + HZDLog(@"Requesting Chartboost show interstitial for location: %@", nsLocation); [HZUnityAdapterChartboostProxy showInterstitial:nsLocation]; } } diff --git a/Assets/Scripts/AdManager.cs b/Assets/Scripts/AdManager.cs index d58f9dde..0b5a5328 100644 --- a/Assets/Scripts/AdManager.cs +++ b/Assets/Scripts/AdManager.cs @@ -1,12 +1,12 @@ using UnityEngine; using UnityEngine.UI; -using UnityEngine.Assertions.Must; using Heyzap; +using System; using System.Collections; using System.Collections.Generic; -public class AdManager : MonoBehaviour { - +public class AdManager : MonoBehaviour +{ [SerializeField] private Text adTagTextField; [SerializeField] @@ -22,7 +22,8 @@ public class AdManager : MonoBehaviour { [SerializeField] private Text offerwallCurrencyIdTextField; - private enum AdType { + private enum AdType + { Interstitial, Video, Incentivized, @@ -31,32 +32,38 @@ private enum AdType { } private AdType _selectedAdType; - private AdType SelectedAdType { + private AdType SelectedAdType + { get { return _selectedAdType; } - set { + set + { _selectedAdType = value; - this.console.Append("AdType: " + value.ToString()); + console.Append("AdType: " + value.ToString()); ShowAdTypeControls(); } } private string bannerPosition; - public void UpdateLocation(float latitude, float longitude, float horizAcc, float vertAcc, float alt, double timestamp) { + public void UpdateLocation(float latitude, float longitude, float horizAcc, float vertAcc, float alt, double timestamp) + { //HZDemographics.SetUserLocation(latitude, longitude, horizAcc, vertAcc, alt, timestamp); } - void Awake() { - this.adTagTextField.MustNotBeNull(); - this.bannerControls.MustNotBeNull(); - this.standardControls.MustNotBeNull(); - this.offerwallControls.MustNotBeNull(); - this.console.MustNotBeNull(); + void Awake() + { + UnityEngine.Assertions.Assert.IsNotNull(adTagTextField); + UnityEngine.Assertions.Assert.IsNotNull(bannerControls); + UnityEngine.Assertions.Assert.IsNotNull(standardControls); + UnityEngine.Assertions.Assert.IsNotNull(offerwallControls); + UnityEngine.Assertions.Assert.IsNotNull(console); } - void Start () { - HeyzapAds.NetworkCallbackListener networkCallbackListener = delegate(string network, string callback) { - this.console.Append("[" + network + "]: " + callback); + void Start() + { + HeyzapAds.NetworkCallbackListener networkCallbackListener = delegate (string network, string callback) + { + console.Append("[" + network + "]: " + callback); }; // HZDemographics.SetUserGender(HZDemographics.Gender.MALE); @@ -68,128 +75,158 @@ void Start () { // UnityEngine.Debug.Log ("calling loc service"); // TestLocationService locServ = new TestLocationService(); - // locServ.Start(this.console); + // locServ.Start(console); - HeyzapAds.SetNetworkCallbackListener(networkCallbackListener); - HeyzapAds.ShowDebugLogs(); - HeyzapAds.Start("ENTER_YOUR_PUBLISHER_ID_HERE", HeyzapAds.FLAG_NO_OPTIONS); + HeyzapAds.SetNetworkCallbackListener(networkCallbackListener); + HeyzapAds.ShowDebugLogs(); + HeyzapAds.Start("ENTER_YOUR_PUBLISHER_ID_HERE", HeyzapAds.FLAG_NO_OPTIONS); - HZBannerAd.SetDisplayListener(delegate(string adState, string adTag) { - this.console.Append("BANNER: " + adState + " Tag : " + adTag); - if (adState == "loaded") { + HZBannerAd.SetDisplayListener(delegate (string adState, string adTag) + { + console.Append("BANNER: " + adState + " Tag : " + adTag); + if (adState == "loaded") + { Rect dimensions = new Rect(); HZBannerAd.GetCurrentBannerDimensions(out dimensions); - this.console.Append(string.Format(" (x,y): ({0},{1}) - WxH: {2}x{3}", dimensions.x, dimensions.y, dimensions.width, dimensions.height)); + console.Append(string.Format(" (x,y): ({0},{1}) - WxH: {2}x{3}", dimensions.x, dimensions.y, dimensions.width, dimensions.height)); } }); - HZInterstitialAd.SetDisplayListener(delegate(string adState, string adTag) { - this.console.Append("INTERSTITIAL: " + adState + " Tag : " + adTag); + HZInterstitialAd.SetDisplayListener(delegate (string adState, string adTag) + { + console.Append("INTERSTITIAL: " + adState + " Tag : " + adTag); }); - HZIncentivizedAd.SetDisplayListener(delegate(string adState, string adTag) { - this.console.Append("INCENTIVIZED: " + adState + " Tag : " + adTag); + HZIncentivizedAd.SetDisplayListener(delegate (string adState, string adTag) + { + console.Append("INCENTIVIZED: " + adState + " Tag : " + adTag); }); - HZVideoAd.SetDisplayListener(delegate(string adState, string adTag) { - this.console.Append("VIDEO: " + adState + " Tag : " + adTag); + HZVideoAd.SetDisplayListener(delegate (string adState, string adTag) + { + console.Append("VIDEO: " + adState + " Tag : " + adTag); }); - HZOfferWallAd.SetDisplayListener(delegate(string adState, string adTag) { - this.console.Append("OFFERWALL: " + adState + " Tag : " + adTag); + HZOfferWallAd.SetDisplayListener(delegate (string adState, string adTag) + { + console.Append("OFFERWALL: " + adState + " Tag : " + adTag); }); - HZOfferWallAd.SetVirtualCurrencyResponseListener(delegate(VirtualCurrencyResponse response) { - this.console.Append("OFFERWALL VCS Response: id:" + response.CurrencyID + " name: '" + response.CurrencyName + "' amount : " + response.DeltaOfCurrency + " trans: " + response.LatestTransactionID); + HZOfferWallAd.SetVirtualCurrencyResponseListener(delegate (VirtualCurrencyResponse response) + { + console.Append("OFFERWALL VCS Response: id:" + response.CurrencyID + " name: '" + response.CurrencyName + "' amount : " + response.DeltaOfCurrency + " trans: " + response.LatestTransactionID); }); - HZOfferWallAd.SetVirtualCurrencyErrorListener(delegate(string errorMsg) { - this.console.Append("OFFERWALL VCS Error: " + errorMsg); + HZOfferWallAd.SetVirtualCurrencyErrorListener(delegate (string errorMsg) + { + console.Append("OFFERWALL VCS Error: " + errorMsg); }); // UI defaults - this.bannerPosition = HZBannerShowOptions.POSITION_TOP; - this.SelectedAdType = AdType.Interstitial; + bannerPosition = HZBannerShowOptions.POSITION_TOP; + SelectedAdType = AdType.Interstitial; - this.ShowAdTypeControls(); + ShowAdTypeControls(); } - public void InterstitialSelected(bool selected) { - if (selected) { - this.SelectedAdType = AdType.Interstitial; + public void InterstitialSelected(bool selected) + { + if (selected) + { + SelectedAdType = AdType.Interstitial; } } - public void VideoSelected(bool selected) { - if (selected) { - this.SelectedAdType = AdType.Video; + public void VideoSelected(bool selected) + { + if (selected) + { + SelectedAdType = AdType.Video; } } - public void IncentivizedSelected(bool selected) { - if (selected) { - this.SelectedAdType = AdType.Incentivized; + public void IncentivizedSelected(bool selected) + { + if (selected) + { + SelectedAdType = AdType.Incentivized; } } - public void BannerSelected(bool selected) { - if (selected) { - this.SelectedAdType = AdType.Banner; + public void BannerSelected(bool selected) + { + if (selected) + { + SelectedAdType = AdType.Banner; } } - public void OfferwallSelected(bool selected) { - if (selected) { - this.SelectedAdType = AdType.Offerwall; + public void OfferwallSelected(bool selected) + { + if (selected) + { + SelectedAdType = AdType.Offerwall; } } - public void IsAvailableButton() { - string tag = this.adTag(); + public void IsAvailableButton() + { + string tagText = getTagOrNull(adTagTextField.text); bool available = false; - switch (this.SelectedAdType) { - case AdType.Interstitial: - available = HZInterstitialAd.IsAvailable(tag); - break; - case AdType.Video: - available = HZVideoAd.IsAvailable(tag); - break; - case AdType.Incentivized: - available = HZIncentivizedAd.IsAvailable(tag); - break; - case AdType.Banner: - // Not applicable - break; - case AdType.Offerwall: - available = HZOfferWallAd.IsAvailable(tag); - break; + switch (SelectedAdType) + { + case AdType.Interstitial: + available = HZInterstitialAd.IsAvailable(tagText); + break; + case AdType.Video: + available = HZVideoAd.IsAvailable(tagText); + break; + case AdType.Incentivized: + available = HZIncentivizedAd.IsAvailable(tagText); + break; + case AdType.Banner: + // Not applicable + break; + case AdType.Offerwall: + available = HZOfferWallAd.IsAvailable(tagText); + break; } string availabilityMessage = available ? "available" : "not available"; - this.console.Append(this.SelectedAdType.ToString() + " with tag: " + tag + " is " + availabilityMessage); + console.Append(SelectedAdType.ToString() + " with tag: " + tagText + " is " + availabilityMessage); } - public void ShowButton() { - string tag = this.adTag(); + public void ShowButton() + { + string tagText = getTagOrNull(adTagTextField.text); - HZShowOptions showOptions = new HZShowOptions(); - showOptions.Tag = tag; + HZShowOptions showOptions = new HZShowOptions + { + Tag = tagText + }; - HZIncentivizedShowOptions incentivizedOptions = new HZIncentivizedShowOptions(); - incentivizedOptions.Tag = tag; - incentivizedOptions.IncentivizedInfo = "test app incentivized info!"; + HZIncentivizedShowOptions incentivizedOptions = new HZIncentivizedShowOptions + { + Tag = tagText, + IncentivizedInfo = "test app incentivized info!" + }; - HZBannerShowOptions bannerOptions = new HZBannerShowOptions(); - bannerOptions.Tag = tag; - bannerOptions.Position = this.bannerPosition; + HZBannerShowOptions bannerOptions = new HZBannerShowOptions + { + Tag = tagText, + Position = bannerPosition + }; - HZOfferWallShowOptions offerwallOptions = new HZOfferWallShowOptions(); - offerwallOptions.ShouldCloseAfterFirstClick = offerwallCloseOnFirstClickToggle.isOn; - offerwallOptions.Tag = tag; + HZOfferWallShowOptions offerwallOptions = new HZOfferWallShowOptions + { + ShouldCloseAfterFirstClick = offerwallCloseOnFirstClickToggle.isOn, + Tag = tag + }; - this.console.Append("Showing " + this.SelectedAdType.ToString() + " with tag: " + tag); - switch (this.SelectedAdType) { + console.Append("Showing " + SelectedAdType.ToString() + " with tag: " + tagText); + switch (SelectedAdType) + { case AdType.Interstitial: HZInterstitialAd.ShowWithOptions(showOptions); break; @@ -208,62 +245,78 @@ public void ShowButton() { } } - public void FetchButton() { - string tag = this.adTag(); - this.console.Append("Fetching " + this.SelectedAdType.ToString() + " with tag: " + tag); - switch(this.SelectedAdType) { + public void FetchButton() + { + string tagText = getTagOrNull(adTagTextField.text); + console.Append("Fetching " + SelectedAdType.ToString() + " with tag: " + tagText); + switch (SelectedAdType) + { case AdType.Interstitial: - HZInterstitialAd.Fetch(tag); + HZInterstitialAd.Fetch(tagText); break; case AdType.Video: - HZVideoAd.Fetch(tag); + HZVideoAd.Fetch(tagText); break; case AdType.Incentivized: - HZIncentivizedAd.Fetch(tag); + HZIncentivizedAd.Fetch(tagText); break; case AdType.Offerwall: - HZOfferWallAd.Fetch(tag); + HZOfferWallAd.Fetch(tagText); break; } } - public void HideButton() { - if (this.SelectedAdType == AdType.Banner) { - this.console.Append("Hiding Banner"); + private String getTagOrNull(string tagText) + { + return String.IsNullOrEmpty(tagText) ? null : tagText; + } + + public void HideButton() + { + if (SelectedAdType == AdType.Banner) + { + console.Append("Hiding Banner"); HZBannerAd.Hide(); } } - public void DestroyButton() { - if (this.SelectedAdType == AdType.Banner) { - this.console.Append("Destroying Banner"); + public void DestroyButton() + { + if (SelectedAdType == AdType.Banner) + { + console.Append("Destroying Banner"); HZBannerAd.Destroy(); } } - public void RemoteDataButton() { - this.console.Append("Remote data: " + HeyzapAds.GetRemoteData()); + public void RemoteDataButton() + { + console.Append("Remote data: " + HeyzapAds.GetRemoteData()); } - public void DebugLogSwitch(bool on) { - if (on) { - this.console.Append("Enabling debug logging"); + public void DebugLogSwitch(bool on) + { + if (on) + { + console.Append("Enabling debug logging"); HeyzapAds.ShowDebugLogs(); - } else { - this.console.Append("Disabling debug logging"); + } + else + { + console.Append("Disabling debug logging"); HeyzapAds.HideDebugLogs(); } - } + } public void AcceptGdprButton() - { - this.console.Append("Accepting GDPR"); - HeyzapAds.SetGdprConsent(true); - } + { + console.Append("Accepting GDPR"); + HeyzapAds.SetGdprConsent(true); + } public void RejectGdprButton() { - this.console.Append("Rejecting GDPR"); + console.Append("Rejecting GDPR"); HeyzapAds.SetGdprConsent(false); } @@ -313,58 +366,62 @@ private Dictionary GetGdprConsentDataB() return data; } - public void BannerPositionTop(bool selected) { - if (selected) { + public void BannerPositionTop(bool selected) + { + if (selected) + { this.bannerPosition = HZBannerShowOptions.POSITION_TOP; } } - public void BannerPositionBottom(bool selected) { - if (selected) { - this.bannerPosition = HZBannerShowOptions.POSITION_BOTTOM; + public void BannerPositionBottom(bool selected) + { + if (selected) + { + bannerPosition = HZBannerShowOptions.POSITION_BOTTOM; } } - public void VCSRequestButton() { - HZOfferWallAd.RequestDeltaOfCurrency(this.currencyId()); + public void VCSRequestButton() + { + HZOfferWallAd.RequestDeltaOfCurrency(CurrencyId()); } - public void ShowMediationTest() { - this.console.Append("Showing mediation test suite"); + public void ShowMediationTest() + { + console.Append("Showing mediation test suite"); HeyzapAds.ShowMediationTestSuite(); } - private void ShowAdTypeControls() { - if (this.SelectedAdType == AdType.Banner) { - this.bannerControls.SetActive(true); - this.standardControls.SetActive(false); - this.offerwallControls.SetActive(false); - } else if (this.SelectedAdType == AdType.Offerwall) { - this.bannerControls.SetActive(false); - this.offerwallControls.SetActive(true); - this.standardControls.SetActive(false); - } else { - this.bannerControls.SetActive(false); - this.offerwallControls.SetActive(false); - this.standardControls.SetActive(true); + private void ShowAdTypeControls() + { + if (SelectedAdType == AdType.Banner) + { + bannerControls.SetActive(true); + standardControls.SetActive(false); + offerwallControls.SetActive(false); } - } - - private string adTag() { - string tag = this.adTagTextField.text; - if (tag == null || tag.Trim().Length == 0) { - return "default"; - } else { - return tag; + else if (SelectedAdType == AdType.Offerwall) + { + bannerControls.SetActive(false); + offerwallControls.SetActive(true); + standardControls.SetActive(false); + } + else + { + bannerControls.SetActive(false); + offerwallControls.SetActive(false); + standardControls.SetActive(true); } } - private string currencyId() { - string currencyId = this.offerwallCurrencyIdTextField.text; - if (currencyId == null || tag.Trim().Length == 0) { + private string CurrencyId() + { + string currencyId = offerwallCurrencyIdTextField.text; + if (currencyId == null || tag.Trim().Length == 0) + { return null; - } else { - return currencyId; } + return currencyId; } } diff --git a/Assets/Scripts/ScrollingTextArea.cs b/Assets/Scripts/ScrollingTextArea.cs index 7505e1cf..5fcb120f 100644 --- a/Assets/Scripts/ScrollingTextArea.cs +++ b/Assets/Scripts/ScrollingTextArea.cs @@ -1,8 +1,7 @@ using UnityEngine; -using System.Collections; -using UnityEngine.UI; -public class ScrollingTextArea : MonoBehaviour { +public class ScrollingTextArea : MonoBehaviour +{ public Vector2 scrollPosition; private string text = ""; @@ -14,24 +13,29 @@ public class ScrollingTextArea : MonoBehaviour { private Texture2D consoleBackgroundTexture; private GUIStyle consoleTextStyle; private GUIStyle consoleBackgroundStyle; - void Start () { - consoleBackgroundTexture = new Texture2D(1,1); - for(var i = 0; i < consoleBackgroundTexture.width; i++) + + void Start() + { + consoleBackgroundTexture = new Texture2D(1, 1); + for (var i = 0; i < consoleBackgroundTexture.width; i++) { - for(var j = 0; j < consoleBackgroundTexture.height; j++) + for (var j = 0; j < consoleBackgroundTexture.height; j++) { consoleBackgroundTexture.SetPixel(i, j, new Color(0f, 0f, 0f, 0.7f)); } } - consoleTextStyle = new GUIStyle(); - consoleTextStyle.fontSize = 28; + consoleTextStyle = new GUIStyle + { + fontSize = 28 + }; consoleTextStyle.normal.textColor = Color.white; consoleTextStyle.richText = true; consoleBackgroundStyle = new GUIStyle(); consoleBackgroundStyle.normal.background = consoleBackgroundTexture; } - void OnGUI() { + void OnGUI() + { GUI.skin.verticalScrollbar.fixedWidth = Screen.width * 0.05f; GUI.skin.verticalScrollbarThumb.fixedWidth = Screen.width * 0.05f; @@ -39,15 +43,16 @@ void OnGUI() { GUI.skin.horizontalScrollbarThumb.fixedHeight = Screen.width * 0.035f; - GUI.BeginGroup(new Rect (xPadding, Screen.height - height - yPadding, Screen.width-xPadding*2, height), consoleBackgroundStyle); - scrollPosition = GUILayout.BeginScrollView(scrollPosition, false/*horizontal scroll bar*/, true/*vertical scroll bar*/, GUILayout.Width(Screen.width-xPadding*2), GUILayout.Height(height)); + GUI.BeginGroup(new Rect(xPadding, Screen.height - height - yPadding, Screen.width - xPadding * 2, height), consoleBackgroundStyle); + scrollPosition = GUILayout.BeginScrollView(scrollPosition, false/*horizontal scroll bar*/, true/*vertical scroll bar*/, GUILayout.Width(Screen.width - xPadding * 2), GUILayout.Height(height)); GUILayout.Label(text, consoleTextStyle); GUILayout.EndScrollView(); - + GUI.EndGroup(); } - public void Append(string append, bool newline=true) { + public void Append(string append, bool newline = true) + { if (newline && this.text.Length > 0) this.text += "\n"; this.text += "[" + System.DateTime.UtcNow.ToString("HH:mm:ss") + "] "; diff --git a/Assets/Scripts/TestLocationService.cs b/Assets/Scripts/TestLocationService.cs index 8c6078fe..8182025e 100644 --- a/Assets/Scripts/TestLocationService.cs +++ b/Assets/Scripts/TestLocationService.cs @@ -1,19 +1,17 @@ using UnityEngine; -using UnityEngine.UI; using System.Collections; -using Heyzap; public class TestLocationService : MonoBehaviour { [SerializeField] - private ScrollingTextArea console; + private readonly ScrollingTextArea console; [SerializeField] private AdManager adManager; public IEnumerator Start() { - UnityEngine.Debug.Log ("location service start"); + UnityEngine.Debug.Log("location service start"); // First, check if user has location service enabled // if (!Input.location.isEnabledByUser){ // console.Append("Location disabled by user... quitting");