Skip to content

Commit

Permalink
Merge pull request #8 from AGulev/unity-3-4-2
Browse files Browse the repository at this point in the history
Unity 3.4.2
  • Loading branch information
AGulev authored Mar 8, 2020
2 parents f392571 + 5d9543b commit aa58b05
Show file tree
Hide file tree
Showing 21 changed files with 579 additions and 345 deletions.
51 changes: 38 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ _“This plugin is not endorsed or sponsored by Unity Technologies. This is an i
# DefVideoAds (plugin for Unity ADS)

This is [UnityAds](https://unity3d.com/ru/services/ads) native extension for [Defold engine](http://www.defold.com).
Extension supported IOS and Android.
Extension supported IOS (minimum iOS version is 9.0) and Android.

## Installation

Expand All @@ -24,6 +24,7 @@ See the [example folder](https://github.com/AGulev/DefVideoAds/tree/master/examp


## LUA Api
Please, read [Android API docs](https://docs.unity3d.com/Packages/[email protected]/manual/MonetizationResourcesApiAndroid.html) and [iOS API docs](https://docs.unity3d.com/Packages/[email protected]/manual/MonetizationResourcesApiIos.html)
### Methods
#### unityads.initialize(gameID, callback)
#### unityads.initialize(gameID, callback, testMode)
Expand Down Expand Up @@ -108,8 +109,10 @@ unityads.show() -- show default ad
unityads.show("rewardedVideo") -- show rewardedVideo
```
#### unityads.loadBanner(placementId)
#### unityads.loadBanner(placementId, banner_width, banner_height)
```lua
unityads.loadBanner("banner") -- load banner
unityads.loadBanner("banner") -- load banner, by defaulf width = 320, height = 50
unityads.loadBanner("banner", 320, 50) -- load banner
```
#### unityads.unloadBanner()
```lua
Expand All @@ -135,7 +138,6 @@ unityads.BANNER_POSITION_BOTTOM_LEFT
unityads.BANNER_POSITION_BOTTOM_CENTER
unityads.BANNER_POSITION_BOTTOM_RIGHT
unityads.BANNER_POSITION_CENTER
unityads.BANNER_POSITION_NONE
```

### Constants
Expand All @@ -152,6 +154,7 @@ unityads.TYPE_DID_START
unityads.TYPE_DID_ERROR
unityads.TYPE_DID_FINISH
unityads.TYPE_BANNER
unityads.TYPE_BANNER_ERROR
```
##### unityads.TYPE_IS_READY
```lua
Expand All @@ -173,7 +176,7 @@ end
```lua
local function defunityads_callback(self, msg_type, message)
if msg_type == unityads.TYPE_DID_ERROR then
pprint(message) -- message = {state = ERROR_*, message = "string"}
pprint(message) -- message = {error = ERROR_*, message = "string"}
end
end
```
Expand All @@ -189,18 +192,24 @@ end
```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
if message.event == BANNER_EVENT_DID_LOAD then
pprint(message) -- message = {event = BANNER_EVENT_*, placementId = "string"}
end
end
end
```
##### unityads.TYPE_BANNER_ERROR
```lua
local function defunityads_callback(self, msg_type, message)
if msg_type == unityads.TYPE_BANNER_ERROR then
pprint(message) -- message = {error = BANNER_ERROR_*, message = "string"}
end
end
```
#### Error types
[Original doc about error types](https://github.com/Unity-Technologies/unity-ads-ios/wiki/sdk_ios_api_errors)
```lua
--possible message.error :
--possible message.error for unityads.TYPE_DID_ERROR:
unityads.ERROR_NOT_INITIALIZED --kUnityAdsErrorNotInitialized
unityads.ERROR_INITIALIZED_FAILED --kUnityAdsErrorInitializedFailed
unityads.ERROR_INVALID_ARGUMENT --kUnityAdsErrorInvalidArgument
Expand All @@ -222,6 +231,25 @@ local function defunityads_callback(self, msg_type, message)
end
end
```
#### Banner error types
[Original doc about error types](https://docs.unity3d.com/Packages/[email protected]/manual/MonetizationResourcesApiAndroid.html#bannerview)
```lua
--possible message.error for unityads.TYPE_BANNER_ERROR:
unityads.BANNER_ERROR_UNKNOWN --
unityads.BANNER_ERROR_NATIVE
unityads.BANNER_ERROR_WEBVIEW
unityads.BANNER_ERROR_NOFILL
```
```lua
local function defunityads_callback(self, msg_type, message)
if msg_type == unityads.TYPE_BANNER_ERROR then
if message.error == unityads.BANNER_ERROR_UNKNOWN then
...
elseif message.error == unityads.BANNER_ERROR_NATIVE then
...
end
end
```
#### Finish states
[Original doc about finish states](https://github.com/Unity-Technologies/unity-ads-ios/wiki/sdk_ios_api_finishstates)
```lua
Expand All @@ -244,18 +272,15 @@ end
```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
unityads.BANNER_EVENT_DID_LEAVE_APP
```
```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
elseif message.event == unityads.BANNER_EVENT_DID_CLICK then
...
end
end
Expand Down
Binary file modified defunityads/lib/android/classes.jar
Binary file not shown.
69 changes: 11 additions & 58 deletions defunityads/lib/ios/UnityAds.framework/Headers/UADSBanner.h
Original file line number Diff line number Diff line change
@@ -1,56 +1,8 @@
#include <UIKit/UIKit.h>
#include "UnityAdsBannerDelegate.h"

NS_ASSUME_NONNULL_BEGIN

/**
* UnityAdsBannerDelegate is a delegate class for callbacks from Unity Ads Banner operations.
*/
@protocol UnityAdsBannerDelegate <NSObject>

/**
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.
*/
Expand All @@ -72,36 +24,37 @@ typedef NS_ENUM(NSInteger, UnityAdsBannerPosition) {
@interface UnityAdsBanner : NSObject

/**
* Loads the banner with the default banner placement.
* Loads a banner with the default banner placement.
*/
+(void)loadBanner;
+(void)loadBanner __attribute__((deprecated));

/**
* 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;
+(void)loadBanner:(nonnull NSString *)placementId __attribute__((deprecated));

/**
* Destroys the banner.
* Destroys the current banner placement.
*/
+(void)destroy;
+(void)destroy __attribute__((deprecated));

+(void)setBannerPosition:(UnityAdsBannerPosition)bannerPosition __attribute__((deprecated));

/**
* Provides the currently assigned `UnityAdsBannerDelegate`.
*
* @return The current `UnityAdsBannerDelegate`.
*/
+(nullable id <UnityAdsBannerDelegate>)getDelegate;
+(nullable id <UnityAdsBannerDelegate>)getDelegate __attribute__((deprecated));

/**
* Asigns the banner delegate.
*
* @param delegate The new `UnityAdsBannerDelegate' for UnityAds to send banner callbacks to.
*/
+(void)setDelegate:(id <UnityAdsBannerDelegate>)delegate;
+(void)setDelegate:(id <UnityAdsBannerDelegate>)delegate __attribute__((deprecated));

@end

NS_ASSUME_NONNULL_END
18 changes: 18 additions & 0 deletions defunityads/lib/ios/UnityAds.framework/Headers/UADSBannerError.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSInteger, UADSBannerErrorCode) {
UADSBannerErrorCodeUnknown = 0,
UADSBannerErrorCodeNativeError = 1,
UADSBannerErrorCodeWebViewError = 2,
UADSBannerErrorCodeNoFillError = 3
};

@interface UADSBannerError : NSError

- (instancetype)initWithCode:(UADSBannerErrorCode)code userInfo:(nullable NSDictionary<NSErrorUserInfoKey, id> *)dict;

@end

NS_ASSUME_NONNULL_END
19 changes: 19 additions & 0 deletions defunityads/lib/ios/UnityAds.framework/Headers/UADSBannerView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "UADSBannerViewDelegate.h"

NS_ASSUME_NONNULL_BEGIN

@interface UADSBannerView : UIView

@property(nonatomic, readonly) CGSize size;
@property(nonatomic, readwrite, nullable, weak) NSObject <UADSBannerViewDelegate> *delegate;
@property(nonatomic, readonly) NSString *placementId;

-(instancetype)initWithPlacementId:(NSString *)placementId size:(CGSize)size;

-(void)load;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#import <Foundation/Foundation.h>
#import "UADSBannerError.h"

@class UADSBannerView;

/**
* UnityAdsBannerDelegate is a delegate class for callbacks from Unity Ads Banner operations.
*/
@protocol UADSBannerViewDelegate <NSObject>

@optional
/**
Called when the banner is loaded and ready to be placed in the view hierarchy.
@param bannerView View that was loaded
*/
- (void)bannerViewDidLoad:(UADSBannerView *)bannerView;

/**
* Called when the user clicks the banner.
*
* @param bannerView View that the click occurred on.
*/
- (void)bannerViewDidClick:(UADSBannerView *)bannerView;

/**
* Called when a banner causes
* @param bannerView View that triggered leaving application
*/
- (void)bannerViewDidLeaveApplication:(UADSBannerView *)bannerView;

/**
* 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 bannerView View that encountered an error.
* @param error UADSBannerError that occurred
*/
- (void)bannerViewDidError:(UADSBannerView *)bannerView error:(UADSBannerError *)error;

@end
Loading

0 comments on commit aa58b05

Please sign in to comment.