fix: 修复了foreach遍历警告的问题

refact: 移动UdpListener到Utils文件夹
This commit is contained in:
jackfiled 2023-02-27 13:34:19 +08:00
parent 5113929728
commit 6eba30e268
3 changed files with 8 additions and 119 deletions

View File

@ -10,7 +10,6 @@ public class MainBehaviour : MonoBehaviour
private readonly List<PoseTransform> _poseTransforms = new List<PoseTransform>();
private readonly UdpListener _listener = new UdpListener();
private const float Scale = 0.2f;
private GameObject sample ;
// Start is called before the first frame update
private void Start()
@ -18,7 +17,6 @@ private void Start()
CreateNodes();
CreateBonds();
_listener.AddHandler(OnReceive);
_listener.Connect(5000);
}
@ -26,18 +24,14 @@ private void Start()
// Update is called once per frame
private void Update()
{
foreach (var poseTransform in _poseTransforms)
for (var i = 0; i < 33; i++)
{
var index = (int)poseTransform.MediaPipeName;
var temp = new Vector4(_poseTransforms[i].MediaPipePos.x,
_poseTransforms[i].MediaPipePos.y,
_poseTransforms[i].MediaPipePos.z,
1);
var temp = new Vector4(_poseTransforms[index].MediaPipePos.x,
_poseTransforms[index].MediaPipePos.y,
_poseTransforms[index].MediaPipePos.z,1);
//temp = RotateAxisX(-45) * temp;
//warning:乘法的顺序不能改!
_nodes[index].transform.position = new Vector3(-temp.x, -temp.y, -temp.z) * 5;
//_nodes[index].transform.position = _poseTransforms[index].MediaPipePos * 5;
_nodes[i].transform.position = new Vector3(-temp.x, -temp.y, -temp.z) * 5;
}
foreach (var bond in _bonds)
@ -87,111 +81,6 @@ private void CreateNodes()
private void CreateBonds()
{
/*var temp = new Bonds(_nodes[0], _nodes[4], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[0], _nodes[1], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[1], _nodes[2], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[2], _nodes[3], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[3], _nodes[7], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[4], _nodes[5], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[5], _nodes[6], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[6], _nodes[8], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[9], _nodes[10], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[2], _nodes[3], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[11], _nodes[12], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[12], _nodes[14], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[14], _nodes[16], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[16], _nodes[22], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[16], _nodes[18], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[18], _nodes[20], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[16], _nodes[20], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[11], _nodes[13], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[13], _nodes[15], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[15], _nodes[17], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[15], _nodes[21], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[15], _nodes[19], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[17], _nodes[19], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[12], _nodes[24], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[23], _nodes[24], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[11], _nodes[23], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[24], _nodes[26], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[26], _nodes[28], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[28], _nodes[32], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[28], _nodes[30], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[23], _nodes[25], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[25], _nodes[27], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[27], _nodes[29], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[27], _nodes[31], Scale);
_bonds.Add(temp);
temp = new Bonds(_nodes[29], _nodes[31], Scale);
_bonds.Add(temp);*/
var headBonds = new[]
{
PoseLandmarkType.RightEar,