///
/// ZWN-XHJ
/// 左右手的手腕点的显示和隐藏
/// 20211013
///
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;
}
}
}
}
///
/// 第一个点
///
///
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;
}
///
/// 第二个点
///
///
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;
}
///
/// 左手掌位置
///
///
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;
}
///
/// 左手掌位置
///
///
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;
}
}