Berkelium plugin: rendering interactive websites

Discussion in 'Showcase' started by JeDi, Jul 6, 2010.

  1. chirhotec

    chirhotec

    New Member

    Joined:
    Mar 30, 2010
    Messages:
    39
    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

    New Member

    Joined:
    Mar 30, 2010
    Messages:
    39
    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

    New Member

    Joined:
    Oct 10, 2008
    Messages:
    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

    New Member

    Joined:
    Oct 10, 2008
    Messages:
    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

    New Member

    Joined:
    Oct 9, 2010
    Messages:
    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

    New Member

    Joined:
    Sep 27, 2010
    Messages:
    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

    Member

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

    chirhotec

    New Member

    Joined:
    Mar 30, 2010
    Messages:
    39
    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

    New Member

    Joined:
    Jun 16, 2010
    Messages:
    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

    New Member

    Joined:
    Oct 10, 2010
    Messages:
    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

    Member

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

    stubborngorilla

    New Member

    Joined:
    Oct 10, 2010
    Messages:
    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

    New Member

    Joined:
    Sep 14, 2010
    Messages:
    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

    Member

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

    Quickfingers

    Member

    Joined:
    Aug 29, 2009
    Messages:
    230
    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

    New Member

    Joined:
    Oct 10, 2010
    Messages:
    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

    New Member

    Joined:
    Sep 14, 2009
    Messages:
    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

    New Member

    Joined:
    Oct 10, 2010
    Messages:
    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

    New Member

    Joined:
    Feb 22, 2010
    Messages:
    34
    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

    New Member

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

    stubborngorilla

    New Member

    Joined:
    Oct 10, 2010
    Messages:
    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

    Member

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

    ulele

    New Member

    Joined:
    Dec 14, 2010
    Messages:
    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

    New Member

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

    ulele

    New Member

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

    Pinusi

    New Member

    Joined:
    Jan 9, 2011
    Messages:
    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. megmaltese

    megmaltese

    Member

    Joined:
    Mar 19, 2009
    Messages:
    1,897
    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. megmaltese

    megmaltese

    Member

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

    stubborngorilla

    New Member

    Joined:
    Oct 10, 2010
    Messages:
    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

    New Member

    Joined:
    Jan 9, 2011
    Messages:
    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

    New Member

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

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

    Pinusi

    New Member

    Joined:
    Jan 9, 2011
    Messages:
    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

    New Member

    Joined:
    Oct 10, 2010
    Messages:
    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

    New Member

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

    Pinusi

    New Member

    Joined:
    Jan 9, 2011
    Messages:
    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

    New Member

    Joined:
    Oct 10, 2010
    Messages:
    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

    New Member

    Joined:
    May 28, 2008
    Messages:
    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

    New Member

    Joined:
    Oct 10, 2010
    Messages:
    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

    New Member

    Joined:
    May 28, 2008
    Messages:
    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

    New Member

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

    Johannes5

    New Member

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

    benfattino

    Member

    Joined:
    Nov 26, 2010
    Messages:
    28
    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

    Member

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

    Thanks,

    Dan
  44. ytniu

    ytniu

    New Member

    Joined:
    Sep 19, 2011
    Messages:
    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

    New Member

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

    JeDi

    New Member

    Joined:
    Jun 16, 2010
    Messages:
    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

    Member

    Joined:
    Sep 22, 2005
    Messages:
    329
    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

    New Member

    Joined:
    Oct 25, 2011
    Messages:
    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

    New Member

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

    shaojingkk

    New Member

    Joined:
    Oct 25, 2011
    Messages:
    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