2 using System.Collections;
8 public Vector3 newPos {
get; set; }
9 private Vector3 velocity = Vector3.one;
11 private GameObject meshNode;
12 private GameObject meshPositionNode;
13 private GameObject meshViewerBase;
14 private Vector3[] pointsOnLabel =
new Vector3[4];
15 private float[] distances =
new float[4];
16 public GameObject annotationPoint {
get; set; }
18 public bool move =
true;
20 public float labelScale = 0.04f;
25 meshViewerBase = GameObject.Find(
"MeshViewerBase");
26 meshNode = GameObject.Find(
"MeshViewerBase/MeshViewerScale");
27 meshPositionNode = GameObject.Find(
"MeshViewerBase/MeshViewerScale/MeshRotationNode/MeshPositionNode");
34 adaptLabelToZooming();
37 this.transform.position = Vector3.SmoothDamp(this.transform.position, newPos, ref velocity, 2f);
39 updateConnectionLine ();
42 public void updateConnectionLine()
45 if(annotationPoint != null) {
46 this.GetComponent<LineRenderer>().SetPosition(0, annotationPoint.transform.position);
50 float width = this.GetComponent<RectTransform>().rect.width *
this.transform.parent.localScale.x *
this.GetComponent<RectTransform>().localScale.x * meshNode.transform.localScale.x * meshPositionNode.transform.localScale.x * meshViewerBase.transform.localScale.x;
51 float height = this.GetComponent<RectTransform>().rect.height *
this.transform.parent.localScale.x *
this.GetComponent<RectTransform>().localScale.x * meshNode.transform.localScale.x * meshPositionNode.transform.localScale.x * meshViewerBase.transform.localScale.x;
53 pointsOnLabel[0] = this.transform.position + this.transform.up * (height / 2) + this.transform.right * (width / 2);
54 pointsOnLabel[1] = this.transform.position + this.transform.up * (height / 2) - this.transform.right * (width / 2);
55 pointsOnLabel[2] = this.transform.position - this.transform.up * (height / 2) + this.transform.right * (width / 2);
56 pointsOnLabel[3] = this.transform.position - this.transform.up * (height / 2) - this.transform.right * (width / 2);
60 for (
int i = 0; i < distances.Length; i++)
63 if(annotationPoint != null)
65 distances[i] = (pointsOnLabel[i] - annotationPoint.transform.position).magnitude;
71 for (
int i = 0; i < distances.Length; i++)
73 bool smallest =
false;
75 for (
int j = i; j < distances.Length; j++)
78 if (distances[i] <= distances[j])
92 this.GetComponent<LineRenderer>().SetPosition(1, pointsOnLabel[i]);
98 this.GetComponent<LineRenderer>().enabled =
true;
101 public void adaptLabelToZooming()
104 this.GetComponent<RectTransform>().localScale =
new Vector3(labelScale / meshNode.transform.localScale.x, labelScale / meshNode.transform.localScale.x, labelScale / meshNode.transform.localScale.x);