Browse Source

6/2更新

添加遛狗游戏结算画面,等待后端接口开发完成后增加通讯功能。
Jees 5 days ago
parent
commit
ff020fe05b

+ 38 - 0
Assets/Resources/Data/languages.json

@@ -1002,6 +1002,44 @@
             }
         }
     },
+    "WalkDogsScore":{
+        "button": {
+            "confirm": {
+                "en": "Confirm",
+                "zh-cn": "确认"
+            }
+        },
+        "label": {
+            "score": {
+                "en": "Score:",
+                "zh-cn": "得分:"
+            },
+            "maxCombo": {
+                "en": "Combo:",
+                "zh-cn": "连击:"
+            },
+            "perfect": {
+                "en": "Perfect:",
+                "zh-cn": "完美:"
+            },
+            "good": {
+                "en": "Good:",
+                "zh-cn": "良好:"
+            },
+            "miss": {
+                "en": "Miss:",
+                "zh-cn": "未击中:"
+            },
+            "poor": {
+                "en": "Poor:",
+                "zh-cn": "差:"
+            },
+            "coin": {
+                "en": "Coin:",
+                "zh-cn": "金币:"
+            }
+        }
+    },
     "item": {
         "food": {
             "food_00001": {

+ 2 - 2
Assets/Resources/Shopping/ShoppingController.cs

@@ -299,11 +299,11 @@ public class ShoppingController : MonoBehaviour
 
             // 重新写入用户数据
             string userInfo = data["user_info"].ToString();
-            UserProperty.FreshUserInfo(userInfo);
+            UserProperty.RefreshUserInfo(userInfo);
 
             // TODO 然后重新写入道具数据
             string props = data["props"].ToString();
-            UserProperty.FreshUserItems(props);
+            UserProperty.RefreshUserItems(props);
 
             // 弹出窗户提示购买成功
             string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "shoppingUI", "message", "purchase_success", EnviromentSetting.languageCode });

+ 54 - 3
Assets/Scenes/WalkDogs.unity

@@ -129,6 +129,7 @@ GameObject:
   m_Component:
   - component: {fileID: 231689925}
   - component: {fileID: 231689926}
+  - component: {fileID: 231689927}
   m_Layer: 5
   m_Name: UIDocument
   m_TagString: Untagged
@@ -170,6 +171,24 @@ MonoBehaviour:
   m_WorldSpaceSizeMode: 1
   m_WorldSpaceWidth: 1920
   m_WorldSpaceHeight: 1080
+--- !u!114 &231689927
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 231689924}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 416698994b5d345cb8e6518f9b64aed3, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  score: 1
+  maxCombo: 2
+  perfect: 100
+  good: 3
+  poor: 4
+  miss: 5
 --- !u!1001 &334978417
 PrefabInstance:
   m_ObjectHideFlags: 0
@@ -893,6 +912,38 @@ MonoBehaviour:
   speed: 2
   hitTime: 4
   action: right
+--- !u!1 &686717305
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 686717306}
+  m_Layer: 0
+  m_Name: UI
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 1
+--- !u!4 &686717306
+Transform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 686717305}
+  serializedVersion: 2
+  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+  m_LocalPosition: {x: 1.1619562, y: 8.387269, z: -2.5946975}
+  m_LocalScale: {x: 1, y: 1, z: 1}
+  m_ConstrainProportionsScale: 0
+  m_Children:
+  - {fileID: 1658264217}
+  m_Father: {fileID: 0}
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
 --- !u!1 &844310270
 GameObject:
   m_ObjectHideFlags: 0
@@ -1699,7 +1750,7 @@ GameObject:
   - component: {fileID: 1658264215}
   - component: {fileID: 1658264214}
   m_Layer: 5
-  m_Name: ResultPanel
+  m_Name: ScorePanel
   m_TagString: Untagged
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
@@ -1781,7 +1832,7 @@ RectTransform:
   m_ConstrainProportionsScale: 0
   m_Children:
   - {fileID: 231689925}
-  m_Father: {fileID: 0}
+  m_Father: {fileID: 686717306}
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 0}
   m_AnchorMax: {x: 0, y: 0}
@@ -1925,5 +1976,5 @@ SceneRoots:
   - {fileID: 392723646}
   - {fileID: 334978417}
   - {fileID: 1101318003}
-  - {fileID: 1658264217}
   - {fileID: 1607496260}
+  - {fileID: 686717306}

+ 22 - 0
Assets/Scenes/WalkDogs/ResultPanel.uss

@@ -0,0 +1,22 @@
+.label {
+    width: 40%;
+    -unity-font-definition: url("project://database/Assets/Font/MaoKenZhuYuanTi-MaokenZhuyuanTi-2.ttf?fileID=12800000&guid=50a63638b44907e46a3fa871d63b7d39&type=3#MaoKenZhuYuanTi-MaokenZhuyuanTi-2");
+    font-size: 16px;
+}
+
+.value {
+    width: 40%;
+    font-size: 16px;
+    -unity-font-definition: url("project://database/Assets/Font/MaoKenZhuYuanTi-MaokenZhuyuanTi-2.ttf?fileID=12800000&guid=50a63638b44907e46a3fa871d63b7d39&type=3#MaoKenZhuYuanTi-MaokenZhuyuanTi-2");
+    color: rgb(255, 0, 0);
+    -unity-text-align: upper-right;
+    margin-right: 10px;
+    max-width: 80px;
+    margin-left: 30px;
+}
+
+.item {
+    flex-grow: 1;
+    flex-direction: row;
+    justify-content: center;
+}

+ 25 - 16
Assets/Scenes/WalkDogs/ResultPanel.uxml

@@ -1,26 +1,35 @@
 <ui:UXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
     <Style src="project://database/Assets/Scenes/WalkDogs/ResultPanel.uss?fileID=7433441132597879392&amp;guid=04f73cd94e38aa549b8fb5997b5c165f&amp;type=3#ResultPanel" />
     <ui:VisualElement style="flex-grow: initial; flex-shrink: initial; margin-top: 20px;">
-        <ui:VisualElement name="VisualElement" style="flex-grow: 1; flex-direction: row;">
-            <ui:Label text="&lt;Score&gt;" name="scoreLabel" style="width: 40%; height: auto;" />
-            <ui:Label text="10000" name="scoreResult" style="width: 40%;" />
+        <ui:VisualElement name="VisualElement" class="item label" style="flex-direction: row; flex-shrink: initial; flex-grow: initial; width: initial;">
+            <ui:Label text="&lt;Score&gt;" name="scoreLabel" class="label" style="width: 40%; height: auto; color: rgb(0, 75, 1); -unity-font-style: bold; font-size: 20px;" />
+            <ui:Label text="10000" name="scoreValue" class="value" style="width: 40%; -unity-font-style: bold; color: rgb(0, 75, 1); font-size: 20px;" />
         </ui:VisualElement>
-        <ui:VisualElement name="VisualElement" style="flex-grow: 1; flex-direction: row;">
-            <ui:Label text="&lt;maxCombo&gt;" name="maxComboLabel" style="width: 40%;" />
-            <ui:Label text="10000" name="maxComboScore" style="width: 40%;" />
+        <ui:VisualElement name="VisualElement" class="item" style="flex-grow: 1; flex-direction: row; -unity-font-style: bold; color: rgb(0, 75, 1);">
+            <ui:Label text="&lt;maxCombo&gt;" name="maxComboLabel" class="label" style="width: 40%; color: rgb(0, 75, 1);" />
+            <ui:Label text="10000" name="maxComboValue" class="value" style="width: 40%; color: rgb(0, 75, 1);" />
         </ui:VisualElement>
-        <ui:VisualElement name="VisualElement" style="flex-grow: 1; flex-direction: row;">
-            <ui:Label text="&lt;Perfect&gt;" name="perfectLabel" style="width: 40%;" />
-            <ui:Label text="10000" name="perfectScore" style="width: 40%;" />
+        <ui:VisualElement name="VisualElement" class="item" style="flex-grow: 1; flex-direction: row; -unity-text-outline-color: rgb(0, 75, 1);">
+            <ui:Label text="&lt;Perfect&gt;" name="perfectLabel" class="label" style="width: 40%; color: rgb(0, 75, 1); -unity-font-style: bold;" />
+            <ui:Label text="10000" name="perfectValue" class="value" style="width: 40%; color: rgb(0, 75, 1); -unity-font-style: bold;" />
         </ui:VisualElement>
-        <ui:VisualElement name="VisualElement" style="flex-grow: 1; flex-direction: row;">
-            <ui:Label text="&lt;Good&gt;" name="goodLabel" style="width: 40%;" />
-            <ui:Label text="10000" name="goodScore" style="width: 40%;" />
+        <ui:VisualElement name="VisualElement" class="item" style="flex-grow: 1; flex-direction: row;">
+            <ui:Label text="&lt;Good&gt;" name="goodLabel" class="label" style="width: 40%;" />
+            <ui:Label text="10000" name="goodValue" class="value" style="width: 40%; color: rgb(27, 27, 27);" />
         </ui:VisualElement>
-        <ui:VisualElement name="VisualElement" style="flex-grow: 1; flex-direction: row;">
-            <ui:Label text="&lt;Poor&gt;" name="poorLabel" style="width: 40%;" />
-            <ui:Label text="10000" name="poorScore" style="width: 40%;" />
+        <ui:VisualElement name="VisualElement" class="item" style="flex-grow: 1; flex-direction: row;">
+            <ui:Label text="&lt;Poor&gt;" name="poorLabel" class="label" style="width: 40%; color: rgb(166, 0, 0); font-size: 14px;" />
+            <ui:Label text="10000" name="poorValue" class="value" style="width: 40%; color: rgb(166, 0, 0); font-size: 14px;" />
+        </ui:VisualElement>
+        <ui:VisualElement name="VisualElement" class="item" style="color: rgb(166, 0, 0);">
+            <ui:Label text="&lt;Miss&gt;" name="missLabel" class="label" style="color: rgb(166, 0, 0); font-size: 14px;" />
+            <ui:Label text="10000" name="missValue" class="value" style="color: rgb(166, 0, 0); font-size: 14px;" />
+        </ui:VisualElement>
+        <ui:VisualElement name="VisualElement" class="item" style="flex-grow: 1; background-image: none; margin-top: 20px; margin-bottom: 20px;">
+            <ui:VisualElement name="VisualElement" style="align-self: center; background-image: url(&quot;project://database/Assets/Packages/2D%20Casual%20UI/Sprite/GUI.png?fileID=21300042&amp;guid=1eaee135ce037439d925cee5e41ce026&amp;type=3#GUI_21&quot;); background-size: 30px 30px; width: 30px; height: 30px;" />
+            <ui:Label text="&lt;Coin Award&gt;" name="coinLabel" class="label" style="width: 40%; background-image: none; background-size: 30px 30px; color: rgb(255, 223, 0);" />
+            <ui:Label text="10000" name="coinValue" class="value" style="width: 40%; margin-left: 0; color: rgb(255, 223, 0);" />
         </ui:VisualElement>
-        <ui:Button text="&lt;Confirm&gt;" name="confirm" style="width: 80%; align-self: center;" />
     </ui:VisualElement>
+    <ui:Button text="&lt;Confirm&gt;" name="confirm" style="flex-grow: 1; flex-direction: row; -unity-font-definition: url(&quot;project://database/Assets/Font/MaoKenZhuYuanTi-MaokenZhuyuanTi-2.ttf?fileID=12800000&amp;guid=50a63638b44907e46a3fa871d63b7d39&amp;type=3#MaoKenZhuYuanTi-MaokenZhuyuanTi-2&quot;); font-size: 18px; -unity-font-style: normal; background-color: rgba(188, 188, 188, 0); width: 50%; align-self: center; border-top-color: rgb(27, 27, 27); border-left-color: rgb(27, 27, 27); border-right-color: rgb(27, 27, 27); border-bottom-color: rgb(27, 27, 27); border-top-width: 1.5px; border-right-width: 1.5px; border-bottom-width: 1.5px; border-left-width: 1.5px; border-top-left-radius: 10px; border-top-right-radius: 10px; border-bottom-right-radius: 10px; border-bottom-left-radius: 10px; -unity-text-outline-color: rgb(27, 27, 27); bottom: 15%; position: absolute;" />
 </ui:UXML>

+ 2 - 2
Assets/Scripts/Bathroom/BathroomController.cs

@@ -248,9 +248,9 @@ public class BathroomController : MonoBehaviour
             //     UserProperty.dogs.Add(dog);
             // }
             string dogs = data["dogs"].ToString();
-            UserProperty.FreshDogInfo(dogs);
+            UserProperty.RefreshDogInfo(dogs);
             string props = data["props"].ToString();
-            UserProperty.FreshUserItems(props);
+            UserProperty.RefreshUserItems(props);
 
             string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", "dog_is_clean", EnviromentSetting.languageCode });
             // MessageBoxController.ShowMessage(msg, ()=> SceneManager.LoadScene("Home"));

+ 2 - 3
Assets/Scripts/Develop Script/TestSetup.cs

@@ -51,11 +51,10 @@ public class TestSetup : MonoBehaviour
 
         }
 
-
+        // 如果场景不是从login开始的,初始化环境数据
         if (EnviromentSetting.languageData == null)
         {
-            //EnviromentController.InitialGameEnviroment();
-
+            EnviromentController.InitialGameEnviroment();
         }
     }
     // Start is called once before the first execution of Update after the MonoBehaviour is created

+ 1 - 2
Assets/Scripts/EnviromentSetting.cs

@@ -43,8 +43,7 @@ public static class EnviromentSetting
     public static int maxDogQty = 3;
 
     // 运行环境 
-    // todo 正式版设定为release 未来从服务器获取
-    public static string runEnv = "Test"; // NA, Test, Release
+    public static string runEnv = "Release"; // NA, Dev, Release
 
     // 语音识别通过分数
     public static float voiceRecognitionScore = 0.6f;

+ 5 - 3
Assets/Scripts/GameControllers/UserProperty.cs

@@ -2,6 +2,7 @@
 using System;
 using System.Collections;
 using System.Collections.Generic;
+using System.Runtime.InteropServices;
 using UnityEngine;
 
 /* 本文件中包含2各类文件
@@ -25,6 +26,7 @@ public static class UserProperty
     public static Dictionary<string, int> toy = new();
     public static Dictionary<string, int> other = new();
     public static List<DogProperty> dogs = new();
+    public static string runEnv = "Release"; // NA, Dev, Release
 
     public static string dogNames()
     {
@@ -39,7 +41,7 @@ public static class UserProperty
     }
 
     // 更新用户信息
-    public static void FreshUserInfo(string userInfoJson)
+    public static void RefreshUserInfo(string userInfoJson)
     {
         Dictionary<string, string> userInfo = JsonConvert.DeserializeObject<Dictionary<string, string>>(userInfoJson);
         UserProperty.name = userInfo["user_name"];
@@ -53,7 +55,7 @@ public static class UserProperty
     }
 
     // 更新用户food, toy, other数据
-    public static void FreshUserItems(string itemsJson)
+    public static void RefreshUserItems(string itemsJson)
     {
         UserProperty.food.Clear();
         UserProperty.toy.Clear();
@@ -73,7 +75,7 @@ public static class UserProperty
     }
 
     // 更新用户名下狗的信息
-    public static void FreshDogInfo(string dogsJson)
+    public static void RefreshDogInfo(string dogsJson)
     {
         UserProperty.dogs.Clear();
         DogProperty[] dogProperties = JsonConvert.DeserializeObject<DogProperty[]>(dogsJson);

+ 4 - 4
Assets/Scripts/Home/HomeController.cs

@@ -437,7 +437,7 @@ public class HomeController : MonoBehaviour
         questionMarkParticle = Instantiate(questionMarkParticle);
         questionMarkParticle.name = "QuestionMarkParticle";
         questionMarkParticle.transform.SetParent(dog.transform);
-        questionMarkParticle.transform.localPosition = new Vector3(0, 0.4f, 0.4f);
+        questionMarkParticle.transform.localPosition = new Vector3(0, 0.6f, 0.4f);
         questionMarkParticle.transform.localRotation = Quaternion.Euler(-90, 0, 0);
         ParticleSystem ps = questionMarkParticle.GetComponent<ParticleSystem>();
         ps.Stop();
@@ -480,7 +480,7 @@ public class HomeController : MonoBehaviour
         {
             // 刷新狗的数据
             string dogJson = data["dogs"].ToString();
-            UserProperty.FreshDogInfo(dogJson);
+            UserProperty.RefreshDogInfo(dogJson);
 
             // TODO 根据返回结果设定focusdog
             float highestScore = 0;
@@ -593,7 +593,7 @@ public class HomeController : MonoBehaviour
             {
                 // 刷新狗的数据
                 string dogJson = data["dogs"].ToString();
-                UserProperty.FreshDogInfo(dogJson);
+                UserProperty.RefreshDogInfo(dogJson);
 
                 // 找到得分最高的指令
                 float highestScore = 0;
@@ -660,7 +660,7 @@ public class HomeController : MonoBehaviour
 
                     //  刷新狗的数据,包含dogsInScene
                     string dogJson = data["dogs"].ToString();
-                    UserProperty.FreshDogInfo(dogJson);
+                    UserProperty.RefreshDogInfo(dogJson);
 
                     var trainingDog = dogsInScene[GameData.focusDog];
                     trainingDog.ReloadDogProperty();        // 刷新狗的数据

+ 3 - 3
Assets/Scripts/Home/ItemUseWebCommController.cs

@@ -60,14 +60,14 @@ public class ItemUseWebCommController : MonoBehaviour
         {
             // 刷新用户数据
             var userInfoJson = data["user_info"].ToString();
-            UserProperty.FreshUserInfo(userInfoJson);
+            UserProperty.RefreshUserInfo(userInfoJson);
 
             string dogJson = data["dogs"].ToString();
-            UserProperty.FreshDogInfo(dogJson);
+            UserProperty.RefreshDogInfo(dogJson);
 
             // 刷新道具数据
             var itemsJson = data["props"].ToString();
-            UserProperty.FreshUserItems(itemsJson);
+            UserProperty.RefreshUserItems(itemsJson);
         }
         else
         {

+ 2 - 2
Assets/Scripts/Login/CreateOrAdopt.cs

@@ -201,9 +201,9 @@ public class CreateOrAdopt : MonoBehaviour
         {
             // 成功处理逻辑
             string user_info = data["user_info"].ToString();
-            UserProperty.FreshUserInfo(user_info);
+            UserProperty.RefreshUserInfo(user_info);
             string dog_list = data["dog_list"].ToString();
-            UserProperty.FreshDogInfo(dog_list);
+            UserProperty.RefreshDogInfo(dog_list);
             string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "InitDogUI", "message", "receive_success", EnviromentSetting.languageCode });
             msg = msg.Replace("<<dog_name>>", data["dog_name"].ToString());
             MessageBoxController.ShowMessage(msg, () => SceneManager.LoadScene("Home"));

+ 3 - 3
Assets/Scripts/Login/InitDogUIController.cs

@@ -232,14 +232,14 @@ public class InitDogUIController : MonoBehaviour
         {
             // 刷新用户所有数据
             var user_info = data["user_info"].ToString();
-            UserProperty.FreshUserInfo(user_info);
+            UserProperty.RefreshUserInfo(user_info);
 
             // 保存狗的数据
             string dogsJson = data["dogs"].ToString();
-            UserProperty.FreshDogInfo(dogsJson);
+            UserProperty.RefreshDogInfo(dogsJson);
 
             // 保存道具数据
-            UserProperty.FreshUserItems(data["props"].ToString());
+            UserProperty.RefreshUserItems(data["props"].ToString());
 
             // SceneManager.LoadScene("Home");
             MaskTransitions.TransitionManager.Instance.LoadLevel("Home");

+ 6 - 3
Assets/Scripts/Login/LoginController.cs

@@ -182,14 +182,17 @@ public class LoginController : MonoBehaviour
         if (data != null && data["status"].ToString() == "success")
         {
             var user_info = data["user_info"].ToString();
-            UserProperty.FreshUserInfo(user_info);
+            UserProperty.RefreshUserInfo(user_info);
+            var user_info_dict = JsonConvert.DeserializeObject<Dictionary<string, object>>(user_info);
+            // todo 将用户运行环境保存到设定中
+            // EnviromentSetting.runEnv = user_info_dict["runEnv"].ToString();
 
             // 保存狗的数据
             string dogsJson = data["dogs"].ToString();
-            UserProperty.FreshDogInfo(dogsJson);
+            UserProperty.RefreshDogInfo(dogsJson);
 
             // 保存道具数据
-            UserProperty.FreshUserItems(data["props"].ToString());
+            UserProperty.RefreshUserItems(data["props"].ToString());
 
             // 判断用户狗的数量,如果为0就跳转用户创建狗。
             if (UserProperty.dogs.Count < 1)

+ 21 - 1
Assets/Scripts/WalkDogs/SoundGameController.cs

@@ -54,6 +54,7 @@ public class SoundGameController : MonoBehaviour
     void Update()
     {
         DogStatusUpdate();
+        UpdateAndShowScoreUI();
     }
 
     IEnumerator DogComponentInstaller()
@@ -185,6 +186,8 @@ public class SoundGameController : MonoBehaviour
                 Debug.Log($"Combo: {combo}");
                 Debug.Log($"Max Combo: {maxCombo}");
                 // 结束游戏
+                UpdateAndShowScoreUI();
+
                 break;      // 跳出 while 循环
             }
 
@@ -459,7 +462,7 @@ public class SoundGameController : MonoBehaviour
     }
 
     // 协程控制场景里面的狗按照指定速度移动到指定的位置
-    IEnumerator DogMoveToPosition(GameObject dog, Vector3 targetPosition, float speed=0.5f)
+    IEnumerator DogMoveToPosition(GameObject dog, Vector3 targetPosition, float speed = 0.5f)
     {
         while (Vector3.Distance(dog.transform.position, targetPosition) > 0.1f)
         {
@@ -467,6 +470,23 @@ public class SoundGameController : MonoBehaviour
             yield return null;
         }
     }
+
+    private void UpdateAndShowScoreUI()
+    {
+        // 更新分数显示逻辑
+        // 这里可以添加代码来更新UI上的分数显示
+        // 例如:scoreLabel.text = "Score: " + score;
+        var UI = GameObject.Find("UI");
+        var scorePanel = UI.transform.Find("ScorePanel").gameObject;
+        scorePanel.SetActive(true);
+        var walkDogsScoreController = scorePanel.transform.Find("UIDocument").GetComponent<WalkDogsScoreController>();
+        walkDogsScoreController.score = score;
+        walkDogsScoreController.maxCombo = maxCombo;
+        walkDogsScoreController.perfect = perfectCount;
+        walkDogsScoreController.good = goodCount;
+        walkDogsScoreController.poor = poorCount;
+        walkDogsScoreController.miss = missCount;
+    }
 }
 
 

+ 124 - 0
Assets/Scripts/WalkDogs/WalkDogsScoreController.cs

@@ -0,0 +1,124 @@
+using System.Collections.Generic;
+using Newtonsoft.Json;
+using UnityEngine;
+using UnityEngine.UIElements;
+using ZXing;
+
+/* * WalkDogsScoreController.cs
+ * This script is responsible for managing the score in the Walk Dogs game.
+ * It will handle score updates, display, and any related functionality.
+ */
+
+public class WalkDogsScoreController : MonoBehaviour
+{
+    // Start is called once before the first execution of Update after the MonoBehaviour is created
+    public int score, maxCombo, perfect, good, poor, miss;
+    private int coin;
+    private Label scoreLabel, maxComboLabel, perfectLabel, goodLabel, poorLabel, missLabel, coinLabel;
+    private Label scoreValueLabel, maxComboValueLabel, perfectValueLabel, goodValueLabel, poorValueLabel, missValueLabel, coinValueLabel;
+
+    private Button confirmButton;
+    void Start()
+    {
+        var root = GetComponent<UIDocument>().rootVisualElement;
+        scoreLabel = root.Q<Label>("scoreLabel");
+        maxComboLabel = root.Q<Label>("maxComboLabel");
+        perfectLabel = root.Q<Label>("perfectLabel");
+        goodLabel = root.Q<Label>("goodLabel");
+        poorLabel = root.Q<Label>("poorLabel");
+        missLabel = root.Q<Label>("missLabel");
+        coinLabel = root.Q<Label>("coinLabel");
+        confirmButton = root.Q<Button>("confirm");
+        scoreValueLabel = root.Q<Label>("scoreValue");
+        maxComboValueLabel = root.Q<Label>("maxComboValue");
+        perfectValueLabel = root.Q<Label>("perfectValue");
+        goodValueLabel = root.Q<Label>("goodValue");
+        poorValueLabel = root.Q<Label>("poorValue");
+        missValueLabel = root.Q<Label>("missValue");
+        coinValueLabel = root.Q<Label>("coinValue");
+        confirmButton = root.Q<Button>("confirm");
+        // confirmButton.clicked += ScoreSubmitRequest;
+        confirmButton.clicked += ConfirmButtonClick;
+
+        LabelLanguageLoading();
+    }
+
+    // Update is called once per frame
+    void Update()
+    {
+        ScoreDisplay();
+    }
+
+    // 读取显示正确的语言
+    void LabelLanguageLoading()
+    {
+        string textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "WalkDogsScore", "label", "score", EnviromentSetting.languageCode });
+        scoreLabel.text = textValue;
+        textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "WalkDogsScore", "label", "maxCombo", EnviromentSetting.languageCode });
+        maxComboLabel.text = textValue;
+        textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "WalkDogsScore", "label", "perfect", EnviromentSetting.languageCode });
+        perfectLabel.text = textValue;
+        textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "WalkDogsScore", "label", "good", EnviromentSetting.languageCode });
+        goodLabel.text = textValue;
+        textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "WalkDogsScore", "label", "poor", EnviromentSetting.languageCode });
+        poorLabel.text = textValue;
+        textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "WalkDogsScore", "label", "miss", EnviromentSetting.languageCode });
+        missLabel.text = textValue;
+        textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "WalkDogsScore", "label", "coin", EnviromentSetting.languageCode });
+        coinLabel.text = textValue;
+        textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "WalkDogsScore", "button", "confirm", EnviromentSetting.languageCode });
+        confirmButton.text = textValue;
+    }
+
+    void ScoreDisplay()
+    {
+        coin = Mathf.FloorToInt(score / 1000f);
+        // Display the score and other statistics in the UI
+        scoreValueLabel.text = score.ToString();
+        maxComboValueLabel.text = maxCombo.ToString();
+        perfectValueLabel.text = perfect.ToString();
+        goodValueLabel.text = good.ToString();
+        poorValueLabel.text = poor.ToString();
+        missValueLabel.text = miss.ToString();
+        coinValueLabel.text = coin.ToString();
+
+        // Optionally, you can also log the score to the console for debugging
+        Debug.Log($"Score: {score}, Max Combo: {maxCombo}, Perfect: {perfect}, Good: {good}, Poor: {poor}, Miss: {miss}, Coin: {coin}");
+    }
+    // This method should be called when the score is ready to be displayed
+
+    private void ConfirmButtonClick()
+    {
+        MaskTransitions.TransitionManager.Instance.LoadLevel("Home");
+    }
+
+    private void ScoreSubmitRequest()
+    {
+        Debug.Log("GetUserData request");
+        // 提交POST
+        string url = "/api/walkdogs/score/";
+        WWWForm form = new();
+        form.AddField("user_id", UserProperty.userId);
+        form.AddField("score", score);
+        form.AddField("max_combo", maxCombo);
+        form.AddField("perfect", perfect); 
+        form.AddField("good", good);
+        form.AddField("poor", poor);
+        form.AddField("miss", miss);
+        form.AddField("coin", coin);
+        StartCoroutine(WebController.PostRequest(url, form, callback: ScoreSubmitCallback));
+    }
+
+    private void ScoreSubmitCallback(string response)
+    {
+        var data = JsonConvert.DeserializeObject<Dictionary<string, string>>(response);
+        if (data != null && data["status"] == "success")
+        { 
+            string user_info = data["user_info"].ToString();
+            UserProperty.RefreshUserInfo(user_info);
+            string dogs = data["dogs"].ToString();
+            UserProperty.RefreshDogInfo(dogs);
+            MaskTransitions.TransitionManager.Instance.LoadLevel("Home");
+        }
+    }
+}

+ 2 - 0
Assets/Scripts/WalkDogs/WalkDogsScoreController.cs.meta

@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 416698994b5d345cb8e6518f9b64aed3