MotionCapture/Assets/Models/Bond.cs
jackfiled 5113929728 feature: 添加了批量新建棍子的方法
refact: 重构了Bond和VirutalSkeleton类
2023-02-27 11:07:44 +08:00

44 lines
1.4 KiB
C#

using UnityEngine;
namespace Models
{
/// <summary>
/// 捕捉点之间的连接线
/// </summary>
public class Bond
{
protected readonly GameObject Start;
protected readonly GameObject End;
private readonly GameObject _bond;
public Bond(GameObject start,GameObject end,float scale)
{
Start = start;
End = end;
_bond = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
_bond.transform.localScale = new Vector3(scale/2, scale/2, scale/2);
//这里可以设置材质,具体自己设置
_bond.GetComponent<Renderer>().material.color = Color.cyan;
}
public void UpdateBond()
{
var startPos = Start.transform.position;
var endPos = End.transform.position;
var rightPosition = (startPos + endPos) / 2;
var rightRotation = endPos - startPos;
var halfLength = Vector3.Distance(startPos, endPos) / 2;
var thickness = 0.1f;//线的粗细
//创建圆柱体
//bond.gameObject.transform.parent = transform;
_bond.transform.position = rightPosition;
_bond.transform.rotation = Quaternion.FromToRotation(Vector3.up, rightRotation);
_bond.transform.localScale = new Vector3(thickness, halfLength, thickness);
}
}
}