Advertisement
Guest User

Untitled

a guest
Sep 7th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.25 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.IO;
  4. using System;
  5. using System.Runtime.InteropServices;
  6.  
  7. public class TestScript : MonoBehaviour
  8. {
  9.     // libscreen
  10.     [DllImport("libscreen.so", EntryPoint="screen_create_context")]
  11.     public static extern int screen_create_context(ref IntPtr context, int flags);
  12.    
  13.     [DllImport("libscreen.so", EntryPoint="screen_create_window_type")]
  14.     public static extern int screen_create_window_type(ref IntPtr window, IntPtr context, int flags);
  15.    
  16.     [DllImport("libscreen.so", EntryPoint="screen_create_window_group")]
  17.     public static extern int screen_create_window_group(IntPtr window, string name);
  18.    
  19.     [DllImport("libscreen.so", EntryPoint="screen_join_window_group")]
  20.     public static extern int screen_join_window_group(IntPtr window, string name);
  21.    
  22.     [DllImport("libscreen.so", EntryPoint="screen_destroy_window")]
  23.     public static extern int screen_destroy_window(IntPtr window);
  24.    
  25.     [DllImport("libscreen.so", EntryPoint="screen_destroy_context")]
  26.     public static extern int screen_destroy_context(IntPtr context);
  27.    
  28.     [DllImport("libscreen.so", EntryPoint="screen_set_window_property_iv")]
  29.     public static extern int screen_set_window_property_iv(IntPtr context, int pname, ref int param);
  30.    
  31.     // libbbads
  32.     [DllImport("libbbads.so", EntryPoint="bbads_banner_create")]
  33.     public static extern int bbads_banner_create(ref IntPtr banner, IntPtr window, string name, uint id);
  34.    
  35.     [DllImport("libbbads.so", EntryPoint="bbads_banner_set_size")]
  36.     public static extern int bbads_banner_set_size(IntPtr banner, uint width, uint height);
  37.    
  38.     [DllImport("libbbads.so", EntryPoint="bbads_banner_set_position")]
  39.     public static extern int bbads_banner_set_position(IntPtr banner, uint x, uint y);
  40.    
  41.     [DllImport("libbbads.so", EntryPoint="bbads_banner_load")]
  42.     public static extern int bbads_banner_load(IntPtr banner);
  43.    
  44.     [DllImport("libbbads.so", EntryPoint="bbads_banner_set_window_visible")]
  45.     public static extern int bbads_banner_set_window_visible(IntPtr banner);
  46.    
  47.     [DllImport("libbbads.so", EntryPoint="bbads_banner_display")]
  48.     public static extern int bbads_banner_display(IntPtr banner, IntPtr context, IntPtr _event);
  49.    
  50.     [DllImport("libbbads.so", EntryPoint="bbads_banner_is_visible")]
  51.     public static extern int bbads_banner_is_visible(IntPtr banner, ref int visible);
  52.    
  53.     // libbps
  54.     [DllImport("libbps.so", EntryPoint="bps_get_event")]
  55.     public static extern int bps_get_event(ref IntPtr _event, int timeout);
  56.    
  57.     [DllImport("libbps.so", EntryPoint="screen_get_domain")]
  58.     public static extern int screen_get_domain();
  59.    
  60.     [DllImport("libbps.so", EntryPoint="bps_event_get_domain")]
  61.     public static extern int bps_event_get_domain(IntPtr _event);
  62.    
  63.     [DllImport("libbps.so", EntryPoint="screen_event_get_event")]
  64.     public static extern IntPtr screen_event_get_event(IntPtr _event);
  65.    
  66.     [DllImport("libbps.so", EntryPoint="screen_get_event_property_iv")]
  67.     public static extern int screen_get_event_property_iv(IntPtr _screen_event, int name, ref int parm);
  68.    
  69.     [DllImport("libbps.so", EntryPoint="navigator_event_get_groupid")]
  70.     public static extern IntPtr navigator_event_get_groupid(IntPtr _event);
  71.    
  72.     [DllImport("libbps.so", EntryPoint="bps_event_get_code")]
  73.     public static extern uint bps_event_get_code(IntPtr _event);
  74.    
  75.     // libc
  76.     [DllImport("libc.so", EntryPoint="getpid")]
  77.     public static extern int getpid();
  78.    
  79.     const uint BANNER_TEST_ZONE_ID = 117145;
  80.     const uint BANNER_SIZE_X = 468;
  81.     const uint BANNER_SIZE_Y = 60;
  82.     const uint BANNER_POSITION_X = 180;
  83.     const uint BANNER_POSITION_Y = 150;
  84.    
  85.     const int SCREEN_PROPERTY_TYPE = 47;
  86.     const int SCREEN_EVENT_CREATE = 1;
  87.    
  88.     const int SCREEN_CHILD_WINDOW = 1;
  89.     const int SCREEN_EMBEDDED_WINDOW = 2;
  90.    
  91.     const uint NAVIGATOR_WINDOW_ACTIVE = 0x0a;
  92.     const uint NAVIGATOR_WINDOW_STATE = 0x03;
  93.     const uint NAVIGATOR_WINDOW_INACTIVE = 0x0b;
  94.    
  95.     const int SCREEN_APPLICATION_CONTEXT = 0;
  96.    
  97.     const int SCREEN_FORMAT_RGBA8888 = 8;
  98.     const int SCREEN_USAGE_NATIVE = (1 << 3);
  99.     const int SCREEN_PROPERTY_FORMAT = 14;
  100.     const int SCREEN_PROPERTY_USAGE = 48;
  101.    
  102.     IntPtr context = IntPtr.Zero, window = IntPtr.Zero;
  103.     IntPtr banner = IntPtr.Zero;
  104.    
  105.     void Update()
  106.     {
  107.         try
  108.         {
  109.             IntPtr _event = IntPtr.Zero;
  110.             bps_get_event(ref _event, -1);
  111.             if (_event != IntPtr.Zero)
  112.             {
  113.                 if (screen_get_domain() == bps_event_get_domain(_event))
  114.                 {
  115.                     int screen_val = 0;
  116.                    
  117.                     uint eventID = bps_event_get_code(_event);
  118.                     Debug.Log("eventID: " + eventID);
  119.                     if (eventID == NAVIGATOR_WINDOW_ACTIVE || eventID == NAVIGATOR_WINDOW_STATE || eventID == NAVIGATOR_WINDOW_INACTIVE)
  120.                     {
  121.                         IntPtr id = navigator_event_get_groupid(_event);
  122.                         Debug.Log("navigator_event_get_groupid: " + Marshal.PtrToStringAnsi(id));
  123.                     }
  124.                    
  125.                     IntPtr screenEvent = screen_event_get_event(_event);
  126.                     Debug.Log("screen_event_get_event: " + screenEvent);
  127.                     if (screenEvent == IntPtr.Zero) return;
  128.                     Debug.Log("screen_get_event_property_iv: " + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_TYPE, ref screen_val));
  129.                    
  130.                     Debug.Log("screen_val: " + screen_val);
  131.                     if (screen_val == SCREEN_EVENT_CREATE)
  132.                     {
  133.                         int visible = 0;
  134.                         Debug.Log("bbads_banner_is_visible: " + bbads_banner_is_visible(banner, ref visible));
  135.                         Debug.Log("visible: " + visible);
  136.                         if (visible == 0)
  137.                         {
  138.                             Debug.Log("bbads_banner_set_window_visible: " + bbads_banner_set_window_visible(banner));
  139.                             Debug.Log("bbads_banner_display: " + bbads_banner_display(banner, context, _event));
  140.                         }
  141.                     }
  142.                 }
  143.             }
  144.         }
  145.         catch (Exception e)
  146.         {
  147.             Debug.LogError(e.Message);
  148.         }
  149.     }
  150.    
  151.     void Start()
  152.     {
  153.         Debug.Log("STARTING...");
  154.         try
  155.         {
  156.             // get root window group id
  157.             int id = getpid();
  158.             string windowGroup = id.ToString();
  159.             Debug.Log("getpid: " + id);
  160.        
  161.             // create a screen to place ads in
  162.             Debug.Log("screen_create_context: " + screen_create_context(ref context, SCREEN_APPLICATION_CONTEXT));
  163.             Debug.Log("screen_create_window_type: " + screen_create_window_type(ref window, context, SCREEN_EMBEDDED_WINDOW));
  164.             //Debug.Log("screen_create_window_group: " + screen_create_window_group(window, windowGroup));
  165.             Debug.Log("screen_join_window_group: " + screen_join_window_group(window, windowGroup));
  166.            
  167.             int format = SCREEN_FORMAT_RGBA8888;
  168.             Debug.Log("screen_set_window_property_iv: " + screen_set_window_property_iv(window, SCREEN_PROPERTY_FORMAT, ref format));
  169.             int usage = SCREEN_USAGE_NATIVE;
  170.             Debug.Log("screen_set_window_property_iv: " + screen_set_window_property_iv(window, SCREEN_PROPERTY_USAGE, ref usage));
  171.            
  172.             // create ad banner
  173.             Debug.Log("bbads_banner_create: " + bbads_banner_create(ref banner, window, windowGroup, BANNER_TEST_ZONE_ID));
  174.             Debug.Log("bbads_banner_set_size: " + bbads_banner_set_size(banner, BANNER_SIZE_X, BANNER_SIZE_Y));
  175.             Debug.Log("bbads_banner_set_position: " + bbads_banner_set_position(banner, BANNER_POSITION_X, BANNER_POSITION_Y));
  176.             Debug.Log("bbads_banner_load: " + bbads_banner_load(banner));
  177.         }
  178.         catch (System.Exception e)
  179.         {
  180.             Debug.LogError("ERROR: " + e.Message);
  181.         }
  182.         Debug.Log("ENDING...");
  183.     }
  184.    
  185.     void OnDestroy()
  186.     {
  187.         Debug.Log("screen_destroy_window: " + screen_destroy_window(window));
  188.         Debug.Log("screen_destroy_context: " + screen_destroy_context(context));
  189.     }
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement