Skip to content

Commit

Permalink
Update unity.js
Browse files Browse the repository at this point in the history
  • Loading branch information
SeoulSKY committed Dec 29, 2023
1 parent c0d6c7d commit a25c815
Showing 1 changed file with 44 additions and 24 deletions.
68 changes: 44 additions & 24 deletions web-server/public/unity.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,59 @@ function main() {

document.body.style.textAlign = "left";

if (window.location.hostname === "localhost") {
setupUnityWebGL({
"loaderUrl": "Build/WebGL.loader.js",
"dataUrl": "Build/WebGL.data.unityweb",
"frameworkUrl": "Build/WebGL.framework.js.unityweb",
"codeUrl": "Build/WebGL.wasm.unityweb",
"productVersion": "v0.0.0",
});
return;
}

fetch("https://api.github.com/repos/seoulsky/desdemona/releases/latest")
.then(response => {
let unity = new UnityWebgl("#unity-canvas", {
loaderUrl: response["assets"].filter(asset => asset["name"] === "WebGL.loader.js")[0]["browser_download_url"],
dataUrl: response["assets"].filter(asset => asset["name"] === "WebGL.data.unityweb")[0]["browser_download_url"],
frameworkUrl: response["assets"].filter(asset => asset["name"] === "WebGL.framework.js.unityweb")[0]["browser_download_url"],
codeUrl: response["assets"].filter(asset => asset["name"] === "WebGL.wasm.unityweb")[0]["browser_download_url"],
streamingAssetsUrl: "StreamingAssets",
companyName: "SeoulSKY",
productName: "Desdemona",
productVersion: response["tag_name"],
setupUnityWebGL({
"loaderUrl": response["assets"].filter(asset => asset["name"] === "WebGL.loader.js")[0]["browser_download_url"],
"dataUrl": response["assets"].filter(asset => asset["name"] === "WebGL.data.unityweb")[0]["browser_download_url"],
"frameworkUrl": response["assets"].filter(asset => asset["name"] === "WebGL.framework.js.unityweb")[0]["browser_download_url"],
"codeUrl": response["assets"].filter(asset => asset["name"] === "WebGL.wasm.unityweb")[0]["browser_download_url"],
"productVersion": response["tag_name"],
});
}).catch(error => {
alert("Failed to load the game. Please try again later.");
console.error(error);
});
}

let progressBar = document.getElementById("progress-bar");
function setupUnityWebGL(data) {
let unity = new UnityWebgl("#unity-canvas", {
loaderUrl: data["loaderUrl"],
dataUrl: data["dataUrl"],
frameworkUrl: data["frameworkUrl"],
codeUrl: data["codeUrl"],
streamingAssetsUrl: "StreamingAssets",
companyName: "SeoulSKY",
productName: "Desdemona",
productVersion: data["productVersion"],
});

unity.on("progress", (progression) => {
progressBar.style.width = 100 * progression + "%";
});
let progressBar = document.getElementById("progress-bar");

unity.on("mounted", () => {
let spinner = document.getElementById("spinner");
spinner.style.display = "none";
unity.on("progress", (progression) => {
progressBar.style.width = 100 * progression + "%";
});

progressBar.style.display = "none";
unity.on("mounted", () => {
let spinner = document.getElementById("spinner");
spinner.style.display = "none";

let canvas = document.getElementById("unity-canvas");
canvas.style.display = "block";
});
progressBar.style.display = "none";

}).catch(error => {
alert("Failed to load the game. Please try again later.");
console.error(error);
});
let canvas = document.getElementById("unity-canvas");
canvas.style.display = "block";
});
}


Expand Down

0 comments on commit a25c815

Please sign in to comment.