| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- /// <summary>
- /// ZWN-XHJ
- /// 左右手的手腕点的显示和隐藏
- /// 20211013
- /// </summary>
- using UnityEngine;
- using System.Collections;
- public class JointFollow : MonoBehaviour
- {
- public static JointFollow single;
- void Awake()
- {
- single = this;
- default_pos = new Vector2(-Screen.width, -Screen.height);
- prepos = default_pos;
- prepos2 = default_pos;
- left.gameObject.SetActive(false);
- right.gameObject.SetActive(false);
- }
- Vector2 default_pos = new Vector2(-Screen.width, -Screen.height);
- Vector2 curpos = new Vector2(0, 0), curpos2 = new Vector2(0, 0);
- Vector2 prepos = new Vector2(-1920, -1080), prepos2 = new Vector2(-1920, -1080);
- [HideInInspector]
- public bool left_flag = false, right_flag = false;
- bool leftlist_flag = false, rightlist_flag = false;
- [HideInInspector]
- public Vector3 left_vec, right_vec;
- public Transform left, right;
- bool ret = false;
- bool follow_flag = false;
- public void init_follow()
- {
- follow_flag = true;
- }
- public void end_follow()
- {
- follow_flag = false;
- left.gameObject.SetActive(false);
- prepos = default_pos;
- right.gameObject.SetActive(false);
- prepos2 = default_pos;
- }
- void Update()
- {
- if (follow_flag)
- {
- ret = true;
- if (ret)
- {
- left_flag = Tra_Pos();
- right_flag = Tra_Pos2();
- if (Application.platform == RuntimePlatform.Android)
- {
- if (left_flag && ZwnAmlogicHelperData.isSomeone == true)
- {
- prepos = curpos;
- left.localPosition = leftdistance();
- curpos = left_vec;
- if (prepos == default_pos)
- {
- prepos = curpos;
- }
- left.gameObject.SetActive(true);
- }
- else
- {
- left.gameObject.SetActive(false);
- prepos = default_pos;
- }
- }
- if (right_flag && ZwnAmlogicHelperData.isSomeone == true)
- {
- prepos2 = curpos2;
- right.localPosition = rightdistance();
- curpos2 = right_vec;
- if (prepos2 == default_pos)
- {
- prepos2 = curpos2;
- }
- right.gameObject.SetActive(true);
- }
- else
- {
- right.gameObject.SetActive(false);
- prepos2 = default_pos;
- }
- }
- if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer)
- {
- if (right_flag)
- {
- prepos2 = curpos2;
- right.localPosition = rightdistance();
- curpos2 = right_vec;
- if (prepos2 == default_pos)
- {
- prepos2 = curpos2;
- }
- right.gameObject.SetActive(true);;
- }
- else
- {
- right.gameObject.SetActive(false);
- prepos2 = default_pos;
- }
- if (left_flag && ZwnAmlogicHelperData.isSomeone == true)
- {
- prepos = curpos;
- left.localPosition = leftdistance();
- curpos = left_vec;
- if (prepos == default_pos)
- {
- prepos = curpos;
- }
- left.gameObject.SetActive(true);
- }
- else
- {
- left.gameObject.SetActive(false);
- prepos = default_pos;
- }
- }
- }
- }
- /// <summary>
- /// 第一个点
- /// </summary>
- /// <returns></returns>
- bool Tra_Pos()
- {
- if (zwn_common_data.single.zwn_transform_pose != null)
- {
- if (Application.platform == RuntimePlatform.WindowsEditor
- || Application.platform == RuntimePlatform.WindowsPlayer)
- {
- if (zwn_common_data.single.zwn_transform_pose.Length >= 17)
- {
- left_vec = zwn_common_data.single.zwn_transform_pose[9];
- }
- }
- if (Application.platform == RuntimePlatform.Android)// 使用Unity切换Platform无法模拟
- {
- if (zwn_common_data.single.zwn_transform_pose.Length >= 17)
- {
- left_vec = zwn_common_data.single.zwn_transform_pose[9];
- }
- }
- }
- else
- {
- left_vec = new Vector3(-Screen.width, -Screen.height, 0);
- }
- if (left_vec.x < -1920 / 2 || left_vec.x > 1920 / 2
- || left_vec.y < -1080 / 2 || left_vec.y > 1080 / 2)
- {
- return false;
- }
- return true;
- }
- /// <summary>
- /// 第二个点
- /// </summary>
- /// <returns></returns>
- bool Tra_Pos2()
- {
- if (zwn_common_data.single.zwn_transform_pose != null)
- {
- if (Application.platform == RuntimePlatform.WindowsEditor
- || Application.platform == RuntimePlatform.WindowsPlayer)
- {
- if (zwn_common_data.single.zwn_transform_pose.Length >= 17)
- {
- right_vec = zwn_common_data.single.zwn_transform_pose[10];
- }
- }
- if (Application.platform == RuntimePlatform.Android)// 使用Unity切换Platform无法模拟
- {
- if (zwn_common_data.single.zwn_transform_pose.Length >= 17)
- {
- right_vec = zwn_common_data.single.zwn_transform_pose[10];
- }
- }
- }
- else
- {
- right_vec = new Vector3(-Screen.width, -Screen.height, 0);
- }
- if (right_vec.x < -1920 / 2 || right_vec.x > 1920 / 2
- || right_vec.y < -1080 / 2 || right_vec.y > 1080 / 2)
- {
- return false;
- }
- return true;
- }
- /// <summary>
- /// 左手掌位置
- /// </summary>
- /// <returns></returns>
- Vector3 leftdistance()
- {
- Vector3 vec_left;
- Vector3 leftelbow = Vector3.zero;
- if (zwn_common_data.single.zwn_transform_pose.Length >= 17)
- {
- leftelbow = zwn_common_data.single.zwn_transform_pose[7];
- }
- vec_left = left_vec - ((leftelbow + left_vec) / 2 - left_vec) / 2;
- return vec_left;
- }
- /// <summary>
- /// 左手掌位置
- /// </summary>
- /// <returns></returns>
- Vector3 rightdistance()
- {
- Vector3 vec_right;
- Vector3 rightelbow = Vector3.zero;
- if (zwn_common_data.single.zwn_transform_pose.Length >= 17)
- {
- rightelbow = zwn_common_data.single.zwn_transform_pose[8];
- }
- vec_right = right_vec - ((rightelbow + right_vec) / 2 - right_vec) / 2;
- return vec_right;
- }
- }
|