123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- using UnityEngine;
- using System.Collections;
- using System.Runtime.InteropServices;
- using System;
- using System.Collections.Generic;
- using System.Threading;
- public class OneWaySDK : MonoBehaviour
- {
- public static AndroidJavaObject _plugin;
- // Use this for initialization
- void Start () {
-
- }
-
- // Update is called once per frame
- void Update () {
- }
- public enum OneWaySDKPlacementState
- {
- //A state that indicates that the placement is ready to show an ad. The `show:` selector can be called.
- kOneWaySDKPlacementStateReady = 0,
-
- // A state that indicates that no state is information is available.
- // @warning This state can that OneWaySDK is not initialized or that the placement is not correctly configured in the oneway ads admin tool.
- kOneWaySDKPlacementStateNotAvailable,
-
- // A state that indicates that the placement is currently disabled. The placement can be enabled in the oneway ads admin tools.
- kOneWaySDKPlacementStateDisabled,
-
- // 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.
- kOneWaySDKPlacementStateWaiting,
-
- // A state that indicates that the placement is properly configured, but there are currently no ads available for the placement.
- kOneWaySDKPlacementStateNoFill
- };
- public enum OneWaySDKFinishState
- {
- kOneWaySDKFinishStateError = 0,
- kOneWaySDKFinishStateSkipped ,
-
- kOneWaySDKFinishStateCompleted
- };
- public enum OneWaySDKError
- {
-
- // An error that indicates failure due to `OneWaySDK` currently being uninitialized.
- kOneWaySDKErrorNotInitialized = 0,
-
- // An error that indicates failure due to a failure in the initialization process.
- kOneWaySDKErrorInitializedFailed,
-
- // An error that indicates failure due to attempting to initialize `OneWaySDK` with invalid parameters.
- kOneWaySDKErrorInvalidArgument,
-
- // An error that indicates failure of the video player.
- kOneWaySDKErrorVideoPlayerError,
-
- // An error that indicates failure due to having attempted to initialize the `OneWaySDK` class in an invalid environment.
- kOneWaySDKErrorInitSanityCheckFail,
-
- // An error that indicates failure due to the presence of an ad blocker.
- kOneWaySDKErrorAdBlockerDetected,
-
- // An error that indicates failure due to inability to read or write a file.
- kOneWaySDKErrorFileIoError,
-
- // An error that indicates failure due to a bad device identifier.
- kOneWaySDKErrorDeviceIdError,
- // An error that indicates a failure when attempting to show an ad.
- kOneWaySDKErrorShowError,
-
- // An error that indicates an internal failure in `OneWaySDK`.
- kOneWaySDKErrorInternalError,
-
- // A state that indicates that the SDK is properly configured, but there are currently no ads available.
- kOneWaySDKCampaignNoFill
- }
- #region Constructor and Lifecycle
- static OneWaySDK()
- {
- // try/catch this so that we can warn users if they try to stick this script on a GO manually
- try
- {
- // create a new GO for our manager
- var go = new GameObject( "OneWaySDK" );
- go.AddComponent<OneWaySDK>();
- DontDestroyOnLoad( go );
- }
- catch( UnityException ) {
- Debug.LogWarning ("It looks like you have the OneWaySDK on a GameObject in your scene. Please remove the script from your scene.");
- }
- #if UNITY_ANDROID
- using( var pluginClass = new AndroidJavaClass( "mobi.oneway.OneWaySdkPlugin" ) )
- _plugin = pluginClass.CallStatic<AndroidJavaObject>( "instance" );
- #endif
- }
- // used to ensure the VungleManager will always be in the scene to avoid SendMessage logs if the user isn't using any events
- public static void noop(){}
- #endregion
- #region Events
- // Fired when a Vungle ad starts
- public static event Action <string> onOneWaySDKReadyEvent;
- public static event Action <string> onOneWaySDKDidStartEvent;
- public static event Action <string,string> onOneWaySDKDidFinishEvent;
- public static event Action <string,string> onOneWaySDKDidErrorEvent;
- #endregion
- void onOneWaySDKReady (string placementID) {
- try{
- onOneWaySDKReadyEvent (placementID);
- }catch(Exception e){
- print("-------------- OneWaySDK Warning : Method 'onOneWaySDKReadyEvent ' not implemented --------------"+e.Message);
- }
- }
- void onOneWaySDKDidStart (string placementID) {
- try{
- onOneWaySDKDidStartEvent (placementID);
- }catch(Exception e){
- Debug.LogWarning ("-------------- OneWaySDK Warning : Method 'onOneWaySDKDidStartEvent ' not implemented --------------"+e.Message);
- }
-
-
- }
- void onOneWaySDKDidFinish (string msg) {
- Dictionary<string,object> attrs = (Dictionary<string,object>) MiniJSONV.Json.Deserialize( msg );
- try{
- onOneWaySDKDidFinishEvent (attrs["placementId"].ToString(),attrs["state"].ToString());
- }catch(Exception e){
- Debug.LogWarning ("-------------- OneWaySDK Warning : Method 'onOneWaySDKDidFinishEvent ' not implemented --------------"+e.Message);
- }
- }
- void onOneWaySDKDidError (string msg) {
- Dictionary<string,object> attrs = (Dictionary<string,object>) MiniJSONV.Json.Deserialize( msg );
- try{
- onOneWaySDKDidErrorEvent (attrs["error"].ToString(),attrs["message"].ToString());
- }catch(Exception e){
- Debug.LogWarning ("-------------- OneWaySDK Warning : Method 'onOneWaySDKDidErrorEvent ' not implemented --------------"+e.Message);
- }
- }
- // init
- [DllImport ("__Internal")]
- private static extern void _OneWaySDKInit(string PId,bool debugMode);
- public static void init(string iOSPId , string androidPId, bool debugMode)
- {
- #if UNITY_IPHONE
- _OneWaySDKInit( iOSPId, debugMode);
- #elif UNITY_ANDROID
- _plugin.Call("init",androidPId,debugMode);
- #endif
- }
- // show
- [DllImport ("__Internal")]
- private static extern void _OneWaySDKShow();
- public static void show()
- {
- #if UNITY_IPHONE
- _OneWaySDKShow();
- #elif UNITY_ANDROID
- _plugin.Call("showOneWayAd");
- #endif
- }
- //ShowPlacementID
- [DllImport ("__Internal")]
- private static extern void _OneWaySDKShowPlacementID(string placementID);
- public static void showPlacementID(string placementID)
- {
- #if UNITY_IPHONE
- _OneWaySDKShowPlacementID(placementID);
- #elif UNITY_ANDROID
- _plugin.Call("showPlacementID",placementID);
- #endif
- }
- //isReady
- [DllImport ("__Internal")]
- private static extern bool _OneWaySDKIsReady();
- public static bool IsReady()
- {
- #if UNITY_IPHONE
- return _OneWaySDKIsReady();
- #elif UNITY_ANDROID
- return _plugin.Call<bool>("isVideoAvailable");
- #else
- return false;
- #endif
- }
- }
|