├── LICENSE ├── README.md └── Web3Template ├── TemplateData ├── UnityProgress.js ├── favicon.ico ├── fullscreen.png ├── progressEmpty.Dark.png ├── progressEmpty.Light.png ├── progressFull.Dark.png ├── progressFull.Light.png ├── progressLogo.Dark.png ├── progressLogo.Light.png ├── style.css ├── web3.min.js ├── web3Connect.js └── webgl-logo.png └── index.html /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 _dLabs 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # web3-webgl-template 2 | 3 | Article: https://medium.com/@leondo/unity-engine-metamask-wallet-6797d4699e45 4 | 5 | Automagically connect your Unity game to Metamask 6 | 7 |  8 | 9 | ## How to use 10 | 11 | Create a folder called `WebGLTemplates` under `/Assets` 12 | 13 | Download `Web3Template` from here and paste under `WebGLTemplates` 14 | 15 |  16 | 17 | In Unity 18 | 19 |  20 | 21 | Change template 22 | 23 |  24 | 25 | Build as webgl 26 | 27 | ## Under the hood 28 | 29 | ```javascript 30 | // Web3Template/TemplateData/web3Connect.js 31 | 32 | if (window.ethereum) { 33 | web3 = new Web3(window.ethereum); 34 | // connect popup 35 | ethereum.enable(); 36 | } else { 37 | alert("Non-Ethereum browser detected. Please connect to a wallet"); 38 | } 39 | ``` 40 | -------------------------------------------------------------------------------- /Web3Template/TemplateData/UnityProgress.js: -------------------------------------------------------------------------------- 1 | function UnityProgress(unityInstance, progress) { 2 | if (!unityInstance.Module) 3 | return; 4 | if (!unityInstance.logo) { 5 | unityInstance.logo = document.createElement("div"); 6 | unityInstance.logo.className = "logo " + unityInstance.Module.splashScreenStyle; 7 | unityInstance.container.appendChild(unityInstance.logo); 8 | } 9 | if (!unityInstance.progress) { 10 | unityInstance.progress = document.createElement("div"); 11 | unityInstance.progress.className = "progress " + unityInstance.Module.splashScreenStyle; 12 | unityInstance.progress.empty = document.createElement("div"); 13 | unityInstance.progress.empty.className = "empty"; 14 | unityInstance.progress.appendChild(unityInstance.progress.empty); 15 | unityInstance.progress.full = document.createElement("div"); 16 | unityInstance.progress.full.className = "full"; 17 | unityInstance.progress.appendChild(unityInstance.progress.full); 18 | unityInstance.container.appendChild(unityInstance.progress); 19 | } 20 | unityInstance.progress.full.style.width = (100 * progress) + "%"; 21 | unityInstance.progress.empty.style.width = (100 * (1 - progress)) + "%"; 22 | if (progress == 1) 23 | unityInstance.logo.style.display = unityInstance.progress.style.display = "none"; 24 | } -------------------------------------------------------------------------------- /Web3Template/TemplateData/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoredLabs/web3-webgl-template/51fe115e25943d7bfa61ffc06509614f9f861779/Web3Template/TemplateData/favicon.ico -------------------------------------------------------------------------------- /Web3Template/TemplateData/fullscreen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoredLabs/web3-webgl-template/51fe115e25943d7bfa61ffc06509614f9f861779/Web3Template/TemplateData/fullscreen.png -------------------------------------------------------------------------------- /Web3Template/TemplateData/progressEmpty.Dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoredLabs/web3-webgl-template/51fe115e25943d7bfa61ffc06509614f9f861779/Web3Template/TemplateData/progressEmpty.Dark.png -------------------------------------------------------------------------------- /Web3Template/TemplateData/progressEmpty.Light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoredLabs/web3-webgl-template/51fe115e25943d7bfa61ffc06509614f9f861779/Web3Template/TemplateData/progressEmpty.Light.png -------------------------------------------------------------------------------- /Web3Template/TemplateData/progressFull.Dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoredLabs/web3-webgl-template/51fe115e25943d7bfa61ffc06509614f9f861779/Web3Template/TemplateData/progressFull.Dark.png -------------------------------------------------------------------------------- /Web3Template/TemplateData/progressFull.Light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoredLabs/web3-webgl-template/51fe115e25943d7bfa61ffc06509614f9f861779/Web3Template/TemplateData/progressFull.Light.png -------------------------------------------------------------------------------- /Web3Template/TemplateData/progressLogo.Dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoredLabs/web3-webgl-template/51fe115e25943d7bfa61ffc06509614f9f861779/Web3Template/TemplateData/progressLogo.Dark.png -------------------------------------------------------------------------------- /Web3Template/TemplateData/progressLogo.Light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoredLabs/web3-webgl-template/51fe115e25943d7bfa61ffc06509614f9f861779/Web3Template/TemplateData/progressLogo.Light.png -------------------------------------------------------------------------------- /Web3Template/TemplateData/style.css: -------------------------------------------------------------------------------- 1 | .webgl-content * {border: 0; margin: 0; padding: 0} 2 | .webgl-content {position: absolute; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%);} 3 | 4 | .webgl-content .logo, .progress {position: absolute; left: 50%; top: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%);} 5 | .webgl-content .logo {background: url('progressLogo.Light.png') no-repeat center / contain; width: 154px; height: 130px;} 6 | .webgl-content .progress {height: 18px; width: 141px; margin-top: 90px;} 7 | .webgl-content .progress .empty {background: url('progressEmpty.Light.png') no-repeat right / cover; float: right; width: 100%; height: 100%; display: inline-block;} 8 | .webgl-content .progress .full {background: url('progressFull.Light.png') no-repeat left / cover; float: left; width: 0%; height: 100%; display: inline-block;} 9 | 10 | .webgl-content .logo.Dark {background-image: url('progressLogo.Dark.png');} 11 | .webgl-content .progress.Dark .empty {background-image: url('progressEmpty.Dark.png');} 12 | .webgl-content .progress.Dark .full {background-image: url('progressFull.Dark.png');} 13 | 14 | .webgl-content .footer {margin-top: 5px; height: 38px; line-height: 38px; font-family: Helvetica, Verdana, Arial, sans-serif; font-size: 18px;} 15 | .webgl-content .footer .webgl-logo, .title, .fullscreen {height: 100%; display: inline-block; background: transparent center no-repeat;} 16 | .webgl-content .footer .webgl-logo {background-image: url('webgl-logo.png'); width: 204px; float: left;} 17 | .webgl-content .footer .title {margin-right: 10px; float: right;} 18 | .webgl-content .footer .fullscreen {background-image: url('fullscreen.png'); width: 38px; float: right;} 19 | -------------------------------------------------------------------------------- /Web3Template/TemplateData/web3Connect.js: -------------------------------------------------------------------------------- 1 | if (window.ethereum) { 2 | web3 = new Web3(window.ethereum); 3 | // connect popup 4 | ethereum.enable(); 5 | 6 | window.ethereum.on("accountsChanged", function () { 7 | location.reload(); 8 | }); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Web3Template/TemplateData/webgl-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoredLabs/web3-webgl-template/51fe115e25943d7bfa61ffc06509614f9f861779/Web3Template/TemplateData/webgl-logo.png -------------------------------------------------------------------------------- /Web3Template/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 |