DogInScene.cs 23 KB

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