GithubHelp home page GithubHelp logo

tunerok / unity_browser Goto Github PK

View Code? Open in Web Editor NEW
96.0 7.0 22.0 99.03 MB

Open source Unity3d web browser created by Vitaly Chashin https://bitbucket.org/vitaly_chashin/simpleunitybrowser

License: GNU General Public License v3.0

HTML 2.58% C# 90.60% CSS 4.97% JavaScript 1.85%
unity-browser unity3d browser

unity_browser's Introduction

unity_browser

Open source Unity3d web browser created by Vitaly Chashin https://bitbucket.org/vitaly_chashin/simpleunitybrowser and fixed buld crashes by Stulov Dmitry https://bitbucket.org/ShadowTeolog/simpleunitybrowser.

Basic setup

Import the package to Unity or just open test.unity file. There will be a few folders in Assets/SimpleWebBrowser. You can move/rename all of them, but in case of Assets/SimpleWebBrowser/PluginServer you will need to change the runtime and deployment paths in Scripts/BrowserEngine.cs and in Editor/BrowserPostBuild.cs:

 public void InitPlugin(int width, int height, string sharedfilename, int port, string initialURL)
        {

            //Initialization (for now) requires a predefined path to PluginServer,
            //so change this section if you move the folder
            //Also change the path in deployment script.

#if UNITY_EDITOR_64
            string PluginServerPath = Application.dataPath + @"\SimpleWebBrowser\PluginServer\x64";
#else
#if UNITY_EDITOR_32
        string PluginServerPath = Application.dataPath + @"\SimpleWebBrowser\PluginServer\x86";

The package contains two demo scenes, for the inworld and canvas browser; you can use them as a reference, or just drag one of the prefabs to the scene.

Settings

browser_settings

  • Width and height - width and height of the browser texture.
  • Memory file and Port - in general, you can keep them random. Memory file is the name of a shared memory file, which is used to send the texture data, and port is a TCP port for the communication between browser and plugin. In case of random, memory file will be a random GUID, and a port will be between 8000 and 9000. But you can set them manually, if you want.
  • Initial URL - obviously, the initial browser URL.
  • WebRTC - enable/disable WebRTC support.
  • UI settings - settings for the main browser controls. You can customize them the way you like, changing they appearance in editor and behaviour in BrowserUI.cs.
  • Dialog settings - same as UI, but for modal dialogs.
  • 2D browser setup is almost the same, except the Browser2D raw image texture setting, which is the base texture for browser.

Deployment

The plugin works for Win32/64, both in editor and in app. The post-build step is automated, it creates a folder named PluginServer in your output folder. You can change this, for example, put the PluginServer into the Data folder, but in such case you need to change the deployment paths (see Basic Setup).

JavaScript integration

Currently you can execute any JS code in the browser window by calling WebBrowser.RunJavaScript(string js) and send the message from the web page (see Demo/SampleJSQueryHandler.cs). On JavaScript side, you need code like this:

// Send a query to the browser process.
function sendMessage() {
  window.cefQuery({
    request: 'BindingTest:' + document.getElementById("message").value,
    onSuccess: function(response) {
      document.getElementById('result').value = 'Response: '+response;
    },
    onFailure: function(error_code, error_message) {}
  });
}

See BindingTest.html for an example.

Building the PluginServer from the repository

You can build the plugin server from scratch, for example, if you want to change something in communication or page rendering.

Folder structure:

  • MessageLibrary - an implementation of communication protocol
  • packages - nuget folder
  • SharedPluginServer - the main project
  • TestClient - WinForms client for tests. Warning - the code is not cleaned up, not commented, etc.
  • third_party - prebuilt libraries used in project
    • cef_64 - CEF x64 runtime
    • cef_86 - CEF x86 runtime
    • SharedMemory_86 - SharedMemory.dll for x86 builds
    • SharedMemory_86_Unity - SharedMemory.dll for Unity x86
    • SharedMemory_Unity - SharedMemory for Unity x64
    • log4net.dll
    • SharedMemory.dll - the base x64 SharedMemory realization
    • Xilium.CefGlue.dll
  • UnityClient - the main Unity project.

Building the main solution

In general, just build it. By default it set to Debug/x64; in case of building it for x86, you need to remove the references to third_party\SharedMemory.dll from SharedPluginServer and TestClient, and add the references to third_party\SharedMemory_86\SharedMemory.dll.

Testing and debugging

Set the TestClient as the startup project. Change the path to SharedPluginServer in Form1.cs:

Process pluginProcess = new Process()
            {
                StartInfo = new ProcessStartInfo()
                {
                    WorkingDirectory =
                        //  @"D:\work\unity\StandaloneConnector\SharedPluginServerClean\UnityClient\Output\x86\PluginServer",
                        @"D:\work\unity\StandaloneConnector\SimpleUnityBrowser\SharedPluginServer\bin\x64\Debug",
                    FileName =
                     //@"D:\work\unity\StandaloneConnector\SharedPluginServerClean\UnityClient\Output\x86\PluginServer\SharedPluginServer.exe",
                        @"D:\work\unity\StandaloneConnector\SimpleUnityBrowser\SharedPluginServer\bin\x64\Debug\SharedPluginServer.exe",
                    Arguments = args

                }
            };

Copy the CEF runtime from the appropriate folder in third_party to the SharedPluginServer output folder, and run the TestClient. It may crash for the first time (when Windows asks for network access), but after that it should work fine.

unity_browser's People

Contributors

tunerok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

unity_browser's Issues

Localhost browser

Hello,
Thank you for this plugin I just want to ask how to apply it to a server that is running locally for example Localhost:4200 instead of google for initial URL. and thank you

Browser2D not working

Thanks for the package, but Browser2D not work for me .No error occurs. Does anyone know

SharedCommServer could not be found

I cloned the latest repo and open it with VS2019.
Also added DLLs from third_party as dependencies however I couldn't compile the project and got the following error msg.

Error CS0246 The type or namespace name 'SharedCommServer' could not be found (are you missing a using directive or an assembly reference?)

linear color space problem

hi
until stay on gamma color space everything is fine but when i am going to use linear color space browser 2d (raw image) will be too bright and this is happening on both demo scenes . any advice to solve this problem will be appreciated cause its not usable like this .
thank you

Mouse Click events on a webpage

Hello, I'm creating a project where I can control the webpage content using hand tracking mouse control. So I'm adding mouse simulations (drag, click....) using the "StandaloneInputModule". The click simulation for example is working with MainUI toolbar, I can click on back and forward using mouse click event simulation. But when working on the content of the webpage like Google Earth I can't control it because it is not set as a RayCast target (clickable events). So my question is where can I find in this plugin the settings for the webpage content, so I can set the content as RayCast target. i added a screenshot for my project's architecture.

PI - SampleScene - PC, Mac   Linux Standalone - Unity 2020 3 4f1 Personal DX11 4_25_2021 8_49_10 AM (2)

Thank You.

"Space spacing" issue

First Thank you for your "unity browser engine".

I build a Window program with this package in Unity.
When the program's path has a ' '(Space character), it doesn't start a plugin process...
But if this program's path doesn't have a ' '(Space character), it start a plugin process and do very well!!

How can I fix it for program which has a ' '(Space character)??

Thanks

Trying to use this to sign into google

Hello! As above I'm trying to use this to sign into google but on login it says "Cannot sign in, this browser may not be secure" is there anything I can do to make this work?
This is the exact error
image

loading CSS

Hello. Thank you for this plugin. I just have a question, how can I override the External CSS?

I'd like to use the js initialization code to load StreamingAssets/CSS files if that's possible, does anyone know?

How can I capture network requests?

I’ve tried using SampleDynamicRequestHandler, but this doesn’t seem to get called. I’ve also tried using OnJsQuery, but this also doesn’t seem to get called.

Is there a way to capture the browser’s queries to and responses from the server?

Thank you

mouse buttons not working on windows build

hi again!
the mouse are completely functionally on editor (no problem at all) but on windows build mouse pointer are there and move around but all three buttons not working i'm using unity 2019.4.17.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.