| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import { callIframeFu } from '@/utils/history'
- import { isPc } from '@/utils/http'
- // 获取unityDom
- const getUnityDomFu = () => {
- const modalIframe = document.getElementById('modalIframe') as HTMLIFrameElement | null
- return modalIframe
- }
- // 开始加载unity
- export const lodingUnityFu = () => {
- const modalIframe = getUnityDomFu()
- if (modalIframe) {
- modalIframe.style.display = 'block'
- modalIframe.src = `unity${isPc ? 'Pc' : 'Mo'}/index.html`
- }
- }
- // unity场景的显示和隐藏
- export const unityShow = (val: boolean) => {
- const modalIframe = getUnityDomFu()
- if (modalIframe) {
- modalIframe.style.display = val ? 'block' : 'none'
- }
- }
- // 切换unity
- export const cutUnityFu = (
- val: 'TombstoneView' | 'RoomScene' | 'DrawingBoard',
- backFu: () => void
- ) => {
- const dom: any = document.getElementById('modalIframe')
- if (dom.src.includes('unity')) {
- if (dom && dom.contentWindow) {
- const iframeWindow = dom.contentWindow
- if (iframeWindow.sceneStaRes) {
- const res: any = iframeWindow.sceneStaRes()
- if (res !== val) {
- unityShow(true)
- callIframeFu('loadScene', val)
- backFu()
- }
- }
- }
- } else {
- // 被销毁了,需要重新加载
- // lodingUnityFu()
- }
- }
- // 重新加载unity
- // export const lodingUnityAgainFu = () => {
- // const rootDom = document.querySelector('#root') as HTMLDivElement
- // if (rootDom) {
- // }
- // }
|