Explorar el Código

unity小游戏的右上角按钮

任一存 hace 1 año
padre
commit
1022b1fee9

+ 3 - 7
game/README.md

@@ -11,12 +11,8 @@ https://sit-cnzhengquan.4dage.com/game/index.html#/
 ## 还缺资源:
 
 ## todo
-积分达到上限时的提示文字样式,每个游戏都要改
-
-而且新增积分始终为0。
+unity的4个游戏不用限制竖屏,有适配PC宽屏任一存(任一存)
 
-乡村林场:“请明天再来”要识别各个用户
-
-助农课堂:有bug
+积分达到上限时的提示文字样式,每个游戏都要改
 
-unity游戏的按钮?
+积分达到上限时新增积分始终为0。

BIN
game/public/unity/lost-children/Build/H5Game-ChinaSecuritiesMuseumMaze.data.unityweb


BIN
game/public/unity/lost-children/Build/H5Game-ChinaSecuritiesMuseumMaze.framework.js.unityweb


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 1 - 0
game/public/unity/lost-children/Build/H5Game-ChinaSecuritiesMuseumMaze.loader.js


BIN
game/public/unity/lost-children/Build/H5Game-ChinaSecuritiesMuseumMaze.wasm.unityweb


+ 4 - 4
game/public/unity/lost-children/ServiceWorker.js

@@ -1,9 +1,9 @@
 const cacheName = "4dkk-Maze-0.1";
 const contentToCache = [
-    "Build/寻找丢失儿童.loader.js",
-    "Build/寻找丢失儿童.framework.js.unityweb",
-    "Build/寻找丢失儿童.data.unityweb",
-    "Build/寻找丢失儿童.wasm.unityweb",
+    "Build/H5Game-ChinaSecuritiesMuseumMaze.loader.js",
+    "Build/H5Game-ChinaSecuritiesMuseumMaze.framework.js.unityweb",
+    "Build/H5Game-ChinaSecuritiesMuseumMaze.data.unityweb",
+    "Build/H5Game-ChinaSecuritiesMuseumMaze.wasm.unityweb",
     "TemplateData/style.css"
 
 ];

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 1 - 0
game/public/unity/lost-children/StreamingAssets/UnityServicesProjectConfiguration.json


+ 4 - 4
game/public/unity/lost-children/index.html

@@ -58,11 +58,11 @@
       }
 
       var buildUrl = "Build";
-      var loaderUrl = buildUrl + "/寻找丢失儿童.loader.js";
+      var loaderUrl = buildUrl + "/H5Game-ChinaSecuritiesMuseumMaze.loader.js";
       var config = {
-        dataUrl: buildUrl + "/寻找丢失儿童.data.unityweb",
-        frameworkUrl: buildUrl + "/寻找丢失儿童.framework.js.unityweb",
-        codeUrl: buildUrl + "/寻找丢失儿童.wasm.unityweb",
+        dataUrl: buildUrl + "/H5Game-ChinaSecuritiesMuseumMaze.data.unityweb",
+        frameworkUrl: buildUrl + "/H5Game-ChinaSecuritiesMuseumMaze.framework.js.unityweb",
+        codeUrl: buildUrl + "/H5Game-ChinaSecuritiesMuseumMaze.wasm.unityweb",
         streamingAssetsUrl: "StreamingAssets",
         companyName: "4dkk",
         productName: "Maze",

+ 6 - 3
game/src/views/ExamPaper2.vue

@@ -13,6 +13,7 @@
         @click="onClickReturnHome"
       />
       <button
+        v-if="store.state.gameRuleList[1].rtf"
         class="game-rule"
         @click="isShowRule = true"
       />
@@ -246,9 +247,11 @@ const isCorrect = computed(() => {
   return true
 })
 function onClickOption(idx) {
-  this.selectedIdx = idx
-  if (this.selectedIdx === questionList.value[currentQuestionIdx.value].rightOptionIdx) {
-    bonusPoint.value += store.state.gameRuleList[1].score
+  selectedIdx.value = idx
+  if (selectedIdx.value === questionList.value[currentQuestionIdx.value].rightOptionIdx) {
+    if (store.state.loginStatus) {
+      bonusPoint.value += store.state.gameRuleList[1].score
+    }
     correntCount.value++
   }
 }

+ 89 - 1
game/src/views/GameByUnity.vue

@@ -5,6 +5,30 @@
       :src="gameUrl"
       frameborder="0"
     />
+    <!-- 左上角按钮 -->
+    <div class="btn-group">
+      <button
+        class="return-home"
+        :style="{
+          backgroundImage: `url(${returnHomeBtnBgImgUrl})`,
+        }"
+        @click="onClickReturnHome"
+      />
+      <button
+        v-if="store.state.gameRuleList[gameRuleConfig.idxInGameRule].rtf"
+        class="game-rule"
+        :style="{
+          backgroundImage: `url(${gameRuleBtnBgImgUrl})`,
+        }"
+        @click="isShowRule = true"
+      />
+    </div>
+    <GameRule
+      v-show="isShowRule"
+      :game-title="gameRuleConfig.title"
+      :rich-text="store.state.gameRuleList[gameRuleConfig.idxInGameRule].rtf"
+      @close="isShowRule=false"
+    />
   </div>
 </template>
 
@@ -12,11 +36,17 @@
 import { ref, computed, watch, onMounted } from "vue"
 import { useRoute, useRouter } from "vue-router"
 import { useStore } from "vuex"
+import GameRule from '@/components/GameRule.vue'
 
 const route = useRoute()
 const router = useRouter()
 const store = useStore()
 
+const {
+  windowSizeInCssForRef,
+  windowSizeWhenDesignForRef,
+} = useSizeAdapt(390, 752)
+
 let gameUrlQuery = ''
 if (store.state.loginStatus) {
   gameUrlQuery = `?userId=${store.state.userInfo.id}&token=${store.state.token}`
@@ -27,9 +57,45 @@ const gameUrlMap = {
   EnviromentProtection: `unity/enviroment-protection/index.html${gameUrlQuery}#/`,
   LostChildren: `unity/lost-children/index.html${gameUrlQuery}#/`,
 }
-
 const gameUrl = gameUrlMap[route.query.gameName]
 
+const floatingBtnFileNameAffixMap = {
+  AntibodyBattle: ``,
+  DisasterRelief: ``,
+  EnviromentProtection: ``,
+  LostChildren: `_dark`,
+}
+const floatingBtnFileNameAffix = floatingBtnFileNameAffixMap[route.query.gameName]
+const returnHomeBtnBgImgUrl = require(`@/assets/images/icon_home${floatingBtnFileNameAffix}.png`)
+const gameRuleBtnBgImgUrl = require(`@/assets/images/icon_rules${floatingBtnFileNameAffix}.png`)
+
+function onClickReturnHome() {
+  router.push({
+    name: 'HomeView',
+  })
+}
+
+const gameRuleConfigMap = {
+  AntibodyBattle: {
+    title: '抗体大作战',
+    idxInGameRule: 3,
+  },
+  DisasterRelief: {
+    title: '应急救灾',
+    idxInGameRule: 4,
+  },
+  EnviromentProtection: {
+    title: '生态保护',
+    idxInGameRule: 5,
+  },
+  LostChildren: {
+    title: '找回走失儿童',
+    idxInGameRule: 6,
+  },
+}
+const gameRuleConfig = gameRuleConfigMap[route.query.gameName]
+const isShowRule = ref(false)
+
 </script>
 
 <style lang="less" scoped>
@@ -46,5 +112,27 @@ const gameUrl = gameUrlMap[route.query.gameName]
     width: 100%;
     height: 100%;
   }
+  >.btn-group{
+    position: absolute;
+    top: calc(36 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
+    right: calc(12 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
+    display: flex;
+    flex-direction: column;
+    gap: calc(16 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
+    >button.return-home{
+      background-size: contain;
+      background-repeat: no-repeat;
+      background-position: center center;
+      width: calc(40 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
+      height: calc(40 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
+    }
+    >button.game-rule{
+      background-size: contain;
+      background-repeat: no-repeat;
+      background-position: center center;
+      width: calc(40 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
+      height: calc(40 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
+    }
+  }
 }
 </style>

+ 4 - 1
game/src/views/PairUp.vue

@@ -19,6 +19,7 @@
         @click="onClickReturnHome"
       />
       <button
+        v-if="store.state.gameRuleList[2].rtf"
         class="game-rule"
         @click="isShowRule = true"
       />
@@ -296,7 +297,9 @@ function onClickCard(card, cardIdx) {
         if (cardList.value.every((item) => {
           return item.isDone
         })) {
-          bonusPoint.value += store.state.gameRuleList[2].score
+          if (store.state.loginStatus) {
+            bonusPoint.value += store.state.gameRuleList[2].score
+          }
           setCardList()
         }
       }, 400)

+ 20 - 17
game/src/views/PlantTree.vue

@@ -13,6 +13,7 @@
         @click="onClickReturnHome"
       />
       <button
+        v-if="store.state.gameRuleList[0].rtf"
         class="game-rule"
         @click="isShowRule = true"
       />
@@ -232,31 +233,31 @@ const stepList = [
   },
 ]
 const currentStepIdx = ref(0)
-const lastPlayTimeStr = localStorage.getItem('plant-tree-last-time')
-if (process.env.VUE_APP_CLI_MODE !== 'dev') {
-  if (lastPlayTimeStr) {
-    const lastPlayTime = new Date(Number(lastPlayTimeStr))
-    const lastPlayYear = lastPlayTime.getFullYear()
-    const lastPlayMonth = lastPlayTime.getMonth()
-    const lastPlayDay = lastPlayTime.getDay()
+const lastPlayTimeStr = localStorage.getItem(`plant-tree-last-time-${store.state.token}`)
+// if (process.env.VUE_APP_CLI_MODE !== 'dev') {
+if (lastPlayTimeStr) {
+  const lastPlayTime = new Date(Number(lastPlayTimeStr))
+  const lastPlayYear = lastPlayTime.getFullYear()
+  const lastPlayMonth = lastPlayTime.getMonth()
+  const lastPlayDay = lastPlayTime.getDay()
 
-    const currentTime = new Date()
-    const currentYear = currentTime.getFullYear()
-    const currentMonth = currentTime.getMonth()
-    const currentDay = currentTime.getDay()
+  const currentTime = new Date()
+  const currentYear = currentTime.getFullYear()
+  const currentMonth = currentTime.getMonth()
+  const currentDay = currentTime.getDay()
 
-    if (lastPlayYear === currentYear && lastPlayMonth === currentMonth && lastPlayDay === currentDay) {
-      currentStepIdx.value = stepList.length - 1
-      bonusPoint.value = 4 * store.state.gameRuleList[0].score
-    }
+  if (lastPlayYear === currentYear && lastPlayMonth === currentMonth && lastPlayDay === currentDay) {
+    currentStepIdx.value = stepList.length - 1
+    bonusPoint.value = 4 * store.state.gameRuleList[0].score
   }
 }
+// }
 const isOver = computed(() => {
   return currentStepIdx.value === stepList.length - 1
 })
 watch(isOver, (vNew) => {
   if (vNew) {
-    localStorage.setItem('plant-tree-last-time', (new Date()).getTime())
+    localStorage.setItem(`plant-tree-last-time-${store.state.token}`, (new Date()).getTime())
     if (store.state.loginStatus && !store.state.ifScoreLimitReached && bonusPoint.value !== 0) {
       addScore(bonusPoint.value).then(() => {
         getScore().then((res) => {
@@ -276,7 +277,9 @@ function onClickTool(toolIdx) {
   } else {
     if (currentStepIdx.value < stepList.length - 1) {
       currentStepIdx.value++
-      bonusPoint.value += store.state.gameRuleList[0].score
+      if (store.state.loginStatus) {
+        bonusPoint.value += store.state.gameRuleList[0].score
+      }
     }
   }
 }