|
|
@ -9,21 +9,21 @@ public class ArrowManager : MonoBehaviour |
|
|
public int arrowNodeNum; |
|
|
public int arrowNodeNum; |
|
|
public float scaleFactor = 1f;//节点缩放
|
|
|
public float scaleFactor = 1f;//节点缩放
|
|
|
|
|
|
|
|
|
private RectTransform origin;//Æðµã
|
|
|
private Transform origin;//Æðµã
|
|
|
private List<RectTransform> arrowNodes = new List<RectTransform>();//ÿ¸ö½ÚµãλÖÃ
|
|
|
private List<Transform> arrowNodes = new List<Transform>();//ÿ¸ö½ÚµãλÖÃ
|
|
|
private List<Vector2> controlPoints = new List<Vector2>();//贝塞尔曲线控制节点p0-p3
|
|
|
private List<Vector2> controlPoints = new List<Vector2>();//贝塞尔曲线控制节点p0-p3
|
|
|
private readonly List<Vector2> controlPointFactors = new List<Vector2>() { new Vector2(-0.3f, 0.8f), new Vector2(0.1f, 1.4f) };//决定p1和p2位置的向量因子
|
|
|
private readonly List<Vector2> controlPointFactors = new List<Vector2>() { new Vector2(-0.3f, 0.8f), new Vector2(0.1f, 1.4f) };//决定p1和p2位置的向量因子
|
|
|
|
|
|
|
|
|
private void Awake() |
|
|
private void Awake() |
|
|
{ |
|
|
{ |
|
|
this.origin = this.GetComponent<RectTransform>(); |
|
|
this.origin = this.transform; |
|
|
|
|
|
|
|
|
for (int i=0;i<this .arrowNodeNum;++i) |
|
|
for (int i=0;i<this .arrowNodeNum;++i) |
|
|
{ |
|
|
{ |
|
|
this.arrowNodes.Add(Instantiate(this.arrowNodePrefab, this.transform).GetComponent<RectTransform>()); |
|
|
this.arrowNodes.Add(Instantiate(this.arrowNodePrefab, this.transform).transform); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.arrowNodes.Add(Instantiate(this.arrowHeadPrefab, this.transform).GetComponent<RectTransform>()); |
|
|
this.arrowNodes.Add(Instantiate(this.arrowHeadPrefab, this.transform).transform); |
|
|
|
|
|
|
|
|
//todo-隐藏?
|
|
|
//todo-隐藏?
|
|
|
|
|
|
|
|
|
@ -36,13 +36,20 @@ public class ArrowManager : MonoBehaviour |
|
|
public void Update() |
|
|
public void Update() |
|
|
{ |
|
|
{ |
|
|
//p0是起始位置
|
|
|
//p0是起始位置
|
|
|
Vector3 worldstart = transform.parent.TransformPoint(transform.position); |
|
|
|
|
|
this.controlPoints[0] = new Vector2(worldstart.x, worldstart.y); |
|
|
// Vector3 worldstart = transform.parent.position ;
|
|
|
Debug.Log(controlPoints[0]); |
|
|
// Debug.Log(transform.parent.name + transform.parent.position );
|
|
|
|
|
|
this.controlPoints[0] = new Vector2(0, 0); |
|
|
|
|
|
|
|
|
|
|
|
// Vector3 worldstart = transform.parent.TransformPoint(transform.position);
|
|
|
|
|
|
// this.controlPoints[0] = new Vector2(worldstart.x, worldstart.y);
|
|
|
|
|
|
//Debug.Log(controlPoints[0]);
|
|
|
//p3是鼠标位置-------鼠标在ui平面上的位置
|
|
|
//p3是鼠标位置-------鼠标在ui平面上的位置
|
|
|
Vector3 position = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 8f); |
|
|
|
|
|
|
|
|
Vector3 position = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10f); |
|
|
Vector3 worldPoint = Camera.main.ScreenToWorldPoint(position); |
|
|
Vector3 worldPoint = Camera.main.ScreenToWorldPoint(position); |
|
|
this.controlPoints[3] = new Vector2(worldPoint .x,worldPoint .y); |
|
|
Vector3 localPoint = transform.InverseTransformPoint(worldPoint); |
|
|
|
|
|
this.controlPoints[3] = new Vector2(localPoint .x,localPoint .y); |
|
|
|
|
|
|
|
|
//p1p2通过p0p3计算
|
|
|
//p1p2通过p0p3计算
|
|
|
this.controlPoints[1] = this.controlPoints[0] + (this.controlPoints[3] - this.controlPoints[0] )* this.controlPointFactors[0]; |
|
|
this.controlPoints[1] = this.controlPoints[0] + (this.controlPoints[3] - this.controlPoints[0] )* this.controlPointFactors[0]; |
|
|
@ -58,12 +65,12 @@ public class ArrowManager : MonoBehaviour |
|
|
3 * (1 - t) * Mathf.Pow(t, 2) * this.controlPoints[2] + |
|
|
3 * (1 - t) * Mathf.Pow(t, 2) * this.controlPoints[2] + |
|
|
Mathf.Pow(t, 3) * this.controlPoints[3]; |
|
|
Mathf.Pow(t, 3) * this.controlPoints[3]; |
|
|
|
|
|
|
|
|
this.arrowNodes[i].position = currentPoint; |
|
|
this.arrowNodes[i].localPosition = currentPoint; |
|
|
this.arrowNodes[i].localPosition -= new Vector3(0, 0, this.arrowNodes[i].localPosition.z); |
|
|
//this.arrowNodes[i].localPosition -= new Vector3(0, 0, this.arrowNodes[i].localPosition.z);
|
|
|
|
|
|
|
|
|
if (i > 0) |
|
|
if (i > 0) |
|
|
{ |
|
|
{ |
|
|
var euler = new Vector3 (0,0,Vector2.SignedAngle(CardActiveSort.Instance.transform.InverseTransformDirection(transform.up), this.arrowNodes[i].position-this.arrowNodes[i-1].position)); |
|
|
var euler = new Vector3 (0,0,Vector2.SignedAngle(CardActiveSort.Instance.transform.InverseTransformDirection(transform.up), this.arrowNodes[i].localPosition-this.arrowNodes[i-1].localPosition)); |
|
|
this.arrowNodes[i].localRotation = Quaternion.Euler(euler); |
|
|
this.arrowNodes[i].localRotation = Quaternion.Euler(euler); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|