{"id":19281257,"url":"https://github.com/zouloux/unity-web-view","last_synced_at":"2025-04-22T01:30:56.441Z","repository":{"id":106856601,"uuid":"125541386","full_name":"zouloux/unity-web-view","owner":"zouloux","description":"Allow making hybrid Unity apps, based on web technologies. Windows, MacOS, Android and iOS compatible. With a communication gateway between Unity and Javascript.","archived":false,"fork":false,"pushed_at":"2018-03-20T10:36:29.000Z","size":15,"stargazers_count":26,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-01T17:53:12.075Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zouloux.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-16T16:20:46.000Z","updated_at":"2025-03-25T14:18:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"cb7cca1d-6956-45b1-8d7e-0df9886d4a53","html_url":"https://github.com/zouloux/unity-web-view","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zouloux%2Funity-web-view","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zouloux%2Funity-web-view/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zouloux%2Funity-web-view/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zouloux%2Funity-web-view/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zouloux","download_url":"https://codeload.github.com/zouloux/unity-web-view/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250161941,"owners_count":21385012,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T21:22:09.824Z","updated_at":"2025-04-22T01:30:56.429Z","avatar_url":"https://github.com/zouloux.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unity WebView\n\nAllow making hybrid Unity apps, based on web technologies.\nWindows, MacOS, Android and iOS compatible.\nWith a communication gateway between Unity and Javascript.\n\n\n# Usage\n\nThis will allow a transparent WebView to be on top of Unity graphics, and will manage communication between Javascript and Unity runtime.\nPerformances are pretty good on iOS and Android.\n\n\n# The WebView\n\nThe WebView part is from [this unity package](https://github.com/gree/unity-webview).\nTo enable WebView capabilites, [download it](https://github.com/gree/unity-webview/blob/master/dist/unity-webview.unitypackage?raw=true) and install it into your Unity project.\n\n\n# The WebView installer\n\nTo be able to use web view properly, html and other assets have to be copied to the device.\nThis is done automatically by `WebViewComponent.cs`.\n\n### Installation\n\n1. Copy `WebViewComponent.cs` into `Assets/App/Scripts/`\n2. Create a new GameObject into your Unity scene.\n3. Select `WebViewComponent` as a new behavior.\n4. Enter web files to be copied on the device.\n5. Keep `index.html` on top so it's automatically loaded on startup.\n\nWeb files will be copied from `Assets/StreamingAssets/webview/`.\nKeep a flat file system (no folders).\n\n\n# The Gateway\n\nThe communication Gateway is a javascript file to load from the WebView. This file is available as an [ES6 javascript module](https://github.com/zouloux/unity-web-view/blob/master/UnityGateway.js) and is also available if you use [Solidify lib](https://github.com/solid-js/solidify).\n\n\n### Communicate from Javascript to Unity\n\n#### In Unity\n\nEdit directly method `messageFromWebView` into `WebViewComponent.cs` (at line 120) to implement your actions into Unity.\n\nFor ex :\n```\nif (pParameters[0] == @\"myAction\")\n{\n\tgameObject.doThis( pParameters[1], pParameters[2] );\n\treturn @\"\";\n}\n```\n\nYou can also respond to javascript by a return\n```\nif (pParameters[0] == @\"myAction\")\n{\n\treturn @\"{json: 'yes !'}\";\n}\n```\n\nNote that you can send complex values thanks to JSON.\n\nReturn `null` if this is an async action. Then call `webViewDirectHandler` to send back answer to the WebView when it's done :\n```\nif (pParameters[0] == @\"takeScreenshot\")\n{\n\tStartCoroutine (this.cameraObject.TakePhoto( (value) =\u003e\n\t{\n\t\t// Now we can send back our answer\n\t\tthis.webViewDirectHandler(\n\t\t\t@\"{photo:\" + value + \"}\"\n\t\t);\n\t}));\n\n\t// We return null here to keep the JS Promise open\n\treturn null;\n}\n```\n\n\n##### In javascript\n\n1. Init your gateway `UnityGateway.initGateway()` an handler is also available because this method is async.\n2. Call your action with `UnityGateway.callUnity('myAction', 'a string parameters', 5)`\n\n*Important* : Javascript is sending commands to Unity through URL parameters. So this is not advice to send Huge data or files. Also, there is no JSON encoding when message are going this way. Only string are received into Unity, you have to parse them manually.\n\n\n### Communicate from Unity to Javascript\n\n##### In Unity\n\nCall this method from Unity to send a message to the WebView `WebViewComponent.sendMessageToWebView(@\"{message: 'hello from unity', value: 5}\")`\nThis is also JSON here.\n\n##### In Javascript\n\nListen to messages in javascript, with : \n```\nUnityGateway.onMessage = (jsonObject) =\u003e\n{\n\tconsole.log('Message from Unity !', jsonObject);\n};\n```\n\nIf you are using Solidify lib, `onMessage` is a `Signal` :\n```\nUnityGateway.onMessage.add(this.myHandler, this);\n```\n\nUnity is sending commands to Javascript by injection, so there is nearly no technical limit about size or types.\n\n\n### isUnity\n\nTo know if your webview is running into a Unity environment, check `UnityGateway.isUnity == true` .\nIf you are not in Unity environment, every `UnityGateway.callUnity` will respond automatically with a parameter `{isUnity: false}`, to avoid blocking.\n\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzouloux%2Funity-web-view","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzouloux%2Funity-web-view","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzouloux%2Funity-web-view/lists"}