data.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { callIframeFu } from '@/utils/history'
  2. import { isPc } from '@/utils/http'
  3. // 获取unityDom
  4. const getUnityDomFu = () => {
  5. const modalIframe = document.getElementById('modalIframe') as HTMLIFrameElement | null
  6. return modalIframe
  7. }
  8. // 开始加载unity
  9. export const lodingUnityFu = () => {
  10. const modalIframe = getUnityDomFu()
  11. if (modalIframe) {
  12. modalIframe.style.display = 'block'
  13. modalIframe.src = `unity${isPc ? 'Pc' : 'Mo'}/index.html`
  14. }
  15. }
  16. // unity场景的显示和隐藏
  17. export const unityShow = (val: boolean) => {
  18. const modalIframe = getUnityDomFu()
  19. if (modalIframe) {
  20. modalIframe.style.display = val ? 'block' : 'none'
  21. }
  22. }
  23. // 切换unity
  24. export const cutUnityFu = (
  25. val: 'TombstoneView' | 'RoomScene' | 'DrawingBoard',
  26. backFu: () => void
  27. ) => {
  28. const dom: any = document.getElementById('modalIframe')
  29. if (dom.src.includes('unity')) {
  30. if (dom && dom.contentWindow) {
  31. const iframeWindow = dom.contentWindow
  32. if (iframeWindow.sceneStaRes) {
  33. const res: any = iframeWindow.sceneStaRes()
  34. if (res !== val) {
  35. unityShow(true)
  36. callIframeFu('loadScene', val)
  37. backFu()
  38. }
  39. }
  40. }
  41. } else {
  42. // 被销毁了,需要重新加载
  43. // lodingUnityFu()
  44. }
  45. }
  46. // 重新加载unity
  47. // export const lodingUnityAgainFu = () => {
  48. // const rootDom = document.querySelector('#root') as HTMLDivElement
  49. // if (rootDom) {
  50. // }
  51. // }