Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.IO;
- using System;
- using System.Runtime.InteropServices;
- public class TestScript : MonoBehaviour
- {
- // libscreen
- [DllImport("libscreen.so", EntryPoint="screen_create_context")]
- public static extern int screen_create_context(ref IntPtr context, int flags);
- [DllImport("libscreen.so", EntryPoint="screen_create_window_type")]
- public static extern int screen_create_window_type(ref IntPtr window, IntPtr context, int flags);
- [DllImport("libscreen.so", EntryPoint="screen_create_window_group")]
- public static extern int screen_create_window_group(IntPtr window, string name);
- [DllImport("libscreen.so", EntryPoint="screen_join_window_group")]
- public static extern int screen_join_window_group(IntPtr window, string name);
- [DllImport("libscreen.so", EntryPoint="screen_destroy_window")]
- public static extern int screen_destroy_window(IntPtr window);
- [DllImport("libscreen.so", EntryPoint="screen_destroy_context")]
- public static extern int screen_destroy_context(IntPtr context);
- [DllImport("libscreen.so", EntryPoint="screen_set_window_property_iv")]
- public static extern int screen_set_window_property_iv(IntPtr context, int pname, ref int param);
- // libbbads
- [DllImport("libbbads.so", EntryPoint="bbads_banner_create")]
- public static extern int bbads_banner_create(ref IntPtr banner, IntPtr window, string name, uint id);
- [DllImport("libbbads.so", EntryPoint="bbads_banner_set_size")]
- public static extern int bbads_banner_set_size(IntPtr banner, uint width, uint height);
- [DllImport("libbbads.so", EntryPoint="bbads_banner_set_position")]
- public static extern int bbads_banner_set_position(IntPtr banner, uint x, uint y);
- [DllImport("libbbads.so", EntryPoint="bbads_banner_load")]
- public static extern int bbads_banner_load(IntPtr banner);
- [DllImport("libbbads.so", EntryPoint="bbads_banner_set_window_visible")]
- public static extern int bbads_banner_set_window_visible(IntPtr banner);
- [DllImport("libbbads.so", EntryPoint="bbads_banner_display")]
- public static extern int bbads_banner_display(IntPtr banner, IntPtr context, IntPtr _event);
- [DllImport("libbbads.so", EntryPoint="bbads_banner_is_visible")]
- public static extern int bbads_banner_is_visible(IntPtr banner, ref int visible);
- // libbps
- [DllImport("libbps.so", EntryPoint="bps_get_event")]
- public static extern int bps_get_event(ref IntPtr _event, int timeout);
- [DllImport("libbps.so", EntryPoint="screen_get_domain")]
- public static extern int screen_get_domain();
- [DllImport("libbps.so", EntryPoint="bps_event_get_domain")]
- public static extern int bps_event_get_domain(IntPtr _event);
- [DllImport("libbps.so", EntryPoint="screen_event_get_event")]
- public static extern IntPtr screen_event_get_event(IntPtr _event);
- [DllImport("libbps.so", EntryPoint="screen_get_event_property_iv")]
- public static extern int screen_get_event_property_iv(IntPtr _screen_event, int name, ref int parm);
- [DllImport("libbps.so", EntryPoint="navigator_event_get_groupid")]
- public static extern IntPtr navigator_event_get_groupid(IntPtr _event);
- [DllImport("libbps.so", EntryPoint="bps_event_get_code")]
- public static extern uint bps_event_get_code(IntPtr _event);
- // libc
- [DllImport("libc.so", EntryPoint="getpid")]
- public static extern int getpid();
- const uint BANNER_TEST_ZONE_ID = 117145;
- const uint BANNER_SIZE_X = 468;
- const uint BANNER_SIZE_Y = 60;
- const uint BANNER_POSITION_X = 180;
- const uint BANNER_POSITION_Y = 150;
- const int SCREEN_PROPERTY_TYPE = 47;
- const int SCREEN_EVENT_CREATE = 1;
- const int SCREEN_CHILD_WINDOW = 1;
- const int SCREEN_EMBEDDED_WINDOW = 2;
- const uint NAVIGATOR_WINDOW_ACTIVE = 0x0a;
- const uint NAVIGATOR_WINDOW_STATE = 0x03;
- const uint NAVIGATOR_WINDOW_INACTIVE = 0x0b;
- const int SCREEN_APPLICATION_CONTEXT = 0;
- const int SCREEN_FORMAT_RGBA8888 = 8;
- const int SCREEN_USAGE_NATIVE = (1 << 3);
- const int SCREEN_PROPERTY_FORMAT = 14;
- const int SCREEN_PROPERTY_USAGE = 48;
- IntPtr context = IntPtr.Zero, window = IntPtr.Zero;
- IntPtr banner = IntPtr.Zero;
- void Update()
- {
- try
- {
- IntPtr _event = IntPtr.Zero;
- bps_get_event(ref _event, -1);
- if (_event != IntPtr.Zero)
- {
- if (screen_get_domain() == bps_event_get_domain(_event))
- {
- int screen_val = 0;
- uint eventID = bps_event_get_code(_event);
- Debug.Log("eventID: " + eventID);
- if (eventID == NAVIGATOR_WINDOW_ACTIVE || eventID == NAVIGATOR_WINDOW_STATE || eventID == NAVIGATOR_WINDOW_INACTIVE)
- {
- IntPtr id = navigator_event_get_groupid(_event);
- Debug.Log("navigator_event_get_groupid: " + Marshal.PtrToStringAnsi(id));
- }
- IntPtr screenEvent = screen_event_get_event(_event);
- Debug.Log("screen_event_get_event: " + screenEvent);
- if (screenEvent == IntPtr.Zero) return;
- Debug.Log("screen_get_event_property_iv: " + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_TYPE, ref screen_val));
- Debug.Log("screen_val: " + screen_val);
- if (screen_val == SCREEN_EVENT_CREATE)
- {
- int visible = 0;
- Debug.Log("bbads_banner_is_visible: " + bbads_banner_is_visible(banner, ref visible));
- Debug.Log("visible: " + visible);
- if (visible == 0)
- {
- Debug.Log("bbads_banner_set_window_visible: " + bbads_banner_set_window_visible(banner));
- Debug.Log("bbads_banner_display: " + bbads_banner_display(banner, context, _event));
- }
- }
- }
- }
- }
- catch (Exception e)
- {
- Debug.LogError(e.Message);
- }
- }
- void Start()
- {
- Debug.Log("STARTING...");
- try
- {
- // get root window group id
- int id = getpid();
- string windowGroup = id.ToString();
- Debug.Log("getpid: " + id);
- // create a screen to place ads in
- Debug.Log("screen_create_context: " + screen_create_context(ref context, SCREEN_APPLICATION_CONTEXT));
- Debug.Log("screen_create_window_type: " + screen_create_window_type(ref window, context, SCREEN_EMBEDDED_WINDOW));
- //Debug.Log("screen_create_window_group: " + screen_create_window_group(window, windowGroup));
- Debug.Log("screen_join_window_group: " + screen_join_window_group(window, windowGroup));
- int format = SCREEN_FORMAT_RGBA8888;
- Debug.Log("screen_set_window_property_iv: " + screen_set_window_property_iv(window, SCREEN_PROPERTY_FORMAT, ref format));
- int usage = SCREEN_USAGE_NATIVE;
- Debug.Log("screen_set_window_property_iv: " + screen_set_window_property_iv(window, SCREEN_PROPERTY_USAGE, ref usage));
- // create ad banner
- Debug.Log("bbads_banner_create: " + bbads_banner_create(ref banner, window, windowGroup, BANNER_TEST_ZONE_ID));
- Debug.Log("bbads_banner_set_size: " + bbads_banner_set_size(banner, BANNER_SIZE_X, BANNER_SIZE_Y));
- Debug.Log("bbads_banner_set_position: " + bbads_banner_set_position(banner, BANNER_POSITION_X, BANNER_POSITION_Y));
- Debug.Log("bbads_banner_load: " + bbads_banner_load(banner));
- }
- catch (System.Exception e)
- {
- Debug.LogError("ERROR: " + e.Message);
- }
- Debug.Log("ENDING...");
- }
- void OnDestroy()
- {
- Debug.Log("screen_destroy_window: " + screen_destroy_window(window));
- Debug.Log("screen_destroy_context: " + screen_destroy_context(context));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement