diff --git a/README.md b/README.md index e2fff39..ff1c41a 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ or point to the ZIP file of a [specific release](https://github.com/AGulev/DefVi See the [example folder](https://github.com/AGulev/DefVideoAds/tree/master/example) for understand how to use extension. Especially [ui.gui_script](https://github.com/AGulev/DefVideoAds/blob/master/example/ui.gui_script) file. -![Example screenshot](https://user-images.githubusercontent.com/2209596/40448649-cf08e002-5ede-11e8-9681-c20d17c0512a.jpg) +![Example screenshot](https://user-images.githubusercontent.com/2209596/60367270-1b40ab80-99ee-11e9-87e8-7dc9f8108615.gif) ## LUA Api @@ -107,6 +107,36 @@ unityads.getVersion() -- Returns the Unity Ads SDK version as a string. unityads.show() -- show default ad unityads.show("rewardedVideo") -- show rewardedVideo ``` +#### unityads.loadBanner(placementId) +```lua +unityads.loadBanner("banner") -- load banner +``` +#### unityads.unloadBanner() +```lua +unityads.unloadBanner() -- unload banner +``` +#### unityads.showBanner() +```lua +unityads.showBanner() -- show loaded banner +``` +#### unityads.hideBanner() +```lua +unityads.hideBanner() -- hide banner +``` +#### unityads.setBannerPosition(position) +```lua +unityads.setBannerPosition(position) -- set position of the banner +-- default value is unityads.BANNER_POSITION_TOP_CENTER +--possible positions: +unityads.BANNER_POSITION_TOP_LEFT +unityads.BANNER_POSITION_TOP_CENTER +unityads.BANNER_POSITION_TOP_RIGHT +unityads.BANNER_POSITION_BOTTOM_LEFT +unityads.BANNER_POSITION_BOTTOM_CENTER +unityads.BANNER_POSITION_BOTTOM_RIGHT +unityads.BANNER_POSITION_CENTER +unityads.BANNER_POSITION_NONE +``` ### Constants ```lua @@ -121,6 +151,7 @@ unityads.TYPE_IS_READY unityads.TYPE_DID_START unityads.TYPE_DID_ERROR unityads.TYPE_DID_FINISH +unityads.TYPE_BANNER ``` ##### unityads.TYPE_IS_READY ```lua @@ -154,6 +185,18 @@ local function defunityads_callback(self, msg_type, message) end end ``` +##### unityads.TYPE_BANNER +```lua +local function defunityads_callback(self, msg_type, message) + if msg_type == unityads.TYPE_BANNER then + if message.event == BANNER_EVENT_DID_ERROR then + pprint(message) -- message = {event = BANNER_EVENT_DID_ERROR, error = "string"} + else + pprint(message) -- message = {event = BANNER_EVENT_*, placementId = "string"} + end + end +end +``` #### Error types [Original doc about error types](https://github.com/Unity-Technologies/unity-ads-ios/wiki/sdk_ios_api_errors) ```lua @@ -197,5 +240,27 @@ local function defunityads_callback(self, msg_type, message) end end ``` +#### Banner events +```lua +--possible banner events: +unityads.BANNER_EVENT_DID_LOAD +unityads.BANNER_EVENT_DID_UNLOAD +unityads.BANNER_EVENT_DID_SHOW +unityads.BANNER_EVENT_DID_HIDE +unityads.BANNER_EVENT_DID_CLICK +unityads.BANNER_EVENT_DID_ERROR +``` +```lua +local function defunityads_callback(self, msg_type, message) + if msg_type == unityads.TYPE_BANNER then + if message.event == unityads.BANNER_EVENT_DID_LOAD then + ... + elseif message.event == unityads.BANNER_EVENT_DID_UNLOAD then + ... + end +end +``` + +--- If you have any issues, questions or suggestions please [create an issue](https://github.com/AGulev/DefVideoAds/issues) or contact me: me@agulev.com diff --git a/defunityads/api/DefUnityAds.script_api b/defunityads/api/DefUnityAds.script_api index 09cdbfc..cf431e0 100755 --- a/defunityads/api/DefUnityAds.script_api +++ b/defunityads/api/DefUnityAds.script_api @@ -93,6 +93,39 @@ - name: placementId type: string +#***************************************************************************************************** + + - name: loadBanner + type: function + + parameters: + - name: placementId + type: string + +#***************************************************************************************************** + + - name: unloadBanner + type: function + +#***************************************************************************************************** + + - name: showBanner + type: function + +#***************************************************************************************************** + + - name: hideBanner + type: function + +#***************************************************************************************************** + + - name: setBannerPosition + type: function + + parameters: + - name: position + type: number + #***************************************************************************************************** - name: TYPE_IS_READY @@ -107,6 +140,9 @@ - name: TYPE_DID_FINISH type: number + - name: TYPE_BANNER + type: number + #***************************************************************************************************** @@ -141,4 +177,51 @@ type: number -#***************************************************************************************************** \ No newline at end of file +#***************************************************************************************************** + + - name: BANNER_POSITION_TOP_LEFT + type: number + + - name: BANNER_POSITION_TOP_CENTER + type: number + + - name: BANNER_POSITION_TOP_RIGHT + type: number + + - name: BANNER_POSITION_BOTTOM_LEFT + type: number + + - name: BANNER_POSITION_BOTTOM_CENTER + type: number + + - name: BANNER_POSITION_BOTTOM_RIGHT + type: number + + - name: BANNER_POSITION_CENTER + type: number + + - name: BANNER_POSITION_NONE + type: number + +#***************************************************************************************************** + + - name: BANNER_EVENT_DID_LOAD + type: number + + - name: BANNER_EVENT_DID_UNLOAD + type: number + + - name: BANNER_EVENT_DID_SHOW + type: number + + - name: BANNER_EVENT_DID_HIDE + type: number + + - name: BANNER_EVENT_DID_CLICK + type: number + + - name: BANNER_EVENT_DID_ERROR + type: number + +#***************************************************************************************************** + \ No newline at end of file diff --git a/defunityads/lib/android/classes.jar b/defunityads/lib/android/classes.jar index d1eca91..bb3a17b 100644 Binary files a/defunityads/lib/android/classes.jar and b/defunityads/lib/android/classes.jar differ diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/NSString+UnityAdsError.h b/defunityads/lib/ios/UnityAds.framework/Headers/NSString+UnityAdsError.h new file mode 100644 index 0000000..e593a7a --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/NSString+UnityAdsError.h @@ -0,0 +1,5 @@ +#import "UnityAds.h" + +@interface NSString (UnityAdsError) +- (UnityAdsError)unityAdsErrorFromString; +@end diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UADSBanner.h b/defunityads/lib/ios/UnityAds.framework/Headers/UADSBanner.h new file mode 100644 index 0000000..30aab96 --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UADSBanner.h @@ -0,0 +1,107 @@ +#include + +NS_ASSUME_NONNULL_BEGIN + +/** + * UnityAdsBannerDelegate is a delegate class for callbacks from Unity Ads Banner operations. + */ +@protocol UnityAdsBannerDelegate + +/** + Called when the banner is loaded and ready to be placed in the view hierarchy. + + @param placementId The ID of the placement of the banner that is loaded. + @param view View that is to be placed in the view hierarchy. +*/ +-(void)unityAdsBannerDidLoad:(NSString *)placementId view:(UIView *)view; + +/** + Called when the banner is unloaded and references to it should be discarded. + The view provided in unityAdsBannerDidLoad will be removed from the view hierarchy before + this method is called. + */ +-(void)unityAdsBannerDidUnload:(NSString *)placementId; + +/** + * Called when the banner is shown. + * + * @param placementId The ID of the placement that has shown. + */ +-(void)unityAdsBannerDidShow:(NSString *)placementId; + +/** + * Called when the banner is hidden. + * + * @param placementId the ID of the that has hidden. + */ +-(void)unityAdsBannerDidHide:(NSString *)placementId; + +/** + * Called when the user clicks the banner. + * + * @param placementId the ID of the placement that has been clicked. + */ +-(void)unityAdsBannerDidClick:(NSString *)placementId; + +/** + * Called when `UnityAdsBanner` encounters an error. All errors will be logged but this method can be used as an additional debugging aid. This callback can also be used for collecting statistics from different error scenarios. + * + * @param message A human readable string indicating the type of error encountered. + */ +-(void)unityAdsBannerDidError:(NSString *)message; +@end + +/** + * An enumeration for the various ways to position the Unity Ads banner placement. + */ +typedef NS_ENUM(NSInteger, UnityAdsBannerPosition) { + kUnityAdsBannerPositionTopLeft, + kUnityAdsBannerPositionTopCenter, + kUnityAdsBannerPositionTopRight, + kUnityAdsBannerPositionBottomLeft, + kUnityAdsBannerPositionBottomCenter, + kUnityAdsBannerPositionBottomRight, + kUnityAdsBannerPositionCenter, + kUnityAdsBannerPositionNone +}; + +/** + * UnityAdsBanner is a static class for handling showing and hiding the Unity Ads banner. + */ + +@interface UnityAdsBanner : NSObject + +/** + * Loads the banner with the default banner placement. + */ ++(void)loadBanner; + +/** + * Loads the banner with the given placement. + * @param placementId The placement ID, as defined in the Unity Ads admin tools. + */ ++(void)loadBanner:(NSString *)placementId; + ++(void)setBannerPosition:(UnityAdsBannerPosition)bannerPosition; + +/** + * Destroys the banner. + */ ++(void)destroy; + +/** + * Provides the currently assigned `UnityAdsBannerDelegate`. + * + * @return The current `UnityAdsBannerDelegate`. + */ ++(nullable id )getDelegate; + +/** + * Asigns the banner delegate. + * + * @param delegate The new `UnityAdsBannerDelegate' for UnityAds to send banner callbacks to. + */ ++(void)setDelegate:(id )delegate; +@end + +NS_ASSUME_NONNULL_END diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UADSMetaData.h b/defunityads/lib/ios/UnityAds.framework/Headers/UADSMetaData.h index 6ea5644..35fc15b 100644 --- a/defunityads/lib/ios/UnityAds.framework/Headers/UADSMetaData.h +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UADSMetaData.h @@ -1,6 +1,6 @@ -#import "UADSJsonStorage.h" +#import "USRVJsonStorage.h" -@interface UADSMetaData : UADSJsonStorage +@interface UADSMetaData : USRVJsonStorage @property (nonatomic, strong) NSString *category; diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UANAApiAnalytics.h b/defunityads/lib/ios/UnityAds.framework/Headers/UANAApiAnalytics.h new file mode 100644 index 0000000..9bd7722 --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UANAApiAnalytics.h @@ -0,0 +1,14 @@ + +NS_ASSUME_NONNULL_BEGIN + +// C# +@protocol UANAEngineDelegate +-(void)addExtras:(NSString *)extras; +@end + +// Webview +@interface UANAApiAnalytics : NSObject ++(void)setAnalyticsDelegate:(id )analyticsDelegate; +@end + +NS_ASSUME_NONNULL_END diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UMONCustomEvent.h b/defunityads/lib/ios/UnityAds.framework/Headers/UMONCustomEvent.h new file mode 100644 index 0000000..0b31b36 --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UMONCustomEvent.h @@ -0,0 +1,17 @@ +NS_ASSUME_NONNULL_BEGIN + +@interface UMONCustomEventBuilder : NSObject +@property (nonatomic) NSString* category; +@property (nonatomic) NSString* type; +@property (nonatomic) NSDictionary* userInfo; +@end + +@interface UMONCustomEvent : NSObject +@property (strong) NSString* category; +@property (strong) NSString* type; +@property (strong) NSDictionary* userInfo; +-(instancetype)initWithBuilder:(UMONCustomEventBuilder*)builder; ++(instancetype)build:(void (^)(UMONCustomEventBuilder *))buildBlock; +@end + +NS_ASSUME_NONNULL_END diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UMONItem.h b/defunityads/lib/ios/UnityAds.framework/Headers/UMONItem.h new file mode 100644 index 0000000..9d0a1d0 --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UMONItem.h @@ -0,0 +1,15 @@ +@interface UMONItemBuilder : NSObject +@property(strong, nonatomic) NSString *productId; +@property(nonatomic) double quantity; +@property(strong, nonatomic) NSString *type; +@end + +@interface UMONItem : NSObject ++(instancetype)build:(void (^)(UMONItemBuilder *))buildBlock; + +-(instancetype)initWithBuilder:(UMONItemBuilder *)builder; + +@property(nonatomic, strong, readonly) NSString *productId; +@property(nonatomic, readonly) double quantity; +@property(nonatomic, strong, readonly) NSString *type; +@end diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UMONNativePromoAdapter.h b/defunityads/lib/ios/UnityAds.framework/Headers/UMONNativePromoAdapter.h new file mode 100644 index 0000000..9116ef0 --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UMONNativePromoAdapter.h @@ -0,0 +1,22 @@ +#import "UPURTransactionDetails.h" +#import "UMONPlacementContent.h" +#import "UMONPromoAdPlacementContent.h" + +typedef NS_ENUM(NSInteger, UMONNativePromoShowType) { + kNativePromoShowTypePreview, + kNativePromoShowTypeFull +}; + +@interface UMONNativePromoAdapter : NSObject +-(instancetype)initWithPromo:(UMONPromoAdPlacementContent *)promo; + +-(void)promoDidShow; + +-(void)promoDidShow:(UMONNativePromoShowType)showType; + +-(void)promoDidClick; + +-(void)promoDidClose; + +-(UMONPromoMetaData *)metadata; +@end diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UMONPlacementContent.h b/defunityads/lib/ios/UnityAds.framework/Headers/UMONPlacementContent.h new file mode 100644 index 0000000..37d97b2 --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UMONPlacementContent.h @@ -0,0 +1,20 @@ +#import "UnityMonetizationPlacementContentState.h" +#import "UMONCustomEvent.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface UMONPlacementContent : NSObject +-(instancetype)initWithPlacementId:(NSString *)placementId withParams:(NSDictionary *)params; + +@property(nonatomic, readonly, getter=isReady) BOOL ready; +@property(nonatomic, readonly) NSString *type; +@property(retain, nonatomic, readonly) NSString *placementId; +@property(nonatomic) UnityMonetizationPlacementContentState state; +@property(nonatomic) NSDictionary *userInfo; +-(void)sendCustomEvent:(UMONCustomEvent*)customEvent; +-(void)sendCustomEvent:(NSString*)type withUserInfo:(NSDictionary* __nullable)userInfo; +-(void)sendCustomEventWithType:(NSString*)type; +-(NSString*)defaultEventCategory; +@end + +NS_ASSUME_NONNULL_END diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UMONPromoAdPlacementContent.h b/defunityads/lib/ios/UnityAds.framework/Headers/UMONPromoAdPlacementContent.h new file mode 100644 index 0000000..e4632a6 --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UMONPromoAdPlacementContent.h @@ -0,0 +1,12 @@ +#import "UMONShowAdPlacementContent.h" +#import "UMONPromoMetaData.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface UMONPromoAdPlacementContent : UMONShowAdPlacementContent +-(instancetype)initWithPlacementId:(NSString *)placementId withParams:(NSDictionary *)params; + +@property(nonatomic, strong, readonly) UMONPromoMetaData *metadata; +@end + +NS_ASSUME_NONNULL_END diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UMONPromoMetaData.h b/defunityads/lib/ios/UnityAds.framework/Headers/UMONPromoMetaData.h new file mode 100644 index 0000000..feaf106 --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UMONPromoMetaData.h @@ -0,0 +1,32 @@ + +#import "UMONItem.h" +#import "UPURProduct.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface UMONPromoMetaDataBuilder : NSObject +@property(strong, nonatomic) NSDate *impressionDate; +@property(nonatomic) NSTimeInterval offerDuration; +@property(strong) UPURProduct *premiumProduct; +@property(strong) NSArray *costs; +@property(strong) NSArray *payouts; +@property(strong) NSDictionary *userInfo; +@end + +@interface UMONPromoMetaData : NSObject +-(instancetype)initWithBuilder:(UMONPromoMetaDataBuilder *)builder; + +@property(strong, nonatomic, nullable) NSDate *impressionDate; +@property(nonatomic, readonly) NSTimeInterval offerDuration; +@property(strong, readonly, nullable) UPURProduct *premiumProduct; +@property(strong, readonly) NSArray *costs; +@property(strong, readonly) NSArray *payouts; +@property(strong, readonly) NSDictionary *userInfo; +-(BOOL)isExpired; +-(BOOL)isPremium; +-(NSTimeInterval)timeRemaining; +-(UMONItem *__nullable)cost; +-(UMONItem *__nullable)payout; +@end + +NS_ASSUME_NONNULL_END diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UMONRewardablePlacementContent.h b/defunityads/lib/ios/UnityAds.framework/Headers/UMONRewardablePlacementContent.h new file mode 100644 index 0000000..a444686 --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UMONRewardablePlacementContent.h @@ -0,0 +1,10 @@ +#import "UMONPlacementContent.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface UMONRewardablePlacementContent : UMONPlacementContent +@property(nonatomic) BOOL rewarded; +@property(strong, nonatomic) NSString *rewardId; +@end + +NS_ASSUME_NONNULL_END diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UMONShowAdPlacementContent.h b/defunityads/lib/ios/UnityAds.framework/Headers/UMONShowAdPlacementContent.h new file mode 100644 index 0000000..6fef0dc --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UMONShowAdPlacementContent.h @@ -0,0 +1,14 @@ +#import +#import "UMONRewardablePlacementContent.h" +#import "UnityAdsFinishState.h" + +@protocol UMONShowAdDelegate +-(void)unityAdsDidStart:(NSString*)placementId; +-(void)unityAdsDidFinish:(NSString*)placementId withFinishState:(UnityAdsFinishState)finishState; +@end + +@interface UMONShowAdPlacementContent : UMONRewardablePlacementContent +@property (strong, nonatomic) id delegate; +-(void)show:(UIViewController *)viewController; +-(void)show:(UIViewController *)viewController withDelegate:(id)delegate; +@end diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UPURProduct.h b/defunityads/lib/ios/UnityAds.framework/Headers/UPURProduct.h new file mode 100644 index 0000000..1104d05 --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UPURProduct.h @@ -0,0 +1,25 @@ + +NS_ASSUME_NONNULL_BEGIN + +@interface UPURProductBuilder : NSObject +@property(strong, nonatomic) NSString *productId; +@property(strong, nonatomic) NSString *localizedPriceString; +@property(strong, nonatomic) NSString *localizedTitle; +@property(strong, nonatomic) NSString *isoCurrencyCode; +@property(strong, nonatomic) NSDecimalNumber *localizedPrice; +@property(strong, nonatomic) NSString *localizedDescription; +@property(strong, nonatomic) NSString *productType; +@end + +@interface UPURProduct : NSObject +@property(strong, nonatomic, readonly) NSString *productId; +@property(strong, nonatomic, readonly) NSString *localizedPriceString; +@property(strong, nonatomic, readonly) NSString *localizedTitle; +@property(strong, nonatomic, readonly) NSString *isoCurrencyCode; +@property(strong, nonatomic, readonly) NSDecimalNumber *localizedPrice; +@property(strong, nonatomic, readonly) NSString *localizedDescription; +@property(strong, nonatomic, readonly) NSString *productType; ++(instancetype)build:(void (^)(UPURProductBuilder *))buildBlock; +@end + +NS_ASSUME_NONNULL_END diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UPURStore.h b/defunityads/lib/ios/UnityAds.framework/Headers/UPURStore.h new file mode 100644 index 0000000..6e0e2fa --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UPURStore.h @@ -0,0 +1,20 @@ + +NS_ASSUME_NONNULL_BEGIN + +typedef NS_ENUM(NSInteger, UPURStore) { + kUPURStoreNotSpecified, + kUPURStoreGooglePlay, + kUPURStoreAmazonAppStore, + kUPURStoreCloudMoolah, + kUPURStoreSamsungApps, + kUPURStoreXiaomiMiPay, + kUPURStoreMacAppStore, + kUPURStoreAppleAppStore, + kUPURStoreWinRT, + kUPURStoreTizenStore, + kUPURStoreFacebookStore +}; + +NSString *NSStringFromUPURAppStore(UPURStore); + +NS_ASSUME_NONNULL_END diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UPURTransactionDetails.h b/defunityads/lib/ios/UnityAds.framework/Headers/UPURTransactionDetails.h new file mode 100644 index 0000000..a2e37d5 --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UPURTransactionDetails.h @@ -0,0 +1,25 @@ +NS_ASSUME_NONNULL_BEGIN + +@interface UPURTransactionDetailsBuilder : NSObject +@property(strong, nonatomic) NSString *productId; +@property(strong, nonatomic) NSString *transactionId; +@property(strong, nonatomic) NSString *receipt; +@property(strong, nonatomic) NSDecimalNumber *price; +@property(strong, nonatomic) NSString *currency; +@property(strong, nonatomic) NSMutableDictionary *extras; + +-(UPURTransactionDetailsBuilder *)putExtra:(NSString *)key value:(NSObject *)value; +@end + +@interface UPURTransactionDetails : NSObject +@property(strong, nonatomic, readonly) NSString *productId; +@property(strong, nonatomic, readonly) NSString *transactionId; +@property(strong, nonatomic, readonly) NSString *receipt; +@property(strong, nonatomic, readonly) NSDecimalNumber *price; +@property(strong, nonatomic, readonly) NSString *currency; +@property(strong, nonatomic, readonly) NSDictionary *extras; + ++(instancetype)build:(void (^)(UPURTransactionDetailsBuilder *))buildBlock; +@end + +NS_ASSUME_NONNULL_END diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UPURTransactionError.h b/defunityads/lib/ios/UnityAds.framework/Headers/UPURTransactionError.h new file mode 100644 index 0000000..318676c --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UPURTransactionError.h @@ -0,0 +1,15 @@ + +NS_ASSUME_NONNULL_BEGIN + +typedef NS_ENUM(NSInteger, UPURTransactionError) { + kUPURTransactionErrorUnknownError, + kUPURTransactionErrorNotSupported, + kUPURTransactionErrorItemUnavailable, + kUPURTransactionErrorUserCancelled, + kUPURTransactionErrorNetworkError, + kUPURTransactionErrorServerError +}; + +NSString *NSStringFromUPURTransactionError(UPURTransactionError); + +NS_ASSUME_NONNULL_END diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UPURTransactionErrorDetails.h b/defunityads/lib/ios/UnityAds.framework/Headers/UPURTransactionErrorDetails.h new file mode 100644 index 0000000..bec30b5 --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UPURTransactionErrorDetails.h @@ -0,0 +1,30 @@ + +#import "UPURTransactionError.h" +#import "UPURStore.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface UPURTransactionErrorDetailsBuilder: NSObject +@property (nonatomic) UPURTransactionError transactionError; +@property (strong, nonatomic) NSString *exceptionMessage; +@property (nonatomic) UPURStore store; +@property (strong, nonatomic) NSString *storeSpecificErrorCode; +@property (strong, nonatomic) NSMutableDictionary *extras; + +-(void)putExtra:(NSString *)key value:(NSObject *)value; + +@end + +@interface UPURTransactionErrorDetails : NSObject + +@property (nonatomic, readonly) UPURTransactionError transactionError; +@property (strong, nonatomic, readonly) NSString *exceptionMessage; +@property (nonatomic, readonly) UPURStore store; +@property (strong, nonatomic, readonly) NSString *storeSpecificErrorCode; +@property (strong, nonatomic, readonly) NSDictionary *extras; + ++(instancetype)build:(void (^)(UPURTransactionErrorDetailsBuilder *))buildBlock; + +@end + +NS_ASSUME_NONNULL_END diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UADSJsonStorage.h b/defunityads/lib/ios/UnityAds.framework/Headers/USRVJsonStorage.h similarity index 89% rename from defunityads/lib/ios/UnityAds.framework/Headers/UADSJsonStorage.h rename to defunityads/lib/ios/UnityAds.framework/Headers/USRVJsonStorage.h index 1ed3c43..3aee117 100644 --- a/defunityads/lib/ios/UnityAds.framework/Headers/UADSJsonStorage.h +++ b/defunityads/lib/ios/UnityAds.framework/Headers/USRVJsonStorage.h @@ -1,4 +1,4 @@ -@interface UADSJsonStorage : NSObject +@interface USRVJsonStorage : NSObject @property (nonatomic, strong) NSMutableDictionary *storageContents; diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/USRVUnityPurchasing.h b/defunityads/lib/ios/UnityAds.framework/Headers/USRVUnityPurchasing.h new file mode 100644 index 0000000..9af93f9 --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/USRVUnityPurchasing.h @@ -0,0 +1,10 @@ +#import "USRVUnityPurchasingDelegate.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface USRVUnityPurchasing : NSObject ++(void)setDelegate:(id)delegate; ++(nullable id)getDelegate; +@end + +NS_ASSUME_NONNULL_END diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/USRVUnityPurchasingDelegate.h b/defunityads/lib/ios/UnityAds.framework/Headers/USRVUnityPurchasingDelegate.h new file mode 100644 index 0000000..6ad155a --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/USRVUnityPurchasingDelegate.h @@ -0,0 +1,19 @@ +#import "UPURProduct.h" +#import "UPURTransactionDetails.h" +#import "UPURTransactionErrorDetails.h" + +NS_ASSUME_NONNULL_BEGIN + +typedef void (^UnityPurchasingLoadProductsCompletionHandler)(NSArray*); +typedef void (^UnityPurchasingTransactionCompletionHandler)(UPURTransactionDetails*); +typedef void (^UnityPurchasingTransactionErrorHandler)(UPURTransactionErrorDetails *); + +@protocol USRVUnityPurchasingDelegate +-(void)loadProducts:(UnityPurchasingLoadProductsCompletionHandler)completionHandler; +-(void)purchaseProduct:(NSString *)productId + completionHandler:(UnityPurchasingTransactionCompletionHandler)completionHandler + errorHandler:(UnityPurchasingTransactionErrorHandler)errorHandler + userInfo:(nullable NSDictionary *)extras; +@end + +NS_ASSUME_NONNULL_END diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UnityAds.h b/defunityads/lib/ios/UnityAds.framework/Headers/UnityAds.h index d010704..a57abe0 100644 --- a/defunityads/lib/ios/UnityAds.framework/Headers/UnityAds.h +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UnityAds.h @@ -3,141 +3,33 @@ #import #import #import +#import +#import "UADSBanner.h" +#import "UADSPurchasing.h" +#import "UANAApiAnalytics.h" +#import "UMONPlacementContent.h" +#import "UMONPromoMetaData.h" +#import "UMONRewardablePlacementContent.h" +#import "UPURProduct.h" +#import "UPURTransactionDetails.h" +#import "UPURTransactionError.h" +#import "UPURTransactionErrorDetails.h" +#import "UPURStore.h" +#import "USRVUnityPurchasing.h" +#import "UnityAnalytics.h" +#import "UnityAnalyticsAcquisitionType.h" +#import "UnityMonetizationDelegate.h" +#import "UnityAdsFinishState.h" +#import "UMONShowAdPlacementContent.h" +#import "UMONPromoAdPlacementContent.h" +#import "UMONNativePromoAdapter.h" +#import "UnityMonetization.h" +#import "UnityAdsDelegate.h" +#import "UnityAdsPlacementState.h" +#import "NSString+UnityAdsError.h" +#import "UnityAdsExtendedDelegate.h" -/** - * An enumerate that describes the state of `UnityAds` placements. - * @note All placement states, other than `kUnityAdsPlacementStateReady`, indicate that the placement is not currently ready to show ads. - */ -typedef NS_ENUM(NSInteger, UnityAdsPlacementState) { - /** - * A state that indicates that the placement is ready to show an ad. The `show:` selector can be called. - */ - kUnityAdsPlacementStateReady, - /** - * A state that indicates that no state is information is available. - * @warning This state can that UnityAds is not initialized or that the placement is not correctly configured in the Unity Ads admin tool. - */ - kUnityAdsPlacementStateNotAvailable, - /** - * A state that indicates that the placement is currently disabled. The placement can be enabled in the Unity Ads admin tools. - */ - kUnityAdsPlacementStateDisabled, - /** - * A state that indicates that the placement is not currently ready, but will be in the future. - * @note This state most likely indicates that the ad content is currently caching. - */ - kUnityAdsPlacementStateWaiting, - /** - * A state that indicates that the placement is properly configured, but there are currently no ads available for the placement. - */ - kUnityAdsPlacementStateNoFill -}; - -/** - * An enumeration for the completion state of an ad. - */ -typedef NS_ENUM(NSInteger, UnityAdsFinishState) { - /** - * A state that indicates that the ad did not successfully display. - */ - kUnityAdsFinishStateError, - /** - * A state that indicates that the user skipped the ad. - */ - kUnityAdsFinishStateSkipped, - /** - * A state that indicates that the ad was played entirely. - */ - kUnityAdsFinishStateCompleted -}; - -/** - * An enumeration for the various errors that can be emitted through the `UnityAdsDelegate` `unityAdsDidError:withMessage:` method. - */ -typedef NS_ENUM(NSInteger, UnityAdsError) { - /** - * An error that indicates failure due to `UnityAds` currently being uninitialized. - */ - kUnityAdsErrorNotInitialized = 0, - /** - * An error that indicates failure due to a failure in the initialization process. - */ - kUnityAdsErrorInitializedFailed, - /** - * An error that indicates failure due to attempting to initialize `UnityAds` with invalid parameters. - */ - kUnityAdsErrorInvalidArgument, - /** - * An error that indicates failure of the video player. - */ - kUnityAdsErrorVideoPlayerError, - /** - * An error that indicates failure due to having attempted to initialize the `UnityAds` class in an invalid environment. - */ - kUnityAdsErrorInitSanityCheckFail, - /** - * An error that indicates failure due to the presence of an ad blocker. - */ - kUnityAdsErrorAdBlockerDetected, - /** - * An error that indicates failure due to inability to read or write a file. - */ - kUnityAdsErrorFileIoError, - /** - * An error that indicates failure due to a bad device identifier. - */ - kUnityAdsErrorDeviceIdError, - /** - * An error that indicates a failure when attempting to show an ad. - */ - kUnityAdsErrorShowError, - /** - * An error that indicates an internal failure in `UnityAds`. - */ - kUnityAdsErrorInternalError, -}; - -/** - * The `UnityAdsDelegate` protocol defines the required methods for receiving messages from UnityAds. - * Must be implemented by the hosting app. - * The unityAdsReady: method is called when it's possible to show an ad. - * All other methods are used to provide notifications of events of the ad lifecycle. - * @note On initialization, there are ready (or error) callbacks for each placement attached to the game identifier. - */ NS_ASSUME_NONNULL_BEGIN -@protocol UnityAdsDelegate -/** - * Called when `UnityAds` is ready to show an ad. After this callback you can call the `UnityAds` `show:` method for this placement. - * Note that sometimes placement might no longer be ready due to exceptional reasons. These situations will give no new callbacks. - * - * @warning To avoid error situations, it is always best to check `isReady` method status before calling show. - * @param placementId The ID of the placement that is ready to show, as defined in Unity Ads admin tools. - */ -- (void)unityAdsReady:(NSString *)placementId; -/** - * Called when `UnityAds` encounters an error. All errors will be logged but this method can be used as an additional debugging aid. This callback can also be used for collecting statistics from different error scenarios. - * - * @param error A `UnityAdsError` error enum value indicating the type of error encountered. - * @param message A human readable string indicating the type of error encountered. - */ -- (void)unityAdsDidError:(UnityAdsError)error withMessage:(NSString *)message; -/** - * Called on a successful start of advertisement after calling the `UnityAds` `show:` method. - * - * @warning If there are errors in starting the advertisement, this method may never be called. Unity Ads will directly call `unityAdsDidFinish:withFinishState:` with error status. - * - * @param placementId The ID of the placement that has started, as defined in Unity Ads admin tools. - */ -- (void)unityAdsDidStart:(NSString *)placementId; -/** - * Called after the ad has closed. - * - * @param placementId The ID of the placement that has finished, as defined in Unity Ads admin tools. - * @param state An enum value indicating the finish state of the ad. Possible values are `Completed`, `Skipped`, and `Error`. - */ -- (void)unityAdsDidFinish:(NSString *)placementId - withFinishState:(UnityAdsFinishState)state; -@end /** * `UnityAds` is a static class with methods for preparing and showing ads. @@ -182,17 +74,30 @@ NS_ASSUME_NONNULL_BEGIN */ + (void)show:(UIViewController *)viewController placementId:(NSString *)placementId; /** - * Provides the currently assigned `UnityAdsDelegate`. + * Provides the currently assigned `UnityAdsDelegate`. Meant to support use of single delegate * * @return The current `UnityAdsDelegate`. */ -+ (id)getDelegate; ++ (id)getDelegate __attribute__((deprecated("Please migrate to using addDelegate and removeDelegate. This now returns the first delegate added"))); /** - * Allows the delegate to be reassigned after UnityAds has already been initialized. + * Allows the delegate to be reassigned after UnityAds has already been initialized. Meant to support use of a single delegate. + * Use `addDelegate` if you wish to have multiple `UnityAdsDelegate` * * @param delegate The new `UnityAdsDelegate' for UnityAds to send callbacks to. */ -+ (void)setDelegate:(id)delegate; ++ (void)setDelegate:(id)delegate __attribute__((deprecated("Please migrate to using addDelegate and removeDelegate"))); +/** + * Allows a delegate to be registered after UnityAds has already been initialized. + * + * @param delegate The new `UnityAdsDelegate' for UnityAds to send callbacks to. + */ ++ (void)addDelegate:(id)delegate; +/** + * Allows a delegate to be removed after UnityAds has already been initialized. + * + * @param delegate The already added `UnityAdsDelegate' for UnityAds to send callbacks to. + */ ++ (void)removeDelegate:(id)delegate; /** * Get the current debug status of `UnityAds`. * @@ -253,4 +158,8 @@ NS_ASSUME_NONNULL_BEGIN + (BOOL)isInitialized; @end + +@interface UnityServicesListener : NSObject +@end + NS_ASSUME_NONNULL_END diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UnityAdsDelegate.h b/defunityads/lib/ios/UnityAds.framework/Headers/UnityAdsDelegate.h new file mode 100644 index 0000000..2e52ea9 --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UnityAdsDelegate.h @@ -0,0 +1,47 @@ +#import "UnityAdsFinishState.h" +#import "UnityAdsError.h" + +NS_ASSUME_NONNULL_BEGIN + +/** + * The `UnityAdsDelegate` protocol defines the required methods for receiving messages from UnityAds. + * Must be implemented by the hosting app. + * The unityAdsReady: method is called when it's possible to show an ad. + * All other methods are used to provide notifications of events of the ad lifecycle. + * @note On initialization, there are ready (or error) callbacks for each placement attached to the game identifier. + */ +@protocol UnityAdsDelegate +/** + * Called when `UnityAds` is ready to show an ad. After this callback you can call the `UnityAds` `show:` method for this placement. + * Note that sometimes placement might no longer be ready due to exceptional reasons. These situations will give no new callbacks. + * + * @warning To avoid error situations, it is always best to check `isReady` method status before calling show. + * @param placementId The ID of the placement that is ready to show, as defined in Unity Ads admin tools. + */ +- (void)unityAdsReady:(NSString *)placementId; +/** + * Called when `UnityAds` encounters an error. All errors will be logged but this method can be used as an additional debugging aid. This callback can also be used for collecting statistics from different error scenarios. + * + * @param error A `UnityAdsError` error enum value indicating the type of error encountered. + * @param message A human readable string indicating the type of error encountered. + */ +- (void)unityAdsDidError:(UnityAdsError)error withMessage:(NSString *)message; +/** + * Called on a successful start of advertisement after calling the `UnityAds` `show:` method. + * + * @warning If there are errors in starting the advertisement, this method may never be called. Unity Ads will directly call `unityAdsDidFinish:withFinishState:` with error status. + * + * @param placementId The ID of the placement that has started, as defined in Unity Ads admin tools. + */ +- (void)unityAdsDidStart:(NSString *)placementId; +/** + * Called after the ad has closed. + * + * @param placementId The ID of the placement that has finished, as defined in Unity Ads admin tools. + * @param state An enum value indicating the finish state of the ad. Possible values are `Completed`, `Skipped`, and `Error`. + */ +- (void)unityAdsDidFinish:(NSString *)placementId + withFinishState:(UnityAdsFinishState)state; +@end + +NS_ASSUME_NONNULL_END diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UnityAdsError.h b/defunityads/lib/ios/UnityAds.framework/Headers/UnityAdsError.h new file mode 100644 index 0000000..a6d11b0 --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UnityAdsError.h @@ -0,0 +1,45 @@ +/** + * An enumeration for the various errors that can be emitted through the `UnityAdsDelegate` `unityAdsDidError:withMessage:` method. + */ +typedef NS_ENUM(NSInteger, UnityAdsError) { + /** + * An error that indicates failure due to `UnityAds` currently being uninitialized. + */ + kUnityAdsErrorNotInitialized = 0, + /** + * An error that indicates failure due to a failure in the initialization process. + */ + kUnityAdsErrorInitializedFailed, + /** + * An error that indicates failure due to attempting to initialize `UnityAds` with invalid parameters. + */ + kUnityAdsErrorInvalidArgument, + /** + * An error that indicates failure of the video player. + */ + kUnityAdsErrorVideoPlayerError, + /** + * An error that indicates failure due to having attempted to initialize the `UnityAds` class in an invalid environment. + */ + kUnityAdsErrorInitSanityCheckFail, + /** + * An error that indicates failure due to the presence of an ad blocker. + */ + kUnityAdsErrorAdBlockerDetected, + /** + * An error that indicates failure due to inability to read or write a file. + */ + kUnityAdsErrorFileIoError, + /** + * An error that indicates failure due to a bad device identifier. + */ + kUnityAdsErrorDeviceIdError, + /** + * An error that indicates a failure when attempting to show an ad. + */ + kUnityAdsErrorShowError, + /** + * An error that indicates an internal failure in `UnityAds`. + */ + kUnityAdsErrorInternalError, +}; diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UnityAdsExtended.h b/defunityads/lib/ios/UnityAds.framework/Headers/UnityAdsExtended.h index 1435037..ad62725 100644 --- a/defunityads/lib/ios/UnityAds.framework/Headers/UnityAdsExtended.h +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UnityAdsExtended.h @@ -1,21 +1,3 @@ -#import "UnityAds.h" +#import "UnityAdsExtendedDelegate.h" -NS_ASSUME_NONNULL_BEGIN -@protocol UnityAdsExtendedDelegate -/** - * Called when a click event happens. - * - * @param placementId The ID of the placement that was clicked. - */ -- (void)unityAdsDidClick:(NSString *)placementId; - -/** - * Called when a placement changes state. - * - * @param placementId The ID of the placement that changed state. - * @param oldState The state before the change. - * @param newState The state after the change. - */ -- (void)unityAdsPlacementStateChanged:(NSString *)placementId oldState:(UnityAdsPlacementState)oldState newState:(UnityAdsPlacementState)newState; -@end -NS_ASSUME_NONNULL_END +#warning "UnityAdsExtended.h" is deprecated and will be removed in the next major version please move to using "UnityAdsExtendedDelegate.h" diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UnityAdsExtendedDelegate.h b/defunityads/lib/ios/UnityAds.framework/Headers/UnityAdsExtendedDelegate.h new file mode 100644 index 0000000..1435037 --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UnityAdsExtendedDelegate.h @@ -0,0 +1,21 @@ +#import "UnityAds.h" + +NS_ASSUME_NONNULL_BEGIN +@protocol UnityAdsExtendedDelegate +/** + * Called when a click event happens. + * + * @param placementId The ID of the placement that was clicked. + */ +- (void)unityAdsDidClick:(NSString *)placementId; + +/** + * Called when a placement changes state. + * + * @param placementId The ID of the placement that changed state. + * @param oldState The state before the change. + * @param newState The state after the change. + */ +- (void)unityAdsPlacementStateChanged:(NSString *)placementId oldState:(UnityAdsPlacementState)oldState newState:(UnityAdsPlacementState)newState; +@end +NS_ASSUME_NONNULL_END diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UnityAdsFinishState.h b/defunityads/lib/ios/UnityAds.framework/Headers/UnityAdsFinishState.h new file mode 100644 index 0000000..fa0bb73 --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UnityAdsFinishState.h @@ -0,0 +1,17 @@ +/** + * An enumeration for the completion state of an ad. + */ +typedef NS_ENUM(NSInteger, UnityAdsFinishState) { + /** + * A state that indicates that the ad did not successfully display. + */ + kUnityAdsFinishStateError, + /** + * A state that indicates that the user skipped the ad. + */ + kUnityAdsFinishStateSkipped, + /** + * A state that indicates that the ad was played entirely. + */ + kUnityAdsFinishStateCompleted +}; diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UnityAdsPlacementState.h b/defunityads/lib/ios/UnityAds.framework/Headers/UnityAdsPlacementState.h new file mode 100644 index 0000000..43564cc --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UnityAdsPlacementState.h @@ -0,0 +1,30 @@ +#import + +/** + * An enumerate that describes the state of `UnityAds` placements. + * @note All placement states, other than `kUnityAdsPlacementStateReady`, indicate that the placement is not currently ready to show ads. + */ +typedef NS_ENUM(NSInteger, UnityAdsPlacementState) { + /** + * A state that indicates that the placement is ready to show an ad. The `show:` selector can be called. + */ + kUnityAdsPlacementStateReady, + /** + * A state that indicates that no state is information is available. + * @warning This state can that UnityAds is not initialized or that the placement is not correctly configured in the Unity Ads admin tool. + */ + kUnityAdsPlacementStateNotAvailable, + /** + * A state that indicates that the placement is currently disabled. The placement can be enabled in the Unity Ads admin tools. + */ + kUnityAdsPlacementStateDisabled, + /** + * A state that indicates that the placement is not currently ready, but will be in the future. + * @note This state most likely indicates that the ad content is currently caching. + */ + kUnityAdsPlacementStateWaiting, + /** + * A state that indicates that the placement is properly configured, but there are currently no ads available for the placement. + */ + kUnityAdsPlacementStateNoFill +}; diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UnityAnalytics.h b/defunityads/lib/ios/UnityAds.framework/Headers/UnityAnalytics.h new file mode 100644 index 0000000..9389129 --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UnityAnalytics.h @@ -0,0 +1,84 @@ +#import "UnityAnalyticsAcquisitionType.h" + +NS_ASSUME_NONNULL_BEGIN + +/** + * `UnityAnalytics` is a static class with methods for sending analytics events + */ +@interface UnityAnalytics : NSObject + +/** + * Sends an item acquired event to Unity Analytics + * + * @param transactionId Unique Identifier that can be used to identify the transaction in which the item was acquired. It is recommended to use the transactionId from the app store. + * @param itemId Identifier for the item that is acquired + * @param transactionContext Description about the game context in which the item was acquired. Example : "third_level_shop" + * @param level Developer defined level that the player was on when the item was acquired + * @param itemType Developer defined type that the item is grouped into + * @param amount Number of items acquired + * @param balance Number of items that the player now has after the transaction + * @param acquisitionType The type of acquisition : `kUnityAnalyticsAcquisitionTypeSoft` or `kUnityAnalyticsAcquisitionTypePremium` + */ ++(void)onItemAcquired:(NSString *)transactionId itemId:(NSString *)itemId transactionContext:(NSString *)transactionContext level:(NSString *)level itemType:(NSString *)itemType amount:(float)amount balance:(float)balance acquisitionType:(UnityAnalyticsAcquisitionType)acquisitionType; + +/** + * Send an item spent event to Unity Analyitcs + * + * @param transactionId Unique Identifier that can be used to identify the transaction in which the item was spent. It is recommended to use the transactionId from the app store. + * @param itemId Identifier for the item that is spent + * @param transactionContext Description about the game context in which the item was spent. Example : "third_level_shop" + * @param level Developer defined level that the player was on when the item was spent + * @param itemType Developer defined type that the item is grouped into + * @param amount Number of items spent + * @param balance Number of items that the player now has after the transaction + * @param acquisitionType The type of acquisition : `kUnityAnalyticsAcquisitionTypeSoft` or `kUnityAnalyticsAcquisitionTypePremium` + */ ++(void)onItemSpent:(NSString *)transactionId itemId:(NSString *)itemId transactionContext:(NSString *)transactionContext level:(NSString *)level itemType:(NSString *)itemType amount:(float)amount balance:(float)balance acquisitionType:(UnityAnalyticsAcquisitionType)acquisitionType; + +/** + * Sends a level fail event to Unity Analytics + * + * @param levelIndex The index for the level that the player failed + */ ++(void)onLevelFail:(NSString *)levelIndex; + +/** + * Sends a level up event to Unity Analytics + * + * @param theNewLevelIndex The index for the new level that the player just unlocked + */ ++(void)onLevelUp:(NSString *)theNewLevelIndex; + +/** + * Send an Ad Complete event to Unity Analytics + * + * @param placementId The Placement ID for the Ad + * @param network Add network name + * @param rewarded Boolean indicating if the Ad was rewarded or not + */ ++(void)onAdComplete:(NSString *)placementId network:(NSString *)network rewarded:(BOOL)rewarded; + +/** + * Send an In App Purchase Transaction event to Unity Analytics + * + * @param productId The Product Id specified by the developer for a promo + * @param amount The price to purchase the promo + * @param currency The iso currency code for the amount + * @param isPromo A boolean specifying if the transaction came from a promo + * @param receipt A json string of containing information about the transaction + */ ++(void)onIapTransaction:(NSString *)productId amount:(float)amount currency:(NSString *)currency isPromo:(BOOL)isPromo receipt:(NSString *)receipt; + +/** + * Send an analytics event. + * The dictionary structure must be 100% correct when using this method or the event will not be validated and sent. + * + * @param jsonObject Json dictionary with all necessary fields that will be sent to analytics + * + * @note It is strongly encouraged to use a specific event handler so that the event format is correct + */ ++(void)onEvent:(NSDictionary *)jsonObject; + +@end + +NS_ASSUME_NONNULL_END diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UnityAnalyticsAcquisitionType.h b/defunityads/lib/ios/UnityAds.framework/Headers/UnityAnalyticsAcquisitionType.h new file mode 100644 index 0000000..94c2922 --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UnityAnalyticsAcquisitionType.h @@ -0,0 +1,12 @@ + +NS_ASSUME_NONNULL_BEGIN + +typedef NS_ENUM(NSInteger, UnityAnalyticsAcquisitionType) { + kUnityAnalyticsAcquisitionTypeUnset, + kUnityAnalyticsAcquisitionTypeSoft, + kUnityAnalyticsAcquisitionTypePremium +}; + +NSString *NSStringFromUnityAnalyticsAcquisitionType(UnityAnalyticsAcquisitionType); + +NS_ASSUME_NONNULL_END diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UnityMonetization.h b/defunityads/lib/ios/UnityAds.framework/Headers/UnityMonetization.h new file mode 100644 index 0000000..c328b49 --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UnityMonetization.h @@ -0,0 +1,25 @@ +#import "UMONPlacementContent.h" +#import "UMONRewardablePlacementContent.h" +#import "UMONShowAdPlacementContent.h" +#import "UMONPromoAdPlacementContent.h" +#import "UMONNativePromoAdapter.h" +#import "UnityMonetizationDelegate.h" +#import "UnityMonetizationPlacementContentState.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface UnityMonetization : NSObject ++(void)setDelegate:(id )delegate; ++(nullable id )getDelegate; ++(BOOL)isReady:(NSString *)placementId; ++(nullable UMONPlacementContent *)getPlacementContent:(NSString *)placementId; + ++ (void)initialize:(NSString *)gameId + delegate:(nullable id)delegate; + ++ (void)initialize:(NSString *)gameId + delegate:(nullable id)delegate + testMode:(BOOL)testMode; +@end + +NS_ASSUME_NONNULL_END diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UnityMonetizationDelegate.h b/defunityads/lib/ios/UnityAds.framework/Headers/UnityMonetizationDelegate.h new file mode 100644 index 0000000..60ca4fb --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UnityMonetizationDelegate.h @@ -0,0 +1,12 @@ +#import "UMONPlacementContent.h" +#import "UnityMonetizationPlacementContentState.h" +#import "UnityServices.h" + +NS_ASSUME_NONNULL_BEGIN + +@protocol UnityMonetizationDelegate +-(void)placementContentReady:(NSString *)placementId placementContent:(UMONPlacementContent *)decision; +-(void)placementContentStateDidChange:(NSString *)placementId placementContent:(UMONPlacementContent *)placementContent previousState:(UnityMonetizationPlacementContentState)previousState newState:(UnityMonetizationPlacementContentState)newState; +@end + +NS_ASSUME_NONNULL_END diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UnityMonetizationPlacementContentState.h b/defunityads/lib/ios/UnityAds.framework/Headers/UnityMonetizationPlacementContentState.h new file mode 100644 index 0000000..0ac73db --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UnityMonetizationPlacementContentState.h @@ -0,0 +1,15 @@ +NS_ASSUME_NONNULL_BEGIN + +typedef NS_ENUM(NSInteger, UnityMonetizationPlacementContentState) { + kPlacementContentStateReady, + kPlacementContentStateNotAvailable, + kPlacementContentStateDisabled, + kPlacementContentStateWaiting, + kPlacementContentStateNoFill +}; + +NSString *NSStringFromPlacementContentState(UnityMonetizationPlacementContentState); + +UnityMonetizationPlacementContentState PlacementContentStateFromNSString(NSString *); + +NS_ASSUME_NONNULL_END diff --git a/defunityads/lib/ios/UnityAds.framework/Headers/UnityServices.h b/defunityads/lib/ios/UnityAds.framework/Headers/UnityServices.h new file mode 100644 index 0000000..94c9c2e --- /dev/null +++ b/defunityads/lib/ios/UnityAds.framework/Headers/UnityServices.h @@ -0,0 +1,65 @@ + +NS_ASSUME_NONNULL_BEGIN + +typedef NS_ENUM(NSInteger, UnityServicesError) { + kUnityServicesErrorInvalidArgument, + kUnityServicesErrorInitSanityCheckFail +}; + +@protocol UnityServicesDelegate +- (void)unityServicesDidError:(UnityServicesError)error withMessage:(NSString *)message; +@end + +@interface UnityServices : NSObject + +- (instancetype)init NS_UNAVAILABLE; ++ (instancetype)initialize NS_UNAVAILABLE; +/** + * Initializes UnityAds. UnityAds should be initialized when app starts. + * + * @param gameId Unique identifier for a game, given by Unity Ads admin tools or Unity editor. + * @param delegate delegate for UnityAdsDelegate callbacks + * @param testMode Set this flag to `YES` to indicate test mode and show only test ads. + */ ++ (void)initialize:(NSString *)gameId + delegate:(nullable id)delegate + testMode:(BOOL)testMode; + +/** + * Get the current debug status of `UnityAds`. + * + * @return If `YES`, `UnityAds` will provide verbose logs. + */ ++ (BOOL)getDebugMode; + +/** + * Set the logging verbosity of `UnityAds`. Debug mode indicates verbose logging. + * @warning Does not relate to test mode for ad content. + * @param enableDebugMode `YES` for verbose logging. + */ ++ (void)setDebugMode:(BOOL)enableDebugMode; + +/** + * Check to see if the current device supports using Unity Ads. + * + * @return If `NO`, the current device cannot initialize `UnityAds` or show ads. + */ ++ (BOOL)isSupported; + +/** + * Check the version of this `UnityAds` SDK + * + * @return String representing the current version name. + */ ++ (NSString *)getVersion; + +/** + * Check that `UnityAds` has been initialized. This might be useful for debugging initialization problems. + * + * @return If `YES`, Unity Ads has been successfully initialized. + */ ++ (BOOL)isInitialized; + +@end + +NS_ASSUME_NONNULL_END diff --git a/defunityads/lib/ios/UnityAds.framework/Modules/module.modulemap b/defunityads/lib/ios/UnityAds.framework/Modules/module.modulemap index 9160057..62d01d6 100644 --- a/defunityads/lib/ios/UnityAds.framework/Modules/module.modulemap +++ b/defunityads/lib/ios/UnityAds.framework/Modules/module.modulemap @@ -1,7 +1,33 @@ framework module UnityAds { umbrella header "UnityAds.h" + header "UnityAdsFinishState.h" header "UnityAdsExtended.h" + header "UnityAdsExtendedDelegate.h" header "UADSPurchasing.h" + header "UnityServices.h" + header "UnityAnalytics.h" + header "UANAApiAnalytics.h" + + header "USRVUnityPurchasing.h" + header "USRVUnityPurchasingDelegate.h" + header "UPURProduct.h" + header "UPURTransactionDetails.h" + header "UPURTransactionError.h" + header "UPURStore.h" + header "UPURTransactionErrorDetails.h" + + header "UnityMonetization.h" + header "UnityMonetizationPlacementContentState.h" + header "UnityMonetizationDelegate.h" + header "UMONPlacementContent.h" + header "UMONCustomEvent.h" + header "UMONRewardablePlacementContent.h" + header "UMONShowAdPlacementContent.h" + header "UMONPromoAdPlacementContent.h" + header "UMONPromoMetaData.h" + header "UADSBanner.h" + header "UMONNativePromoAdapter.h" + header "UMONItem.h" export * module * { export * } diff --git a/defunityads/lib/ios/UnityAds.framework/UnityAds b/defunityads/lib/ios/UnityAds.framework/UnityAds index 1dc6955..960474b 100644 Binary files a/defunityads/lib/ios/UnityAds.framework/UnityAds and b/defunityads/lib/ios/UnityAds.framework/UnityAds differ diff --git a/defunityads/manifests/android/AndroidManifest.xml b/defunityads/manifests/android/AndroidManifest.xml index f6d687b..409ca50 100755 --- a/defunityads/manifests/android/AndroidManifest.xml +++ b/defunityads/manifests/android/AndroidManifest.xml @@ -5,16 +5,34 @@ + + + + + + diff --git a/defunityads/manifests/android/proguard.pro b/defunityads/manifests/android/proguard.pro new file mode 100644 index 0000000..5ee519a --- /dev/null +++ b/defunityads/manifests/android/proguard.pro @@ -0,0 +1,22 @@ +# Keep filenames and line numbers for stack traces +-keepattributes SourceFile,LineNumberTable + +# Keep JavascriptInterface for WebView bridge +-keepattributes JavascriptInterface + +# Sometimes keepattributes is not enough to keep annotations +-keep class android.webkit.JavascriptInterface { + *; +} + +# Keep all classes in Unity Ads package +-keep class com.unity3d.ads.** { + *; +} + +# Keep all classes in Unity Services package +-keep class com.unity3d.services.** { + *; +} + +-dontwarn com.google.ar.core.** \ No newline at end of file diff --git a/defunityads/src/DefUnityAds.cpp b/defunityads/src/DefUnityAds.cpp index 8d3f039..9415c8c 100755 --- a/defunityads/src/DefUnityAds.cpp +++ b/defunityads/src/DefUnityAds.cpp @@ -85,6 +85,36 @@ static int setDebugMode(lua_State* L) { return 0; } +static int setBannerPosition(lua_State* L) { + int position_lua = luaL_checknumber(L, 1); + DefUnityAds_setBannerPosition(position_lua); + return 0; +} + +static int loadBanner(lua_State* L) { + char *placementId_lua = ""; + if (lua_type(L, 1) != LUA_TNONE) { + placementId_lua = (char*)luaL_checkstring(L, 1); + } + DefUnityAds_loadBanner(placementId_lua); + return 0; +} + +static int unloadBanner(lua_State* L) { + DefUnityAds_unloadBanner(); + return 0; +} + +static int showBanner(lua_State* L) { + DefUnityAds_showBanner(); + return 0; +} + +static int hideBanner(lua_State* L) { + DefUnityAds_hideBanner(); + return 0; +} + static const luaL_reg Module_methods[] = { {"initialize", Initialize}, @@ -97,6 +127,11 @@ static const luaL_reg Module_methods[] = {"getPlacementState", getPlacementState}, {"setDebugMode", setDebugMode}, {"setCallback", setCallback}, + {"setBannerPosition", setBannerPosition}, + {"loadBanner", loadBanner}, + {"unloadBanner", unloadBanner}, + {"showBanner", showBanner}, + {"hideBanner", hideBanner}, {0, 0} }; @@ -113,6 +148,7 @@ static void LuaInit(lua_State* L) SETCONSTANT(TYPE_DID_START) SETCONSTANT(TYPE_DID_ERROR) SETCONSTANT(TYPE_DID_FINISH) + SETCONSTANT(TYPE_BANNER) SETCONSTANT(FINISH_STATE_ERROR) SETCONSTANT(FINISH_STATE_COMPLETED) @@ -135,6 +171,22 @@ static void LuaInit(lua_State* L) SETCONSTANT(PLACEMENT_STATE_WAITING) SETCONSTANT(PLACEMENT_STATE_NO_FILL) + SETCONSTANT(BANNER_POSITION_TOP_LEFT) + SETCONSTANT(BANNER_POSITION_TOP_CENTER) + SETCONSTANT(BANNER_POSITION_TOP_RIGHT) + SETCONSTANT(BANNER_POSITION_BOTTOM_LEFT) + SETCONSTANT(BANNER_POSITION_BOTTOM_CENTER) + SETCONSTANT(BANNER_POSITION_BOTTOM_RIGHT) + SETCONSTANT(BANNER_POSITION_CENTER) + SETCONSTANT(BANNER_POSITION_NONE) + + SETCONSTANT(BANNER_EVENT_DID_LOAD) + SETCONSTANT(BANNER_EVENT_DID_UNLOAD) + SETCONSTANT(BANNER_EVENT_DID_SHOW) + SETCONSTANT(BANNER_EVENT_DID_HIDE) + SETCONSTANT(BANNER_EVENT_DID_CLICK) + SETCONSTANT(BANNER_EVENT_DID_ERROR) + #undef SETCONSTANT lua_pop(L, 1); assert(top == lua_gettop(L)); diff --git a/defunityads/src/DefUnityCallback.cpp b/defunityads/src/DefUnityCallback.cpp index 9b82bca..ae3e217 100755 --- a/defunityads/src/DefUnityCallback.cpp +++ b/defunityads/src/DefUnityCallback.cpp @@ -95,7 +95,7 @@ void DefUnityCallback_set_callback(lua_State* L, int pos){ } } -void add_to_queue(int type, char*key_1, char*value_1, char*key_2, int value_2){ +void DefUnityCallback_add_to_queue(int type, char*key_1, char*value_1, char*key_2, int value_2){ DM_MUTEX_SCOPED_LOCK(m_mutex); CallbackData data; @@ -112,22 +112,6 @@ void add_to_queue(int type, char*key_1, char*value_1, char*key_2, int value_2){ m_callbacksQueue.Push(data); } -void DefUnityCallback_lua_unityAdsReady(char*placementId) { - add_to_queue((int)TYPE_IS_READY,(char*)"placementId", placementId, NULL, 0); -} - -void DefUnityCallback_lua_unityAdsDidStart(char*placementId) { - add_to_queue((int)TYPE_DID_START,(char*)"placementId", placementId, NULL, 0); -} - -void DefUnityCallback_lua_unityAdsDidError(int error, char* message) { - add_to_queue((int)TYPE_DID_ERROR,(char*)"message", message, (char*)"error", error); -} - -void DefUnityCallback_lua_unityAdsDidFinish (char *placementId, int state) { - add_to_queue((int)TYPE_DID_FINISH,(char*)"placementId", placementId, (char*)"state", state); -} - void DefUnityCallback_callback_updates(){ if (m_callbacksQueue.Empty()) { return; diff --git a/defunityads/src/android/DefUnityAdsAndr.cpp b/defunityads/src/android/DefUnityAdsAndr.cpp index 3bd296d..8e1a9b0 100755 --- a/defunityads/src/android/DefUnityAdsAndr.cpp +++ b/defunityads/src/android/DefUnityAdsAndr.cpp @@ -6,28 +6,72 @@ JNIEXPORT void JNICALL Java_com_agulev_defunityads_DefUnityAds_onUnityAdsReady(JNIEnv *env, jclass jcls, jstring jstr) { const char* ch = env->GetStringUTFChars(jstr, 0); - DefUnityCallback_lua_unityAdsReady((char*)ch); + DefUnityCallback_add_to_queue((int)TYPE_IS_READY,(char*)"placementId", (char*)ch, NULL, 0); env->ReleaseStringUTFChars(jstr, ch); } JNIEXPORT void JNICALL Java_com_agulev_defunityads_DefUnityAds_onUnityAdsStart(JNIEnv *env, jclass jcls, jstring jstr) { const char* ch = env->GetStringUTFChars(jstr, 0); - DefUnityCallback_lua_unityAdsDidStart((char*)ch); + DefUnityCallback_add_to_queue((int)TYPE_DID_START,(char*)"placementId", (char*)ch, NULL, 0); env->ReleaseStringUTFChars(jstr, ch); } JNIEXPORT void JNICALL Java_com_agulev_defunityads_DefUnityAds_onUnityAdsError(JNIEnv *env, jclass jcls, jint type, jstring jstr) { const char* ch = env->GetStringUTFChars(jstr, 0); - DefUnityCallback_lua_unityAdsDidError((int)type, (char*)ch); + DefUnityCallback_add_to_queue((int)TYPE_DID_ERROR,(char*)"message", (char*)ch, (char*)"error", (int)type); env->ReleaseStringUTFChars(jstr, ch); } JNIEXPORT void JNICALL Java_com_agulev_defunityads_DefUnityAds_onUnityAdsFinish(JNIEnv *env, jclass jcls, jstring jstr, jint type) { const char* ch = env->GetStringUTFChars(jstr, 0); - DefUnityCallback_lua_unityAdsDidFinish((char*)ch, (int)type); + DefUnityCallback_add_to_queue((int)TYPE_DID_FINISH,(char*)"placementId", (char*)ch, (char*)"state", (int)type); + env->ReleaseStringUTFChars(jstr, ch); +} + +//---- + +JNIEXPORT void JNICALL Java_com_agulev_defunityads_DefUnityAds_onUnityBannerLoaded(JNIEnv *env, jclass jcls, jstring jstr) +{ + const char* ch = env->GetStringUTFChars(jstr, 0); + DefUnityCallback_add_to_queue((int)TYPE_BANNER,(char*)"placementId", (char*)ch, (char*)"event", (int)BANNER_EVENT_DID_LOAD); + env->ReleaseStringUTFChars(jstr, ch); +} + +JNIEXPORT void JNICALL Java_com_agulev_defunityads_DefUnityAds_onUnityBannerUnloaded(JNIEnv *env, jclass jcls, jstring jstr) +{ + const char* ch = env->GetStringUTFChars(jstr, 0); + DefUnityCallback_add_to_queue((int)TYPE_BANNER,(char*)"placementId", (char*)ch, (char*)"event", (int)BANNER_EVENT_DID_UNLOAD); + env->ReleaseStringUTFChars(jstr, ch); +} + +JNIEXPORT void JNICALL Java_com_agulev_defunityads_DefUnityAds_onUnityBannerShow(JNIEnv *env, jclass jcls, jstring jstr) +{ + const char* ch = env->GetStringUTFChars(jstr, 0); + DefUnityCallback_add_to_queue((int)TYPE_BANNER,(char*)"placementId", (char*)ch, (char*)"event", (int)BANNER_EVENT_DID_SHOW); + env->ReleaseStringUTFChars(jstr, ch); +} + +JNIEXPORT void JNICALL Java_com_agulev_defunityads_DefUnityAds_onUnityBannerClick(JNIEnv *env, jclass jcls, jstring jstr) +{ + const char* ch = env->GetStringUTFChars(jstr, 0); + DefUnityCallback_add_to_queue((int)TYPE_BANNER,(char*)"placementId", (char*)ch, (char*)"event", (int)BANNER_EVENT_DID_CLICK); + env->ReleaseStringUTFChars(jstr, ch); +} + +JNIEXPORT void JNICALL Java_com_agulev_defunityads_DefUnityAds_onUnityBannerHide(JNIEnv *env, jclass jcls, jstring jstr) +{ + const char* ch = env->GetStringUTFChars(jstr, 0); + DefUnityCallback_add_to_queue((int)TYPE_BANNER,(char*)"placementId", (char*)ch, (char*)"event", (int)BANNER_EVENT_DID_HIDE); + env->ReleaseStringUTFChars(jstr, ch); +} + +JNIEXPORT void JNICALL Java_com_agulev_defunityads_DefUnityAds_onUnityBannerError(JNIEnv *env, jclass jcls, jstring jstr) +{ + const char* ch = env->GetStringUTFChars(jstr, 0); + DefUnityCallback_add_to_queue((int)TYPE_BANNER,(char*)"message", (char*)ch, (char*)"event", (int)BANNER_EVENT_DID_ERROR); env->ReleaseStringUTFChars(jstr, ch); } @@ -46,6 +90,11 @@ struct DefUnityAdsClass jmethodID m_getDebugMode; jmethodID m_getVersion; jmethodID m_getPlacementState; + jmethodID m_setBannerPosition; + jmethodID m_loadBanner; + jmethodID m_unloadBanner; + jmethodID m_showBanner; + jmethodID m_hideBanner; }; DefUnityAdsClass g_duads; @@ -65,6 +114,11 @@ void DefUnityAds_InitExtension() { g_duads.m_getDebugMode = env->GetMethodID(cls, "getDebugMode", "()Z"); g_duads.m_getVersion = env->GetMethodID(cls, "getVersion", "()Ljava/lang/String;"); g_duads.m_getPlacementState = env->GetMethodID(cls, "getPlacementState", "(Ljava/lang/String;)I"); + g_duads.m_setBannerPosition = env->GetMethodID(cls, "setBannerPosition", "(Ljava/lang/String;)V"); + g_duads.m_loadBanner = env->GetMethodID(cls, "loadBanner", "(Ljava/lang/String;)V"); + g_duads.m_unloadBanner = env->GetMethodID(cls, "unloadBanner", "()V"); + g_duads.m_showBanner = env->GetMethodID(cls, "showBanner", "()V"); + g_duads.m_hideBanner = env->GetMethodID(cls, "hideBanner", "()V"); jmethodID jni_constructor = env->GetMethodID(cls, "", "(Landroid/app/Activity;)V"); g_duads.m_DUADS_JNI = env->NewGlobalRef(env->NewObject(cls, jni_constructor, dmGraphics::GetNativeAndroidActivity())); @@ -156,4 +210,46 @@ int DefUnityAds_getPlacementState(char* placementId) { return JNI_TRUE == return_value; } +static const char *positions[] = { "topleft", "topcenter", + "topright", "bottomleft", "bottomcenter", "bottomright", "center", "none" }; + +void DefUnityAds_setBannerPosition(int position) { + ThreadAttacher attacher; + JNIEnv *env = attacher.env; + + jstring jposition = env->NewStringUTF(positions[position]); + env->CallVoidMethod(g_duads.m_DUADS_JNI, g_duads.m_setBannerPosition, jposition); + env->DeleteLocalRef(jposition); +} + +void DefUnityAds_loadBanner(char* placementId) { + ThreadAttacher attacher; + JNIEnv *env = attacher.env; + + jstring jplacementId = env->NewStringUTF(placementId); + env->CallVoidMethod(g_duads.m_DUADS_JNI, g_duads.m_loadBanner, jplacementId); + env->DeleteLocalRef(jplacementId); +} + +void DefUnityAds_unloadBanner() { + ThreadAttacher attacher; + JNIEnv *env = attacher.env; + + env->CallVoidMethod(g_duads.m_DUADS_JNI, g_duads.m_unloadBanner); +} + +void DefUnityAds_showBanner() { + ThreadAttacher attacher; + JNIEnv *env = attacher.env; + + env->CallVoidMethod(g_duads.m_DUADS_JNI, g_duads.m_showBanner); +} + +void DefUnityAds_hideBanner() { + ThreadAttacher attacher; + JNIEnv *env = attacher.env; + + env->CallVoidMethod(g_duads.m_DUADS_JNI, g_duads.m_hideBanner); +} + #endif diff --git a/defunityads/src/android/com/agulev/defunityads/DefUnityAds.java b/defunityads/src/android/com/agulev/defunityads/DefUnityAds.java index fea36f4..4435926 100644 --- a/defunityads/src/android/com/agulev/defunityads/DefUnityAds.java +++ b/defunityads/src/android/com/agulev/defunityads/DefUnityAds.java @@ -1,71 +1,232 @@ package com.agulev.defunityads; import android.app.Activity; - +import android.graphics.PixelFormat; +import android.view.View; +import android.view.ViewGroup.LayoutParams; +import android.view.ViewGroup.MarginLayoutParams; +import android.view.WindowManager; +import android.widget.LinearLayout; +import android.view.Gravity; + +import com.unity3d.ads.IUnityAdsListener; import com.unity3d.ads.UnityAds; +import com.unity3d.services.banners.IUnityBannerListener; +import com.unity3d.services.banners.UnityBanners; +import com.unity3d.services.banners.view.BannerPosition; public class DefUnityAds { -public static DefUnityAdsListener defUnityAdsListener; - -public static native void onUnityAdsReady(String placementId); -public static native void onUnityAdsStart(String placementId); -public static native void onUnityAdsError(int error, String message); -public static native void onUnityAdsFinish(String placementId, int result); - -//----- - -private Activity activity; - -public DefUnityAds(Activity appActivity) { - activity = appActivity; - defUnityAdsListener = new DefUnityAdsListener(); -} - -public void initialize(String gameId, boolean testMode) { - UnityAds.initialize(activity, gameId, defUnityAdsListener, testMode); -} - -public void show(String placementId) { - if (placementId == null || placementId.isEmpty()) { - UnityAds.show(activity); - } else { - UnityAds.show(activity, placementId); - } -} - -public void setDebugMode(boolean debugMode) { - UnityAds.setDebugMode(debugMode); -} - -public boolean getDebugMode() { - return UnityAds.getDebugMode(); -} - -public boolean isReady(String placementId) { - if (placementId == null || placementId.isEmpty()) { - return UnityAds.isReady(); - } - return UnityAds.isReady(placementId); -} - -public boolean isInitialized() { - return UnityAds.isInitialized(); -} - -public boolean isSupported() { - return UnityAds.isSupported(); -} - -public String getVersion() { - return UnityAds.getVersion(); -} - -public int getPlacementState(String placementId) { - if (placementId == null || placementId.isEmpty()) { - return UnityAds.getPlacementState().ordinal(); - } - return UnityAds.getPlacementState(placementId).ordinal(); -} - -} + private DefUnityAdsListener defUnityAdsListener; + private DefUnityBannerListener defUnityAdsBannerListener; + private View bannerView; + + public static native void onUnityAdsReady(String placementId); + public static native void onUnityAdsStart(String placementId); + public static native void onUnityAdsError(int error, String message); + public static native void onUnityAdsFinish(String placementId, int result); + + public static native void onUnityBannerLoaded(String placementId); + public static native void onUnityBannerUnloaded(String placementId); + public static native void onUnityBannerShow(String placementId); + public static native void onUnityBannerClick(String placementId); + public static native void onUnityBannerHide(String placementId); + public static native void onUnityBannerError(String message); + + //----- + + private Activity activity; + private LinearLayout layout; + private WindowManager.LayoutParams windowParams; + private BannerPosition m_bannerPosition = BannerPosition.BOTTOM_CENTER; + + private boolean isShown = false; + + public DefUnityAds(Activity appActivity) { + activity = appActivity; + defUnityAdsListener = new DefUnityAdsListener(); + defUnityAdsBannerListener = new DefUnityBannerListener(); + } + + public void initialize(String gameId, boolean testMode) { + UnityBanners.setBannerListener(defUnityAdsBannerListener); + UnityAds.initialize(activity, gameId, defUnityAdsListener, testMode); + } + + public void show(String placementId) { + if (placementId == null || placementId.isEmpty()) { + UnityAds.show(activity); + } else { + UnityAds.show(activity, placementId); + } + } + + public void setDebugMode(boolean debugMode) { + UnityAds.setDebugMode(debugMode); + } + + public boolean getDebugMode() { + return UnityAds.getDebugMode(); + } + + public boolean isReady(String placementId) { + if (placementId == null || placementId.isEmpty()) { + return UnityAds.isReady(); + } + return UnityAds.isReady(placementId); + } + + public boolean isInitialized() { + return UnityAds.isInitialized(); + } + + public boolean isSupported() { + return UnityAds.isSupported(); + } + + public String getVersion() { + return UnityAds.getVersion(); + } + + public int getPlacementState(String placementId) { + if (placementId == null || placementId.isEmpty()) { + return UnityAds.getPlacementState().ordinal(); + } + return UnityAds.getPlacementState(placementId).ordinal(); + } + + public void setBannerPosition(String position) { + m_bannerPosition = BannerPosition.fromString(position); + } + + public void loadBanner(String placementId) { + UnityBanners.setBannerPosition(m_bannerPosition); + UnityBanners.loadBanner(activity, placementId); + } + + public void unloadBanner() { + _hideBanner(); + UnityBanners.destroy(); + } + + private void _hideBanner() { + if (!isShown) { + return; + } + + isShown = false; + activity.runOnUiThread(new Runnable() { + + @Override + public void run() { + WindowManager wm = activity.getWindowManager(); + wm.removeView(layout); + } + + }); + + } + + public void showBanner() { + if (bannerView == null) { + return; + } + + activity.runOnUiThread(new Runnable() { + + @Override + public void run() { + WindowManager wm = activity.getWindowManager(); + windowParams.gravity = m_bannerPosition.getGravity(); + wm.addView(layout, windowParams); + } + }); + } + + public void hideBanner() { + if (bannerView == null) { + return; + } + + _hideBanner(); + } + + private class DefUnityAdsListener implements IUnityAdsListener { + @Override + public void onUnityAdsReady(final String placementId) { + DefUnityAds.onUnityAdsReady(placementId); + } + + @Override + public void onUnityAdsStart(String placementId) { + DefUnityAds.onUnityAdsStart(placementId); + } + + @Override + public void onUnityAdsError(UnityAds.UnityAdsError error, String message) { + DefUnityAds.onUnityAdsError(error.ordinal(), message); + } + + @Override + public void onUnityAdsFinish(String placementId, UnityAds.FinishState result) { + DefUnityAds.onUnityAdsFinish(placementId, result.ordinal()); + } + } + + private class DefUnityBannerListener implements IUnityBannerListener { + + @Override + public void onUnityBannerLoaded(String placementId, View view) { + bannerView = view; + + layout = new LinearLayout(activity); + layout.setOrientation(LinearLayout.VERTICAL); + + MarginLayoutParams params = new MarginLayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); + params.setMargins(0, 0, 0, 0); + + layout.addView(bannerView, params); + + windowParams = new WindowManager.LayoutParams( + WindowManager.LayoutParams.WRAP_CONTENT, + WindowManager.LayoutParams.WRAP_CONTENT, + WindowManager.LayoutParams.WRAP_CONTENT, + WindowManager.LayoutParams.WRAP_CONTENT, + WindowManager.LayoutParams.TYPE_APPLICATION_PANEL, + WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, + PixelFormat.TRANSLUCENT); + + DefUnityAds.onUnityBannerLoaded(placementId); + } + + @Override + public void onUnityBannerUnloaded(String placementId) { + layout = null; + bannerView = null; + windowParams = null; + DefUnityAds.onUnityBannerUnloaded(placementId); + } + + @Override + public void onUnityBannerShow(String placementId) { + isShown = true; + DefUnityAds.onUnityBannerShow(placementId); + } + + @Override + public void onUnityBannerClick(String placementId) { + DefUnityAds.onUnityBannerClick(placementId); + } + + @Override + public void onUnityBannerHide(String placementId) { + DefUnityAds.onUnityBannerHide(placementId); + } + + @Override + public void onUnityBannerError(String message) { + DefUnityAds.onUnityBannerError(message); + } + } + +} \ No newline at end of file diff --git a/defunityads/src/android/com/agulev/defunityads/DefUnityAdsListener.java b/defunityads/src/android/com/agulev/defunityads/DefUnityAdsListener.java deleted file mode 100644 index 1744023..0000000 --- a/defunityads/src/android/com/agulev/defunityads/DefUnityAdsListener.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.agulev.defunityads; - -import com.unity3d.ads.IUnityAdsListener; -import com.unity3d.ads.UnityAds; - -public class DefUnityAdsListener implements IUnityAdsListener { - -@Override -public void onUnityAdsReady(final String placementId) { - DefUnityAds.onUnityAdsReady(placementId); -} - -@Override -public void onUnityAdsStart(String placementId) { - DefUnityAds.onUnityAdsStart(placementId); -} - -@Override -public void onUnityAdsError(UnityAds.UnityAdsError error, String message) { - DefUnityAds.onUnityAdsError(error.ordinal(), message); -} - -@Override -public void onUnityAdsFinish(String placementId, UnityAds.FinishState result) { - DefUnityAds.onUnityAdsFinish(placementId, result.ordinal()); -} -} diff --git a/defunityads/src/android/com_agulev_defunityads_DefUnityAds.h b/defunityads/src/android/com_agulev_defunityads_DefUnityAds.h index 289ba29..39fc443 100644 --- a/defunityads/src/android/com_agulev_defunityads_DefUnityAds.h +++ b/defunityads/src/android/com_agulev_defunityads_DefUnityAds.h @@ -1,4 +1,3 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ #include /* Header for class com_agulev_defunityads_DefUnityAds */ @@ -39,6 +38,56 @@ JNIEXPORT void JNICALL Java_com_agulev_defunityads_DefUnityAds_onUnityAdsError JNIEXPORT void JNICALL Java_com_agulev_defunityads_DefUnityAds_onUnityAdsFinish (JNIEnv *, jclass, jstring, jint); +//------ + +/* + * Class: com_agulev_defunityads_DefUnityAds + * Method: onUnityBannerLoaded + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_com_agulev_defunityads_DefUnityAds_onUnityBannerLoaded + (JNIEnv *, jclass, jstring); + +/* + * Class: com_agulev_defunityads_DefUnityAds + * Method: onUnityBannerUnloaded + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_com_agulev_defunityads_DefUnityAds_onUnityBannerUnloaded + (JNIEnv *, jclass, jstring); + +/* + * Class: com_agulev_defunityads_DefUnityAds + * Method: onUnityBannerShow + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_com_agulev_defunityads_DefUnityAds_onUnityBannerShow + (JNIEnv *, jclass, jstring); + +/* + * Class: com_agulev_defunityads_DefUnityAds + * Method: onUnityBannerClick + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_com_agulev_defunityads_DefUnityAds_onUnityBannerClick + (JNIEnv *, jclass, jstring); + +/* + * Class: com_agulev_defunityads_DefUnityAds + * Method: onUnityBannerHide + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_com_agulev_defunityads_DefUnityAds_onUnityBannerHide + (JNIEnv *, jclass, jstring); + +/* + * Class: com_agulev_defunityads_DefUnityAds + * Method: onUnityBannerError + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_com_agulev_defunityads_DefUnityAds_onUnityBannerError + (JNIEnv *, jclass, jstring); + #ifdef __cplusplus } #endif diff --git a/defunityads/src/ios/DefUnityAdsIOS.mm b/defunityads/src/ios/DefUnityAdsIOS.mm index bc61618..028e5c5 100755 --- a/defunityads/src/ios/DefUnityAdsIOS.mm +++ b/defunityads/src/ios/DefUnityAdsIOS.mm @@ -6,35 +6,63 @@ #include #include +UIViewController *uiViewController; +UIView *bannerView; -@interface DefUnityAdsDelegate : NSObject{ -} -@end - -@interface DefUnityAdsDelegate () +@interface DefUnityAdsDelegate : NSObject @end @implementation DefUnityAdsDelegate -(void)unityAdsReady:(NSString *)placementId { - DefUnityCallback_lua_unityAdsReady((char*)[placementId UTF8String]); + DefUnityCallback_add_to_queue((int)TYPE_IS_READY,(char*)"placementId", (char*)[placementId UTF8String], NULL, 0); } -(void)unityAdsDidStart:(NSString *)placementId { - DefUnityCallback_lua_unityAdsDidStart((char*)[placementId UTF8String]); + DefUnityCallback_add_to_queue((int)TYPE_DID_START,(char*)"placementId", (char*)[placementId UTF8String], NULL, 0); } -(void)unityAdsDidError:(UnityAdsError)error withMessage:(NSString *)message { - DefUnityCallback_lua_unityAdsDidError((int)error, (char*)[message UTF8String]); + DefUnityCallback_add_to_queue((int)TYPE_DID_ERROR,(char*)"message", (char*)[message UTF8String], (char*)"error", (int)error); } -(void)unityAdsDidFinish:(NSString *)placementId withFinishState:(UnityAdsFinishState)state { - DefUnityCallback_lua_unityAdsDidFinish ((char*)[placementId UTF8String], (int)state); + DefUnityCallback_add_to_queue((int)TYPE_DID_FINISH,(char*)"placementId", (char*)[placementId UTF8String], (char*)"state", (int)state); } @end -UIViewController *uiViewController; +@interface DefUnityAdsBannerDelegate: NSObject +@end + +@implementation DefUnityAdsBannerDelegate + +-(void) unityAdsBannerDidClick: (NSString *) placementId { + DefUnityCallback_add_to_queue((int)TYPE_BANNER,(char*)"placementId", (char*)[placementId UTF8String], (char*)"event", (int)BANNER_EVENT_DID_CLICK); +} + +-(void) unityAdsBannerDidError: (NSString *) message { + DefUnityCallback_add_to_queue((int)TYPE_BANNER,(char*)"message", (char*)[message UTF8String], (char*)"event", (int)BANNER_EVENT_DID_ERROR); +} + +-(void) unityAdsBannerDidHide: (NSString *) placementId { + DefUnityCallback_add_to_queue((int)TYPE_BANNER,(char*)"placementId", (char*)[placementId UTF8String], (char*)"event", (int)BANNER_EVENT_DID_HIDE); +} + +-(void) unityAdsBannerDidShow: (NSString *) placementId { + DefUnityCallback_add_to_queue((int)TYPE_BANNER,(char*)"placementId", (char*)[placementId UTF8String], (char*)"event", (int)BANNER_EVENT_DID_SHOW); +} + +-(void) unityAdsBannerDidLoad: (NSString *) placementId view: (UIView *) view { + bannerView = view; + DefUnityCallback_add_to_queue((int)TYPE_BANNER,(char*)"placementId", (char*)[placementId UTF8String], (char*)"event", (int)BANNER_EVENT_DID_LOAD); +} + +-(void) unityAdsBannerDidUnload: (NSString *) placementId { + bannerView = nil; + DefUnityCallback_add_to_queue((int)TYPE_BANNER,(char*)"placementId", (char*)[placementId UTF8String], (char*)"event", (int)BANNER_EVENT_DID_UNLOAD); +} +@end void DefUnityAds_InitExtension() { @@ -43,6 +71,8 @@ void DefUnityAds_InitExtension() { void DefUnityAds_Initialize(const char*game_id, bool is_debug) { NSString* gameId = [NSString stringWithUTF8String:game_id]; DefUnityAdsDelegate* unityAds = [[DefUnityAdsDelegate alloc] init]; + DefUnityAdsBannerDelegate* unityBannerAds = [[DefUnityAdsBannerDelegate alloc] init]; + [UnityAdsBanner setDelegate: unityBannerAds]; [UnityAds initialize:gameId delegate:unityAds testMode:is_debug ? YES : NO]; UIWindow* window = dmGraphics::GetNativeiOSUIWindow(); @@ -109,4 +139,34 @@ int DefUnityAds_getPlacementState(char* placementId) { return (int)state; } +void DefUnityAds_setBannerPosition(int position) { + [UnityAdsBanner setBannerPosition:position]; +} + +void DefUnityAds_loadBanner(char* placementId) { + if ((placementId != NULL) && (placementId[0] == '\0')) { + [UnityAdsBanner loadBanner]; + } + else { + NSString* placementId_s = [NSString stringWithUTF8String:placementId]; + [UnityAdsBanner loadBanner:placementId_s]; + } +} + +void DefUnityAds_unloadBanner() { + [UnityAdsBanner destroy]; +} + +void DefUnityAds_showBanner() { + if (bannerView){ + [uiViewController.view addSubview:bannerView]; + } +} + +void DefUnityAds_hideBanner() { + if (bannerView) { + [bannerView removeFromSuperview]; + } +} + #endif diff --git a/defunityads/src/private_DefUnityAds.h b/defunityads/src/private_DefUnityAds.h index 98233cf..234374d 100755 --- a/defunityads/src/private_DefUnityAds.h +++ b/defunityads/src/private_DefUnityAds.h @@ -10,11 +10,28 @@ enum DefUnityAdsPlacementState PLACEMENT_STATE_NO_FILL }; +enum DefUnityBannerPosition +{ + BANNER_POSITION_TOP_LEFT, + BANNER_POSITION_TOP_CENTER, + BANNER_POSITION_TOP_RIGHT, + BANNER_POSITION_BOTTOM_LEFT, + BANNER_POSITION_BOTTOM_CENTER, + BANNER_POSITION_BOTTOM_RIGHT, + BANNER_POSITION_CENTER, + BANNER_POSITION_NONE +}; + void DefUnityAds_InitExtension(); void DefUnityAds_Initialize(const char*game_id, bool is_debug); void DefUnityAds_Show(char* placementId); void DefUnityAds_setDebugMode(bool is_debug); +void DefUnityAds_setBannerPosition(int position); +void DefUnityAds_loadBanner(char* placementId); +void DefUnityAds_unloadBanner(); +void DefUnityAds_showBanner(); +void DefUnityAds_hideBanner(); bool DefUnityAds_isReady(char* placementId); bool DefUnityAds_isSupported(); diff --git a/defunityads/src/private_DefUnityCallback.h b/defunityads/src/private_DefUnityCallback.h index 77d368b..12c9477 100755 --- a/defunityads/src/private_DefUnityCallback.h +++ b/defunityads/src/private_DefUnityCallback.h @@ -7,7 +7,8 @@ enum DefUnityAdsCallbackType TYPE_IS_READY, TYPE_DID_START, TYPE_DID_ERROR, - TYPE_DID_FINISH + TYPE_DID_FINISH, + TYPE_BANNER }; enum DefUnityAdsFinishState @@ -31,6 +32,16 @@ enum DefUnityAdsError ERROR_INTERNAL }; +enum DefUnityAdsBannerEvent +{ + BANNER_EVENT_DID_LOAD, + BANNER_EVENT_DID_UNLOAD, + BANNER_EVENT_DID_SHOW, + BANNER_EVENT_DID_HIDE, + BANNER_EVENT_DID_CLICK, + BANNER_EVENT_DID_ERROR +}; + struct DefUnityAdsListener { DefUnityAdsListener() : m_L(0), m_Callback(LUA_NOREF), m_Self(LUA_NOREF) { } @@ -54,7 +65,4 @@ void DefUnityCallback_callback_updates(); void DefUnityCallback_initialize(); void DefUnityCallback_finalize(); -void DefUnityCallback_lua_unityAdsReady(char*placementId); -void DefUnityCallback_lua_unityAdsDidStart(char*placementId); -void DefUnityCallback_lua_unityAdsDidError(int error, char* message); -void DefUnityCallback_lua_unityAdsDidFinish(char *placementId, int state); +void DefUnityCallback_add_to_queue(int type, char*key_1, char*value_1, char*key_2, int value_2); \ No newline at end of file diff --git a/example/main.gui b/example/main.gui index 6908bd6..2a2ee02 100644 --- a/example/main.gui +++ b/example/main.gui @@ -15,8 +15,8 @@ background_color { } nodes { position { - x: 390.78336 - y: 144.56616 + x: 226.0 + y: 576.0 z: 0.0 w: 1.0 } @@ -45,7 +45,7 @@ nodes { w: 1.0 } type: TYPE_TEMPLATE - id: "video" + id: "init" layer: "" inherit_alpha: true alpha: 1.0 @@ -55,7 +55,7 @@ nodes { nodes { position { x: 0.0 - y: -5.684342E-14 + y: -1.2791587 z: 0.0 w: 1.0 } @@ -72,7 +72,7 @@ nodes { w: 1.0 } size { - x: 300.0 + x: 440.0 y: 88.0 z: 0.0 w: 1.0 @@ -86,12 +86,12 @@ nodes { type: TYPE_BOX blend_mode: BLEND_MODE_ALPHA texture: "button/button_normal" - id: "video/larrybutton" + id: "init/larrybutton" xanchor: XANCHOR_NONE yanchor: YANCHOR_NONE pivot: PIVOT_CENTER adjust_mode: ADJUST_MODE_FIT - parent: "video" + parent: "init" layer: "" inherit_alpha: true slice9 { @@ -105,6 +105,7 @@ nodes { clipping_inverted: false alpha: 1.0 overridden_fields: 1 + overridden_fields: 4 template_node_child: true size_mode: SIZE_MODE_MANUAL } @@ -135,15 +136,15 @@ nodes { } color { x: 1.0 - y: 0.0 - z: 0.03137255 + y: 1.0 + z: 1.0 w: 1.0 } type: TYPE_TEXT blend_mode: BLEND_MODE_ALPHA - text: "Show video" + text: "init UnityAds with id" font: "larryfont" - id: "video/larrylabel" + id: "init/larrylabel" xanchor: XANCHOR_NONE yanchor: YANCHOR_NONE pivot: PIVOT_CENTER @@ -161,14 +162,13 @@ nodes { } adjust_mode: ADJUST_MODE_FIT line_break: false - parent: "video/larrybutton" + parent: "init/larrybutton" layer: "" inherit_alpha: true alpha: 1.0 outline_alpha: 1.0 shadow_alpha: 1.0 overridden_fields: 1 - overridden_fields: 5 overridden_fields: 8 template_node_child: true text_leading: 1.0 @@ -176,8 +176,8 @@ nodes { } nodes { position { - x: 779.32587 - y: 144.56616 + x: 320.0 + y: 456.0 z: 0.0 w: 1.0 } @@ -206,7 +206,7 @@ nodes { w: 1.0 } type: TYPE_TEMPLATE - id: "rewardedVideo" + id: "default" layer: "" inherit_alpha: true alpha: 1.0 @@ -239,20 +239,20 @@ nodes { w: 1.0 } color { - x: 1.0 + x: 0.9960785 y: 1.0 - z: 1.0 + z: 0.9921569 w: 1.0 } type: TYPE_BOX blend_mode: BLEND_MODE_ALPHA texture: "button/button_normal" - id: "rewardedVideo/larrybutton" + id: "default/larrybutton" xanchor: XANCHOR_NONE yanchor: YANCHOR_NONE pivot: PIVOT_CENTER adjust_mode: ADJUST_MODE_FIT - parent: "rewardedVideo" + parent: "default" layer: "" inherit_alpha: true slice9 { @@ -267,6 +267,7 @@ nodes { alpha: 1.0 overridden_fields: 1 overridden_fields: 4 + overridden_fields: 5 template_node_child: true size_mode: SIZE_MODE_MANUAL } @@ -296,16 +297,177 @@ nodes { w: 1.0 } color { + x: 0.9921569 + y: 0.9921569 + z: 1.0 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "Show default" + font: "larryfont" + id: "default/larrylabel" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { x: 1.0 - y: 0.023529414 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "default/larrybutton" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 1.0 + overridden_fields: 1 + overridden_fields: 5 + overridden_fields: 8 + template_node_child: true + text_leading: 1.0 + text_tracking: 0.0 +} +nodes { + position { + x: 320.0 + y: 336.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_TEMPLATE + id: "video" + layer: "" + inherit_alpha: true + alpha: 1.0 + template: "/dirtylarry/button.gui" + template_node_child: false +} +nodes { + position { + x: 0.0 + y: -5.684342E-14 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 300.0 + y: 88.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "button/button_normal" + id: "video/larrybutton" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "video" + layer: "" + inherit_alpha: true + slice9 { + x: 32.0 + y: 32.0 + z: 32.0 + w: 32.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + overridden_fields: 1 + template_node_child: true + size_mode: SIZE_MODE_MANUAL +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 z: 0.0 w: 1.0 } + color { + x: 1.0 + y: 0.0 + z: 0.03137255 + w: 1.0 + } type: TYPE_TEXT blend_mode: BLEND_MODE_ALPHA - text: "Show Rewarded video" + text: "Show video" font: "larryfont" - id: "rewardedVideo/larrylabel" + id: "video/larrylabel" xanchor: XANCHOR_NONE yanchor: YANCHOR_NONE pivot: PIVOT_CENTER @@ -323,7 +485,7 @@ nodes { } adjust_mode: ADJUST_MODE_FIT line_break: false - parent: "rewardedVideo/larrybutton" + parent: "video/larrybutton" layer: "" inherit_alpha: true alpha: 1.0 @@ -338,8 +500,8 @@ nodes { } nodes { position { - x: 324.268 - y: 445.168 + x: 320.0 + y: 216.0 z: 0.0 w: 1.0 } @@ -368,7 +530,7 @@ nodes { w: 1.0 } type: TYPE_TEMPLATE - id: "init" + id: "rewardedVideo" layer: "" inherit_alpha: true alpha: 1.0 @@ -395,7 +557,7 @@ nodes { w: 1.0 } size { - x: 440.0 + x: 400.0 y: 88.0 z: 0.0 w: 1.0 @@ -409,12 +571,12 @@ nodes { type: TYPE_BOX blend_mode: BLEND_MODE_ALPHA texture: "button/button_normal" - id: "init/larrybutton" + id: "rewardedVideo/larrybutton" xanchor: XANCHOR_NONE yanchor: YANCHOR_NONE pivot: PIVOT_CENTER adjust_mode: ADJUST_MODE_FIT - parent: "init" + parent: "rewardedVideo" layer: "" inherit_alpha: true slice9 { @@ -459,15 +621,15 @@ nodes { } color { x: 1.0 - y: 1.0 - z: 1.0 + y: 0.023529414 + z: 0.0 w: 1.0 } type: TYPE_TEXT blend_mode: BLEND_MODE_ALPHA - text: "init UnityAds with id" + text: "Show Rewarded video" font: "larryfont" - id: "init/larrylabel" + id: "rewardedVideo/larrylabel" xanchor: XANCHOR_NONE yanchor: YANCHOR_NONE pivot: PIVOT_CENTER @@ -485,13 +647,14 @@ nodes { } adjust_mode: ADJUST_MODE_FIT line_break: false - parent: "init/larrybutton" + parent: "rewardedVideo/larrybutton" layer: "" inherit_alpha: true alpha: 1.0 outline_alpha: 1.0 shadow_alpha: 1.0 overridden_fields: 1 + overridden_fields: 5 overridden_fields: 8 template_node_child: true text_leading: 1.0 @@ -499,8 +662,8 @@ nodes { } nodes { position { - x: 622.14075 - y: 280.25586 + x: 661.0 + y: 576.0 z: 0.0 w: 1.0 } @@ -529,7 +692,7 @@ nodes { w: 1.0 } type: TYPE_TEMPLATE - id: "default" + id: "set_callback" layer: "" inherit_alpha: true alpha: 1.0 @@ -570,12 +733,12 @@ nodes { type: TYPE_BOX blend_mode: BLEND_MODE_ALPHA texture: "button/button_normal" - id: "default/larrybutton" + id: "set_callback/larrybutton" xanchor: XANCHOR_NONE yanchor: YANCHOR_NONE pivot: PIVOT_CENTER adjust_mode: ADJUST_MODE_FIT - parent: "default" + parent: "set_callback" layer: "" inherit_alpha: true slice9 { @@ -627,9 +790,9 @@ nodes { } type: TYPE_TEXT blend_mode: BLEND_MODE_ALPHA - text: "Show default" + text: "Set callback" font: "larryfont" - id: "default/larrylabel" + id: "set_callback/larrylabel" xanchor: XANCHOR_NONE yanchor: YANCHOR_NONE pivot: PIVOT_CENTER @@ -647,7 +810,7 @@ nodes { } adjust_mode: ADJUST_MODE_FIT line_break: false - parent: "default/larrybutton" + parent: "set_callback/larrybutton" layer: "" inherit_alpha: true alpha: 1.0 @@ -662,8 +825,8 @@ nodes { } nodes { position { - x: 143.198 - y: 593.762 + x: 1073.0 + y: 576.0 z: 0.0 w: 1.0 } @@ -692,17 +855,17 @@ nodes { w: 1.0 } type: TYPE_TEMPLATE - id: "input" + id: "remove_callback" layer: "" inherit_alpha: true alpha: 1.0 - template: "/dirtylarry/input.gui" + template: "/dirtylarry/button.gui" template_node_child: false } nodes { position { - x: -13.775061 - y: 0.0 + x: 0.0 + y: -1.2791587 z: 0.0 w: 1.0 } @@ -720,25 +883,25 @@ nodes { } size { x: 400.0 - y: 72.0 + y: 88.0 z: 0.0 w: 1.0 } color { - x: 1.0 + x: 0.9960785 y: 1.0 - z: 1.0 + z: 0.9921569 w: 1.0 } type: TYPE_BOX blend_mode: BLEND_MODE_ALPHA - texture: "button/button_pressed" - id: "input/bg" + texture: "button/button_normal" + id: "remove_callback/larrybutton" xanchor: XANCHOR_NONE yanchor: YANCHOR_NONE - pivot: PIVOT_W + pivot: PIVOT_CENTER adjust_mode: ADJUST_MODE_FIT - parent: "input" + parent: "remove_callback" layer: "" inherit_alpha: true slice9 { @@ -751,13 +914,16 @@ nodes { clipping_visible: true clipping_inverted: false alpha: 1.0 + overridden_fields: 1 + overridden_fields: 4 + overridden_fields: 5 template_node_child: true size_mode: SIZE_MODE_MANUAL } nodes { position { - x: 13.0 - y: 3.0 + x: 0.0 + y: 0.0 z: 0.0 w: 1.0 } @@ -774,45 +940,95 @@ nodes { w: 1.0 } size { - x: 0.0 - y: 32.0 + x: 200.0 + y: 100.0 z: 0.0 w: 1.0 } color { - x: 0.18431373 - y: 0.18431373 - z: 0.18431373 + x: 0.9921569 + y: 0.9921569 + z: 1.0 w: 1.0 } - type: TYPE_BOX + type: TYPE_TEXT blend_mode: BLEND_MODE_ALPHA - texture: "" - id: "input/inner" + text: "Remove callback" + font: "larryfont" + id: "remove_callback/larrylabel" xanchor: XANCHOR_NONE yanchor: YANCHOR_NONE - pivot: PIVOT_W + pivot: PIVOT_CENTER + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } adjust_mode: ADJUST_MODE_FIT - parent: "input/bg" + line_break: false + parent: "remove_callback/larrybutton" layer: "" inherit_alpha: true - slice9 { + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 1.0 + overridden_fields: 1 + overridden_fields: 5 + overridden_fields: 8 + template_node_child: true + text_leading: 1.0 + text_tracking: 0.0 +} +nodes { + position { + x: 920.0 + y: 252.0 + z: 0.0 + w: 1.0 + } + rotation { x: 0.0 y: 0.0 z: 0.0 - w: 0.0 + w: 1.0 } - clipping_mode: CLIPPING_MODE_STENCIL - clipping_visible: true - clipping_inverted: false - alpha: 0.0 - template_node_child: true - size_mode: SIZE_MODE_MANUAL + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_TEMPLATE + id: "banner" + layer: "" + inherit_alpha: true + alpha: 1.0 + template: "/dirtylarry/button.gui" + template_node_child: false } nodes { position { - x: 8.0 - y: 0.0 + x: 0.0 + y: -1.2791587 z: 0.0 w: 1.0 } @@ -829,44 +1045,47 @@ nodes { w: 1.0 } size { - x: 0.0 - y: 48.0 + x: 400.0 + y: 88.0 z: 0.0 w: 1.0 } color { - x: 0.3254902 - y: 0.6666667 - z: 0.9960785 + x: 0.9960785 + y: 1.0 + z: 0.9921569 w: 1.0 } type: TYPE_BOX blend_mode: BLEND_MODE_ALPHA - texture: "" - id: "input/cursor" + texture: "button/button_normal" + id: "banner/larrybutton" xanchor: XANCHOR_NONE yanchor: YANCHOR_NONE - pivot: PIVOT_W + pivot: PIVOT_CENTER adjust_mode: ADJUST_MODE_FIT - parent: "input/inner" + parent: "banner" layer: "" - inherit_alpha: false + inherit_alpha: true slice9 { - x: 0.0 - y: 0.0 - z: 0.0 - w: 0.0 + x: 32.0 + y: 32.0 + z: 32.0 + w: 32.0 } clipping_mode: CLIPPING_MODE_NONE clipping_visible: true clipping_inverted: false alpha: 1.0 + overridden_fields: 1 + overridden_fields: 4 + overridden_fields: 5 template_node_child: true size_mode: SIZE_MODE_MANUAL } nodes { position { - x: 4.0 + x: 0.0 y: 0.0 z: 0.0 w: 1.0 @@ -885,28 +1104,28 @@ nodes { } size { x: 200.0 - y: 32.0 + y: 100.0 z: 0.0 w: 1.0 } color { x: 1.0 - y: 1.0 - z: 1.0 + y: 0.0 + z: 0.0 w: 1.0 } type: TYPE_TEXT blend_mode: BLEND_MODE_ALPHA - text: "Empty" + text: "Load Banner" font: "larryfont" - id: "input/content" + id: "banner/larrylabel" xanchor: XANCHOR_NONE yanchor: YANCHOR_NONE - pivot: PIVOT_W + pivot: PIVOT_CENTER outline { - x: 1.0 - y: 1.0 - z: 1.0 + x: 0.0 + y: 0.0 + z: 0.0 w: 1.0 } shadow { @@ -917,20 +1136,23 @@ nodes { } adjust_mode: ADJUST_MODE_FIT line_break: false - parent: "input/inner" + parent: "banner/larrybutton" layer: "" - inherit_alpha: false + inherit_alpha: true alpha: 1.0 outline_alpha: 1.0 shadow_alpha: 1.0 + overridden_fields: 1 + overridden_fields: 5 + overridden_fields: 8 template_node_child: true text_leading: 1.0 text_tracking: 0.0 } nodes { position { - x: 919.141 - y: 592.256 + x: 920.0 + y: 130.0 z: 0.0 w: 1.0 } @@ -959,7 +1181,7 @@ nodes { w: 1.0 } type: TYPE_TEMPLATE - id: "set_callback" + id: "show_banner" layer: "" inherit_alpha: true alpha: 1.0 @@ -1000,12 +1222,12 @@ nodes { type: TYPE_BOX blend_mode: BLEND_MODE_ALPHA texture: "button/button_normal" - id: "set_callback/larrybutton" + id: "show_banner/larrybutton" xanchor: XANCHOR_NONE yanchor: YANCHOR_NONE pivot: PIVOT_CENTER adjust_mode: ADJUST_MODE_FIT - parent: "set_callback" + parent: "show_banner" layer: "" inherit_alpha: true slice9 { @@ -1050,16 +1272,16 @@ nodes { w: 1.0 } color { - x: 0.9921569 - y: 0.9921569 - z: 1.0 + x: 1.0 + y: 0.0 + z: 0.0 w: 1.0 } type: TYPE_TEXT blend_mode: BLEND_MODE_ALPHA - text: "Set callback" + text: "Show Banner" font: "larryfont" - id: "set_callback/larrylabel" + id: "show_banner/larrylabel" xanchor: XANCHOR_NONE yanchor: YANCHOR_NONE pivot: PIVOT_CENTER @@ -1077,7 +1299,7 @@ nodes { } adjust_mode: ADJUST_MODE_FIT line_break: false - parent: "set_callback/larrybutton" + parent: "show_banner/larrybutton" layer: "" inherit_alpha: true alpha: 1.0 @@ -1092,8 +1314,8 @@ nodes { } nodes { position { - x: 919.141 - y: 448.256 + x: 920.0 + y: 370.0 z: 0.0 w: 1.0 } @@ -1122,7 +1344,7 @@ nodes { w: 1.0 } type: TYPE_TEMPLATE - id: "remove_callback" + id: "banner_pos" layer: "" inherit_alpha: true alpha: 1.0 @@ -1163,12 +1385,12 @@ nodes { type: TYPE_BOX blend_mode: BLEND_MODE_ALPHA texture: "button/button_normal" - id: "remove_callback/larrybutton" + id: "banner_pos/larrybutton" xanchor: XANCHOR_NONE yanchor: YANCHOR_NONE pivot: PIVOT_CENTER adjust_mode: ADJUST_MODE_FIT - parent: "remove_callback" + parent: "banner_pos" layer: "" inherit_alpha: true slice9 { @@ -1220,9 +1442,10 @@ nodes { } type: TYPE_TEXT blend_mode: BLEND_MODE_ALPHA - text: "Remove callback" + text: "Change Banner Pos\n" + "" font: "larryfont" - id: "remove_callback/larrylabel" + id: "banner_pos/larrylabel" xanchor: XANCHOR_NONE yanchor: YANCHOR_NONE pivot: PIVOT_CENTER @@ -1240,7 +1463,7 @@ nodes { } adjust_mode: ADJUST_MODE_FIT line_break: false - parent: "remove_callback/larrybutton" + parent: "banner_pos/larrybutton" layer: "" inherit_alpha: true alpha: 1.0 @@ -1253,6 +1476,68 @@ nodes { text_leading: 1.0 text_tracking: 0.0 } +nodes { + position { + x: 918.0 + y: 470.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "BANNER_POSITION_BOTTOM_CENTER" + font: "larryfont" + id: "baner_pos" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 1.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 +} material: "/builtins/materials/gui.material" adjust_reference: ADJUST_REFERENCE_PARENT max_nodes: 512 diff --git a/example/ui.gui_script b/example/ui.gui_script index 800d67e..6d3fced 100644 --- a/example/ui.gui_script +++ b/example/ui.gui_script @@ -28,8 +28,8 @@ local function print_placement_state(placement) end end -local function btn_ready(self, placementId) - gui.set_color(gui.get_node(placementId.."/larrylabel"), vmath.vector4(1, 1, 1, 1)) +local function btn_ready(self, button_name) + gui.set_color(gui.get_node(button_name.."/larrylabel"), vmath.vector4(1, 1, 1, 1)) end local function unity_ads_callback(self, msg_type, message) @@ -71,6 +71,30 @@ local function unity_ads_callback(self, msg_type, message) elseif message.state == unityads.FINISH_STATE_COMPLETED then print("kUnityAdsFinishStateCompleted") end + elseif msg_type == unityads.TYPE_BANNER then + if message.event == unityads.BANNER_EVENT_DID_CLICK then + print("BANNER_EVENT_DID_CLICK", message.placementId) + elseif message.event == unityads.BANNER_EVENT_DID_ERROR then + print("BANNER_EVENT_DID_ERROR: ", message.message) + elseif message.event == unityads.BANNER_EVENT_DID_HIDE then + print("BANNER_EVENT_DID_HIDE", message.placementId) + gui.set_text(gui.get_node("show_banner/larrylabel"), "Show Banner") + self.is_show_banner = false + elseif message.event == unityads.BANNER_EVENT_DID_LOAD then + print("BANNER_EVENT_DID_LOAD", message.placementId) + btn_ready(self, "show_banner") + self.is_loaded_banner = true + gui.set_text(gui.get_node("banner/larrylabel"), "Unload Banner") + elseif message.event == unityads.BANNER_EVENT_DID_SHOW then + print("BANNER_EVENT_DID_SHOW", message.placementId) + gui.set_text(gui.get_node("show_banner/larrylabel"), "Hide Banner") + self.is_show_banner = true + elseif message.event == unityads.BANNER_EVENT_DID_UNLOAD then + print("BANNER_EVENT_DID_UNLOAD", message.placementId) + gui.set_color(gui.get_node("show_banner/larrylabel"), vmath.vector4(1, 0, 0, 1)) + self.is_loaded_banner = nil + gui.set_text(gui.get_node("banner/larrylabel"), "Load Banner") + end end end @@ -141,40 +165,94 @@ local function remove_callback(self) end end +local function loadbanner(self) + if unityads then + if not self.is_loaded_banner then + unityads.loadBanner("banner") + else + unityads.unloadBanner() + end + end +end + +local function showbanner(self) + if unityads then + if not self.is_show_banner then + unityads.showBanner() + else + unityads.hideBanner() + end + end +end + +local function change_banner_pos(self) + if unityads then + local banners = { + "BANNER_POSITION_TOP_LEFT", + "BANNER_POSITION_TOP_CENTER", + "BANNER_POSITION_TOP_RIGHT", + "BANNER_POSITION_BOTTOM_LEFT", + "BANNER_POSITION_BOTTOM_CENTER", + "BANNER_POSITION_BOTTOM_RIGHT", + "BANNER_POSITION_CENTER", + "BANNER_POSITION_NONE" + } + if not self.banner_pos_num then + self.banner_pos_num = 2 + else + self.banner_pos_num = self.banner_pos_num + 1 + if self.banner_pos_num > #banners then + self.banner_pos_num = 1 + end + end + unityads.setBannerPosition(unityads[banners[self.banner_pos_num]]) + gui.set_text(gui.get_node("baner_pos"), banners[self.banner_pos_num]) + end +end + function on_input(self, action_id, action) - self.input_default = dirtylarry:input("input", action_id, action, gui.KEYBOARD_TYPE_DEFAULT, "AppId") + dirtylarry:button("init", action_id, action, function () - if self.input_default == "Empty" then - self.input_default = gameIDs[sys_name] + init_unity_ads(self, gameIDs[sys_name]) + end) + + dirtylarry:button(REWARDED, action_id, action, function () + print_placement_state(REWARDED) + show_ad(self, REWARDED) + end) + + dirtylarry:button(VIDEO, action_id, action, function () + print_placement_state(VIDEO) + show_ad(self, VIDEO) + end) + + dirtylarry:button("default", action_id, action, function () + show_ad(self) + end) + + dirtylarry:button("set_callback", action_id, action, function () + set_callback(self) + end) + + dirtylarry:button("remove_callback", action_id, action, function () + remove_callback(self) + end) + + dirtylarry:button("banner", action_id, action, function () + loadbanner(self) + end) + + dirtylarry:button("show_banner", action_id, action, function () + showbanner(self) + end) + + dirtylarry:button("banner_pos", action_id, action, function () + change_banner_pos(self) + end) + + if action_id == BACK_KEY and action.released then + print("Time to exit!") + msg.post("@system:", "exit", {code = 0}) end - init_unity_ads(self, self.input_default) -end) - -dirtylarry:button(REWARDED, action_id, action, function () - print_placement_state(REWARDED) - show_ad(self, REWARDED) -end) - -dirtylarry:button(VIDEO, action_id, action, function () - print_placement_state(VIDEO) - show_ad(self, VIDEO) -end) - -dirtylarry:button("default", action_id, action, function () - show_ad(self) -end) - -dirtylarry:button("set_callback", action_id, action, function () - set_callback(self) -end) - -dirtylarry:button("remove_callback", action_id, action, function () - remove_callback(self) -end) - -if action_id == BACK_KEY and action.released then - print("Time to exit!") - msg.post("@system:", "exit", {code = 0}) -end end