Explorar el Código

Merge branch 'master' of http://192.168.0.115:3000/lanxin/Chengzhebei

lanxin hace 1 mes
padre
commit
efa4ce7951

+ 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为去除该效果
-window.setLoadSceneAnimationTime = function(animationTime){
-    window.unityInstance.SendMessage('SceneLoader', 'SetAnimationTime', animationTime)
+window.setLoadSceneAnimationTime = function (animationTime) {
+  window.unityInstance.SendMessage('SceneLoader', 'SetAnimationTime', animationTime)
 }
 
 //切换场景 场景支持以下参数 "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为去除该效果
-window.setLoadSceneAnimationTime = function(animationTime){
-    window.unityInstance.SendMessage('SceneLoader', 'SetAnimationTime', animationTime)
+window.setLoadSceneAnimationTime = function (animationTime) {
+  window.unityInstance.SendMessage('SceneLoader', 'SetAnimationTime', animationTime)
 }
 
 //切换场景 场景支持以下参数 "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
               className={`tab ${activeTab === 1 ? 'tabAc' : ''}`}
               onClick={() => {
-                window.sceneNum = 2
                 window.location.replace('#/ybwx')
               }}
             >

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

@@ -10,7 +10,6 @@
   background-position: center center;
   opacity: 0;
   pointer-events: none;
-  transition: opacity 0.8s;
 
   :global {
 
@@ -61,4 +60,8 @@
 .ZlodingShow {
   opacity: 1;
   pointer-events: auto;
+}
+
+.ZlodingChange {
+  transition: opacity 1s;
 }

+ 21 - 8
src/components/Zloding/index.tsx

@@ -15,6 +15,9 @@ type Props = {
 }
 
 function Zloding({ isShow, bacNum, callBackFu }: Props) {
+  // 增加消失的时候透明度
+  const [flag, setFlag] = useState(false)
+
   const [showFlag, setShowFlag] = useState(false)
 
   useEffect(() => {
@@ -29,20 +32,26 @@ function Zloding({ isShow, bacNum, callBackFu }: Props) {
   const [loding, setLoding] = useState(0)
   const lodingRef = useRef(0)
 
+  const timeRef = useRef(-1)
+
+  const flagRef = useRef(true)
+
   useEffect(() => {
     if (showFlag) {
       window.unityLoading = (progress: number) => {
         const num = Math.round(Number(progress * 100))
         setLoding(num)
-        if (num >= 100) {
-          setShowFlag(false)
-          if (callBackFu) callBackFu()
 
-          setTimeout(() => {
+        if (num >= 100 && flagRef.current) {
+          clearTimeout(timeRef.current)
+          setShowFlag(false)
+          setFlag(true)
+          timeRef.current = window.setTimeout(() => {
             setLoding(0)
-            // 销毁自己
-            // domDelOwnFu('#Zloding')
-          }, 500)
+            setFlag(false)
+          }, 1000)
+          if (callBackFu) callBackFu()
+          flagRef.current = false
         }
       }
     }
@@ -55,7 +64,11 @@ function Zloding({ isShow, bacNum, callBackFu }: Props) {
   return (
     <div
       id='Zloding'
-      className={classNames(styles.Zloding, showFlag ? styles.ZlodingShow : '')}
+      className={classNames(
+        styles.Zloding,
+        showFlag ? styles.ZlodingShow : '',
+        flag && !showFlag ? styles.ZlodingChange : ''
+      )}
       style={{ backgroundImage: `url(${bacImgRes})` }}
     >
       <div className='ZlodingBox'>

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

@@ -11,14 +11,12 @@ const getUnityDomFu = () => {
 export const lodingUnityFu = () => {
   const modalIframe = getUnityDomFu()
   if (modalIframe) {
-    window.sceneNum=1
     modalIframe.style.display = 'block'
     modalIframe.src = `unity${isPc ? 'Pc' : 'Mo'}/index.html`
   }
 }
 
 // unity场景的显示和隐藏
-
 export const unityShow = (val: boolean) => {
   const modalIframe = getUnityDomFu()
   if (modalIframe) {
@@ -26,8 +24,46 @@ export const unityShow = (val: boolean) => {
   }
 }
 
+// 获取当前场景key
+export const getUnityKey = () => {
+  let key = ''
+
+  const dom: any = document.getElementById('modalIframe')
+  if (dom && dom.contentWindow) {
+    const iframeWindow = dom.contentWindow
+
+    if (iframeWindow.sceneStaRes) {
+      key = iframeWindow.sceneStaRes()
+    }
+  }
+  return key
+}
+
 // 切换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')
+  
+  if (dom.src.includes('unity')) {
+    const res = getUnityKey()
+
+    if (res !== val) {
+      unityShow(true)
+      callIframeFu('loadScene', val)
+      backFu()
+    }
+  } else {
+    // 被销毁了,需要重新加载
+    // lodingUnityFu()
+  }
 }
+
+// 重新加载unity
+// export const lodingUnityAgainFu = () => {
+//   const rootDom = document.querySelector('#root') as HTMLDivElement
+//   if (rootDom) {
+
+//   }
+// }

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

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

+ 16 - 6
src/pages/A6ybwx/index.tsx

@@ -9,7 +9,7 @@ import { isPc } from '@/utils/http'
 import MenuSider from '@/components/MenuSider'
 import Skip from '@/components/Skip'
 import { domDelOwnFu } from '@/utils/utilsSome'
-import { cutUnityFu } from '../A0base/data'
+import { cutUnityFu, getUnityKey } from '../A0base/data'
 import Zloding from '@/components/Zloding'
 
 function A6ybwx() {
@@ -18,6 +18,16 @@ function A6ybwx() {
 
   const [isEnter, setIsEnter] = useState(false)
 
+  // 是否还需要重新加载场景
+  const [lodingScene, setLodingScene] = useState(true)
+
+  useEffect(() => {
+    const unityKey = getUnityKey()
+    if (unityKey === 'RoomScene') {
+      setLodingScene(false)
+    }
+  }, [])
+
   useEffect(() => {
     if (videoRefLast.current) videoRefLast.current.play()
   }, [])
@@ -65,10 +75,11 @@ function A6ybwx() {
     if (isEnter) {
       // 销毁视频
       videoRefLast.current?.pause()
-      domDelOwnFu('.videoBox')
-
+      setTimeout(() => {
+        domDelOwnFu('.videoBox')
+      }, 100)
       // 切换场景
-      cutUnityFu('RoomScene')
+      cutUnityFu('RoomScene', () => {})
     }
   }, [isEnter])
 
@@ -77,7 +88,6 @@ function A6ybwx() {
       <div
         className='back'
         onClick={() => {
-          window.sceneNum = 2
           window.location.replace('#/base')
         }}
       >
@@ -127,7 +137,7 @@ function A6ybwx() {
       {gotoTab === 3 && <SangzangHome setGotoTab={setGotoTab} />}
 
       {/* 进度条 */}
-       <Zloding isShow={isEnter} bacNum={2} /> 
+      <Zloding isShow={isEnter&&lodingScene} bacNum={2} />
     </div>
   )
 }

+ 14 - 3
src/pages/A7wjwj/conponents/Discover/index.tsx

@@ -1,20 +1,31 @@
-import React, { useEffect, useState } from 'react'
+import React, { useCallback, useEffect, useState } from 'react'
 import styles from './index.module.scss'
 import { isPc } from '@/utils/http'
 import classNames from 'classnames'
 import { useSelector } from 'react-redux'
 import { RootState } from '@/store'
+// import { cutUnityFu } from '@/pages/A0base/data'
+// import { domDelOwnFu } from '@/utils/utilsSome'
 
 function Discover(props: { style?: React.CSSProperties }) {
+
+  // 待完善 这个时候应该跳空场景
+  useEffect(()=>{
+    // cutUnityFu()
+  },[])
+
   const { myData } = useSelector((state: RootState) => state.A0Layout)
 
   // 将隐藏的页面打开,全景图->诗歌->大场景
-  const lookScene = () => {
+  const lookScene = useCallback(() => {
+    // 销毁unity
+    // domDelOwnFu('#modalIframe')
+
     const panoramicRoot = document.getElementById('panoramic-root') as HTMLElement
     panoramicRoot.style.display = 'block'
     // 打开全景图
     window.setIsShowPano(true)
-  }
+  }, [])
   const [isShowRecord, setIsShowRecord] = useState(true)
 
   // 点击查看流转轨迹之后的动画

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

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