2 using System.Collections;
3 using UnityEngine.EventSystems;
8 public GameObject bobble;
10 public float maxScale = 15f;
11 public float minScale = 0.5f;
13 private bool reScale =
false;
15 private Vector3 rescaleDirection;
17 public void rescaleAnnotation(BaseEventData eventData) {
18 PointerEventData data = eventData as PointerEventData;
19 if (data.button == PointerEventData.InputButton.Left) {
20 rescaleDirection = bobble.transform.localPosition;
25 public void stopRescale(BaseEventData eventData) {
26 PointerEventData data = eventData as PointerEventData;
27 if (data.button == PointerEventData.InputButton.Left) {
33 private void rescaleMesh() {
34 InputDevice inputDevice = InputDeviceManager.instance.currentInputDevice;
35 Plane intersectPlane =
new Plane ();
37 Ray intersectRay = inputDevice.createRay ();
39 intersectRay.origin = inputDevice.getEventCamera ().transform.position;
43 Vector3 globalDir =
this.transform.parent.TransformDirection (rescaleDirection);
44 Vector3 camAnnoVec = (intersectRay.origin - this.transform.parent.position);
46 Vector3 planeVec = Vector3.Cross (globalDir, camAnnoVec);
47 Vector3 normal = Vector3.Cross (globalDir, planeVec);
50 intersectPlane.SetNormalAndPosition (normal, this.transform.parent.position);
52 if (intersectPlane.Raycast (intersectRay, out dist)) {
53 Vector3 intersectPoint = intersectRay.GetPoint (dist);
54 Vector3 intersectDirection = intersectPoint - this.transform.parent.position;
55 if (intersectDirection.magnitude < maxScale && intersectDirection.magnitude > minScale) {
56 bobble.transform.position = intersectPoint;
58 float newScale = bobble.transform.localPosition.magnitude * 2;
59 this.GetComponentInParent<
Annotation> ().rescaleMesh (
new Vector3 (newScale, newScale, newScale));
70 Vector3 scale = this.GetComponentInParent<
Annotation> ().getMeshScale ();
71 bobble.transform.localPosition =
new Vector3 (scale.x / 2f, 0f, 0f);
74 public void Update() {