samuel310 / flutter_unity_widget_web Goto Github PK
View Code? Open in Web Editor NEWFlutter unity widget for embedding unity in flutter web apps.
License: BSD 3-Clause "New" or "Revised" License
Flutter unity widget for embedding unity in flutter web apps.
License: BSD 3-Clause "New" or "Revised" License
Hey it's me again ❤️
I created a cross-platform solution in: https://github.com/Glartek/flutter-unity/pull/55
It's working perfectly for all platforms and thank you again for your web-implementation ❤️
But I recognized that sometimes Unity is not reacting if I send messages to Unity.
I solved this with this: https://github.com/Glartek/flutter-unity/pull/55/commits/0237f6f386cf289b19d1777fdb08ad0e4f7d8717
Maybe you can apply this fix also for this package :)
Thank you so much for your package.
I've inserted everything like this:
let globalUnityInstance;
window["receiveMessageFromUnity"] = function (params) {
window.parent.postMessage(params, "*");
};
window.parent.addEventListener("flutter2js", function (params) {
const obj = JSON.parse(params.data);
globalUnityInstance.SendMessage(obj.gameObject, obj.method, obj.data);
});
var container = document.querySelector("#unity-container");
var canvas = document.querySelector("#unity-canvas");
var loadingBar = document.querySelector("#unity-loading-bar");
var progressBarFull = document.querySelector("#unity-progress-bar-full");
var fullscreenButton = document.querySelector("#unity-fullscreen-button");
var mobileWarning = document.querySelector("#unity-mobile-warning");
// By default Unity keeps WebGL canvas render target size matched with
// the DOM size of the canvas element (scaled by window.devicePixelRatio)
// Set this to false if you want to decouple this synchronization from
// happening inside the engine, and you would instead like to size up
// the canvas DOM size and WebGL render target sizes yourself.
// config.matchWebGLToCanvasSize = false;
if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
container.className = "unity-mobile";
// Avoid draining fillrate performance on mobile devices,
// and default/override low DPI mode on mobile browsers.
config.devicePixelRatio = 1;
mobileWarning.style.display = "block";
setTimeout(() => {
mobileWarning.style.display = "none";
}, 5000);
} else {
canvas.style.width = "960px";
canvas.style.height = "600px";
}
loadingBar.style.display = "block";
var script = document.createElement("script");
script.src = loaderUrl;
script.onload = () => {
createUnityInstance(canvas, config, (progress) => {
progressBarFull.style.width = 100 * progress + "%";
})
.then((unityInstance) => {
window.parent.postMessage("unity_loaded", "*");
globalUnityInstance = unityInstance;
loadingBar.style.display = "none";
fullscreenButton.onclick = () => {
unityInstance.SetFullscreen(1);
};
})
.catch((message) => {
alert(message);
});
};
And this is my dart implementation:
if (kIsWeb) {
return UnityWebWidget(
url: 'http://localhost:${Uri.base.port}/unity/index.html',
listenMessageFromUnity: onUnityMessage,
onUnityLoaded: (webController) => onUnityCreated(
unityWebController: webController,
),
);
}
And this is not working:
if (kIsWeb) {
webController!.sendDataToUnity(
gameObject: 'ComposerInterface',
method: 'ToggleBetweenInsideAndOutside',
data: "$isViewingFromOutside",
);
return;
}
I get: ArgumentException: JSON must represent an object type.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.