DogInScene.cs 23 KB

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