|
@@ -46,6 +46,7 @@ public class HomeController : MonoBehaviour
|
|
|
private string trainingDogId = ""; // 训练的狗id
|
|
|
private bool isTrainingMsgShowed_1 = false; // 第一条是否已经显示训练提示
|
|
|
private bool isTrainingMsgShowed_2 = false; // 第二条是否已经显示训练提示
|
|
|
+ private bool isTrainingAnimationPlayed = false; // 训练动画是否已经播放
|
|
|
|
|
|
private void Awake()
|
|
|
{
|
|
@@ -118,31 +119,21 @@ public class HomeController : MonoBehaviour
|
|
|
}
|
|
|
|
|
|
// 生成一个数据数用于随机开启动画,如果和狗的randomFactor相同就开启动画
|
|
|
- int randomCheck = UnityEngine.Random.Range(0, 51);
|
|
|
+ int sceneRandomFactor = UnityEngine.Random.Range(0, 51);
|
|
|
|
|
|
// 检测是否有狗没有通过voiceCall训练,如果有,立刻进入训练模式
|
|
|
if (sceneMode == SceneMode.NORMAL) // 这段代码用于在NORMAL场景下检测是否有狗进入训练模式
|
|
|
{
|
|
|
foreach (var dog in dogsInScene)
|
|
|
{
|
|
|
+ if (trainingContent != String.Empty) { break; } // 如果已经有狗进入训练模式,跳出循环
|
|
|
if (!dog.dogProperty.voiceCallEnable)
|
|
|
{
|
|
|
- //isTrainingMode = true;
|
|
|
- sceneMode = SceneMode.TRAINING;
|
|
|
- dog.RemoveZzzParticle();
|
|
|
trainingContent = "voiceCall";
|
|
|
- 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); // 交互模式下关闭其他菜单
|
|
|
}
|
|
|
- else if (dog.dogProperty.voiceCall > 40 && dog.dogProperty.voiceCallEnable && !GameData.isVoiceTrainingToday)
|
|
|
+ else if (dog.dogProperty.voiceCall >= 40 && dog.dogProperty.voiceCallEnable && !GameData.isVoiceTrainingToday)
|
|
|
{
|
|
|
- // 当狗的voiceCall大于40,进入第一阶段指令训练模式
|
|
|
+ // 当狗的voiceCall大于等于40,进入第一阶段指令训练模式
|
|
|
int random = UnityEngine.Random.Range(0, 100);
|
|
|
if (random < 25 && !dog.dogProperty.commandSit)
|
|
|
{
|
|
@@ -160,33 +151,55 @@ public class HomeController : MonoBehaviour
|
|
|
{
|
|
|
trainingContent = "commandLieDown";
|
|
|
}
|
|
|
- else
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // trainingContent = String.Empty;
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ else if (dog.dogProperty.voiceCommand >= 40 && dog.dogProperty.voiceCommandEnable && !GameData.isVoiceTrainingToday)
|
|
|
+ {
|
|
|
+ // 当狗的voiceCommand大于等于40,进入第二阶段指令训练模式
|
|
|
+ int random = UnityEngine.Random.Range(0, 100);
|
|
|
+ if (random < 20 && !dog.dogProperty.commandRotate)
|
|
|
{
|
|
|
- trainingContent = String.Empty;
|
|
|
- GameData.isVoiceTrainingToday = true;
|
|
|
+ trainingContent = "commandRotate";
|
|
|
}
|
|
|
-
|
|
|
- if (trainingContent != String.Empty)
|
|
|
+ else if (random < 40 && !dog.dogProperty.commandHug)
|
|
|
{
|
|
|
- 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 (trainingContent != "voiceCall")
|
|
|
- {
|
|
|
- string command = trainingContent.Substring(7);
|
|
|
- dog.animator.SetTrigger(command);
|
|
|
- dog.animator.SetBool("is" + command + "ing", true);
|
|
|
- }
|
|
|
+ trainingContent = "commandHug";
|
|
|
}
|
|
|
+ else if (random < 60 && !dog.dogProperty.commandDeath)
|
|
|
+ {
|
|
|
+ trainingContent = "commandDeath";
|
|
|
+ }
|
|
|
+ else if (random < 80 && !dog.dogProperty.commandTurnL)
|
|
|
+ {
|
|
|
+ trainingContent = "commandTurnL";
|
|
|
+ }
|
|
|
+ else if (random < 100 && !dog.dogProperty.commandTurnR)
|
|
|
+ {
|
|
|
+ trainingContent = "commandTurnR";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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;
|
|
|
+ GameData.isVoiceTrainingToday = true;
|
|
|
+ VoiceButtonOnlySwitch(true); // 交互模式下关闭其他菜单
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -206,10 +219,25 @@ public class HomeController : MonoBehaviour
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+
|
|
|
+ // 开始训练时让狗播放动画
|
|
|
+ if (trainingContent != "voiceCall" && !isTrainingAnimationPlayed)
|
|
|
+ {
|
|
|
+ string command = trainingContent.Substring(7);
|
|
|
+ dog.animator.SetTrigger(command);
|
|
|
+ dog.animator.SetBool(command + "_status", true);
|
|
|
+ isTrainingAnimationPlayed = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 狗完成移动后,开始进入正式训练交互模式
|
|
|
dog.dogState = DogState.TRAINING;
|
|
|
if (!isTrainingMsgShowed_1 && !isTrainingMsgShowed_2 && currentTrainingTimes == 0)
|
|
|
{
|
|
|
string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", trainingContent + "_00", EnviromentSetting.languageCode });
|
|
|
+ if (msg.Contains("<<dog_name>>"))
|
|
|
+ {
|
|
|
+ msg = msg.Replace("<<dog_name>>", dog.dogProperty.dog_name);
|
|
|
+ }
|
|
|
MessageBoxController.ShowMessage(msg);
|
|
|
var BGM = GameObject.Find("BGM");
|
|
|
if (BGM != null)
|
|
@@ -221,6 +249,10 @@ public class HomeController : MonoBehaviour
|
|
|
else if (!isTrainingMsgShowed_2 && isTrainingMsgShowed_1 && currentTrainingTimes == 1)
|
|
|
{
|
|
|
string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", trainingContent + "_01", EnviromentSetting.languageCode });
|
|
|
+ if (msg.Contains("<<dog_name>>"))
|
|
|
+ {
|
|
|
+ msg = msg.Replace("<<dog_name>>", dog.dogProperty.dog_name);
|
|
|
+ }
|
|
|
MessageBoxController.ShowMessage(msg);
|
|
|
isTrainingMsgShowed_2 = true;
|
|
|
}
|
|
@@ -293,7 +325,7 @@ public class HomeController : MonoBehaviour
|
|
|
dog.RandomMove();
|
|
|
}
|
|
|
|
|
|
- else if (randomCheck == dog.randomFactor && !dog.isSleeping) // 当狗自身的随机数和系统随机数相同时候触发。约100秒触发一次。
|
|
|
+ else if (sceneRandomFactor == dog.randomFactor && !dog.isSleeping) // 当狗自身的随机数和系统随机数相同时候触发。约100秒触发一次。
|
|
|
{
|
|
|
TimeSpan ts = DateTime.Now - dog.animationStartTime;
|
|
|
if (ts.Seconds >= 30) // 如果距离上一个动作超过30秒就可以开始新的动作
|
|
@@ -333,8 +365,6 @@ public class HomeController : MonoBehaviour
|
|
|
//void InitialScene()
|
|
|
IEnumerator InitialScene()
|
|
|
{
|
|
|
- //yield return null;
|
|
|
- //yield return null;
|
|
|
yield return null; // 跳过三帧,初始化最多三只狗
|
|
|
//Debug.Log(isInitialDone);
|
|
|
foreach (var dog in UserProperty.dogs)
|
|
@@ -461,6 +491,11 @@ public class HomeController : MonoBehaviour
|
|
|
// 计算多只狗的中心位置,用于主摄像机瞄准
|
|
|
private Vector3 CenterOfDogs()
|
|
|
{
|
|
|
+ if (dogsInScene.Count == 0)
|
|
|
+ {
|
|
|
+ return Vector3.zero;
|
|
|
+ }
|
|
|
+
|
|
|
Vector3 center = Vector3.zero;
|
|
|
foreach (var dog in dogsInScene)
|
|
|
{
|
|
@@ -480,13 +515,7 @@ public class HomeController : MonoBehaviour
|
|
|
WWWForm form = new();
|
|
|
form.AddField("user_id", UserProperty.userId);
|
|
|
|
|
|
- // TODO 待后台开发完成后,开启网络通讯功能,目前暂用临时直接赋值
|
|
|
StartCoroutine(WebController.PostRequest(url, form, filePath, callback: VoiceCallCallback));
|
|
|
- sceneMode = SceneMode.INACTIVE; // 场景进入交互模式
|
|
|
- //isInteractMode = true; // 场景进入交互模式
|
|
|
- dogsInScene[0].SetupInteract();
|
|
|
- interactDog = dogsInScene[0].gameObject;
|
|
|
- VoiceButtonOnlySwitch(true); // 交互模式下关闭其他菜单
|
|
|
}
|
|
|
|
|
|
// 语音呼唤上传回调函数
|
|
@@ -507,39 +536,54 @@ public class HomeController : MonoBehaviour
|
|
|
var scoresList = JsonConvert.DeserializeObject<Dictionary<string, float>>(scores);
|
|
|
foreach (var score in scoresList)
|
|
|
{
|
|
|
- if (score.Value > highestScore)
|
|
|
+ // 根据狗的数量度修正得分。计算方式为狗的voiceCall属性值/1000
|
|
|
+ int dogIndex = UserProperty.GetDogIndexById(score.Key);
|
|
|
+ if (dogIndex < 0)
|
|
|
{
|
|
|
- highestScore = score.Value;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ float scoreFactor = UserProperty.dogs[dogIndex].voiceCall / 1000f;
|
|
|
+ float adjScore = score.Value + scoreFactor;
|
|
|
+ if (adjScore > 1)
|
|
|
+ {
|
|
|
+ adjScore = 1;
|
|
|
+ }
|
|
|
+ if (adjScore > highestScore)
|
|
|
+ {
|
|
|
+ highestScore = adjScore;
|
|
|
+
|
|
|
highestScoreDogId = score.Key;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (highestScore >= 60) // 60分以上才可以进入交互模式
|
|
|
+ if (highestScore >= 0.6) // 60分以上才可以进入交互模式
|
|
|
{
|
|
|
GameData.focusDog = UserProperty.GetDogIndexById(highestScoreDogId);
|
|
|
+ sceneMode = SceneMode.INACTIVE; // 交互模式
|
|
|
VoiceButtonOnlySwitch(true); // 交互模式下关闭其他菜单
|
|
|
foreach (var dog in dogsInScene)
|
|
|
{
|
|
|
if (dog.dogProperty.d_id == highestScoreDogId)
|
|
|
{
|
|
|
- if (GameTool.Random100Check(dog.dogProperty.voiceCall))
|
|
|
+ // if (GameTool.Random100Check(dog.dogProperty.voiceCall))
|
|
|
+ // {
|
|
|
+ // dog.SetupInteract();
|
|
|
+ interactDog = dog.gameObject;
|
|
|
+ // focusdog 开启互动模式
|
|
|
+ // HomeController.dogsInScene[GameData.focusDog].dogState = DogState.INTERACT;
|
|
|
+ HomeController.dogsInScene[GameData.focusDog].SetupInteract();
|
|
|
+ // 其他狗进入隐藏模式
|
|
|
+ foreach (var otherDog in dogsInScene)
|
|
|
{
|
|
|
- dog.SetupInteract();
|
|
|
- interactDog = dog.gameObject;
|
|
|
- // focusdog 开启互动模式
|
|
|
- HomeController.dogsInScene[GameData.focusDog].dogState = DogState.INTERACT;
|
|
|
- HomeController.dogsInScene[GameData.focusDog].SetupInteract();
|
|
|
- // 其他狗进入隐藏模式
|
|
|
- foreach (var otherDog in dogsInScene)
|
|
|
+ if (otherDog.dogProperty.d_id != highestScoreDogId)
|
|
|
{
|
|
|
- if (otherDog.dogProperty.d_id != highestScoreDogId)
|
|
|
- {
|
|
|
- otherDog.gameObject.SetActive(false);
|
|
|
- }
|
|
|
+ otherDog.gameObject.SetActive(false);
|
|
|
}
|
|
|
}
|
|
|
+ // }
|
|
|
}
|
|
|
}
|
|
|
+ HomeSoundEffectController.Instance.PlaySoundEffect(5);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -556,6 +600,7 @@ public class HomeController : MonoBehaviour
|
|
|
// 用户语音呼唤上传,Voice call指令用于呼唤所有的狗,得分最高的过来进入交互模式
|
|
|
public void VoiceCommandRequest(string filePath)
|
|
|
{
|
|
|
+ //Debug.Log("Voice Command Post request");
|
|
|
if (sceneMode == SceneMode.INACTIVE)
|
|
|
{
|
|
|
Debug.Log("Voice Command Post request");
|
|
@@ -569,7 +614,15 @@ public class HomeController : MonoBehaviour
|
|
|
}
|
|
|
else if (sceneMode == SceneMode.TRAINING)
|
|
|
{
|
|
|
+ // todo 临时代码查上传数据
|
|
|
Debug.Log("Voice training Post request");
|
|
|
+ Debug.Log("filepath:" + filePath);
|
|
|
+ Debug.Log("dog_id:" + UserProperty.dogs[GameData.focusDog].d_id);
|
|
|
+ Debug.Log("user_id:" + UserProperty.userId);
|
|
|
+ Debug.Log("trainingContent:" + trainingContent);
|
|
|
+ Debug.Log("current times:" + this.currentTrainingTimes.ToString());
|
|
|
+ Debug.Log("total times:" + totalTrainingTimes.ToString());
|
|
|
+
|
|
|
//Debug.Log("current times before ++:" + this.currentTrainingTimes.ToString());
|
|
|
this.currentTrainingTimes++;
|
|
|
string url = "/api/voice/training/";
|
|
@@ -612,24 +665,17 @@ public class HomeController : MonoBehaviour
|
|
|
highestScoreCommand = score.Key;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ dogsInScene[GameData.focusDog].ResetAnimationStatus(); // 重置狗的动画状态
|
|
|
if (highestScore >= 60)
|
|
|
{
|
|
|
-
|
|
|
- if (GameTool.Random100Check(dogsInScene[GameData.focusDog].dogProperty.voiceCommand))
|
|
|
- {
|
|
|
- string animationTrigger = highestScoreCommand.Substring(5);
|
|
|
- string animationBool = "is" + highestScoreCommand + "ing";
|
|
|
- var animator = dogsInScene[GameData.focusDog].gameObject.GetComponent<Animator>();
|
|
|
- animator.SetTrigger(animationTrigger);
|
|
|
- if (animationBool != "isSiting" || animationBool != "isLieing" || animationBool != "isDieing")
|
|
|
- {
|
|
|
- animator.SetBool(animationBool, true);
|
|
|
- dogsInScene[GameData.focusDog].interactAnimation = animationBool;
|
|
|
- dogsInScene[GameData.focusDog].interactAnimationStartTime = DateTime.Now;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ string animationTrigger = highestScoreCommand.Substring(7);
|
|
|
+ string animationBool = highestScoreCommand + "_status";
|
|
|
+ var animator = dogsInScene[GameData.focusDog].gameObject.GetComponent<Animator>();
|
|
|
+ animator.SetTrigger(animationTrigger);
|
|
|
+ animator.SetBool(animationBool, true);
|
|
|
+
|
|
|
+ // 交互动画执行一段时间后停止
|
|
|
+ StartCoroutine(dogsInScene[GameData.focusDog].InteractAnimationCountDown());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -666,7 +712,7 @@ public class HomeController : MonoBehaviour
|
|
|
}
|
|
|
|
|
|
string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", trainingContent + "_10", EnviromentSetting.languageCode });
|
|
|
- Time.timeScale = 0f;
|
|
|
+ GameTool.PauseGameTime();
|
|
|
|
|
|
MessageBoxController.ShowMessage(msg, ExitTrainingMode);
|
|
|
this.sceneMode = SceneMode.NORMAL;
|
|
@@ -683,7 +729,7 @@ public class HomeController : MonoBehaviour
|
|
|
HomeSoundEffectController.Instance.PlaySoundEffect(4);
|
|
|
|
|
|
string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", trainingContent + "_20", EnviromentSetting.languageCode });
|
|
|
- Time.timeScale = 0f;
|
|
|
+ GameTool.PauseGameTime();
|
|
|
MessageBoxController.ShowMessage(msg, RestartTraining);
|
|
|
}
|
|
|
}
|
|
@@ -714,13 +760,24 @@ public class HomeController : MonoBehaviour
|
|
|
trainingDogId = "";
|
|
|
isTrainingMsgShowed_1 = false;
|
|
|
isTrainingMsgShowed_2 = false;
|
|
|
+ isTrainingAnimationPlayed = false;
|
|
|
+ sceneMode = SceneMode.NORMAL; // 交互模式
|
|
|
Debug.Log("Reset Training Mode Parameters");
|
|
|
- Time.timeScale = 1f;
|
|
|
+ GameTool.ResumeGameTime();
|
|
|
+ GameData.isVoiceTrainingToday = true; // 训练完成,设置为true
|
|
|
var BGM = GameObject.Find("BGM");
|
|
|
if (BGM != null)
|
|
|
{
|
|
|
FadeBGM(BGM.GetComponent<AudioSource>(), true);
|
|
|
}
|
|
|
+ // 恢复因为交互,训练模式隐藏的狗
|
|
|
+ // foreach (var dog in dogsInScene)
|
|
|
+ // {
|
|
|
+ // if (dog.gameObject.activeSelf == false)
|
|
|
+ // {
|
|
|
+ // dog.gameObject.SetActive(true);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
private void RestartTraining()
|
|
@@ -776,7 +833,7 @@ public class HomeController : MonoBehaviour
|
|
|
previousPointerPosition = pointerPosition;
|
|
|
}
|
|
|
}
|
|
|
- if (interactTime > 3) // 如果交互时间超过1秒,播放心形粒子效果
|
|
|
+ if (interactTime > 2.5) // 如果交互时间超过1秒,播放心形粒子效果
|
|
|
{
|
|
|
HeartParticlePlay();
|
|
|
var animation = interactDog.GetComponent<Animator>();
|
|
@@ -822,10 +879,21 @@ public class HomeController : MonoBehaviour
|
|
|
if (!fadeIn)
|
|
|
{
|
|
|
bgmSource.Stop(); // 如果是淡出,停止播放
|
|
|
- }else{
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
bgmSource.Play(); // 如果是淡入,开始播放
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 刷新dogInScene的狗数据
|
|
|
+ public void RefreshDogInScene()
|
|
|
+ {
|
|
|
+ foreach (var dog in dogsInScene)
|
|
|
+ {
|
|
|
+ dog.ReloadDogProperty();
|
|
|
+ }
|
|
|
+ }
|
|
|
#endregion
|
|
|
}
|
|
|
|