JointFollow.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /// <summary>
  2. /// ZWN-XHJ
  3. /// 左右手的手腕点的显示和隐藏
  4. /// 20211013
  5. /// </summary>
  6. using UnityEngine;
  7. using System.Collections;
  8. public class JointFollow : MonoBehaviour
  9. {
  10. public static JointFollow single;
  11. void Awake()
  12. {
  13. single = this;
  14. default_pos = new Vector2(-Screen.width, -Screen.height);
  15. prepos = default_pos;
  16. prepos2 = default_pos;
  17. left.gameObject.SetActive(false);
  18. right.gameObject.SetActive(false);
  19. }
  20. Vector2 default_pos = new Vector2(-Screen.width, -Screen.height);
  21. Vector2 curpos = new Vector2(0, 0), curpos2 = new Vector2(0, 0);
  22. Vector2 prepos = new Vector2(-1920, -1080), prepos2 = new Vector2(-1920, -1080);
  23. [HideInInspector]
  24. public bool left_flag = false, right_flag = false;
  25. bool leftlist_flag = false, rightlist_flag = false;
  26. [HideInInspector]
  27. public Vector3 left_vec, right_vec;
  28. public Transform left, right;
  29. bool ret = false;
  30. bool follow_flag = false;
  31. public void init_follow()
  32. {
  33. follow_flag = true;
  34. }
  35. public void end_follow()
  36. {
  37. follow_flag = false;
  38. left.gameObject.SetActive(false);
  39. prepos = default_pos;
  40. right.gameObject.SetActive(false);
  41. prepos2 = default_pos;
  42. }
  43. void Update()
  44. {
  45. if (follow_flag)
  46. {
  47. ret = true;
  48. if (ret)
  49. {
  50. left_flag = Tra_Pos();
  51. right_flag = Tra_Pos2();
  52. if (Application.platform == RuntimePlatform.Android)
  53. {
  54. if (left_flag && ZwnAmlogicHelperData.isSomeone == true)
  55. {
  56. prepos = curpos;
  57. left.localPosition = leftdistance();
  58. curpos = left_vec;
  59. if (prepos == default_pos)
  60. {
  61. prepos = curpos;
  62. }
  63. left.gameObject.SetActive(true);
  64. }
  65. else
  66. {
  67. left.gameObject.SetActive(false);
  68. prepos = default_pos;
  69. }
  70. }
  71. if (right_flag && ZwnAmlogicHelperData.isSomeone == true)
  72. {
  73. prepos2 = curpos2;
  74. right.localPosition = rightdistance();
  75. curpos2 = right_vec;
  76. if (prepos2 == default_pos)
  77. {
  78. prepos2 = curpos2;
  79. }
  80. right.gameObject.SetActive(true);
  81. }
  82. else
  83. {
  84. right.gameObject.SetActive(false);
  85. prepos2 = default_pos;
  86. }
  87. }
  88. if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer)
  89. {
  90. if (right_flag)
  91. {
  92. prepos2 = curpos2;
  93. right.localPosition = rightdistance();
  94. curpos2 = right_vec;
  95. if (prepos2 == default_pos)
  96. {
  97. prepos2 = curpos2;
  98. }
  99. right.gameObject.SetActive(true);;
  100. }
  101. else
  102. {
  103. right.gameObject.SetActive(false);
  104. prepos2 = default_pos;
  105. }
  106. if (left_flag && ZwnAmlogicHelperData.isSomeone == true)
  107. {
  108. prepos = curpos;
  109. left.localPosition = leftdistance();
  110. curpos = left_vec;
  111. if (prepos == default_pos)
  112. {
  113. prepos = curpos;
  114. }
  115. left.gameObject.SetActive(true);
  116. }
  117. else
  118. {
  119. left.gameObject.SetActive(false);
  120. prepos = default_pos;
  121. }
  122. }
  123. }
  124. }
  125. /// <summary>
  126. /// 第一个点
  127. /// </summary>
  128. /// <returns></returns>
  129. bool Tra_Pos()
  130. {
  131. if (zwn_common_data.single.zwn_transform_pose != null)
  132. {
  133. if (Application.platform == RuntimePlatform.WindowsEditor
  134. || Application.platform == RuntimePlatform.WindowsPlayer)
  135. {
  136. if (zwn_common_data.single.zwn_transform_pose.Length >= 17)
  137. {
  138. left_vec = zwn_common_data.single.zwn_transform_pose[9];
  139. }
  140. }
  141. if (Application.platform == RuntimePlatform.Android)// 使用Unity切换Platform无法模拟
  142. {
  143. if (zwn_common_data.single.zwn_transform_pose.Length >= 17)
  144. {
  145. left_vec = zwn_common_data.single.zwn_transform_pose[9];
  146. }
  147. }
  148. }
  149. else
  150. {
  151. left_vec = new Vector3(-Screen.width, -Screen.height, 0);
  152. }
  153. if (left_vec.x < -1920 / 2 || left_vec.x > 1920 / 2
  154. || left_vec.y < -1080 / 2 || left_vec.y > 1080 / 2)
  155. {
  156. return false;
  157. }
  158. return true;
  159. }
  160. /// <summary>
  161. /// 第二个点
  162. /// </summary>
  163. /// <returns></returns>
  164. bool Tra_Pos2()
  165. {
  166. if (zwn_common_data.single.zwn_transform_pose != null)
  167. {
  168. if (Application.platform == RuntimePlatform.WindowsEditor
  169. || Application.platform == RuntimePlatform.WindowsPlayer)
  170. {
  171. if (zwn_common_data.single.zwn_transform_pose.Length >= 17)
  172. {
  173. right_vec = zwn_common_data.single.zwn_transform_pose[10];
  174. }
  175. }
  176. if (Application.platform == RuntimePlatform.Android)// 使用Unity切换Platform无法模拟
  177. {
  178. if (zwn_common_data.single.zwn_transform_pose.Length >= 17)
  179. {
  180. right_vec = zwn_common_data.single.zwn_transform_pose[10];
  181. }
  182. }
  183. }
  184. else
  185. {
  186. right_vec = new Vector3(-Screen.width, -Screen.height, 0);
  187. }
  188. if (right_vec.x < -1920 / 2 || right_vec.x > 1920 / 2
  189. || right_vec.y < -1080 / 2 || right_vec.y > 1080 / 2)
  190. {
  191. return false;
  192. }
  193. return true;
  194. }
  195. /// <summary>
  196. /// 左手掌位置
  197. /// </summary>
  198. /// <returns></returns>
  199. Vector3 leftdistance()
  200. {
  201. Vector3 vec_left;
  202. Vector3 leftelbow = Vector3.zero;
  203. if (zwn_common_data.single.zwn_transform_pose.Length >= 17)
  204. {
  205. leftelbow = zwn_common_data.single.zwn_transform_pose[7];
  206. }
  207. vec_left = left_vec - ((leftelbow + left_vec) / 2 - left_vec) / 2;
  208. return vec_left;
  209. }
  210. /// <summary>
  211. /// 左手掌位置
  212. /// </summary>
  213. /// <returns></returns>
  214. Vector3 rightdistance()
  215. {
  216. Vector3 vec_right;
  217. Vector3 rightelbow = Vector3.zero;
  218. if (zwn_common_data.single.zwn_transform_pose.Length >= 17)
  219. {
  220. rightelbow = zwn_common_data.single.zwn_transform_pose[8];
  221. }
  222. vec_right = right_vec - ((rightelbow + right_vec) / 2 - right_vec) / 2;
  223. return vec_right;
  224. }
  225. }