Bowman.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5. using SC.InputSystem;
  6. using DG.Tweening;
  7. //肾小囊
  8. public class Bowman : PointerDelegate
  9. {
  10. [SerializeField]
  11. private Transform mTarget;
  12. [SerializeField]
  13. private Transform receivePoint;//重复利用的点
  14. [SerializeField]
  15. private Transform endPoint;//目的地
  16. [SerializeField]
  17. private BloodManager.BloodItemType[] fliterTypes;//可以过滤的东西
  18. [SerializeField]
  19. private BloodManager.BloodItemType[] recycleTypes;//可以回收的
  20. void Start () {
  21. }
  22. private void OnDestroy()
  23. {
  24. }
  25. // Update is called once per frame
  26. void Update () {
  27. CheckRay();
  28. }
  29. Ray ray;
  30. RaycastHit hit;
  31. GameObject obj;
  32. private void CheckRay()
  33. {
  34. if(Camera.main == null)
  35. {
  36. return;
  37. }
  38. if (Input.GetMouseButtonDown(0))
  39. {
  40. ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  41. if (Physics.Raycast(ray, out hit, float.MaxValue,1 << 0))
  42. {
  43. if (hit.rigidbody != null)
  44. {
  45. obj = hit.rigidbody.gameObject;
  46. CheckItem();
  47. }
  48. }
  49. }
  50. }
  51. private void CheckItem()
  52. {
  53. BloodItem item = obj.GetComponentInParent<BloodItem>();
  54. if(item != null)
  55. {
  56. if(Array.IndexOf(fliterTypes, item.MType) == -1 && false)
  57. {
  58. //不是可以过滤的东西
  59. }
  60. else
  61. {
  62. if (item.StopMove())
  63. {
  64. ChangeItemForward(item);
  65. }
  66. }
  67. }
  68. }
  69. //让小球朝向我
  70. private void ChangeItemForward(BloodItem item)
  71. {
  72. item.transform.LookAt(mTarget);
  73. item.transform.DOLocalMove(mTarget.transform.position, 1.0f).SetEase(Ease.Linear).OnComplete(Test).SetAutoKill(true);
  74. return;
  75. //iTween.Stop(item.gameObject);
  76. Hashtable args = new Hashtable();
  77. args.Add("position", mTarget.transform.position);
  78. args.Add("time", 1.0f);
  79. //移动结束时调用,参数和上面类似
  80. args.Add("easeType", iTween.EaseType.linear);
  81. args.Add("oncomplete", "Arrived");
  82. args.Add("oncompleteparams", item);
  83. args.Add("oncompletetarget", gameObject);
  84. iTween.MoveTo(item.gameObject, args);
  85. }
  86. private void Test()
  87. {
  88. Debug.Log("到达了指定地方");
  89. }
  90. //到达了指定的地方
  91. private void Arrived(BloodItem item)
  92. {
  93. Debug.Log("到达了指定地方" + Vector3.Distance(item.transform.position, mTarget.transform.position));
  94. //item.SetMoveDir(-Vector3.forward);
  95. //return;
  96. iTween.Stop(item.gameObject);
  97. if (Array.IndexOf(recycleTypes, item.MType) != -1 && CheckNeedReceived(item.MType))
  98. {
  99. Debug.Log("这是可以回收的");
  100. //不是可以过滤的东西
  101. iTween.MoveTo(item.gameObject, iTween.Hash("position", receivePoint, "easeType", iTween.EaseType.linear, "loopType", iTween.LoopType.none, "delay", 1));
  102. }
  103. else
  104. {
  105. Debug.Log("这是废物");
  106. iTween.MoveTo(item.gameObject, iTween.Hash("position", endPoint, "easeType", iTween.EaseType.linear, "loopType", iTween.LoopType.none, "delay", 1));
  107. }
  108. }
  109. private bool CheckNeedReceived(BloodManager.BloodItemType cType)
  110. {
  111. return false;
  112. var randomValue = UnityEngine.Random.Range(0,100);
  113. var max_value = 0 ;
  114. switch(cType)
  115. {
  116. case BloodManager.BloodItemType.Water:
  117. max_value = 80;
  118. break;
  119. case BloodManager.BloodItemType.MineralSalt:
  120. max_value = 50;
  121. break;
  122. case BloodManager.BloodItemType.Protein:
  123. max_value = 100;
  124. break;
  125. case BloodManager.BloodItemType.Urea:
  126. max_value = 0;
  127. break;
  128. }
  129. if(randomValue < max_value)
  130. {
  131. return true;
  132. }
  133. return false;
  134. }
  135. //加分的部分
  136. public bool IsGod(BloodItem item)
  137. {
  138. if (Array.IndexOf(fliterTypes, item.MType) != -1)
  139. {
  140. return true;
  141. }
  142. return false;
  143. }
  144. //不能漏掉的 要扣分的
  145. public bool IsRecyle(BloodItem item)
  146. {
  147. if (Array.IndexOf(recycleTypes, item.MType) != -1)
  148. {
  149. return true;
  150. }
  151. return false;
  152. }
  153. protected override void partAnyKeyDownDelegate(InputKeyCode keyCode, InputDevicePartBase part)
  154. {
  155. if (!GamePlayerData.Instance.room_data.IsReconnectOwner())
  156. {
  157. //return;//过滤掉不是老师点击的情况
  158. }
  159. CheckRayItem();
  160. }
  161. private void CheckRayItem()
  162. {
  163. ray = new Ray( API_InputSystem.Position, API_InputSystem.Normal);
  164. if (Physics.Raycast(ray, out hit, float.MaxValue, 1 << 0))
  165. {
  166. if (hit.rigidbody != null)
  167. {
  168. obj = hit.rigidbody.gameObject;
  169. CheckItem();
  170. }
  171. }
  172. }
  173. }