Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Berkelium plugin: rendering interactive websites

Discussion in 'Made With Unity' started by JeDi, Jul 6, 2010.

  1. chirhotec

    chirhotec

    Joined:
    Mar 30, 2010
    Posts:
    47
    Is there any other way of flipping the texture? I just realized that my fix with GUIUtility.ScaleAroundPivot is going to be hard to pull off when using GUILayout to create more fluid GUIs.
     
  2. chirhotec

    chirhotec

    Joined:
    Mar 30, 2010
    Posts:
    47
    Anyone get this to work in a Windows Build with Unity 3? I keep getting errors:

    Its saying it can't find the DLL, but the path its looking at is correct, and the dll shows up in that directory.
     
  3. deskchicken

    deskchicken

    Joined:
    Oct 10, 2008
    Posts:
    9

    Hi Chirhotec, I'm also using Unity 3, and am able to get the Berkelium Plugin to work within the editor, but I get the same error when attempting to build and run:

    DllNotFoundException: [full literal path to project Data folder]/Plugins/UnityBerkeliumPlugin.dll
    at (wrapper managed-to-native) UnityBerkelium:init ()
    at RenderWebsite.Start () [0x00000] in <filename unknown>:0

    The dll is indeed at that exact location. Anybody have any ideas?

    Update: solution below
     
    Last edited: Oct 22, 2010
  4. deskchicken

    deskchicken

    Joined:
    Oct 10, 2008
    Posts:
    9
    Chirhotec, I got it working... pilot error. I'm a bit of a n00b, so I can't say this is the best or intended solution, but I copied the contents (just the files, not the subfolders) of this folder:

    http://github.com/jdierckx/UnityBerkeliumPlugin/tree/master/test-release/

    into my executable's directory, and it worked. I had initially grabbed the contents of the Berkelium/bin directory - some of those dll's are different (older?). The contents linked above did it for me anyhow. Let me know if that works for you (maybe you've already figured it out anyway)

    [edited url and for clarity]
     
    Last edited: Oct 22, 2010
  5. santiainen

    santiainen

    Joined:
    Oct 9, 2010
    Posts:
    9
    Wait. Can i make what i've been planning for a long time for my game now... arcade masheens? That play flash games of course. Is THAT possible? O:
     
  6. xomg

    xomg

    Joined:
    Sep 27, 2010
    Posts:
    330
    This is amazing.

    This is evil.

    Hope to see scrolling support soon, as there's just a crazy amount of possibilities for this type of integration. Everybody who thought "adverts!" needs to throw themselves off a bridge, by the way. I'm serious.
     
  7. Vectrex

    Vectrex

    Joined:
    Oct 31, 2009
    Posts:
    267
    Ah but you forgot about racing games, when if you DON'T have ads it looks wrong and people complain :)
     
  8. chirhotec

    chirhotec

    Joined:
    Mar 30, 2010
    Posts:
    47
    Thanks for heads up. I did end up using the files from berkelium/bin, but pointing to their test-release made me realize I had been copying the files into the build's data directory, not the directory containing the executable. Once I put it in the right directory, it started working again.
     
  9. JeDi

    JeDi

    Joined:
    Jun 16, 2010
    Posts:
    52
    Wow, for some reason I don't get emails anymore when there are replies to this thread.

    Anyway, I'm afraid I won't have a lot of free time to work on this in the near future. I am busy with other projects, and decorating my home. Did anyone try adding multiple web views to one scene at the same time? Cause I didn't get around to create a decent test scene.

    The scrolling involves some more work because of how the texture updates work right now. We would have to store a separate buffer to do the scrolling in, which would increase memory usage a lot. It could be made optional of course. A workaround for now is adding a fixed element to your site, so that it always has to redraw the entire view when scrolling.

    Does anyone have a use case for scrolling sites inside a game anyway? Maybe for tutorial-like screens...

    Greetings,
    JeDi
     
  10. stubborngorilla

    stubborngorilla

    Joined:
    Oct 10, 2010
    Posts:
    22
    I went ahead and made a Mac framework version of berkelium, suitable for linking into a Unity plugin bundle (or any other use really). In case anyone is interested I've uploaded the framework here. You just need to add it to your plugin project as an existing framework and then make sure it's included in a "Copy Files" phase as a framework. Here's a screen cap of it working in the current test framework.

    -- edit ---

    if you downloaded the framework previous to seeing this message, it has been updated to fix a full path internal link issue and replace with relative links.
     

    Attached Files:

    Last edited: Nov 12, 2010
  11. Falin

    Falin

    Joined:
    Sep 29, 2009
    Posts:
    242
    that's great
     
  12. stubborngorilla

    stubborngorilla

    Joined:
    Oct 10, 2010
    Posts:
    22
    I made a fork of JeDi's git branch and updated the project to include the mac plugin alongside the windows version. I believe it is now resaved as a 3.1 project, in case that matters for anyone, but the old scene file should still work too. You can find the new branch here. If anyone downloads this and finds it working please let me know, as so far I've only tested on one machine.
     
  13. rasmusbs

    rasmusbs

    Joined:
    Sep 14, 2010
    Posts:
    12
    Looks very interesting. Have you got scrolling working? and how are you experiencing stability running berkelium?
    Keep up the good work!
     
  14. Vectrex

    Vectrex

    Joined:
    Oct 31, 2009
    Posts:
    267
    that's great. It'll be terrific to have a unified web solution
     
  15. Quickfingers

    Quickfingers

    Joined:
    Aug 29, 2009
    Posts:
    268
    stubborngorilla, tested your branch on my macbook pro, test project worked perfectly. Great to see this wonderful plugin working on mac too now
     
  16. stubborngorilla

    stubborngorilla

    Joined:
    Oct 10, 2010
    Posts:
    22
    Actually I did just get scrolling working. Not sure how performance is yet on larger scrolling windows, but seems to work fine on my 512x300 test window. I don't think it causes a memory issue either. I also found a bug in the dirty rect update code that may or may not appear outside of the scrolling case.

    Stability seems fine but I haven't really done a large amount of testing yet. Has this plugin been historically unstable for people?

    I will post my scrolling updates later this week after doing some more testing and possibly further development.
     
  17. AzulValium

    AzulValium

    Joined:
    Sep 14, 2009
    Posts:
    103
    Looks really great, since a long time ago I'm looking for something like this for win.

    What about the players or users, do they need install chrome or some libraries?

    Have you tested in web? :)
     
  18. stubborngorilla

    stubborngorilla

    Joined:
    Oct 10, 2010
    Posts:
    22
    Azul, it comes packaged with everything you need already other than a flash browser plugin.

    It's taking a bit longer to package up my updates than I anticipated, but if anyone is interested let me know and I'll try to get to it soon.
     
  19. rkite

    rkite

    Joined:
    Feb 22, 2010
    Posts:
    33
    Hey stubborngorilla, I would love to take a look at the package with scrolling working, I downloaded the one from here https://github.com/sgorilla/UnityBerkeliumPlugin but scrolling does not seem to work.

    Is there any chance I can get a look at a project with scrolling working? Thanks.
     
  20. rasmusbs

    rasmusbs

    Joined:
    Sep 14, 2010
    Posts:
    12
  21. stubborngorilla

    stubborngorilla

    Joined:
    Oct 10, 2010
    Posts:
    22
    I updated the git project with all my most recent changes, but it will probably take a bit of work on the part of anyone that wants to use this version as I didn't have time to package it up properly. I think the plugin API wrapper may be missing from my changes as well, but that should be easy to update.

    There are a lot of changes in RenderWebsite.cs and perhaps some in UnityBerkeliumPlugin.cpp that are probably too usage-specific, but may be useful to others. Here is a brief rundown:

    - texture is flipped to upright now
    - added an initial clear of the texture to prevent garbage frames before a website loads
    - added a hook to get called when a specific URL base is redirected in the browser. The returns the full URL which can be parsed for additional arguments, for example.
    - scrolling is implemented - this required a change inside the plugin .cpp file and to the RenderWebsite script to handle moving the scrolled pixels directly in the texture.
    - added a quick hack to allow for netsync mouse up and mouse down events
    - allow the cache directory to be passed in so that persistent cookies or other cache data can be taken advantage of if desired
    - added tab handling to the keyboard input
    - put in a delay before rendering the first page update, so that if you request a URL it doesn't draw until the "title" is returned. this is a bit hacky and not desired in all cases, so should be removed if not applicable.
    ...
    probably some others i'm forgetting

    This was only tested on mac, but if you need to use the windows plugin I don't see any reason why it would be platform-specific.

    Usual caveats of unsupported and no real time to help out apply, but if this helps you cool, enjoy!
     
  22. Vectrex

    Vectrex

    Joined:
    Oct 31, 2009
    Posts:
    267
    Cool thanks. Can this be merged with the original git project? It's getting confusing and fragmented which discourages cooperation I feel.
     
  23. BulberryMain

    BulberryMain

    Joined:
    Dec 14, 2010
    Posts:
    5
    stubborngorilla, thank for your great commitment!

    Can you please update "test-project/Assets/Plugins/UnityBerkelium.cs"? Win platform uses this file to access UnityBerkeliumPlugin, some methods (delegates?) are absent (like ScrollRectFunc used in RenderWebsite). My C-to-C# skills are not so complex to implement these functions.
     
  24. stubborngorilla

    stubborngorilla

    Joined:
    Oct 10, 2010
    Posts:
    22
    Done. No guarantees of course, but hopefully this helps you get something working.
     
  25. BulberryMain

    BulberryMain

    Joined:
    Dec 14, 2010
    Posts:
    5
    Thank you a lot! This helped me get something working really :)
     
  26. Pinusi

    Pinusi

    Joined:
    Jan 9, 2011
    Posts:
    24
    Hi everybody.
    Im' using the berkelium plugin on mac os. I managed to make it work but the mouse events, i can't still click the texture, it just get the keyboard events....Can somebody help me?
     
  27. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    So now we can finally render a website that plays a Unity web browser that plays a Unity web browser that plays a Unity web browser that plays a Unity web browser that plays a Unity web browser that plays a Unity web browser that plays a Unity web browser that plays a Unity web browser that plays a Unity web browser that plays a Unity...
     
  28. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    Joke apart, great stuff, I'm now just trying to figure out some useful applications for it :D
     
  29. stubborngorilla

    stubborngorilla

    Joined:
    Oct 10, 2010
    Posts:
    22
    Pinusi - there is a chance the current RenderWebsite.cs has a bug related to that, but there's no magic in it. Make sure you have a collider on the texture plane or if you are just intercepting mouse events, either way you just need to convert to x,y relative in the website/texture space and pass to Unity.Berkelium.Window.mouseXX
     
  30. Pinusi

    Pinusi

    Joined:
    Jan 9, 2011
    Posts:
    24
    I'm trying your project, that i downloaded...there is the mesh collider....

    This is the RenderWebsite.cs:
    Code (csharp):
    1. // Copyright (c) 2010 Jeroen Dierckx - Expertise Centre for Digital Media. All Rights reserved.
    2. // Part of this source code is developed for the flemish (Belgian) OSMA project (http://osma.phl.be/)
    3. //
    4. // Contributors (Unity forum usernames): reissgrant, agentdm
    5. //
    6. // Use of this source code is governed by a BSD-style license that can be
    7. // found in the LICENSE file.
    8.  
    9. using UnityEngine;
    10. using System;
    11. using System.Runtime.InteropServices;
    12. using System.Collections;
    13.  
    14. public class RenderWebsite : MonoBehaviour
    15. {
    16.     public int width = 512;
    17.     public int height = 512;
    18.     public string url = "http://www.google.com";
    19.     public string navHookUrl = "http://url_i_am_looking_for.com";
    20.     public bool interactive = true;
    21.     public bool transparency = false;
    22.     public bool waitForTitle = true;
    23.     public bool initBerkelium = true;
    24.    
    25.     private Texture2D m_Texture;
    26.     private Color[] m_Pixels;
    27.     private GCHandle m_PixelsHandle;
    28.     private int m_TextureID;
    29.     private bool m_BrowserReady;
    30.    
    31.     private bool m_IsGuiTexture;
    32.     private Rect texRect;
    33.     private float texScaleX;
    34.     private float texScaleY;
    35.     private Vector3 lastMousePos;
    36.    
    37.     private bool m_HookUrlWasRequested;
    38.     private string m_HookUrl;
    39.  
    40.     private UnityBerkelium.SetPixelsFunc m_setPixelsFunc;
    41.     private UnityBerkelium.ApplyTextureFunc m_applyTextureFunc;
    42.     private UnityBerkelium.ScrollRectFunc m_scrollRectFunc;
    43.     private UnityBerkelium.ExternalHostFunc m_externalHostFunc;
    44.     private UnityBerkelium.NavHookCb m_navHookCb;
    45.     private UnityBerkelium.LoadCb m_loadCb;
    46.    
    47.     private Component m_eventSubscriber;
    48.    
    49.    
    50.     void Start ()
    51.     {
    52.         if(initBerkelium)
    53.         {
    54.             string appDir = "/tmp/webcache";
    55.            
    56. #if UNITY_STANDALONE_OSX
    57.             appDir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
    58.             appDir = appDir + "/Library/Application Support/MyAppName/webcache";
    59. #endif
    60.            
    61. #if UNITY_STANDALONE_WIN           
    62.             appDir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData);
    63.             appDir = appDir + "/MyAppName/webcache";
    64. #endif
    65.            
    66.             System.IO.Directory.CreateDirectory(appDir);
    67.             Debug.Log(appDir);
    68.            
    69.             // Initialize Berkelium
    70.             UnityBerkelium.init(appDir);
    71.         }
    72.        
    73.         // Create the texture that will represent the website (with optional transparency and without mipmaps)
    74.         TextureFormat texFormat = transparency ? TextureFormat.ARGB32 : TextureFormat.RGB24;
    75.         m_Texture = new Texture2D (width, height, texFormat, false);
    76.  
    77.         // Create the pixel array for the plugin to write into at startup    
    78.         m_Pixels = m_Texture.GetPixels (0);
    79.         // "pin" the array in memory, so we can pass direct pointer to it's data to the plugin,
    80.         // without costly marshaling of array of structures.
    81.         m_PixelsHandle = GCHandle.Alloc(m_Pixels, GCHandleType.Pinned);
    82.  
    83.         // Save the texture ID
    84.         m_TextureID = m_Texture.GetInstanceID();
    85.        
    86.         // Improve rendering at shallow angles
    87.         m_Texture.filterMode = FilterMode.Trilinear;
    88.         m_Texture.anisoLevel = 2;
    89.        
    90.         // set us to initially not ready
    91.         m_BrowserReady = false;
    92.        
    93.         m_IsGuiTexture = false;
    94.        
    95.         m_HookUrlWasRequested = false;
    96.        
    97.         m_eventSubscriber = null;
    98.        
    99.         // init the texture
    100.         initTexturePixels();
    101.  
    102.         // Assign texture to the renderer
    103.         if (renderer)
    104.         {
    105.             renderer.material.mainTexture = m_Texture;
    106.            
    107.             // Transparency?
    108.             if(transparency)
    109.                 renderer.material.shader = Shader.Find("Transparent/Diffuse");
    110.             else
    111.                 renderer.material.shader = Shader.Find("Diffuse");
    112.            
    113.             renderer.enabled = false;
    114.         }
    115.         // or gui texture
    116.         else if (GetComponent(typeof(GUITexture)))
    117.         {
    118.             GUITexture gui = GetComponent(typeof(GUITexture)) as GUITexture;
    119.             gui.texture = m_Texture;
    120.             guiTexture.enabled = false;
    121.             m_IsGuiTexture = true;
    122.             texRect = gui.GetScreenRect();
    123.             texScaleX = texRect.width / width; //these two lines are important.
    124.             texScaleY = texRect.height / height; //they scale the screen position to match the same pixel on
    125.         }
    126.         else
    127.         {
    128.             Debug.Log("Game object has no renderer or gui texture to assign the generated texture to!");
    129.         }
    130.        
    131.         // Create new web window
    132.         UnityBerkelium.Window.create(m_TextureID, m_PixelsHandle.AddrOfPinnedObject(), transparency, width,height, url);
    133.         print("Created new web window: " + m_TextureID);
    134.        
    135.         // Paint callbacks
    136.         m_setPixelsFunc = new UnityBerkelium.SetPixelsFunc(this.SetPixels);
    137.         m_applyTextureFunc = new UnityBerkelium.ApplyTextureFunc(this.ApplyTexture);
    138.         m_scrollRectFunc = new UnityBerkelium.ScrollRectFunc(this.ScrollRect);
    139.         UnityBerkelium.Window.setPaintFunctions(m_TextureID, m_setPixelsFunc, m_applyTextureFunc, m_scrollRectFunc);
    140.        
    141.         // Set the external host callback (for calling Unity functions from javascript)
    142.         m_externalHostFunc = new UnityBerkelium.ExternalHostFunc(this.onExternalHost);
    143.         UnityBerkelium.Window.setExternalHostCallback(m_TextureID, m_externalHostFunc);
    144.        
    145.         // Set the navigation callbacks
    146.         m_navHookCb = new UnityBerkelium.NavHookCb(this.onNavHook);
    147.         m_loadCb = new UnityBerkelium.LoadCb(this.onLoad);
    148.         UnityBerkelium.Window.setNavigationFunctions(m_TextureID, navHookUrl, m_navHookCb, m_loadCb);
    149.     }
    150.    
    151.     void SetPixels(/*int left, int top, int width, int height*/)
    152.     {
    153.         UnityBerkelium.Rect rect = UnityBerkelium.Window.getLastDirtyRect(m_TextureID);
    154.         //print("Painting rect: (" + rect.left + ", " + rect.top + ", " + rect.width + ", " + rect.height + ")");
    155.         m_Texture.SetPixels(rect.left, rect.top, rect.width, rect.height, m_Pixels, 0);
    156.     }
    157.    
    158.     void ApplyTexture()
    159.     {
    160.         //print("Applying texture");
    161.         m_Texture.Apply();
    162.     }
    163.    
    164.     void ScrollRect(int left, int top, int width, int height, int dx, int dy)
    165.     {
    166.         //print("Scroll rect: " + left + ", " + top + ", " + width + ", " + height);
    167.        
    168.         Color[] scrollPixels = m_Texture.GetPixels (left, top, width, height);
    169.            
    170.         m_Texture.SetPixels(left + dx, top + dy, width, height, scrollPixels, 0);
    171.     }
    172.  
    173.     void onExternalHost(/*string message*/)
    174.     {
    175.         string message = Marshal.PtrToStringUni(UnityBerkelium.Window.getLastExternalHostMessage(m_TextureID));
    176.         print("Message from javascript: " + message);
    177.        
    178.         // Broadcast the message
    179.         SendMessage("OnExternalHost", message, SendMessageOptions.DontRequireReceiver);
    180.  
    181.         // Parse the JSON object
    182.         object parsedObject = JSON.JsonDecode(message);
    183.         if(parsedObject is Hashtable)
    184.         {
    185.             Hashtable table = (Hashtable) parsedObject;
    186.            
    187.             string func = (string) table["func"];
    188.             Hashtable args = (Hashtable) table["args"];
    189.            
    190.             print("  function: " + func);
    191.             print("  #arguments: " + args.Count);
    192.            
    193.             IDictionaryEnumerator enumerator = args.GetEnumerator();
    194.             while(enumerator.MoveNext())
    195.                 print("  " + enumerator.Key.ToString() + " = " + enumerator.Value.ToString());
    196.            
    197.             // Broadcast the function
    198.             SendMessage(func, args, SendMessageOptions.DontRequireReceiver);
    199.         }
    200.     }
    201.    
    202.     void onNavHook(string url)
    203.     {
    204.         if(m_eventSubscriber)
    205.         {
    206.             m_eventSubscriber.SendMessage("onNavHook", url);
    207.         }
    208.        
    209.         m_HookUrl = url;
    210.         m_HookUrlWasRequested = true;
    211.         if(m_IsGuiTexture)
    212.         {
    213.             guiTexture.enabled = false;
    214.         }
    215.         else
    216.         {
    217.             renderer.enabled = false;
    218.         }      
    219.     }
    220.  
    221.     void onLoad(string url)
    222.     {
    223.         if(m_BrowserReady || UnityBerkelium.Window.everReceivedTitleUpdate(m_TextureID) || (waitForTitle == false))
    224.         {
    225.             if(m_IsGuiTexture)
    226.             {
    227.                 guiTexture.enabled = true;
    228.             }
    229.             else
    230.             {
    231.                 renderer.enabled = true;
    232.             }
    233.             m_BrowserReady = true;
    234.         }
    235.     }
    236.  
    237.     void OnDisable() {
    238.         // Destroy the web window
    239.         UnityBerkelium.Window.destroy(m_TextureID);
    240.        
    241.         // Free the pinned array handle.
    242.         m_PixelsHandle.Free();
    243.     }
    244.    
    245.    
    246.  
     

    Attached Files:

  31. Pinusi

    Pinusi

    Joined:
    Jan 9, 2011
    Posts:
    24
    Code was too long... Here's the rest...

    Code (csharp):
    1. void OnApplicationQuit()
    2.     {
    3.         // Destroy Berkelium
    4.         //UnityBerkelium.destroy();
    5.         //print("Destroyed Berkelium");
    6.     }
    7.  
    8.     void Update ()
    9.     {
    10.         // Update Berkelium
    11.         // TODO This only has to be done once in stead of per object
    12.         UnityBerkelium.update();
    13.     }
    14.    
    15.     void OnMouseEnter()
    16.     {
    17.     }
    18.    
    19.     void OnMouseExit()
    20.     {
    21.     }
    22.    
    23.     void TestMouseOver()
    24.     {
    25.         // Only when interactive is enabled
    26.         if(!interactive)
    27.             return;
    28.        
    29.         bool eventActive = false;
    30.         int x = 0, y = 0;
    31.        
    32.         if(m_IsGuiTexture)
    33.         {
    34.             eventActive = texRect.Contains(Input.mousePosition);
    35.             float offset_x = Input.mousePosition.x - texRect.xMin; //Find the mouse position
    36.             float offset_y = height - (Input.mousePosition.y - texRect.yMin); //Find the mouse position
    37.  
    38.             x = (int)(offset_x / texScaleX);
    39.             y = (int)(offset_y / texScaleY);
    40.         }
    41.         else
    42.         {
    43.             RaycastHit hit;
    44.             if (Physics.Raycast (Camera.main.ScreenPointToRay(Input.mousePosition), out hit)  hit.transform == this.transform)
    45.             {
    46.                 eventActive = true;
    47.                 x = /*width -*/ (int) (hit.textureCoord.x * width);
    48.                 y = height - (int) (hit.textureCoord.y * height);
    49.             }
    50.         }
    51.        
    52.         if(eventActive)
    53.         {
    54.             networkView.RPC ("BerkeliumMouseOver", RPCMode.All, x, y);
    55.         }
    56.     }
    57.    
    58.     void TestMouseDown()
    59.     {
    60.         // Only when interactive is enabled
    61.         if(!interactive)
    62.             return;
    63.        
    64.         bool eventActive = false;
    65.         int x = 0, y = 0;
    66.        
    67.         if(m_IsGuiTexture)
    68.         {
    69.             eventActive = texRect.Contains(Input.mousePosition);
    70.             float offset_x = Input.mousePosition.x - texRect.xMin; //Find the mouse position
    71.             float offset_y = height - (Input.mousePosition.y - texRect.yMin); //Find the mouse position
    72.  
    73.             x = (int)(offset_x / texScaleX);
    74.             y = (int)(offset_y / texScaleY);
    75.         }
    76.         else
    77.         {
    78.             RaycastHit hit;
    79.             if (Physics.Raycast (Camera.main.ScreenPointToRay(Input.mousePosition), out hit)  hit.transform == this.transform)
    80.             {
    81.                 eventActive = true;
    82.                 x = /*width -*/ (int) (hit.textureCoord.x * width);
    83.                 y = height - (int) (hit.textureCoord.y * height);
    84.             }
    85.         }
    86.        
    87.         if(eventActive)
    88.         {
    89.             networkView.RPC ("BerkeliumMouseDown", RPCMode.All, x, y);
    90.         }
    91.     }
    92.    
    93.     void TestMouseUp()
    94.     {
    95.         // Only when interactive is enabled
    96.         if(!interactive)
    97.             return;
    98.  
    99.         bool eventActive = false;
    100.         int x = 0, y = 0;
    101.        
    102.         if(m_IsGuiTexture)
    103.         {
    104.             eventActive = texRect.Contains(Input.mousePosition);
    105.             float offset_x = Input.mousePosition.x - texRect.xMin; //Find the mouse position
    106.             float offset_y = height - (Input.mousePosition.y - texRect.yMin); //Find the mouse position
    107.  
    108.             x = (int)(offset_x / texScaleX);
    109.             y = (int)(offset_y / texScaleY);
    110.         }
    111.         else
    112.         {
    113.             RaycastHit hit;
    114.             if (Physics.Raycast (Camera.main.ScreenPointToRay(Input.mousePosition), out hit)  hit.transform == this.transform)
    115.             {
    116.                 eventActive = true;
    117.                 x = /*width -*/ (int) (hit.textureCoord.x * width);
    118.                 y = height - (int) (hit.textureCoord.y * height);
    119.             }
    120.         }
    121.        
    122.         if(eventActive)
    123.         {
    124.             networkView.RPC ("BerkeliumMouseUp", RPCMode.All, x, y);
    125.         }
    126.     }
    127.    
    128.     void OnGUI()
    129.     {
    130.         if(!interactive) return;
    131.        
    132.         if(Vector3.Distance(Input.mousePosition, lastMousePos) >= 2)
    133.         {
    134.             lastMousePos = Input.mousePosition;
    135.             TestMouseOver();
    136.         }
    137.        
    138.         if(Event.current == null) return;
    139.        
    140.         // Inject input into the page when the GUI doesn't have focus
    141.         if(Event.current.isKey  GUIUtility.keyboardControl == 0)
    142.         {
    143.             KeyCode key = Event.current.keyCode;
    144.             bool pressed = (Event.current.type == EventType.KeyDown);
    145.            
    146.             if(key == KeyCode.Return)
    147.             {
    148.                 UnityBerkelium.Window.keyEvent(m_TextureID, pressed, 0, 13, 0);
    149.                 return;
    150.             }
    151.            
    152.             // Insert character
    153.             UnityBerkelium.Window.textEvent(m_TextureID, Event.current.character);
    154.            
    155.             // Special case for backspace or tab
    156.             if(key == KeyCode.Backspace)
    157.                 UnityBerkelium.Window.keyEvent(m_TextureID, pressed, 0, 08, 0);
    158.             else if(key == KeyCode.Tab)
    159.                 // shift mod is 1 << 0
    160.                 UnityBerkelium.Window.keyEvent(m_TextureID, pressed, Event.current.shift ? 1 : 0, 09, 0);
    161.            
    162.             // TODO Handle all keys
    163.             /*int mods = 0;
    164.             int vk_code = UnityBerkelium.convertKeyCode(Event.current.keyCode);
    165.             int scancode = 0;
    166.             UnityBerkelium.Window.keyEvent(m_TextureID, pressed, mods, vk_code, scancode);
    167.             print("Key event: " + pressed + ", " + Event.current.keyCode);*/
    168.         }
    169.         else
    170.         {
    171.             switch (Event.current.type)
    172.             {
    173.                 case EventType.MouseDown:
    174.                     TestMouseDown();
    175.                     break;
    176.  
    177.                 case EventType.MouseUp:
    178.                     TestMouseUp();
    179.                     break;
    180.             }
    181.         }
    182.     }
    183.    
    184.     void initTexturePixels()
    185.     {
    186.         int mipCount = Mathf.Min( 3, m_Texture.mipmapCount );
    187.        
    188.         // tint each mip level
    189.         for( int mip = 0; mip < mipCount; ++mip ) {
    190.             Color[] cols = m_Texture.GetPixels( mip );
    191.             for( int i = 0; i < cols.Length; ++i ) {
    192.                 cols[i] = new Color( 0, 0, 0 );
    193.             }
    194.             m_Texture.SetPixels( cols, mip );
    195.         }
    196.        
    197.         // actually apply all SetPixels, don't recalculate mip levels
    198.         m_Texture.Apply( false );
    199.     }
    200.    
    201.     public string getHookUrl()
    202.     {
    203.         return m_HookUrl;
    204.     }
    205.    
    206.     public bool hookUrlWasRequested()
    207.     {
    208.         return m_HookUrlWasRequested;
    209.     }
    210.    
    211.     public void navigateTo(string url)
    212.     {
    213.         print("Changing url to " + url);
    214.         UnityBerkelium.Window.navigateTo(m_TextureID, url);
    215.     }
    216.    
    217.     public void subscribeForEvents(Component eventSubscriber)
    218.     {
    219.         m_eventSubscriber = eventSubscriber;
    220.     }
    221.  
    222.     public void executeJavascript(string javascript)
    223.     {
    224.         print("Executing Javascript: " + javascript);
    225.         UnityBerkelium.Window.executeJavascript(m_TextureID, javascript);
    226.     }
    227.    
    228.     public Texture2D getTexture()
    229.     {
    230.         return m_Texture;
    231.     }
    232.  
    233.     [RPC]
    234.     void BerkeliumMouseUp(int x, int y)
    235.     {
    236.         UnityBerkelium.Window.mouseMove(m_TextureID, x, y);
    237.         UnityBerkelium.Window.mouseUp(m_TextureID, 0);
    238.     }
    239.    
    240.     [RPC]
    241.     void BerkeliumMouseDown(int x, int y)
    242.     {
    243.         // Focus the window
    244.         UnityBerkelium.Window.focus(m_TextureID);
    245.    
    246.         UnityBerkelium.Window.mouseMove(m_TextureID, x, y);
    247.         UnityBerkelium.Window.mouseDown(m_TextureID, 0);
    248.     }
    249.    
    250.     [RPC]
    251.     void BerkeliumMouseOver(int x, int y)
    252.     {
    253.         UnityBerkelium.Window.mouseMove(m_TextureID, x, y);
    254.     }
    255. }
     
  32. Pinusi

    Pinusi

    Joined:
    Jan 9, 2011
    Posts:
    24
    I think maybe its' because of the error Unity gives me.
    It says:

    MissingComponentException: There is no 'NetworkView' attached to the "Plane" game object, but a script is trying to access it.
    You probably need to add a NetworkView to the game object "Plane". Or your script needs to check if the component is attached before using it.
    UnityEngine.NetworkView.RPC (System.String name, RPCMode mode, System.Object[] args)
    RenderWebsite.TestMouseOver () (at Assets/Scripts/RenderWebsite.cs:298)
    RenderWebsite.OnGUI () (at Assets/Scripts/RenderWebsite.cs:379)

    When I attach a Network view, it says:

    Can't send RPC function since no connection was started.
    UnityEngine.NetworkView:RPC(String, RPCMode, Object[])
    RenderWebsite:TestMouseUp() (at Assets/Scripts/RenderWebsite.cs:368)
    RenderWebsite:OnGUI() (at Assets/Scripts/RenderWebsite.cs:422)
     
  33. stubborngorilla

    stubborngorilla

    Joined:
    Oct 10, 2010
    Posts:
    22
    That makes sense. I had to fix that bug in another branch. The easiest thing to do is just remove the network view altogether and then inside the if(eventactive) test you can change it to directly call the handler functions instead of rpc calling them.
     
  34. Pinusi

    Pinusi

    Joined:
    Jan 9, 2011
    Posts:
    24
    GREAT!
    Now everything's working!
    Thank u so much!
     
  35. Pinusi

    Pinusi

    Joined:
    Jan 9, 2011
    Posts:
    24
    stubborngorilla I tryed to trigger the RenderWebsite function, and I wrote a code like this below, and I attached it to another Gameobject, a cube with a mesh collider that i triggered.
    Code (csharp):
    1. var GameO: GameObject;
    2.  
    3. function OnTriggerEnter()
    4. {
    5.     print("Fatto");
    6.     //GameC=GameO.GetComponent("RenderWebsiteTrigger");
    7.     GameO.GetComponent("RenderWebsiteTrigger").Parti=true;
    8.     //print(GameO.GetComponent("RenderWebsiteTrigger").Parti);
    9.     GameO.GetComponent("RenderWebsiteTrigger").Start();
    10.    
    11. }
    12.  
    13. function OnTriggerExit()
    14. {
    15.     print("Uscita");
    16.     //GameC=GameO.GetComponent("RenderWebsiteTrigger");
    17.     //GameO.GetComponent("RenderWebsiteTrigger").Parti=false;
    18.     GameO.GetComponent("RenderWebsiteTrigger").Stop();
    19.     //GameO.GetComponent("RenderWebsiteTrigger").Update();
    20.    
    21. }
    then I modify the RenderWebsite code adding:

    Code (csharp):
    1.  void Start()
    2.     {
    3.         //Parti=true;
    4.         if(Parti){
    5.         if(initBerkelium)
    6.         {
    This at the beginning below the classic start and this function:

    Code (csharp):
    1.  void Stop(){
    2.         Parti=false;
    3.         // Destroy the web window
    4.         UnityBerkelium.Window.destroy(m_TextureID);
    5.        
    6.         // Free the pinned array handle.
    7.         m_PixelsHandle.Free();
    8.        
    9.         // Assign texture to the renderer
    10.         if (renderer)
    11.         {
    12.             renderer.material.mainTexture = null;
    13.            
    14.                 }
    15.         // or gui texture
    16.         else if (GetComponent(typeof(GUITexture)))
    17.         {
    18.             GUITexture gui = GetComponent(typeof(GUITexture)) as GUITexture;
    19.             gui.texture = null;
    20.            
    21.         }
    22.         else
    23.         {
    24.             Debug.Log("Game object has no renderer or gui texture to assign the generated texture to!");
    25.         }
    26.  
    27.        
    28.  
    29.        
    30.        
    31.         }
    32.  
    But Unity crashes everytime....
    Better, if I have my project open and I reada every function it works, If I open the project with all the function set it crashes, it also crashes when i build it.
    What's the mistake? Can u help me?
     
  36. stubborngorilla

    stubborngorilla

    Joined:
    Oct 10, 2010
    Posts:
    22
    afraid I don't have an answer for that and not much time to help out here these days. my guess would be stop getting called multiple times or something else going on with the m_PixelHandle.Free call, but it really could be any number of things. shouldn't be too bad to debug it given that you haven't changed much to cause the issue. let us know if you find a bug in the RenderWebsite script or the plugin.
     
  37. Johannes5

    Johannes5

    Joined:
    May 28, 2008
    Posts:
    11
    I tried to get this working: github -> sgorilla / UnityBerkeliumPlugin, but it does not seem to work under windows (some entry points are missing). I tried to compile the UnityBerkeliumPlugin with VS2008 but I get strange compiler errors. Do you have a windows version where scrolling works? Does scrolling work without the missing entry points?
    regards
    Johannes
     
  38. stubborngorilla

    stubborngorilla

    Joined:
    Oct 10, 2010
    Posts:
    22
    View attachment $UnityBerkeliumPlugin.dll.zip

    I believe this works with the berekelium 10/31/2010 executable and dll I found on one of the original contributor's github sites.

    Can't remember if I had to change anything to compile it but it seemed to work ok for me. I used VC 2010 express.
     
  39. Johannes5

    Johannes5

    Joined:
    May 28, 2008
    Posts:
    11
    Hi,
    thanks for the quick response. It does run now! BUT scrolling does not really seem to work (windows). Sometimes it scrolls, sometimes not, most of the time the executable crashes.
    BTW if you copy the Berkelium/bin content in the root of the Unity Project (here: test-project) it does seem to work in the editor.
     
  40. Johannes5

    Johannes5

    Joined:
    May 28, 2008
    Posts:
    11
    Do I have to change the RenderWebsite.cs to get scrolling to work?
     
  41. Johannes5

    Johannes5

    Joined:
    May 28, 2008
    Posts:
    11
    But it still is so cool ... good work!
     
  42. benfattino

    benfattino

    Joined:
    Nov 26, 2010
    Posts:
    43
    Great work. I will try to use this plugin. I have three questions:
    1 - What is the best version I can download? In the post there is 3-4 different version...
    2 - It's work on web version of unity?
    3 - Scroll? :-(
    Thanks.
     
    Last edited: Aug 9, 2011
  43. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    510
    Will any of these work on the iphone or any other system besides windows?

    Thanks,

    Dan
     
  44. ytniu

    ytniu

    Joined:
    Sep 19, 2011
    Posts:
    2
    If you read the whole thread you'll find that the plugin warks under mac.

    And if you read it carefully you'll find 2 versions. https://github.com/jdierckx/UnityBerkeliumPlugin and the second one where the mac plugin was added scroll fixed.
     
  45. ytniu

    ytniu

    Joined:
    Sep 19, 2011
    Posts:
    2
  46. JeDi

    JeDi

    Joined:
    Jun 16, 2010
    Posts:
    52
    Hi,

    Awesomium is free for indy development nowadays, and they are working on an official Unity plugin. Check this: http://support.awesomium.com/discussions/questions/32-awesomium-and-unity-3d-possible

    I'm afraid I still don't have, and won't have in the near future, time to work on this plugin. Other people did their best to keep it a bit up-to-date, for which I am very gratefull. But because of the lack of support, and because Awesomium works pretty darn good, you should check it out.

    Greetings,
    JeDi
     
  47. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    510
    Awesomium is 2900 dollars. Plus it won't run on the iphone. Do you know why? Something about chromium can't run on iphone???


    Dan
     
  48. shaojingkk

    shaojingkk

    Joined:
    Oct 25, 2011
    Posts:
    10
    Hi, I want to use this plugin under mac. I check out code in github, and in runtime, it shows error: "DllNotFoundException: UnityBerkeliumPlugin".
    the second one which work for mac, and scroll fixed is the zip package under this thread?
     
  49. shaojingkk

    shaojingkk

    Joined:
    Oct 25, 2011
    Posts:
    10
  50. shaojingkk

    shaojingkk

    Joined:
    Oct 25, 2011
    Posts:
    10
    I got a problem. Marshal.PtrToStringUni(UnityBerkelium.Window.getLastExternalHostMessage(m_TextureID))
    this always return the first character, does any one meet this problem?
    Can anyone help? thanks