Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
251 changes: 129 additions & 122 deletions Assets/WebGLTemplates/Template/index.html
Original file line number Diff line number Diff line change
@@ -1,136 +1,143 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{{{ PRODUCT_NAME }}}</title>
<style>
html,
body {
background: #000000;
width: 100%;
height: 100%;
overflow: visible;
padding: 0;
margin: 0;
}

<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>{{{ PRODUCT_NAME }}}</title>
<style>
html,
body {
background: '#000';
width: 100%;
height: 100%;
overflow: visible;
padding: 0;
margin: 0;
}
div#gameContainer {
background: transparent !important;
position: absolute;
}

div#gameContainer {
background: transparent !important;
position: absolute;
}
div#gameContainer canvas {
position: absolute;
}

div#gameContainer canvas {
position: absolute;
}
div#gameContainer canvas[data-pixel-art="true"] {
position: absolute;
image-rendering: optimizeSpeed;
image-rendering: -webkit-crisp-edges;
image-rendering: -moz-crisp-edges;
image-rendering: -o-crisp-edges;
image-rendering: crisp-edges;
image-rendering: -webkit-optimize-contrast;
image-rendering: optimize-contrast;
image-rendering: pixelated;
-ms-interpolation-mode: nearest-neighbor;
}

div#gameContainer canvas[data-pixel-art="true"] {
position: absolute;
image-rendering: optimizeSpeed;
image-rendering: -webkit-crisp-edges;
image-rendering: -moz-crisp-edges;
image-rendering: -o-crisp-edges;
image-rendering: crisp-edges;
image-rendering: -webkit-optimize-contrast;
image-rendering: optimize-contrast;
image-rendering: pixelated;
-ms-interpolation-mode: nearest-neighbor;
}
.button-container {
z-index: 99999;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}

.button {
cursor: pointer;
background: #542e91;
border: none;
border-radius: 4px;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}

.button-container {
z-index: 99999;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
.button:hover {
background: #6e46ad;
}
</style>
</head>

.button {
cursor: pointer;
background: #542E91;
border: none;
border-radius: 4px;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}
<body>
<div id="gameContainer">
<canvas
id="unity-canvas"
data-pixel-art="{{{ OPTIMIZE_FOR_PIXEL_ART }}}"
></canvas>
<script src="Build/{{{ LOADER_FILENAME }}}"></script>
<script>
var canvas = document.querySelector("#unity-canvas");
var config = {
dataUrl: "Build/{{{ DATA_FILENAME }}}",
frameworkUrl: "Build/{{{ FRAMEWORK_FILENAME }}}",
codeUrl: "Build/{{{ CODE_FILENAME }}}",
memoryUrl: "Build/{{{ MEMORY_FILENAME }}}",
symbolsUrl: "Build/{{{ SYMBOLS_FILENAME }}}",
streamingAssetsUrl: "StreamingAssets",
companyName: "{{{ COMPANY_NAME }}}",
productName: "{{{ PRODUCT_NAME }}}",
productVersion: "{{{ PRODUCT_VERSION }}}",
};
var scaleToFit = true;
function progressHandler(progress) {
var percent = progress * 100 + "%";
canvas.style.background =
"linear-gradient(to right, white, white " +
percent +
", transparent " +
percent +
", transparent) no-repeat center";
canvas.style.backgroundSize = "100% 1rem";
}
function onResize() {
var container = canvas.parentElement;
var w = window.innerWidth;
var h = window.innerHeight;

.button:hover {
background: #6e46ad;
}
</style>
</head>
container.style.width = canvas.style.width = w + "px";
container.style.height = canvas.style.height = h + "px";
container.style.top = Math.floor((window.innerHeight - h) / 2) + "px";
container.style.left = Math.floor((window.innerWidth - w) / 2) + "px";
}

<body>
<div id="gameContainer">
<canvas id="unity-canvas" data-pixel-art="{{{ OPTIMIZE_FOR_PIXEL_ART }}}"></canvas>
<script src="Build/{{{ LOADER_FILENAME }}}"></script>
<script>
var canvas = document.querySelector("#unity-canvas");
var config = {
dataUrl: "Build/{{{ DATA_FILENAME }}}",
frameworkUrl: "Build/{{{ FRAMEWORK_FILENAME }}}",
codeUrl: "Build/{{{ CODE_FILENAME }}}",
memoryUrl: "Build/{{{ MEMORY_FILENAME }}}",
symbolsUrl: "Build/{{{ SYMBOLS_FILENAME }}}",
streamingAssetsUrl: "StreamingAssets",
companyName: "{{{ COMPANY_NAME }}}",
productName: "{{{ PRODUCT_NAME }}}",
productVersion: "{{{ PRODUCT_VERSION }}}",
};
var scaleToFit = true;
function progressHandler(progress) {
var percent = progress * 100 + '%';
canvas.style.background = 'linear-gradient(to right, white, white ' + percent + ', transparent ' + percent + ', transparent) no-repeat center';
canvas.style.backgroundSize = '100% 1rem';
}
function onResize() {
var container = canvas.parentElement;
var w = window.innerWidth;
var h = window.innerHeight;
function loadUI() {
const container = document.createElement("div");
container.className = "button-container";

container.style.width = canvas.style.width = w + "px";
container.style.height = canvas.style.height = h + "px";
container.style.top = Math.floor((window.innerHeight - h) / 2) + "px";
container.style.left = Math.floor((window.innerWidth - w) / 2) + "px";
}
const button = document.createElement("button");
button.className = "button";
button.innerHTML = "Connect your Backpack";
button.addEventListener("click", () => {
window.unityInstance.SendMessage("Bkpk", "FetchAvatars");
container.remove();
});
container.appendChild(button);
document.body.appendChild(container);
}

function loadUI() {
const container = document.createElement('div')
container.className = "button-container"

const button = document.createElement('button')
button.className = "button"
button.innerHTML = "Connect your Backpack"
button.addEventListener('click', () => {
window.unityInstance.SendMessage("Bkpk", "FetchAvatars")
container.remove()
})
container.appendChild(button)
document.body.appendChild(container)
}
createUnityInstance(canvas, config, progressHandler).then(function (
instance
) {
canvas = instance.Module.canvas;
window.unityInstance = instance;
loadUI();
onResize();
});

createUnityInstance(canvas, config, progressHandler).then(function (instance) {
canvas = instance.Module.canvas;
window.unityInstance = instance;
loadUI();
onResize();
});

window.addEventListener('resize', onResize);
onResize();
</script>
</div>
</body>

</html>
window.addEventListener("resize", onResize);
onResize();
</script>
</div>
</body>
</html>
4 changes: 2 additions & 2 deletions Assets/content/Scripts/SceneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class SceneManager : MonoBehaviour

void Awake()
{
Bkpk.Config.ClientID = "b2e14bcc-8728-4c2f-8af1-b539aaaa122e";
Bkpk.Config.IpfsGateway = "https://ipfs.mona.gallery";
Bkpk.Config.ClientID = "f596bf0f-1fb9-4826-95e9-3c1e8a90a137";
Bkpk.Config.IpfsGateway = "https://nftstorage.link";

_DefaultRotation = Platform.transform.rotation.eulerAngles.y;
_DefaultPlatformSize = Platform.transform.localScale;
Expand Down
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
# Metaverse Backpack Dressing Room Sample

Example WebGL Demo of the Metaverse Backpack

## Setup
## Getting started

### Setup

`$ git clone github.com/metaverse-backpack/unity-dressing-room-sample`

`$ cd unity-dressing-room-sample`

`$ git submodule update --init --recursive`

`$ git submodule update --init --recursive`
### Build settings

Open up the Unity project in the Unity Hub. If there is a popup asking if you want to open the project in safe mode, click on `Ignore`. This is because the project starts with a native build target causing dependencies not to be loaded. Change the Build target to WebGL by choosing `File -> Build Settings...`. Then select `WebGL` in the `Platform` selection panel. Ensure `Scene` is selected under `Scenes in Build`.

### Build and run

Select `File -> Build And Run` to start a unity development web server and run the project in a browser (`http://localhost:51326`).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tobias-petrasch Unity actually just selects an available port so this isn't consistent. Unfortunately, I don't think there's any way to explicitly set which port this runs on, so we might need to remove those redirect URI check restrictions in the backend temporarily if we want to support that.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also use an external http server (e.g., npx http-server) with a fixed port. Instead of running build & run in Unity, we only run the build command. Don't think it makes sense to change the backend.


### Additional settings

The dressing room is authorized via OAuth2 to read from Backpack. You can use the client ID `f596bf0f-1fb9-4826-95e9-3c1e8a90a137` for development purposes. The client ID can be set in `Assets/Scripts/SceneManager.cs`. It's important to use a development client ID as the redirect URI is validated by the server and rejected if not matching with the production deployment webserver.

## Engine version

# Engine version
[Unity 2020.3.36f](https://unity3d.com/unity/whats-new/2020.3.36)
[Unity 2021.3.10f1](https://unity3d.com/unity/whats-new/2021.3.10)