humancost.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /// <summary>
  2. /// ZWN-XHJ
  3. /// 20211019
  4. /// </summary>
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using UnityEngine;
  8. using UnityEngine.UI;
  9. /*using static System.Net.Mime.MediaTypeNames;*/
  10. public class humancost : MonoBehaviour
  11. {
  12. public human_area human_cur;
  13. //public FollowBoxManager followBoxManager;
  14. public Image show;
  15. public Sprite[] show_spr;
  16. private Color32 color_start = new Color32(255, 255, 255, 0),
  17. color_end = new Color32(255, 255, 255, 255);
  18. private Vector3 vec_start = new Vector3(-1920, 0, 0),
  19. vec_end = new Vector3(0, 0, 0);
  20. bool human_cost = false;
  21. bool cost_success = false;
  22. public GameObject show_green;
  23. public GameObject total, half;
  24. float alignArea = 0;
  25. public float AlignArea
  26. {
  27. get { return alignArea; }
  28. set { alignArea = value; }
  29. }
  30. /// <summary>
  31. /// 当符合条件后,判断为True
  32. /// </summary>
  33. public bool Cost_Success
  34. {
  35. get { return cost_success; }
  36. set { cost_success = value; }
  37. }
  38. int area_num = -1;
  39. public int Area_Num
  40. {
  41. get { return area_num; }
  42. set { area_num = value; }
  43. }
  44. int last_num = -2;
  45. private Transform tra_self;
  46. /// <summary>
  47. /// 当符合条件后,判断为True
  48. /// </summary>
  49. public bool Cost_Change
  50. {
  51. get { return cost_change; }
  52. set { cost_change = value; }
  53. }
  54. bool cost_change = false;
  55. // Use this for initialization
  56. void Start()
  57. {
  58. if (!human_cost)
  59. {
  60. if (human_cur.human_area_state_cur == human_area_state.totalbody)
  61. {
  62. total.SetActive(true);
  63. half.SetActive(false);
  64. }
  65. else if (human_cur.human_area_state_cur == human_area_state.halfbody)
  66. {
  67. total.SetActive(false);
  68. half.SetActive(true);
  69. }
  70. show_green.SetActive(false);
  71. if (tra_self == null)
  72. {
  73. tra_self = this.transform;
  74. }
  75. tra_self.localPosition = vec_start;
  76. area_num = -1;
  77. show_true();
  78. cost_success = false;
  79. human_cost = false;
  80. }
  81. }
  82. /// <summary>
  83. /// 开始检测需调用
  84. /// </summary>
  85. public void human_init()
  86. {
  87. // zwn_interface.single.zwn_init();
  88. if (time_cost != 0)
  89. time_cost = 0;
  90. if (human_cur.human_area_state_cur == human_area_state.totalbody)
  91. {
  92. total.SetActive(true);
  93. half.SetActive(false);
  94. }
  95. else if (human_cur.human_area_state_cur == human_area_state.halfbody)
  96. {
  97. total.SetActive(false);
  98. half.SetActive(true);
  99. }
  100. show_green.SetActive(false);
  101. if (tra_self == null)
  102. {
  103. tra_self = this.transform;
  104. }
  105. tra_self.localPosition = vec_end;
  106. area_num = -1;
  107. last_num = -2;
  108. show_true();
  109. cost_change = false;
  110. cost_success = false;
  111. human_cost = true;
  112. }
  113. /// <summary>
  114. /// 结束检测
  115. /// </summary>
  116. public void human_end()
  117. {
  118. show_green.SetActive(false);
  119. if (tra_self == null)
  120. {
  121. tra_self = this.transform;
  122. }
  123. tra_self.localPosition = vec_start;
  124. area_num = -1;
  125. last_num = -2;
  126. show_true();
  127. cost_change = false;
  128. cost_success = true;
  129. human_cost = false;
  130. }
  131. float time_cost = 0;
  132. //public Text text_id;
  133. // Update is called once per frame
  134. void Update()
  135. {
  136. if (Application.platform == RuntimePlatform.Android)// 使用Unity切换Platform无法模拟
  137. {
  138. //text_id.text = "当前ID:" + zwn_interface_android.single.Cur_ID;
  139. }
  140. /* if (Cost_Change)
  141. {
  142. switch (Area_Num)
  143. {
  144. case -1: //没有人
  145. break;
  146. case 0://对齐
  147. break;
  148. case 1://请向右一点
  149. break;
  150. case 2://请向左一点
  151. break;
  152. case 3://请向后一点
  153. break;
  154. case 4://请向前一点
  155. break;
  156. }
  157. Cost_Change = false;
  158. }*/
  159. if (human_cost && !cost_success)
  160. {
  161. //area_num = human_cur.human_area_true();
  162. ////print("area_num " + area_num);
  163. //if (last_num != area_num)
  164. //{
  165. // cost_change = true;
  166. // last_num = area_num;
  167. //}
  168. ////print("area_num" + area_num);
  169. //show_true();
  170. //if (area_num == 0)
  171. if (FollowBoxManager.sigle.GetIsSuccee)
  172. {
  173. show_green.SetActive(true);
  174. time_cost += Time.deltaTime;
  175. if (time_cost >= 2)
  176. {
  177. human_end();
  178. float x = (zwn_common_data.single.zwn_transform_pose[5].x - zwn_common_data.single.zwn_transform_pose[6].x);
  179. float y = (zwn_common_data.single.zwn_transform_pose[5].y - zwn_common_data.single.zwn_transform_pose[11].y);
  180. float area = Mathf.Abs(x * y);
  181. alignArea = area;
  182. }
  183. }
  184. else
  185. {
  186. show_green.SetActive(false);
  187. if (time_cost != 0)
  188. time_cost = 0;
  189. }
  190. }
  191. }
  192. void show_true()
  193. {
  194. if (area_num == -1)
  195. {
  196. if (show.color != color_start)
  197. show.color = color_start;
  198. }
  199. else
  200. {
  201. for (int i = 0; i < show_spr.Length; i++)
  202. {
  203. if (area_num == i)
  204. {
  205. show.sprite = show_spr[i];
  206. show.SetNativeSize();
  207. }
  208. }
  209. if (show.color != color_end)
  210. show.color = color_end;
  211. }
  212. }
  213. public void halfbody()
  214. {
  215. human_cur.human_area_state_cur = human_area_state.halfbody;
  216. human_init1();
  217. }
  218. public void totalbody()
  219. {
  220. human_cur.human_area_state_cur = human_area_state.totalbody;
  221. human_init1();
  222. }
  223. /// <summary>
  224. /// 开始检测需调用
  225. /// </summary>
  226. public void human_init1()
  227. {
  228. if (time_cost != 0)
  229. time_cost = 0;
  230. if (human_cur.human_area_state_cur == human_area_state.totalbody)
  231. {
  232. total.SetActive(true);
  233. half.SetActive(false);
  234. }
  235. else if (human_cur.human_area_state_cur == human_area_state.halfbody)
  236. {
  237. total.SetActive(false);
  238. half.SetActive(true);
  239. }
  240. show_green.SetActive(false);
  241. if (tra_self == null)
  242. {
  243. tra_self = this.transform;
  244. }
  245. tra_self.localPosition = vec_end;
  246. area_num = -1;
  247. last_num = -2;
  248. show_true();
  249. cost_change = false;
  250. cost_success = false;
  251. human_cost = true;
  252. }
  253. public void SetCostChange(bool bCostChange)
  254. {
  255. cost_change = bCostChange;
  256. }
  257. public void SetCostSuccess(bool bCostSuccess)
  258. {
  259. cost_success = bCostSuccess;
  260. }
  261. }