feature: 添加了批量新建棍子的方法
refact: 重构了Bond和VirutalSkeleton类
This commit is contained in:
44
Assets/Models/Bond.cs
Normal file
44
Assets/Models/Bond.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Models/Bond.cs.meta
Normal file
3
Assets/Models/Bond.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94a8f8c83e58421d9447173d38482d74
|
||||
timeCreated: 1677230676
|
35
Assets/Models/VirtualSkeleton.cs
Normal file
35
Assets/Models/VirtualSkeleton.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Models
|
||||
{
|
||||
public class VirtualSkeleton : Bond
|
||||
{
|
||||
private readonly GameObject _virtualSkeleton;
|
||||
|
||||
public VirtualSkeleton(GameObject start,GameObject end,float scale) : base(start,end,scale)
|
||||
{
|
||||
_virtualSkeleton = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
|
||||
|
||||
_virtualSkeleton.transform.localScale = new Vector3(scale/2, scale/2, scale/2);
|
||||
|
||||
_virtualSkeleton.GetComponent<Renderer>().material.color = Color.white;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 覆盖基类的更新方法
|
||||
/// </summary>
|
||||
public new void UpdateBond()
|
||||
{
|
||||
var startPos = Start.transform.position;
|
||||
var endPos = End.transform.position;
|
||||
|
||||
var rightPosition = (startPos + endPos) / 2;
|
||||
var rightRotation = endPos - startPos;
|
||||
var lThickness = 0.2f;
|
||||
|
||||
_virtualSkeleton.transform.position = rightPosition;
|
||||
_virtualSkeleton.transform.rotation = Quaternion.FromToRotation(Vector3.up, rightRotation);
|
||||
_virtualSkeleton.transform.localScale = new Vector3(lThickness, lThickness, lThickness);
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Models/VirtualSkeleton.cs.meta
Normal file
3
Assets/Models/VirtualSkeleton.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f725336fc6a4481a4c7d74ec0e3b17b
|
||||
timeCreated: 1677413910
|
Reference in New Issue
Block a user