Quellcode durchsuchen

4/21更新

解决场景虚化问题。完成大部分语音训练流程
Jees vor 1 Monat
Ursprung
Commit
f594bfb170

+ 2 - 0
.gitignore

@@ -8,3 +8,5 @@
 /.utmp/
 /.vsconfig
 .DS_Store
+.sln
+.csproj

+ 6 - 6
Assets/Resources/Data/languages.json

@@ -222,19 +222,19 @@
             "en": "Will you send <<dog name>> to your friend?",
             "zh-cn": "把<<dog name>>送给你的好友吗?"
         },
-        "record_dog_name": {
+        "voiceCall_00": {
             "en": "Are you ready? Please hold record and say the puppy's name.",
             "zh-cn": "准备好了吗?按住下面的录音按键说出狗狗的名字。"
         },
-        "record_again": {
+        "voiceCall_01": {
             "en": "Record again. Ensure that the two recordings are consistent.",
             "zh-cn": "再输入一次。确保两次录音一致。"
         },
-        "record_success": {
-            "en": "Now your dog knows its own name. In the future, you can call it by pressing the voice recording button.",
-            "zh-cn": "现在它知道自己的名字了。以后按下录音键就可以呼唤它了。"
+        "voiceCall_10": {
+            "en": "Now your dog knows its own name. In the future, you can call it by pressing the voice recording button.<br>Call it often, and it will be more obedient.",
+            "zh-cn": "现在它知道自己的名字了。以后按下录音键就可以呼唤它了。<br>经常呼叫他,它会更听话哦。"
         },
-        "record_fail": {
+        "voiceCall_20": {
             "en": "Record fail. Please try again.",
             "zh-cn": "录音失败。请再试一次。"
         },

+ 4 - 3
Assets/Resources/VoiceAndManu/VoiceController.cs

@@ -16,7 +16,7 @@ public class VoiceController : MonoBehaviour
     private Coroutine waveCoroutine;
     private AudioClip audioClip;    // 保存的音频
     private bool isRecording = false;
-    private string filePathWav, filePathZip; 
+    private string filePathWav, filePathZip;
     public bool isCommandMode = false;       // 是否在命令对话模式下,是的话只显示语音按钮
     private DateTime startRecTime, stopRecTime;
 
@@ -94,7 +94,7 @@ public class VoiceController : MonoBehaviour
         foreach (var dog in HomeController.dogsInScene)
         {
             dog.RemoveZzzParticle();
-            dog.animator.SetTrigger("Listen");
+            dog.animator.SetTrigger("listen");
             dog.animator.SetBool("isListening", true);
         }
         StartRecording();
@@ -188,7 +188,8 @@ public class VoiceController : MonoBehaviour
     }
 
     // 保存音频文件wav
-    void SaveWavFile(string path, AudioClip audio) {
+    void SaveWavFile(string path, AudioClip audio)
+    {
         // 创建文件流
         using (FileStream fileStream = new(path, FileMode.Create))
         {

+ 22 - 4
Assets/Scenes/Home.unity

@@ -12610,7 +12610,7 @@ MonoBehaviour:
   m_RendererIndex: -1
   m_VolumeLayerMask:
     serializedVersion: 2
-    m_Bits: 64
+    m_Bits: 4294967295
   m_VolumeTrigger: {fileID: 1189983932}
   m_VolumeFrameworkUpdateModeOption: 2
   m_RenderPostProcessing: 1
@@ -13531,6 +13531,7 @@ GameObject:
   - component: {fileID: 1707757223}
   - component: {fileID: 1707757225}
   - component: {fileID: 1707757224}
+  - component: {fileID: 1707757226}
   m_Layer: 0
   m_Name: VCam Dog
   m_TagString: Untagged
@@ -13600,7 +13601,7 @@ MonoBehaviour:
   m_PrefabInstance: {fileID: 0}
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 1707757219}
-  m_Enabled: 1
+  m_Enabled: 0
   m_EditorHideFlags: 0
   m_Script: {fileID: 11500000, guid: 172515602e62fb746b5d573b38a5fe58, type: 3}
   m_Name: 
@@ -13630,7 +13631,7 @@ MonoBehaviour:
   m_RendererIndex: -1
   m_VolumeLayerMask:
     serializedVersion: 2
-    m_Bits: 1
+    m_Bits: 4294967295
   m_VolumeTrigger: {fileID: 0}
   m_VolumeFrameworkUpdateModeOption: 2
   m_RenderPostProcessing: 1
@@ -13661,7 +13662,7 @@ Camera:
   m_PrefabInstance: {fileID: 0}
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 1707757219}
-  m_Enabled: 1
+  m_Enabled: 0
   serializedVersion: 2
   m_ClearFlags: 1
   m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
@@ -13705,6 +13706,23 @@ Camera:
   m_OcclusionCulling: 1
   m_StereoConvergence: 10
   m_StereoSeparation: 0.022
+--- !u!114 &1707757226
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1707757219}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 449ef5ebbe24720439ec31d15f7b6f3d, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  m_FocusTracksTarget: 0
+  m_FocusTracking: 1
+  m_FocusTarget: {fileID: 0}
+  m_FocusOffset: 0
+  m_Profile: {fileID: 11400000, guid: 623e2f7043efeb447b7c23ba4264efd9, type: 2}
 --- !u!1 &1726968932
 GameObject:
   m_ObjectHideFlags: 0

+ 2 - 43
Assets/Scenes/Home_Profiles/VCam Dog Profile(URP).asset

@@ -29,8 +29,8 @@ MonoBehaviour:
     m_OverrideState: 0
     m_Value: 0
   focusDistance:
-    m_OverrideState: 0
-    m_Value: 5.36
+    m_OverrideState: 1
+    m_Value: 13.6
   aperture:
     m_OverrideState: 1
     m_Value: 1.4
@@ -60,48 +60,7 @@ MonoBehaviour:
   m_EditorClassIdentifier: 
   components:
   - {fileID: -1084599845642456363}
-  - {fileID: 2480849421263016942}
   - {fileID: 2710441084306040090}
---- !u!114 &2480849421263016942
-MonoBehaviour:
-  m_ObjectHideFlags: 3
-  m_CorrespondingSourceObject: {fileID: 0}
-  m_PrefabInstance: {fileID: 0}
-  m_PrefabAsset: {fileID: 0}
-  m_GameObject: {fileID: 0}
-  m_Enabled: 1
-  m_EditorHideFlags: 0
-  m_Script: {fileID: 11500000, guid: 97c23e3b12dc18c42a140437e53d3951, type: 3}
-  m_Name: Tonemapping
-  m_EditorClassIdentifier: 
-  active: 1
-  mode:
-    m_OverrideState: 1
-    m_Value: 2
-  neutralHDRRangeReductionMode:
-    m_OverrideState: 0
-    m_Value: 2
-  acesPreset:
-    m_OverrideState: 0
-    m_Value: 3
-  hueShiftAmount:
-    m_OverrideState: 0
-    m_Value: 0
-  detectPaperWhite:
-    m_OverrideState: 0
-    m_Value: 0
-  paperWhite:
-    m_OverrideState: 0
-    m_Value: 300
-  detectBrightnessLimits:
-    m_OverrideState: 0
-    m_Value: 1
-  minNits:
-    m_OverrideState: 0
-    m_Value: 0.005
-  maxNits:
-    m_OverrideState: 0
-    m_Value: 1000
 --- !u!114 &2710441084306040090
 MonoBehaviour:
   m_ObjectHideFlags: 3

+ 5 - 5
Assets/Scripts/Develop Script/TestSetup.cs

@@ -76,11 +76,11 @@ public class TestSetup : MonoBehaviour
     {
         if (SceneManager.GetActiveScene().name == "Login")
         {
-            //PlayerPrefs.SetString("LoginToken", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiSlRZTlpQOU8iLCJleHAiOjE3NTY1NDUxNzd9.oQgjY_6ZHJVYaYxh2b_LMIkUaCJ9FX8UpxpHOt_yLg8");
-            //DateTime now = DateTime.Now;
-            //DateTime oneHourAgo = now.AddHours(-1);
-            //PlayerPrefs.SetString("LoginTokenTime", oneHourAgo.ToString());
-            //EnviromentSetting.UUID = "abc";
+            PlayerPrefs.SetString("LoginToken", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiSlRZTlpQOU8iLCJleHAiOjE3NTY1NDUxNzd9.oQgjY_6ZHJVYaYxh2b_LMIkUaCJ9FX8UpxpHOt_yLg8");
+            DateTime now = DateTime.Now;
+            DateTime oneHourAgo = now.AddHours(-1);
+            PlayerPrefs.SetString("LoginTokenTime", oneHourAgo.ToString());
+            EnviromentSetting.UUID = "abc";
 
             // PlayerPrefs.DeleteAll();
             // EnviromentSetting.languageCode = "en";

+ 21 - 1
Assets/Scripts/EnviromentController.cs

@@ -6,7 +6,9 @@ using System.IO;
 using Unity.VisualScripting.FullSerializer;
 
 
-/* EnviromentController类主要功能是操作EnviromentSetting类,包含初始化数据,设置语言等 */
+/* EnviromentController类主要功能是操作EnviromentSetting类,包含初始化数据,设置语言等 
+ * 必须挂载在第一个场景的Camera上
+ */
 
 public class EnviromentController : MonoBehaviour
 {
@@ -79,7 +81,25 @@ public class EnviromentController : MonoBehaviour
         //Application.logMessageReceived -= LogMessage;       
     }
 
+    void PlayerPrefsLoader()
+    {
+        if (PlayerPrefs.HasKey("lastTrainingDate"))
+        {
+            // 读取存储的日期
+            string lastTrainingDate = PlayerPrefs.GetString("lastTrainingDate");
+            string today = System.DateTime.Now.ToString("yyyy-MM-dd");
+            if (lastTrainingDate != today)
+            {
+                // 如果不是同一天,执行相应的操作
+                GameData.isVoiceTrainingToday = false;
+            }
+            else
+            {
+                GameData.isVoiceTrainingToday = true;
+            }
+        }
 
+    }
     // Update is called once per frame
     //void Update()
     //{

+ 1 - 0
Assets/Scripts/GameControllers/GameData.cs

@@ -8,5 +8,6 @@ public static class GameData
     public static int homeCamFocusDog = 100;      // Home场景下,摄像机聚焦的狗。100表示不聚焦任何的狗
     public static string playedToy = string.Empty;        // 用于暂存游戏中使用的玩具
     public static string bathItemId = string.Empty;        // 用于暂存洗澡场景中使用的道具
+    public static bool isVoiceTrainingToday;        // 是否今天已经进行过语音训练
 
 }

+ 66 - 16
Assets/Scripts/Home/HomeController.cs

@@ -40,7 +40,7 @@ public class HomeController : MonoBehaviour
     float interactTime = 0f;        // 交互时间
 
     //private bool isTrainingMode = false;        // 是否在训练状态
-    private string trainingContent = "";        // 训练内容
+    private string trainingContent = String.Empty;        // 训练内容 _xx 对于language.json 0x开始提示 1x成功提示 2x失败提示
     private int totalTrainingTimes = 2;        // 训练总次数
     private int currentTrainingTimes = 0;        // 当前训练次数
     private string trainingDogId = "";        // 训练的狗id
@@ -125,7 +125,7 @@ public class HomeController : MonoBehaviour
             {
                 foreach (var dog in dogsInScene)
                 {
-                    if (dog.dogProperty.voiceCall == 0)
+                    if (!dog.dogProperty.voiceCallEnable)
                     {
                         //isTrainingMode = true;
                         sceneMode = SceneMode.TRAINING;
@@ -140,11 +140,49 @@ public class HomeController : MonoBehaviour
                         interactDog = dogsInScene[GameData.focusDog].gameObject;
                         VoiceButtonOnlySwitch(true);        // 交互模式下关闭其他菜单
                     }
+                    else if (dog.dogProperty.voiceCall > 40 && !dog.dogProperty.voiceCommandEnable && dog.dogProperty.voiceCallEnable)
+                    {
+                        // 当狗的voiceCall大于40,且没有voiceCommand能力时,进入第一阶段指令训练模式
+                        int random = UnityEngine.Random.Range(0, 100);
+                        if (random < 25 && !dog.dogProperty.commandSit)
+                        {
+                            trainingContent = "commandSit";
+                        }
+                        else if (random < 50 && !dog.dogProperty.commandStand)
+                        {
+                            trainingContent = "commandStand";
+                        }
+                        else if (random < 75 && !dog.dogProperty.commandBark)
+                        {
+                            trainingContent = "commandBark";
+                        }
+                        else if (random < 100 && !dog.dogProperty.commandLieDown)
+                        {
+                            trainingContent = "commandLieDown";
+                        }
+                        else
+                        {
+                            trainingContent = String.Empty;
+                        }
+
+                        if (trainingContent != String.Empty)
+                        {
+                            sceneMode = SceneMode.TRAINING;
+                            dog.RemoveZzzParticle();
+                            trainingDogId = dog.dogProperty.d_id;
+                            totalTrainingTimes = 2;
+                            currentTrainingTimes = 0;
+                            GameData.focusDog = dogsInScene.IndexOf(dog);
+                            //GameData.focusDog = UserProperty.GetDogIndexById(dog.dogProperty.d_id);
+                            dogsInScene[GameData.focusDog].SetupInteract();
+                            interactDog = dogsInScene[GameData.focusDog].gameObject;
+                            VoiceButtonOnlySwitch(true);        // 交互模式下关闭其他菜单
+                        }
+                    }
                 }
             }
 
-
-            if (this.sceneMode == SceneMode.TRAINING)
+            else if (this.sceneMode == SceneMode.TRAINING)
             {
                 foreach (var dog in dogsInScene)
                 {
@@ -159,28 +197,31 @@ public class HomeController : MonoBehaviour
                         }
                         else
                         {
-                            //dog.dogState = "training";
                             dog.dogState = DogState.TRAINING;
                             if (!isTrainingMsgShowed_1 && !isTrainingMsgShowed_2 && currentTrainingTimes == 0)
                             {
-                                string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", "record_dog_name", EnviromentSetting.languageCode });
+                                string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", trainingContent + "_00", EnviromentSetting.languageCode });
                                 MessageBoxController.ShowMessage(msg);
                                 var BGM = GameObject.Find("BGM");
                                 if (BGM != null)
                                 {
-                                    //BGM.GetComponent<AudioSource>().Stop();
                                     FadeBGM(BGM.GetComponent<AudioSource>(), false);
                                 }
                                 isTrainingMsgShowed_1 = true;
                             }
                             else if (!isTrainingMsgShowed_2 && isTrainingMsgShowed_1 && currentTrainingTimes == 1)
                             {
-                                string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", "record_again", EnviromentSetting.languageCode });
+                                string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", trainingContent + "_01", EnviromentSetting.languageCode });
                                 MessageBoxController.ShowMessage(msg);
                                 isTrainingMsgShowed_2 = true;
                             }
                         }
                     }
+                    else
+                    {
+                        // 暂时将其他非训练状态的狗game object隐藏
+                        dog.gameObject.SetActive(false);
+                    }
                 }
             }
             else if (sceneMode == SceneMode.INACTIVE)
@@ -200,7 +241,7 @@ public class HomeController : MonoBehaviour
                         {
                             dog.ExitInteract();
                             sceneMode = SceneMode.NORMAL;       // 交互结束,退出交互状态
-                            //isInteractMode = false;        // 交互结束,退出交互状态
+                                                                //isInteractMode = false;        // 交互结束,退出交互状态
                             VoiceButtonOnlySwitch(false);        // 交互结束,打开其他菜单
                         }
                         else
@@ -217,7 +258,11 @@ public class HomeController : MonoBehaviour
                 foreach (var dog in dogsInScene)
                 {
                     // 如果在eat drink进程结束前不执行随机场景代码
-                    //if (dog.itemConsumeProgress)        // TODO 以后用DogInScene.dogState来判断
+                    // 检测有隐藏的狗,显示出来
+                    if (dog.gameObject.activeSelf == false)
+                    {
+                        dog.gameObject.SetActive(true);
+                    }
                     if (dog.dogState == DogState.ITEM_CONSUME)
                     {
                         if (dog.isMovingToBowl)
@@ -261,8 +306,9 @@ public class HomeController : MonoBehaviour
                 }
             }
             #endregion
-        }
 
+
+        }
     }
 
     private void OnDestroy()
@@ -596,7 +642,7 @@ public class HomeController : MonoBehaviour
                     string dogJson = data["dogs"].ToString();
                     UserProperty.FreshDogInfo(dogJson);
 
-                    string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", "record_success", EnviromentSetting.languageCode });
+                    string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", trainingContent + "_10", EnviromentSetting.languageCode });
                     Time.timeScale = 0f;
                     foreach (var dog in dogsInScene)
                     {
@@ -607,14 +653,18 @@ public class HomeController : MonoBehaviour
                     }
                     MessageBoxController.ShowMessage(msg, ResetTrainingModeParameters);
                     this.sceneMode = SceneMode.NORMAL;
-                    //isTrainingMode = false;
+
+                    GameData.isVoiceTrainingToday = true;        // 训练完成,设置为true
+                    string todayDate = System.DateTime.Now.ToString("yyyy-MM-dd");
+                    PlayerPrefs.SetString("lastTrainingDate", todayDate);
+                    PlayerPrefs.Save();
 
                 }
                 else if (data["message"].ToString() == "fail")
                 {
                     HomeSoundEffectController.Instance.PlaySoundEffect(4);
 
-                    string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", "record_fail", EnviromentSetting.languageCode });
+                    string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", trainingContent + "_20", EnviromentSetting.languageCode });
                     Time.timeScale = 0f;
                     MessageBoxController.ShowMessage(msg, RestartTraining);
                 }
@@ -634,7 +684,7 @@ public class HomeController : MonoBehaviour
     private void ResetTrainingModeParameters()
     {
         //isTrainingMode = false;
-        trainingContent = "";
+        trainingContent = String.Empty;
         totalTrainingTimes = 2;
         currentTrainingTimes = 0;
         trainingDogId = "";
@@ -718,7 +768,7 @@ public class HomeController : MonoBehaviour
 
     #region 场景环境控制
     // 淡入或淡出背景音乐
-    private void FadeBGM(AudioSource bgmSource, bool fadeIn, float duration=2f)
+    private void FadeBGM(AudioSource bgmSource, bool fadeIn, float duration = 2f)
     {
         // fadeIn: true表示淡入 false表示淡出
         if (bgmSource == null) return; // 如果没有 AudioSource,则直接返回