DogInScene.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. //using UnityEngine.Rendering.PostProcessing;
  5. /* 本类用于管理场景中所有狗的状态包括动画状态,随机数分配等
  6. */
  7. //[CreateAssetMenu(fileName = "DogInScene", menuName = "Scriptable Objects/DogInScene")]
  8. public class DogInScene //: ScriptableObject
  9. {
  10. //通用参数段
  11. public DogProperty dogProperty;
  12. public GameObject gameObject { set; get; }
  13. public Animator animator;
  14. public Vector3 moveToLocation;
  15. public float moveSpeed; // 用来控制狗的移动速度 0 0.5跑,0.75快跑,1跳
  16. //public string dogState; // 狗的状态代码分类通道,包括三大类使用道具(itemConsume),闲置(idle),训练(training),自由活动(interact)等
  17. public DogState dogState = DogState.IDLE;
  18. // 喝水吃饭参数段
  19. public DateTime drinkStartTime, eatStartTime; // 记录吃喝开始时间
  20. public bool itemConsumeProgress = false; // 是否在吃和喝的进程中。如果是的话,跳过常规动画检测
  21. public bool isMovingToBowl;
  22. private float shortIntakeTime = 0.5f; // 喝水和吃饭的短时间间隔,单位秒。当宠物吃饱喝足时候调用。
  23. private float longIntakeTime = 10f; // 喝水和吃饭的长时间间隔,单位秒。当宠物没有吃饱喝足时候调用。
  24. // 随机动作参数段
  25. public int randomFactor;
  26. public DateTime animationStartTime; // 记录上一个动画开始时间的,每个随机动作间隔至少30秒
  27. private int activeIndex; // 动物的活动指数
  28. public bool isMoving; // 动物正在移动,避免其他随机动作发生
  29. public bool isSleeping; // 动物正在正在睡觉,避免触发其他动画
  30. // 固定参数
  31. private const float moveSpeedAdj = 0.025f;
  32. // interact training 相关的参数
  33. public DateTime interactLastUpdate; // 上次交互指令时间
  34. public bool isMovingToPlayer; // 是否在向玩家移动
  35. public string interactAnimation = ""; // 交互动画
  36. public DateTime interactAnimationStartTime; // 交互动画开始时间
  37. #region 通用函数段
  38. // 这个函数主要是为了在狗的属性发生变化时,重新加载狗的属性
  39. public void ReloadDogProperty()
  40. {
  41. foreach (var dog in UserProperty.dogs)
  42. {
  43. if (dog.d_id == dogProperty.d_id)
  44. {
  45. this.dogProperty = dog;
  46. break;
  47. }
  48. }
  49. }
  50. public void SetGameObject(GameObject gameObject)
  51. {
  52. this.gameObject = gameObject;
  53. this.animator = gameObject.GetComponent<Animator>();
  54. this.randomFactor = UnityEngine.Random.Range(0, 51); // 生成一个随机整数(0 到 50 之间),用于时间校验
  55. Debug.Log(this.gameObject.name + "random factor is:" + randomFactor);
  56. }
  57. public DogInScene(DogProperty property)
  58. {
  59. this.dogProperty = property;
  60. this.activeIndex = (int)Math.Round((property.liveliness + property.intimate) * UnityEngine.Random.Range(0.01f, 0.5f));
  61. this.isMoving = false;
  62. }
  63. public void RemoveZzzParticle()
  64. {
  65. // 关闭狗的睡觉粒子特效
  66. var zzzParticle = gameObject.transform.Find("zzzParticle").gameObject;
  67. if (zzzParticle != null)
  68. {
  69. zzzParticle.SetActive(false);
  70. }
  71. }
  72. // 关闭所有animation动画的状态,回到默认的状态
  73. public void ResetAnimationStatus()
  74. {
  75. // 获取所有参数
  76. AnimatorControllerParameter[] parameters = animator.parameters;
  77. foreach (AnimatorControllerParameter parameter in parameters)
  78. {
  79. if (parameter.type == AnimatorControllerParameterType.Bool)
  80. {
  81. animator.SetBool(parameter.name, false);
  82. }
  83. }
  84. }
  85. bool IsPlayingAnimation(string stateName)
  86. {
  87. // 获取当前动画状态信息
  88. AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0); // 参数 0 表示第一个动画层
  89. // 检查当前状态是否是目标状态,并且是否正在播放
  90. return stateInfo.IsName(stateName) && stateInfo.normalizedTime < 1.0f;
  91. }
  92. #endregion
  93. #region interact交互函数段
  94. // 启动交互行为准备过程
  95. public void SetupInteract()
  96. {
  97. Debug.Log("SetupInteract:" + this.gameObject.name);
  98. HomeController.Instance.SetDogsIsTrigger(false);
  99. DogBarkController.Instance.PlayDogBarkWithDelay(3); // 狗叫相应一下
  100. RemoveZzzParticle(); // 关闭睡觉粒子特效
  101. if (dogProperty.voiceCall == 10)
  102. {
  103. // GameData.isFirstInteraction = false;
  104. PlayerPrefs.SetString("isFirstInteraction", "false");
  105. PlayerPrefs.Save();
  106. GameTool.PauseGameTime();
  107. string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", "first_touch_interactive", EnviromentSetting.languageCode });
  108. if (msg.Contains("<<dog_name>>"))
  109. {
  110. msg = msg.Replace("<<dog_name>>", dogProperty.dog_name);
  111. }
  112. MessageBoxController.ShowMessage(msg, () => GameTool.ResumeGameTime());
  113. }
  114. // 加载Interact animator controller,避免过于复杂的Animator Controller
  115. Animator animator = gameObject.GetComponent<Animator>();
  116. RuntimeAnimatorController animatorController = Resources.Load<RuntimeAnimatorController>("Dog/AnimatorController/shibaInu/HomeDogInteractController");
  117. if (dogProperty.breed == "shibaInu") { animatorController = Resources.Load<RuntimeAnimatorController>("Dog/AnimatorController/shibaInu/HomeDogInteractController"); }
  118. animator.runtimeAnimatorController = animatorController;
  119. float randomIndex = UnityEngine.Random.Range(0, 1f);
  120. animator.SetFloat("randomIndex", randomIndex);
  121. //this.dogState = "interact";
  122. this.dogState = DogState.INTERACT; // 设置狗的状态为交互状态
  123. this.interactLastUpdate = DateTime.Now;
  124. this.moveToLocation = new Vector3(0f, 0f, -3f);
  125. this.isMovingToPlayer = true;
  126. // 如果狗距离超出一定范围才开始移动
  127. float distance = Vector3.Distance(gameObject.transform.position, moveToLocation);
  128. Debug.Log(this.gameObject.name + "interact move to player distance:" + distance);
  129. if (distance > 2.5f)
  130. {
  131. this.animator.SetTrigger("move"); // 切换为走路动画
  132. this.animator.SetBool("isMoving", true); // 保持为走路动画
  133. this.animator.SetFloat("moveSpeed", 0.5f);
  134. }
  135. else
  136. {
  137. this.animator.SetBool("isMoving", false);
  138. this.gameObject.transform.LookAt(new Vector3(0f, 1f, -8f));
  139. this.isMovingToPlayer = false;
  140. }
  141. }
  142. public void MovetoPlayer()
  143. {
  144. // 如果距离目标小于0.5米就把速度调整为零
  145. if (Vector3.Distance(moveToLocation, this.gameObject.transform.position) < 0.5f)
  146. {
  147. Debug.Log(this.gameObject.name + "current move speed:" + moveSpeed);
  148. this.SetMoveSpeed(0);
  149. Debug.Log(this.gameObject.name + "reduce move speed:" + moveSpeed);
  150. }
  151. // 如果狗距离到达重点就停止跑步动画
  152. float distance = Vector3.Distance(gameObject.transform.position, moveToLocation);
  153. //Debug.Log(this.gameObject.name + "interact move to player distance:" + distance);
  154. if (distance > 2.5f) // 一定距离内就开始停下来,否则刹不住
  155. {
  156. this.gameObject.transform.LookAt(moveToLocation);
  157. this.gameObject.transform.position = Vector3.MoveTowards(gameObject.transform.position, moveToLocation, dogProperty.runSpeed * (1 + moveSpeed) * 0.02f * moveSpeedAdj); // 第一个0.02对应50帧fixupdate画面,后面一个数字对应速度调整,对应RM动画.position = Vector3.MoveTowards(gameObject.transform.position, moveToLocation, dogProperty.runSpeed * (1 + moveSpeed) * 0.02f * moveSpeedAdj); // 第一个0.02对应50帧fixupdate画面,后面一个数字对应速度调整,对应RM动画
  158. }
  159. else
  160. {
  161. this.animator.SetBool("isMoving", false);
  162. this.gameObject.transform.LookAt(new Vector3(0f, 1f, -8f));
  163. this.isMovingToPlayer = false;
  164. }
  165. }
  166. // 交互行为计时器
  167. public bool InteractTimeout()
  168. {
  169. TimeSpan ts = new TimeSpan();
  170. ts = DateTime.Now - this.interactLastUpdate;
  171. if (ts.TotalSeconds > 10)
  172. {
  173. Debug.Log("InteractTimeout:" + this.gameObject.name);
  174. //this.dogState = "idle";
  175. this.dogState = DogState.IDLE;
  176. return true;
  177. }
  178. else { return false; }
  179. }
  180. // 交互动画行为计时器(暂时设定为6秒)
  181. public IEnumerator InteractAnimationCountDown()
  182. {
  183. TimeSpan ts = new TimeSpan();
  184. ts = DateTime.Now - this.interactAnimationStartTime;
  185. if (ts.TotalSeconds < EnviromentSetting.interactTimeoutSec)
  186. {
  187. yield return new WaitForSeconds(0.25f);
  188. }
  189. else
  190. {
  191. Debug.Log("InteractAnimation count down stop:" + this.gameObject.name);
  192. this.ResetAnimationStatus();
  193. }
  194. }
  195. public void ExitInteract()
  196. {
  197. // 结束交互行为,恢复原有的菜单
  198. this.dogState = DogState.IDLE;
  199. HomeController.Instance.SetDogsIsTrigger(true);
  200. // 恢复场景idle对应的Animator Controller
  201. Animator animator = gameObject.GetComponent<Animator>();
  202. RuntimeAnimatorController animatorController = Resources.Load<RuntimeAnimatorController>("Dog/AnimatorController/shibaInu/HomeDogAnimatorController");
  203. if (dogProperty.breed == "shibaInu") { animatorController = Resources.Load<RuntimeAnimatorController>("Dog/AnimatorController/shibaInu/HomeDogAnimatorController"); }
  204. animator.runtimeAnimatorController = animatorController;
  205. this.RandomMove();
  206. }
  207. // 狗播放问号的表情
  208. public void PlayQuestionMark()
  209. {
  210. var questionMark = gameObject.transform.Find("QuestionMarkParticle").gameObject;
  211. if (questionMark != null)
  212. {
  213. var particleQuestionMark = questionMark.GetComponent<ParticleSystem>();
  214. if (particleQuestionMark != null && !particleQuestionMark.isPlaying)
  215. {
  216. particleQuestionMark.Play();
  217. }
  218. }
  219. }
  220. #endregion
  221. #region 随机动作控制函数
  222. // 随机选择宠物动作
  223. public void IdleAnimation()
  224. {
  225. this.animationStartTime = DateTime.Now;
  226. this.animator.SetInteger("activeIndex", activeIndex);
  227. //Debug.Log("activeIndex:" + this.activeIndex);
  228. float randomIndex = UnityEngine.Random.Range(0, 1f);
  229. this.animator.SetFloat("randomIndex", randomIndex);
  230. //this.dogState = "idle";
  231. this.dogState = DogState.IDLE;
  232. //Debug.Log("randomIndex:" + randomIndex);
  233. }
  234. public void SetMoveSpeed(float speed)
  235. {
  236. this.moveSpeed = speed;
  237. }
  238. // 宠物随机移动
  239. public void RandomMove()
  240. {
  241. //this.animator.SetBool("isMoving", true);
  242. // 如果距离目标小于0.5米就把速度调整为零
  243. if (Vector3.Distance(moveToLocation, this.gameObject.transform.position) < 0.5f)
  244. {
  245. //Debug.Log(this.gameObject.name + "current move speed:" + moveSpeed);
  246. this.SetMoveSpeed(0);
  247. //Debug.Log(this.gameObject.name + "reduce move speed:" + moveSpeed);
  248. }
  249. if (isMoving == false)
  250. {
  251. animationStartTime = DateTime.Now; // 设置动画开始时间
  252. float x = UnityEngine.Random.Range(-5f, 5f);
  253. float z = UnityEngine.Random.Range(0f, 5f);
  254. this.moveToLocation = new Vector3(x, 0, z);
  255. //Debug.Log("move to location:" + x + ", " + z);
  256. this.isMoving = true;
  257. //this.animator.SetTrigger("move");
  258. this.animator.SetBool("isMoving", true);
  259. animator.Play("move");
  260. this.animator.SetFloat("moveSpeed", this.moveSpeed);
  261. }
  262. if (this.animator.GetBool("isMoving"))
  263. {
  264. this.gameObject.transform.LookAt(moveToLocation);
  265. this.gameObject.transform.position = Vector3.MoveTowards(gameObject.transform.position, moveToLocation, dogProperty.runSpeed * (1 + moveSpeed) * 0.02f * moveSpeedAdj); // 第一个0.02对应50帧fixupdate画面,后面一个数字对应速度调整,对应RM动画
  266. }
  267. // 如果狗距离到达重点就停止跑步动画
  268. float distance = Vector3.Distance(gameObject.transform.position, moveToLocation);
  269. if (distance < 0.1)
  270. {
  271. this.animator.SetBool("isMoving", false);
  272. //this.moveSpeed = 0.4f;
  273. this.isMoving = false;
  274. IdleAnimation();
  275. }
  276. }
  277. public void Sleep()
  278. {
  279. this.animator.SetTrigger("sleep");
  280. this.animator.SetBool("isSleeping", true);
  281. this.isSleeping = true;
  282. //this.dogState = "sleep";
  283. this.dogState = DogState.SLEEP;
  284. var zzzParticle = gameObject.transform.Find("zzzParticle").gameObject;
  285. if (zzzParticle != null)
  286. {
  287. zzzParticle.SetActive(true);
  288. }
  289. }
  290. public void Listen()
  291. {
  292. //StopCoroutine(movingCoroutine);
  293. //this.animator.SetTrigger("listen");
  294. ResetAnimationStatus();
  295. this.animator.SetBool("isListening", true);
  296. animator.Play("base");
  297. this.isSleeping = false; // 主人呼叫可以唤醒狗
  298. this.gameObject.transform.LookAt(new Vector3(0, 0, -6));
  299. HomeController.playerCam.Priority = 10;
  300. HomeController.dogCam.Priority = 1;
  301. HomeController.lastCameraChange = DateTime.Now;
  302. //this.dogState = "listen";
  303. this.dogState = DogState.LISTEN;
  304. }
  305. public IEnumerator RotationToPlayerAndListen()
  306. {
  307. //计算自己方向和player之间连线的夹角
  308. float rotationSpeed = 30f;
  309. float stopAngle = 15f; // 旋转最小角度,小于这个角度就不旋转
  310. Vector3 virtualLookAtTarget = new Vector3(0, 0, -6);
  311. Vector3 direction = virtualLookAtTarget - this.gameObject.transform.position;
  312. float targetAngle = Vector3.SignedAngle(this.gameObject.transform.forward, direction, Vector3.up); // 目标旋转角度
  313. if (MathF.Abs(targetAngle) <= stopAngle)
  314. {
  315. // 旋转角度小于指定度就不旋转
  316. Listen();
  317. yield break;
  318. }
  319. else
  320. {
  321. if (targetAngle > 0)
  322. {
  323. // 逆时针旋转
  324. this.animator.SetBool("isTurningLeft", true);
  325. if (IsPlayingAnimation("turn Left") == false)
  326. {
  327. this.animator.Play("turn Left");
  328. }
  329. this.gameObject.transform.Rotate(0, rotationSpeed * Time.deltaTime, 0);
  330. }
  331. else
  332. {
  333. // 顺时针旋转
  334. this.animator.SetBool("isTurningRight", true);
  335. if (IsPlayingAnimation("turn Right") == false)
  336. {
  337. this.animator.Play("turn Right");
  338. }
  339. this.gameObject.transform.Rotate(0, -rotationSpeed * Time.deltaTime, 0);
  340. }
  341. }
  342. while (true)
  343. {
  344. yield return new WaitForSeconds(0.1f);
  345. // 再次计算夹角
  346. direction = virtualLookAtTarget - this.gameObject.transform.position;
  347. targetAngle = Vector3.SignedAngle(this.gameObject.transform.forward, direction, Vector3.up); // 目标旋转角度
  348. // Debug.Log("target angle:" + targetAngle);
  349. if (MathF.Abs(targetAngle) <= stopAngle)
  350. {
  351. this.animator.SetBool("isTurningLeft", false);
  352. this.animator.SetBool("isTurningRight", false);
  353. Listen();
  354. yield break;
  355. }
  356. else
  357. {
  358. if (targetAngle > 0)
  359. {
  360. // 逆时针旋转
  361. this.gameObject.transform.Rotate(0, rotationSpeed * Time.deltaTime, 0);
  362. }
  363. else
  364. {
  365. // 顺时针旋转
  366. this.gameObject.transform.Rotate(0, -rotationSpeed * Time.deltaTime, 0);
  367. }
  368. }
  369. }
  370. }
  371. #endregion
  372. #region 喝水,吃食等道具消费函数
  373. // 开始整个使用道具的流程
  374. public void StartItemConsume(ItemGroup group)
  375. {
  376. RemoveZzzParticle(); // 关闭睡觉粒子特效
  377. GameObject bowl = GameObject.Find("Bowl_water"); // 先指定一个碗,编译通过
  378. BoxCollider boxCollider = gameObject.GetComponent<BoxCollider>(); // 喝水吃饭场景关闭isTrigger
  379. boxCollider.isTrigger = false;
  380. this.itemConsumeProgress = true; // 开启使用道具过程
  381. //this.dogState = "itemConsume";
  382. this.dogState = DogState.ITEM_CONSUME;
  383. if (group == ItemGroup.WATER)
  384. {
  385. bowl = GameObject.Find("Bowl_water"); // 开启整个喝水的进程
  386. }
  387. if (group == ItemGroup.FOOD)
  388. {
  389. bowl = GameObject.Find("Bowl_food"); // 开启整个吃食物的进程
  390. }
  391. this.moveToLocation = bowl.transform.position;
  392. this.isMovingToBowl = true;
  393. this.animator.SetTrigger("move"); // 切换为走路动画
  394. this.animator.SetBool("isMoving", true); // 保持为走路动画
  395. this.animator.SetFloat("moveSpeed", this.moveSpeed);
  396. }
  397. public void MovetoBowl()
  398. {
  399. // 如果距离目标小于0.5米就把速度调整为零
  400. if (Vector3.Distance(moveToLocation, this.gameObject.transform.position) < 0.5f)
  401. {
  402. Debug.Log(this.gameObject.name + "current move speed:" + moveSpeed);
  403. this.SetMoveSpeed(0);
  404. Debug.Log(this.gameObject.name + "reduce move speed:" + moveSpeed);
  405. }
  406. var vamUI = GameObject.Find("VoiceAndMenu");
  407. if (vamUI != null)
  408. {
  409. vamUI.SetActive(false);
  410. }
  411. this.gameObject.transform.LookAt(moveToLocation);
  412. this.gameObject.transform.position = Vector3.MoveTowards(gameObject.transform.position, moveToLocation, dogProperty.runSpeed * (1 + moveSpeed) * 0.02f * moveSpeedAdj); // 第一个0.02对应50帧fixupdate画面,后面一个数字对应速度调整,对应RM动画
  413. //this.gameObject.transform.position = Vector3.MoveTowards(gameObject.transform.position, moveToLocation, (100+dogProperty.runSpeed) * (1 + moveSpeed) * 0.02f * 0.015f); // 第一个0.02对应50帧fixupdate画面,后面一个数字对应速度调整,对应IF动画
  414. //Debug.Log("current position:" + gameObject.transform.position.x + "z:" + gameObject.transform.position.z);
  415. // 如果狗距离到达重点就停止跑步动画
  416. float distance = Vector3.Distance(gameObject.transform.position, moveToLocation);
  417. if (distance < 0.1)
  418. {
  419. this.animator.SetBool("isMoving", false);
  420. }
  421. }
  422. public IEnumerator DrinkAnimation()
  423. {
  424. this.animator.SetBool("isMoving", false); // 关闭移动动画
  425. TimeSpan ts = new TimeSpan();
  426. var targetBowl = GameObject.Find("Bowl_water");
  427. // 摄像头看向水盆位置
  428. HomeController.dogCam.m_LookAt = targetBowl.transform;
  429. HomeController.dogCam.Priority = 10;
  430. HomeController.playerCam.Priority = 1;
  431. float intakeTime;
  432. if (dogProperty.thirsty >= 90)
  433. {
  434. intakeTime = shortIntakeTime; // 如果狗口渴程度大于90,喝水时间为短时间
  435. }
  436. else
  437. {
  438. intakeTime = longIntakeTime; // 否则喝水时间为长时间
  439. }
  440. while (ts.TotalSeconds < intakeTime)
  441. {
  442. yield return new WaitForSeconds(0.25f);
  443. ts = DateTime.Now - this.drinkStartTime;
  444. //Debug.Log("结束饮水过程:" + ts.TotalSeconds);
  445. // 狗一致看向碗,确保就算被撞击后依然看向碗
  446. this.gameObject.transform.LookAt(targetBowl.transform.position);
  447. }
  448. // 结束吃狗粮动画
  449. this.animator.SetBool("isEating", false);
  450. itemConsumeProgress = false; // 关闭整个道具使用的进程
  451. dogState = DogState.IDLE;
  452. QuitItemConsume();
  453. if (!HomeController.Instance.isHideBowlRunning)
  454. {
  455. HomeController.Instance.StartCoroutine(HomeController.Instance.HideBowlAfterItemConsume(ItemGroup.WATER)); // 启动碗隐藏的协程
  456. }
  457. }
  458. public IEnumerator EatAnimation()
  459. {
  460. this.animator.SetBool("isMoving", false); // 关闭移动动画
  461. TimeSpan ts = new TimeSpan();
  462. var targetBowl = GameObject.Find("Bowl_food");
  463. // 摄像头看向盆位置
  464. HomeController.dogCam.m_LookAt = targetBowl.transform;
  465. HomeController.dogCam.Priority = 10;
  466. HomeController.playerCam.Priority = 1;
  467. float intakeTime;
  468. if (dogProperty.satiety >= 90)
  469. {
  470. intakeTime = shortIntakeTime; // 如果狗饱腹程度大于90,喝水时间为短时间
  471. }
  472. else
  473. {
  474. intakeTime = longIntakeTime; // 否则喝水时间为长时间
  475. }
  476. while (ts.TotalSeconds < intakeTime)
  477. {
  478. yield return new WaitForSeconds(0.25f);
  479. ts = DateTime.Now - this.eatStartTime;
  480. // 狗一致看向碗,确保就算被撞击后依然看向碗
  481. this.gameObject.transform.LookAt(targetBowl.transform.position);
  482. }
  483. // 结束吃狗粮动画
  484. this.animator.SetBool("isEating", false);
  485. itemConsumeProgress = false; // 关闭整个道具使用的进程
  486. dogState = DogState.IDLE;
  487. QuitItemConsume();
  488. if (!HomeController.Instance.isHideBowlRunning)
  489. {
  490. HomeController.Instance.StartCoroutine(HomeController.Instance.HideBowlAfterItemConsume(ItemGroup.FOOD)); // 启动碗隐藏的协程
  491. }
  492. }
  493. public void QuitItemConsume()
  494. {
  495. // var uiPlaceholder = GameObject.Find("UI Placeholder");
  496. // var vamUI = uiPlaceholder.transform.Find("VoiceAndMenu").gameObject;
  497. // vamUI.SetActive(true);
  498. BoxCollider boxCollider = gameObject.GetComponent<BoxCollider>(); // 喝水吃饭场景关闭isTrigger
  499. boxCollider.isTrigger = true;
  500. this.moveSpeed = UnityEngine.Random.Range(0.3f, 0.6f);
  501. RandomMove();
  502. }
  503. #endregion
  504. }
  505. // Change the accessibility of the DogState enum to public to match the accessibility of the field "dog_state".
  506. public enum DogState
  507. {
  508. ITEM_CONSUME,
  509. IDLE,
  510. TRAINING,
  511. INTERACT,
  512. SLEEP,
  513. LISTEN
  514. }