Comments (10)
可以看这里,有Unity示例:
https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/tree/main/Demo/Ranking/Assets/WX-WASM-SDK/wechat-default/open-data
from minigame-canvas-engine.
这种需求一定要使用开放数据域的方式吗, 限制会比较多
from minigame-canvas-engine.
不是为了绘制好友排行榜之类的需求么?我好奇什么场景非要在unity外绘制一个界面?
from minigame-canvas-engine.
如果不是开放数据域的场景,那么也不复杂,参照这里的实现,将
https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/blob/main/Demo/Ranking/Assets/WX-WASM-SDK/wechat-default/unity-sdk/open-data.js里面关于 sharedCanvas 的使用换成你自己创建的离屏canvas。不过这里的麻烦点在于你需要跟C#的SDK一样,将showOpenData的实现也复刻一份。
from minigame-canvas-engine.
需求是游戏和SDK页面分离, 这样SDK的页面就可以独立于游戏编写, 也不必每次都去把unityi游戏重新打包为小游戏了, 只需要替换js实现即可. 要是使用离屏canvas渲染那渲染纹理是如何获取的那?, 有没有其它例子可以参考
from minigame-canvas-engine.
我的代码如下 showPage方法是从Unity中调用的.
我不太确定纹理是否是这样获取的, 这段代码在调试工具中还是没有任何效果.
function showPage() {
const cachedSharedCanvas = wx.createCanvas();
let context = cachedSharedCanvas.getContext('2d');
// 编写模板字符串
const template = `<view id="container"><text id="testText" class="redText" value="hello canvas"></text></view>`;
// 编写样式
const style = {
container: {
width: 400,
height: 200,
backgroundColor: '#ffffff',
justContent: 'center',
alignItems: 'center',
},
testText: {
color: '#ffffff',
width: 400,
height: 200,
lineHeight: 200,
fontSize: 40,
textAlign: 'center',
},
// 文字的最终颜色为#ff0000
redText: {
color: '#ff0000',
},
};
// 初始化渲染引擎
Layout.init(template, style);
cachedSharedCanvas.width = 100;
cachedSharedCanvas.height = 100;
// 执行渲染
Layout.updateViewPort({
x: 0,
y: 0,
width: 100,
height: 100,
});
Layout.layout(context);
const GL = GameGlobal.manager.gameInstance.Module.GL;
const gl = GL.currentContext.GLctx;
const texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, cachedSharedCanvas);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
// 这里的纹理ID是这样获取的吗?
const textureId = gl.getParameter(gl.TEXTURE_BINDING_2D)
GL.textures[textureId] = texture
}
希望能给个demo或其他的示例 感谢
from minigame-canvas-engine.
emm,不是这样的,我还是好奇你这里SDK在干啥,是小游戏的SDK,会绘制一些游戏活动到屏幕上么?demo的话,看明天有没有时间搞一个。
from minigame-canvas-engine.
https://forum.unity.com/threads/texture2d-createexternaltexture-from-a-webgl-texture.1267220/
如果跟开放数据域没关系,这个帖子应该能够解决你的问题。
from minigame-canvas-engine.
嗯,显示一些独立于游戏的活动页面, 这个方法我试一下
from minigame-canvas-engine.
我在unity创建了一个纹理然后使用离屏canvas来替代了sharedCanvas成功渲染出页面了,
https://forum.unity.com/threads/texture2d-createexternaltexture-from-a-webgl-texture.1267220/
这个帖子我还没实现, 但纹理实际也是在unity层创建的, 貌似无法在js层直接创建纹理使用.
from minigame-canvas-engine.
Related Issues (17)
- 草..现在搞得很很卡,ScrollVIew都滚得好垃圾 HOT 8
- 几个问题,麻烦看一下需要怎么解决 HOT 3
- Github 与 Npm 的版本对应 HOT 5
- 官方文档有个拼写错误 HOT 1
- 几个问题 HOT 2
- 通过微信引擎插件的方式引用到游戏中,只要版本超过0.08就无法上传代码,能否帮忙看一下是什么问题? HOT 6
- 插件在微信小游戏那边添加后,如何移除,网页地址状态一直都是已添加 HOT 2
- scrollview无法滚动 HOT 3
- 是否可以支持显示富文本内容 HOT 6
- 只做离屏,对主屏2d或者webgl同时兼容? HOT 1
- scrollview不支持透明背景效果 即backgroundColor属性设置为transparent无效 HOT 6
- 目前能设置图片的z-index吗? HOT 4
- setfrienduserstorage: size of value exceed HOT 2
- ScrollView不支持横向滚动吗? HOT 1
- 对列表中格子点击事件不准确 HOT 4
- scrollview 不支持背景透明 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from minigame-canvas-engine.