|
@@ -30,7 +30,7 @@ public class HomeController : MonoBehaviour
|
|
|
private bool isSleepChecked = false; // 用于检测第一次睡眠检测是否执行完成
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
|
private GameObject centerOfDogs;
|
|
|
- //private bool isInteract = false; // 是否在交互状态
|
|
|
+ private bool isInteractMode = false; // 是否在交互状态
|
|
|
|
|
|
private void Awake()
|
|
|
{
|
|
@@ -51,7 +51,7 @@ public class HomeController : MonoBehaviour
|
|
|
lastCameraChange = DateTime.Now;
|
|
|
playerCam = GameObject.Find("VCam Player").GetComponent<CinemachineVirtualCamera>();
|
|
|
dogCam = GameObject.Find("VCam Dog").GetComponent<CinemachineVirtualCamera>();
|
|
|
- centerOfDogs= GameObject.Find("CenterOfDogs");
|
|
|
+ centerOfDogs = GameObject.Find("CenterOfDogs");
|
|
|
|
|
|
//InitialScene();
|
|
|
StartCoroutine(InitialScene());
|
|
@@ -64,7 +64,7 @@ public class HomeController : MonoBehaviour
|
|
|
{
|
|
|
// 计算多只狗的中心位置,用于主摄像机瞄准
|
|
|
centerOfDogs.transform.position = CenterOfDogs();
|
|
|
-
|
|
|
+
|
|
|
if (!isSleepChecked) // 每次启动检测只进行一次是否进入睡眠
|
|
|
{
|
|
|
// 判断是否在睡觉时间
|
|
@@ -104,58 +104,70 @@ public class HomeController : MonoBehaviour
|
|
|
// 生成一个数据数用于随机开启动画,如果和狗的randomFactor相同就开启动画
|
|
|
int randomCheck = UnityEngine.Random.Range(0, 51);
|
|
|
|
|
|
- foreach (var dog in dogsInScene)
|
|
|
+ if (isInteractMode)
|
|
|
{
|
|
|
- // 如果在eat drink进程结束前不执行随机场景代码
|
|
|
- //if (dog.itemConsumeProgress) // TODO 以后用DogInScene.dogState来判断
|
|
|
- if (dog.dogState == "itemConsume")
|
|
|
+ foreach (var dog in dogsInScene)
|
|
|
{
|
|
|
- if (dog.isMovingToBowl)
|
|
|
+ if (dog.dogState == "interact")
|
|
|
{
|
|
|
- dog.MovetoBowl();
|
|
|
+ dogCam.m_LookAt = dog.gameObject.transform;
|
|
|
+ dogCam.Priority = 10;
|
|
|
+ // 单只狗在交互的状态控制代码
|
|
|
+ if (dog.isMovingToPlayer)
|
|
|
+ {
|
|
|
+ dog.MovetoPlayer();
|
|
|
+ }
|
|
|
+ if (dog.InteractTimeout()) // 如果交互时间结束,结束交互状态
|
|
|
+ {
|
|
|
+ dog.ExitInteract();
|
|
|
+ isInteractMode = false; // 交互结束,退出交互状态
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- else if (dog.dogState == "interact")
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ foreach (var dog in dogsInScene)
|
|
|
{
|
|
|
- // 单只狗在交互的状态控制代码
|
|
|
- if (dog.isMovingToBowl)
|
|
|
+ // 如果在eat drink进程结束前不执行随机场景代码
|
|
|
+ //if (dog.itemConsumeProgress) // TODO 以后用DogInScene.dogState来判断
|
|
|
+ if (dog.dogState == "itemConsume")
|
|
|
{
|
|
|
- dog.MovetoBowl();
|
|
|
+ if (dog.isMovingToBowl)
|
|
|
+ {
|
|
|
+ dog.MovetoBowl();
|
|
|
+ }
|
|
|
}
|
|
|
- if (dog.InteractTimeout()) // 如果交互时间结束,结束交互状态
|
|
|
+ else
|
|
|
{
|
|
|
- dog.ExitInteract();
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // 随机动作控制控制
|
|
|
- RandomCameraChange();
|
|
|
+ // 随机动作控制控制
|
|
|
+ RandomCameraChange();
|
|
|
|
|
|
- if (listenBreak) // 如果用户按下说话按键,立刻切换到监听状态
|
|
|
- {
|
|
|
- dog.Listen();
|
|
|
- }
|
|
|
- else if (dog.isMoving)
|
|
|
- {
|
|
|
- dog.RandomMove();
|
|
|
- }
|
|
|
+ if (listenBreak) // 如果用户按下说话按键,立刻切换到监听状态
|
|
|
+ {
|
|
|
+ dog.Listen();
|
|
|
+ }
|
|
|
+ else if (dog.isMoving)
|
|
|
+ {
|
|
|
+ dog.RandomMove();
|
|
|
+ }
|
|
|
|
|
|
- else if (randomCheck == dog.randomFactor && !dog.isSleeping) // 当狗自身的随机数和系统随机数相同时候触发。约100秒触发一次。
|
|
|
- {
|
|
|
- TimeSpan ts = DateTime.Now - dog.animationStartTime;
|
|
|
- if (ts.Seconds >= 30) // 如果距离上一个动作超过30秒就可以开始新的动作
|
|
|
+ else if (randomCheck == dog.randomFactor && !dog.isSleeping) // 当狗自身的随机数和系统随机数相同时候触发。约100秒触发一次。
|
|
|
{
|
|
|
- float r = UnityEngine.Random.Range(0, 1f);
|
|
|
- if (r > 0.6) // 随机选择开始动画,或者移动
|
|
|
- {
|
|
|
- dog.IdleAnimation();
|
|
|
- }
|
|
|
- else // 狗狗开始步行移动
|
|
|
+ TimeSpan ts = DateTime.Now - dog.animationStartTime;
|
|
|
+ if (ts.Seconds >= 30) // 如果距离上一个动作超过30秒就可以开始新的动作
|
|
|
{
|
|
|
- dog.SetMoveSpeed(0);
|
|
|
- dog.moveSpeed = 0;
|
|
|
- dog.RandomMove();
|
|
|
+ float r = UnityEngine.Random.Range(0, 1f);
|
|
|
+ if (r > 0.6) // 随机选择开始动画,或者移动
|
|
|
+ {
|
|
|
+ dog.IdleAnimation();
|
|
|
+ }
|
|
|
+ else // 狗狗开始步行移动
|
|
|
+ {
|
|
|
+ dog.SetMoveSpeed(0);
|
|
|
+ dog.moveSpeed = 0;
|
|
|
+ dog.RandomMove();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -246,9 +258,9 @@ public class HomeController : MonoBehaviour
|
|
|
{
|
|
|
int delay = 10; // 延迟10秒执行一次
|
|
|
TimeSpan ts = DateTime.Now - lastCameraChange;
|
|
|
- if (ts.TotalSeconds < delay) {return;}
|
|
|
+ if (ts.TotalSeconds < delay) { return; }
|
|
|
int dogCount = dogsInScene.Count;
|
|
|
- int r = UnityEngine.Random.Range(0, dogCount+1);
|
|
|
+ int r = UnityEngine.Random.Range(0, dogCount + 1);
|
|
|
if (r < dogCount)
|
|
|
{
|
|
|
dogCam.m_LookAt = dogsInScene[r].gameObject.transform;
|
|
@@ -271,7 +283,7 @@ public class HomeController : MonoBehaviour
|
|
|
{
|
|
|
foreach (var dog in dogsInScene)
|
|
|
{
|
|
|
- if(dog.gameObject.GetComponent<Animator>().runtimeAnimatorController == null)
|
|
|
+ if (dog.gameObject.GetComponent<Animator>().runtimeAnimatorController == null)
|
|
|
{
|
|
|
initDone = false;
|
|
|
}
|
|
@@ -279,7 +291,7 @@ public class HomeController : MonoBehaviour
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- initDone=false;
|
|
|
+ initDone = false;
|
|
|
}
|
|
|
//Debug.Log("Home scene initial status:"+initDone);
|
|
|
return initDone;
|
|
@@ -307,7 +319,11 @@ public class HomeController : MonoBehaviour
|
|
|
WWWForm form = new();
|
|
|
form.AddField("user_id", UserProperty.userId);
|
|
|
|
|
|
- StartCoroutine(WebController.PostRequest(url, form, filePath, callback: VoiceCallCallback));
|
|
|
+ // TODO 待后台开发完成后,开启网络通讯功能,目前暂用临时直接赋值
|
|
|
+ // StartCoroutine(WebController.PostRequest(url, form, filePath, callback: VoiceCallCallback));
|
|
|
+ isInteractMode = true; // 进入交互模式
|
|
|
+ dogsInScene[0].SetupInteract();
|
|
|
+ VoiceButtonOnlySwitch(true); // 交互模式下关闭其他菜单
|
|
|
}
|
|
|
|
|
|
// 语音呼唤上传回调函数
|
|
@@ -317,12 +333,37 @@ public class HomeController : MonoBehaviour
|
|
|
var data = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
|
|
|
if (data != null && data["status"].ToString() == "success")
|
|
|
{
|
|
|
-
|
|
|
// 刷新狗的数据
|
|
|
string dogJson = data["dogs"].ToString();
|
|
|
UserProperty.FreshDogInfo(dogJson);
|
|
|
|
|
|
// TODO 根据返回结果设定focusdog
|
|
|
+ float highestScore = 0;
|
|
|
+ string highestScoreDogId = "";
|
|
|
+ var scores = data["scores"].ToString();
|
|
|
+ var scoresList = JsonConvert.DeserializeObject<Dictionary<string, float>>(scores);
|
|
|
+ foreach (var score in scoresList)
|
|
|
+ {
|
|
|
+ if (score.Value > highestScore)
|
|
|
+ {
|
|
|
+ highestScore = score.Value;
|
|
|
+ highestScoreDogId = score.Key;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (highestScore > 60) // 60分以上才可以进入交互模式
|
|
|
+ {
|
|
|
+ GameData.focusDog = UserProperty.GetDogIndex(highestScoreDogId);
|
|
|
+ VoiceButtonOnlySwitch(true); // 交互模式下关闭其他菜单
|
|
|
+ foreach (var dog in dogsInScene)
|
|
|
+ {
|
|
|
+ if (dog.dogProperty.d_id == highestScoreDogId)
|
|
|
+ {
|
|
|
+ dog.SetupInteract();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// focusdog 开启互动模式
|
|
|
HomeController.dogsInScene[GameData.focusDog].dogState = "interact";
|
|
|
HomeController.dogsInScene[GameData.focusDog].SetupInteract();
|
|
@@ -367,7 +408,7 @@ public class HomeController : MonoBehaviour
|
|
|
}
|
|
|
|
|
|
// 改变Voice And Menu 菜单形态
|
|
|
- public void VoiceButtonSwitch(bool state)
|
|
|
+ public void VoiceButtonOnlySwitch(bool state)
|
|
|
{
|
|
|
// 交互时候关闭其他菜单
|
|
|
var vamUI = GameObject.Find("VoiceAndMenu");
|
|
@@ -381,9 +422,6 @@ public class HomeController : MonoBehaviour
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-//
|
|
|
public enum ItemGroup
|
|
|
{
|
|
|
food,
|