Browse Source

5/14更新

2025/5/14 添加购物数量设定
修改TextField rootStyle的式样
修改狗退出互动模式后,出现滑动的画面
增加狗进入听主人呼唤时候,转身的动画
Jees 3 weeks ago
parent
commit
8cd6e9732e

+ 25 - 19
Assets/Resources/Data/languages.json

@@ -1,4 +1,4 @@
-{
+ {
     "version": "0.1.0",
     "release date": "2024/12/9",
     "default language": "en",
@@ -390,7 +390,10 @@
             "en": "Are you sure to quit the game?",
             "zh-cn": "确定要退出游戏吗?"
         },
-
+        "reset_voice_reminder":{
+            "en": "Are you sure to reset <<dog_name>> voice training data?",
+            "zh-cn": "确定要重置<<dog_name>>语音训练数据吗?"
+        },
 
 
         "from here not used. no_more_food": {
@@ -398,7 +401,7 @@
             "zh-cn": "<dog_name>吃饱了。它不想再吃了。"
         },
         "no_more_water": {
-            "en": "<dog_name> doesn't want to drive more water.",
+            "en": "<dog_name> doesn't want to drink more water.",
             "zh-cn": "<dog_name>不想喝水了。"
         },
         "hungry_message": {
@@ -420,22 +423,6 @@
         "sad_mood": {
             "en": "<dog_name> looks not happy.",
             "zh-cn": "<dog_name>看起来不太开心。"
-        },
-        "sit_trainng": {
-            "en": "Are you ready? Now you can train <dog name> to sit down. Press and hold the recording button below to say the command.",
-            "zh-cn": "准备好了吗?现在可以训练<dog name>坐下了。按住下面的录音按键说出指令。"
-        },
-        "lie_down_trainng": {
-            "en": "Are you ready? Now you can train <dog name> to lie down. Press and hold the recording button below to say the command.",
-            "zh-cn": "准备好了吗?现在可以训练<dog name>躺下了。按住下面的录音按键说出指令。"
-        },
-        "spin_trainng": {
-            "en": "Are you ready? Now you can train <dog name> to spin. Press and hold the recording button below to say the command.",
-            "zh-cn": "准备好了吗?现在可以训练<dog name>转圈了。按住下面的录音按键说出指令。"
-        },
-        "reset_voice_reminder":{
-            "en": "Are you sure to reset <<dog name>> voice training data?",
-            "zh-cn": "确定要重置<<dog name>>语音训练数据吗?"
         }
     },
     "canvas": {
@@ -682,6 +669,12 @@
                 "en": "<<item_name>> purchase successful.",
                 "zh-cn": "<<item_name>>购买成功。"
             }
+        },
+        "message_box": {
+            "qty": {
+                "en": "Quantity",
+                "zh-cn": "数量"
+            }
         }
     },
     "warehouseUI": {
@@ -1036,6 +1029,19 @@
                     "en": "Dog Shower Gel",
                     "zh-cn": "沐浴露"
                 }
+            },
+            "other_00002": {
+                "price": 5,
+                "picture": "Shopping/pictures/other_00002",
+                "category": "",
+                "type": "",
+                "property": "",
+                "parameter": "",
+                "max qty": 99,
+                "description": {
+                    "en": "Dog Toothbrush",
+                    "zh-cn": "狗牙刷"
+                }
             }
         }
     }

+ 9 - 15
Assets/Resources/Dog/AnimatorController/shibaInu/HomeDogAnimatorController.controller

@@ -244,8 +244,8 @@ AnimatorStateTransition:
   m_IsExit: 0
   serializedVersion: 3
   m_TransitionDuration: 0.14395118
-  m_TransitionOffset: 0.02549873
-  m_ExitTime: 0.028763173
+  m_TransitionOffset: 0
+  m_ExitTime: 0
   m_HasExitTime: 1
   m_HasFixedDuration: 1
   m_InterruptionSource: 0
@@ -808,10 +808,7 @@ AnimatorStateTransition:
   m_PrefabInstance: {fileID: 0}
   m_PrefabAsset: {fileID: 0}
   m_Name: 
-  m_Conditions:
-  - m_ConditionMode: 1
-    m_ConditionEvent: turnRight
-    m_EventTreshold: 0
+  m_Conditions: []
   m_DstStateMachine: {fileID: 0}
   m_DstState: {fileID: 7237981366999321087}
   m_Solo: 0
@@ -846,7 +843,7 @@ AnimatorStateTransition:
   m_Mute: 0
   m_IsExit: 0
   serializedVersion: 3
-  m_TransitionDuration: 0.9325599
+  m_TransitionDuration: 0.5
   m_TransitionOffset: 0
   m_ExitTime: 0
   m_HasExitTime: 1
@@ -1188,7 +1185,7 @@ AnimatorState:
   m_MirrorParameterActive: 0
   m_CycleOffsetParameterActive: 0
   m_TimeParameterActive: 0
-  m_Motion: {fileID: 0}
+  m_Motion: {fileID: -3339085233561973423, guid: 1a349bfe663f8a848a567303e35c613a, type: 3}
   m_Tag: 
   m_SpeedParameter: 
   m_MirrorParameter: 
@@ -1531,18 +1528,15 @@ AnimatorStateTransition:
   m_PrefabInstance: {fileID: 0}
   m_PrefabAsset: {fileID: 0}
   m_Name: 
-  m_Conditions:
-  - m_ConditionMode: 1
-    m_ConditionEvent: turnLeft
-    m_EventTreshold: 0
+  m_Conditions: []
   m_DstStateMachine: {fileID: 0}
   m_DstState: {fileID: -2934287470583496230}
-  m_Solo: 1
+  m_Solo: 0
   m_Mute: 0
   m_IsExit: 0
   serializedVersion: 3
   m_TransitionDuration: 0.030618595
-  m_TransitionOffset: 0.023092771
+  m_TransitionOffset: 0
   m_ExitTime: 0.0017944714
   m_HasExitTime: 0
   m_HasFixedDuration: 1
@@ -2042,7 +2036,7 @@ AnimatorStateTransition:
   m_Mute: 0
   m_IsExit: 0
   serializedVersion: 3
-  m_TransitionDuration: 0.6
+  m_TransitionDuration: 0.5
   m_TransitionOffset: 0
   m_ExitTime: 0
   m_HasExitTime: 1

+ 34 - 1
Assets/Resources/Shopping/ShoppingController.cs

@@ -24,6 +24,8 @@ public class ShoppingController : MonoBehaviour
     private Button yesButton, noButton;
     private Label msgBody;
     private VisualElement msgRoot, msgField;
+    private TextField qtyField;
+    int puchaseQty = 1; // 购买数量,默认1个    
 
     // 选中的产品
     private string selectedItemId, selectedItemDesc, selectedItemPrice;
@@ -53,8 +55,10 @@ public class ShoppingController : MonoBehaviour
         msgBody = msgField.Q<Label>("msgBody");
         yesButton = msgField.Q<Button>("msgYes");
         noButton = msgField.Q<Button>("msgNo");
+        qtyField = msgField.Q<TextField>("qtyField");
         noButton.clicked += MsgNoClick;
         yesButton.clicked += MsgYesClick;
+        qtyField.RegisterValueChangedCallback(OnQtyFieldValueChanged);
 
         //初始化设定
         LanguageSetting();
@@ -92,6 +96,8 @@ public class ShoppingController : MonoBehaviour
         yesButton.text = textValue;
         textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "shoppingUI", "button", "no", EnviromentSetting.languageCode });
         noButton.text = textValue;
+        textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "shoppingUI", "message_box", "qty", EnviromentSetting.languageCode });
+        qtyField.label = textValue;
     }
 
     /*获取所有产品列表,切换商品分类之后,需要重新读取和加载
@@ -207,6 +213,8 @@ public class ShoppingController : MonoBehaviour
         selectedItemPrice = price;
         msgBody.text = description;
         msgRoot.visible = true;
+        qtyField.value = "1"; // 重置数量输入框
+        puchaseQty = 1; // 重置购买数量
     }
 
     // 数据读取
@@ -280,7 +288,7 @@ public class ShoppingController : MonoBehaviour
         WWWForm form = new();
         form.AddField("user_id", UserProperty.userId);
         form.AddField("item_id", itemId);
-        form.AddField("qty", 1);
+        form.AddField("qty", puchaseQty);
         StartCoroutine(WebController.PostRequest(url, form, callback: PurchaseItemCallback));
     }
 
@@ -309,7 +317,32 @@ public class ShoppingController : MonoBehaviour
         {
             Debug.Log(data["message"]);
         }
+    }
 
+    private void OnQtyFieldValueChanged(ChangeEvent<string> evt)
+    {
+        // 尝试将输入内容转换为整数
+        if (int.TryParse(evt.newValue, out int value))
+        {
+            // 检查是否在 1 到 999 的范围内
+            if (value < 1)
+            {
+                qtyField.value = "1"; // 如果小于 1,自动修正为 1
+            }
+            else if (value > 99)
+            {
+                qtyField.value = "99"; // 如果大于 999,自动修正为 999
+            }
+            yesButton.SetEnabled(true); // 启用确认按钮
+            puchaseQty = value; // 更新购买数量
+        }
+        else
+        {
+            // 如果输入不是有效的整数,清空或提示用户
+            qtyField.value = ""; // 清空输入
+            yesButton.SetEnabled(false); // 禁用确认按钮
+            Debug.Log("请输入有效的整数!");
+        }
     }
 }
 

+ 36 - 0
Assets/Resources/Shopping/ShoppingUI.uss

@@ -25,3 +25,39 @@
     -unity-font-style: bold;
     transition-duration: 0.6s;
 }
+
+.qtyField > .unity-label {
+    width: 70%;
+    height: auto;
+    -unity-font-definition: url("project://database/Assets/Font/MaoKenZhuYuanTi-MaokenZhuyuanTi-2.ttf?fileID=12800000&guid=50a63638b44907e46a3fa871d63b7d39&type=3#MaoKenZhuYuanTi-MaokenZhuyuanTi-2");
+    font-size: 13px;
+    min-width: 0;
+    -unity-text-align: middle-right;
+    flex-shrink: initial;
+}
+
+.qtyField > .unity-base-field__input {
+    width: 30%;
+    height: 20px;
+    -unity-font-definition: url("project://database/Assets/Font/MaoKenZhuYuanTi-MaokenZhuyuanTi-2.ttf?fileID=12800000&guid=50a63638b44907e46a3fa871d63b7d39&type=3#MaoKenZhuYuanTi-MaokenZhuyuanTi-2");
+    font-size: 13px;
+    background-color: rgba(255, 255, 255, 0.63);
+    border-top-left-radius: 10px;
+    border-top-right-radius: 10px;
+    border-bottom-right-radius: 10px;
+    border-bottom-left-radius: 10px;
+    padding-top: 1px;
+    padding-right: 1px;
+    padding-bottom: 1px;
+    padding-left: 1px;
+    margin-top: 0;
+    margin-right: 0;
+    margin-bottom: 0;
+    margin-left: 0;
+    max-width: 100%;
+    -unity-text-align: middle-center;
+}
+
+.qtyField {
+    align-items: center;
+}

+ 2 - 0
Assets/Resources/Shopping/msgRoot.uxml

@@ -1,7 +1,9 @@
 <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
+    <Style src="project://database/Assets/Resources/Shopping/ShoppingUI.uss?fileID=7433441132597879392&amp;guid=2061d71fe2582bb40b712ea028ae8eea&amp;type=3#ShoppingUI" />
     <ui:VisualElement name="msgRoot" style="flex-grow: 1; position: absolute; align-items: center; justify-content: space-around; width: 100%; height: 100%; flex-direction: column; transition-duration: 0.5s;">
         <ui:VisualElement name="msgField" style="flex-grow: initial; width: 240px; height: auto; top: auto; flex-shrink: initial; bottom: auto; background-color: rgba(255, 255, 255, 0.71); border-top-left-radius: 15px; border-top-right-radius: 15px; border-bottom-right-radius: 15px; border-bottom-left-radius: 15px; flex-direction: row; justify-content: space-around; flex-wrap: wrap; border-top-width: 2px; border-left-width: 2px; border-right-width: 2px; border-bottom-width: 2px; border-top-color: rgb(0, 0, 0); border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0);">
             <ui:Label text="message body" name="msgBody" style="width: 100%; flex-wrap: nowrap; height: auto; -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;); padding-left: 4px; padding-right: 4px; min-height: 60px;" />
+            <ui:TextField label="&lt;Quantity&gt;" keyboard-type="NumberPad" name="qtyField" value="1" max-length="-1" class="textField qtyField" style="width: 90%; height: 30px; font-size: 14px;" />
             <ui:Button text="yes" name="msgYes" style="width: 100px; height: 30px; margin-top: 10px; -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;); color: rgb(255, 255, 255); -unity-font-style: bold; background-color: rgba(0, 255, 0, 0.71); border-top-width: 0; border-right-width: 0; border-bottom-width: 0; border-left-width: 0; border-top-left-radius: 10px; border-top-right-radius: 10px; border-bottom-right-radius: 10px; border-bottom-left-radius: 10px; margin-bottom: 10px;" />
             <ui:Button text="no" name="msgNo" style="width: 100px; height: 30px; margin-top: 10px; -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;); -unity-font-style: bold; color: rgb(255, 255, 255); background-color: rgba(255, 0, 0, 0.71); border-top-width: 0; border-right-width: 0; border-bottom-width: 0; border-left-width: 0; border-top-left-radius: 10px; border-top-right-radius: 10px; border-bottom-right-radius: 10px; border-bottom-left-radius: 10px; margin-bottom: 10px;" />
         </ui:VisualElement>

+ 7 - 3
Assets/Scripts/GameControllers/GameData.cs

@@ -5,13 +5,17 @@ using System;
 
 public static class GameData
 {
-    public static string subScene;      // 用于指定子场景用
+    #region 游戏运行数据
     public static int focusDog = 0;     // 游戏中目前玩家主要玩的狗
     public static int homeCamFocusDog = 100;      // Home场景下,摄像机聚焦的狗。100表示不聚焦任何的狗
-    public static string playedToy = string.Empty;        // 用于暂存游戏中使用的玩具
-    public static string bathItemId = string.Empty;        // 用于暂存洗澡场景中使用的道具
     public static bool isVoiceTrainingToday;        // 是否今天已经进行过语音训练
     // public static bool isFirstInteraction = true;        // 是否第一次互动
     public static DateTime lastFeedbackTime = new DateTime(2000, 1, 1);        // 上次反馈的时间
+    #endregion
 
+    #region 临时保存数据
+    public static string subScene;      // 用于指定子场景用
+    public static string playedToy = string.Empty;        // 用于暂存游戏中使用的玩具
+    public static string bathItemId = string.Empty;        // 用于暂存洗澡场景中使用的道具
+    #endregion
 }

+ 5 - 5
Assets/Scripts/Home/DogInScene.cs

@@ -284,8 +284,9 @@ public class DogInScene //: ScriptableObject
             this.moveToLocation = new Vector3(x, 0, z);
             //Debug.Log("move to location:" + x + ", " + z);
             this.isMoving = true;
-            this.animator.SetTrigger("move");
+            //this.animator.SetTrigger("move");
             this.animator.SetBool("isMoving", true);
+            animator.Play("move");
             this.animator.SetFloat("moveSpeed", this.moveSpeed);
         }
         if (this.animator.GetBool("isMoving"))
@@ -324,10 +325,9 @@ public class DogInScene //: ScriptableObject
     {
         //StopCoroutine(movingCoroutine);
         //this.animator.SetTrigger("listen");
+        ResetAnimationStatus();
         this.animator.SetBool("isListening", true);
-        this.animator.SetBool("isMoving", false);
-        this.animator.SetBool("isBarking", false);
-        this.animator.SetBool("isSleeping", false);
+        animator.Play("base");
         this.isSleeping = false;     // 主人呼叫可以唤醒狗
         this.gameObject.transform.LookAt(new Vector3(0, 0, -6));
         HomeController.playerCam.Priority = 10;
@@ -337,7 +337,7 @@ public class DogInScene //: ScriptableObject
         this.dogState = DogState.LISTEN;
     }
 
-    public IEnumerator RotationToPlayer()
+    public IEnumerator RotationToPlayerAndListen()
     {
         //计算自己方向和player之间连线的夹角
         float rotationSpeed = 30f;

+ 1 - 2
Assets/Scripts/Home/HomeController.cs

@@ -324,7 +324,7 @@ public class HomeController : MonoBehaviour
                         if (listenBreak)        // 如果用户按下说话按键,立刻切换到监听状态
                         {
                             // dog.Listen();
-                            StartCoroutine(dog.RotationToPlayer());
+                            StartCoroutine(dog.RotationToPlayerAndListen());
                         }
                         else if (dog.isMoving)
                         {
@@ -404,7 +404,6 @@ public class HomeController : MonoBehaviour
 
         // 加载Rigidbody
         Rigidbody rigidbody = dog.AddComponent<Rigidbody>();
-        //Rigidbody rigidbody = dog.GetComponent<Rigidbody>();
         //rigidbody.isKinematic = true;
         rigidbody.mass = 10;
         rigidbody.linearDamping = 10;

+ 0 - 1
Assets/Scripts/Home/UserFeedbackController.cs

@@ -97,7 +97,6 @@ public class UserFeedbackController : MonoBehaviour
         }
         else
         {
-            Debug.Log("Login Token fail!");
             Debug.Log(json);
         }
     }

+ 11 - 12
Assets/UI Toolkit/Style/rootStyle.uss

@@ -12,16 +12,17 @@
 
 .textField > .unity-label {
     width: 33%;
-    height: 50px;
+    height: auto;
     -unity-font-definition: url("project://database/Assets/Font/MaoKenZhuYuanTi-MaokenZhuyuanTi-2.ttf?fileID=12800000&guid=50a63638b44907e46a3fa871d63b7d39&type=3#MaoKenZhuYuanTi-MaokenZhuyuanTi-2");
     font-size: 13px;
     min-width: 0;
     -unity-text-align: middle-left;
+    flex-shrink: initial;
 }
 
 .textField > .unity-base-field__input {
     width: auto;
-    height: auto;
+    height: 20px;
     -unity-font-definition: url("project://database/Assets/Font/MaoKenZhuYuanTi-MaokenZhuyuanTi-2.ttf?fileID=12800000&guid=50a63638b44907e46a3fa871d63b7d39&type=3#MaoKenZhuYuanTi-MaokenZhuyuanTi-2");
     font-size: 13px;
     background-color: rgba(255, 255, 255, 0.63);
@@ -33,15 +34,16 @@
     padding-right: 1px;
     padding-bottom: 1px;
     padding-left: 1px;
-    margin-top: 10px;
-    margin-right: 10px;
-    margin-bottom: 10px;
-    margin-left: 10px;
+    margin-top: 0;
+    margin-right: 0;
+    margin-bottom: 0;
+    margin-left: 0;
     max-width: 100%;
-    -unity-text-align: upper-left;
+    -unity-text-align: middle-center;
 }
 
 .textField {
+    align-items: center;
 }
 
 .textField__multiline {
@@ -79,15 +81,12 @@
     margin-left: 0;
     max-width: 100%;
     justify-content: flex-start;
-    /* min-width: 100%; */
     position: relative;
     min-height: 40px;
     -unity-text-align: upper-left;
 }
-.textField__multiline > .unity-base-field__input >.unity-base-text-field__multiline-container{
-    /* margin-top: -15px; */
-    /* height: auto; */
-    /* height: 100px; */
+
+.textField__multiline > .unity-base-field__input > .unity-base-text-field__multiline-container {
 }
 
 .err_msg {