shaogen1995 4 tuần trước cách đây
mục cha
commit
3c4e845b9f

+ 17 - 9
public/unityMo/export_main.js

@@ -1,17 +1,25 @@
+let currentScene = 'TombstoneView'
+
 //场景加载进度回调
 //场景加载进度回调
-window.loadSceneProgress = function(progress){
-    if (window.parent && window.parent !== window) {
-        window.parent.unityLoading(progress);
-    }
+window.loadSceneProgress = function (progress) {
+  if (window.parent && window.parent !== window) {
+    window.parent.unityLoading(progress)
+  }
 }
 }
 
 
 //设置场景加载完毕时透明度渐变的时长(秒), 0为去除该效果
 //设置场景加载完毕时透明度渐变的时长(秒), 0为去除该效果
-window.setLoadSceneAnimationTime = function(animationTime){
-    window.unityInstance.SendMessage('SceneLoader', 'SetAnimationTime', animationTime)
+window.setLoadSceneAnimationTime = function (animationTime) {
+  window.unityInstance.SendMessage('SceneLoader', 'SetAnimationTime', animationTime)
 }
 }
 
 
 //切换场景 场景支持以下参数 "TombstoneView", "RoomScene", "DrawingBoard"
 //切换场景 场景支持以下参数 "TombstoneView", "RoomScene", "DrawingBoard"
-window.loadScene = function(sceneName){
-    window.setLoadSceneAnimationTime(sceneName === 'DrawingBoard' ? 1 : 0);
-    window.unityInstance.SendMessage('SceneLoader', 'LoadScene', sceneName)
+window.loadScene = function (sceneName) {
+  window.setLoadSceneAnimationTime(sceneName === 'DrawingBoard' ? 1 : 0)
+  window.unityInstance.SendMessage('SceneLoader', 'LoadScene', sceneName)
+  currentScene = sceneName
+}
+
+// 返回当前场景状态
+window.sceneStaRes = () => {
+  return currentScene
 }
 }

+ 17 - 9
public/unityPc/export_main.js

@@ -1,17 +1,25 @@
+let currentScene = 'TombstoneView'
+
 //场景加载进度回调
 //场景加载进度回调
-window.loadSceneProgress = function(progress){
-    if (window.parent && window.parent !== window) {
-        window.parent.unityLoading(progress);
-    }
+window.loadSceneProgress = function (progress) {
+  if (window.parent && window.parent !== window) {
+    window.parent.unityLoading(progress)
+  }
 }
 }
 
 
 //设置场景加载完毕时透明度渐变的时长(秒), 0为去除该效果
 //设置场景加载完毕时透明度渐变的时长(秒), 0为去除该效果
-window.setLoadSceneAnimationTime = function(animationTime){
-    window.unityInstance.SendMessage('SceneLoader', 'SetAnimationTime', animationTime)
+window.setLoadSceneAnimationTime = function (animationTime) {
+  window.unityInstance.SendMessage('SceneLoader', 'SetAnimationTime', animationTime)
 }
 }
 
 
 //切换场景 场景支持以下参数 "TombstoneView", "RoomScene", "DrawingBoard"
 //切换场景 场景支持以下参数 "TombstoneView", "RoomScene", "DrawingBoard"
-window.loadScene = function(sceneName){
-    window.setLoadSceneAnimationTime(sceneName === 'DrawingBoard' ? 1 : 0);
-    window.unityInstance.SendMessage('SceneLoader', 'LoadScene', sceneName)
+window.loadScene = function (sceneName) {
+  window.setLoadSceneAnimationTime(sceneName === 'DrawingBoard' ? 1 : 0)
+  window.unityInstance.SendMessage('SceneLoader', 'LoadScene', sceneName)
+  currentScene = sceneName
+}
+
+// 返回当前场景状态
+window.sceneStaRes = () => {
+  return currentScene
 }
 }

+ 0 - 1
src/components/MenuSider/index.tsx

@@ -61,7 +61,6 @@ function MenuSider({ activeTab }: { activeTab: number }) {
             <div
             <div
               className={`tab ${activeTab === 1 ? 'tabAc' : ''}`}
               className={`tab ${activeTab === 1 ? 'tabAc' : ''}`}
               onClick={() => {
               onClick={() => {
-                window.sceneNum = 2
                 window.location.replace('#/ybwx')
                 window.location.replace('#/ybwx')
               }}
               }}
             >
             >

+ 6 - 1
src/components/Zloding/index.module.scss

@@ -10,7 +10,6 @@
   background-position: center center;
   background-position: center center;
   opacity: 0;
   opacity: 0;
   pointer-events: none;
   pointer-events: none;
-  transition: opacity 0.8s;
 
 
   :global {
   :global {
 
 
@@ -61,4 +60,10 @@
 .ZlodingShow {
 .ZlodingShow {
   opacity: 1;
   opacity: 1;
   pointer-events: auto;
   pointer-events: auto;
+}
+
+// 新增:这个类用于定义关闭时的过渡效果
+.ZlodingClosing {
+  // 只对 opacity 属性应用过渡,持续0.8秒
+  transition: opacity 0.8s;
 }
 }

+ 1 - 3
src/components/Zloding/index.tsx

@@ -40,9 +40,7 @@ function Zloding({ isShow, bacNum, callBackFu }: Props) {
 
 
           setTimeout(() => {
           setTimeout(() => {
             setLoding(0)
             setLoding(0)
-            // 销毁自己
-            // domDelOwnFu('#Zloding')
-          }, 500)
+          }, 200)
         }
         }
       }
       }
     }
     }

+ 25 - 5
src/pages/A0base/data.ts

@@ -11,14 +11,12 @@ const getUnityDomFu = () => {
 export const lodingUnityFu = () => {
 export const lodingUnityFu = () => {
   const modalIframe = getUnityDomFu()
   const modalIframe = getUnityDomFu()
   if (modalIframe) {
   if (modalIframe) {
-    window.sceneNum=1
     modalIframe.style.display = 'block'
     modalIframe.style.display = 'block'
     modalIframe.src = `unity${isPc ? 'Pc' : 'Mo'}/index.html`
     modalIframe.src = `unity${isPc ? 'Pc' : 'Mo'}/index.html`
   }
   }
 }
 }
 
 
 // unity场景的显示和隐藏
 // unity场景的显示和隐藏
-
 export const unityShow = (val: boolean) => {
 export const unityShow = (val: boolean) => {
   const modalIframe = getUnityDomFu()
   const modalIframe = getUnityDomFu()
   if (modalIframe) {
   if (modalIframe) {
@@ -27,7 +25,29 @@ export const unityShow = (val: boolean) => {
 }
 }
 
 
 // 切换unity
 // 切换unity
-export const cutUnityFu = (val: 'TombstoneView' | 'RoomScene' | 'DrawingBoard') => {
-  unityShow(true)
-  callIframeFu('loadScene', val)
+export const cutUnityFu = (
+  val: 'TombstoneView' | 'RoomScene' | 'DrawingBoard',
+  backFu: () => void
+) => {
+  const dom: any = document.getElementById('modalIframe')
+  const iframeWindow = dom.contentWindow
+
+  const res: any = iframeWindow.sceneStaRes()
+
+  if (res !== val) {
+    unityShow(true)
+    callIframeFu('loadScene', val)
+    backFu()
+  }
 }
 }
+
+//判断是否需要切换unity
+
+// 销毁unity
+// export const delUnityFu = () => {
+//   const modalIframe = getUnityDomFu()
+//   if (modalIframe) {
+//     modalIframe.src = ''
+//     console.log(modalIframe)
+//   }
+// }

+ 2 - 5
src/pages/A0base/index.tsx

@@ -11,12 +11,9 @@ function A0base() {
   const [loding, setLoding] = useState(false)
   const [loding, setLoding] = useState(false)
 
 
   useEffect(() => {
   useEffect(() => {
-    if (window.sceneNum !== 1) {
       // 切换场景
       // 切换场景
-      window.sceneNum = 1
-      cutUnityFu('TombstoneView')
-      setLoding(true)
-    }
+      cutUnityFu('TombstoneView',()=>setLoding(true))
+      
   }, [])
   }, [])
 
 
   const { myData, myLangue } = useSelector((state: RootState) => state.A0Layout)
   const { myData, myLangue } = useSelector((state: RootState) => state.A0Layout)

+ 2 - 5
src/pages/A2yblm/index.tsx

@@ -16,12 +16,9 @@ function A2yblm() {
   const [loding, setLoding] = useState(false)
   const [loding, setLoding] = useState(false)
 
 
   useEffect(() => {
   useEffect(() => {
-    if (window.sceneNum !== 1) {
       // 切换场景
       // 切换场景
-      window.sceneNum = 1
-      cutUnityFu('TombstoneView')
-      setLoding(true)
-    }
+      cutUnityFu('TombstoneView',()=>setLoding(true))
+      
   }, [])
   }, [])
 
 
   const { myData, myLangue } = useSelector((state: RootState) => state.A0Layout)
   const { myData, myLangue } = useSelector((state: RootState) => state.A0Layout)

+ 4 - 4
src/pages/A6ybwx/index.tsx

@@ -65,10 +65,11 @@ function A6ybwx() {
     if (isEnter) {
     if (isEnter) {
       // 销毁视频
       // 销毁视频
       videoRefLast.current?.pause()
       videoRefLast.current?.pause()
-      domDelOwnFu('.videoBox')
-
+      setTimeout(()=>{
+        domDelOwnFu('.videoBox')
+      },100)
       // 切换场景
       // 切换场景
-      cutUnityFu('RoomScene')
+      cutUnityFu('RoomScene',()=>{})
     }
     }
   }, [isEnter])
   }, [isEnter])
 
 
@@ -77,7 +78,6 @@ function A6ybwx() {
       <div
       <div
         className='back'
         className='back'
         onClick={() => {
         onClick={() => {
-          window.sceneNum = 2
           window.location.replace('#/base')
           window.location.replace('#/base')
         }}
         }}
       >
       >

+ 1 - 0
src/pages/A7wjwj/conponents/Discover/index.tsx

@@ -10,6 +10,7 @@ function Discover(props: { style?: React.CSSProperties }) {
 
 
   // 将隐藏的页面打开,全景图->诗歌->大场景
   // 将隐藏的页面打开,全景图->诗歌->大场景
   const lookScene = () => {
   const lookScene = () => {
+
     const panoramicRoot = document.getElementById('panoramic-root') as HTMLElement
     const panoramicRoot = document.getElementById('panoramic-root') as HTMLElement
     panoramicRoot.style.display = 'block'
     panoramicRoot.style.display = 'block'
     // 打开全景图
     // 打开全景图

+ 1 - 2
src/pages/A8byzh/index.tsx

@@ -3,14 +3,13 @@ import styles from './index.module.scss'
 import { cutUnityFu } from '../A0base/data'
 import { cutUnityFu } from '../A0base/data'
 function A8byzh() {
 function A8byzh() {
   useEffect(() => {
   useEffect(() => {
-    cutUnityFu('DrawingBoard')
+    cutUnityFu('DrawingBoard',()=>{})
   }, [])
   }, [])
 
 
   const fromPath =
   const fromPath =
     new URLSearchParams(window.location.hash.split('?')[1] || '').get('fromPath') || ''
     new URLSearchParams(window.location.hash.split('?')[1] || '').get('fromPath') || ''
   console.log(fromPath)
   console.log(fromPath)
   const backToBase = () => {
   const backToBase = () => {
-    window.sceneNum = 3
     window.location.replace(fromPath ? `#/${fromPath}` : '#/base')
     window.location.replace(fromPath ? `#/${fromPath}` : '#/base')
   }
   }