unity3d打包后的WebGL怎么引入到react项目里

212 阅读1分钟

1、先设置好unity3d的打包设置 File -> Build Setting -> WebGL,同时设置Player Settings -> Decompression Fallback 打上勾

image.png

image.png 打包后把build文件直接拷到react项目里的public里,增加文件夹test3d,把刚打包后的build文件直接拷到test3d文件夹下面,如图

image.png

接下来在页面里,通过iframe引入

import React, { useState, useEffect } from 'react';
import './index.less';

export default function Test3d(props) {

    return (
        <div style={{ height: '100%', padding: 24, overflowY: 'auto' }} id="pic">
            <iframe
                frameBorder="no" border="0"
                width='100%' height='100%'
                src='/test3d/index.html'
            />
        </div>
    );
}

最终结果

image.png