-
Notifications
You must be signed in to change notification settings - Fork 417
/
Copy pathNode.cs
51 lines (43 loc) · 1.37 KB
/
Node.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Node : MonoBehaviour {
public int nodeIndex;
public ReorderableList tree;
public TextMesh text;
public bool dragging = false;
Vector3 offset = Vector3.zero;
void Start() {}
void OnMouseDown() {
offset = transform.position - Camera.main.ScreenPointToRay(Input.mousePosition).origin;
}
void OnMouseDrag() {
Vector3 curOffset = transform.position - Camera.main.ScreenPointToRay(Input.mousePosition).origin;
if (!dragging && offset != curOffset) dragging = true;
if (dragging) {
transform.position = Camera.main.ScreenPointToRay(Input.mousePosition).origin + offset;
tree.reevaluateNodeOrder(this);
//Transform socket = tree.sockets[tree.nodes.IndexOf(this)];
//if (socket != null) {
// transform.position += (socket.position - transform.position) * 0.7f;
//}
}
}
void OnMouseUp() {
if (dragging) {
dragging = false;
} else {
//Activate button
}
}
// Update is called once per frame
void Update() {
Transform socket = tree.sockets[tree.nodes.IndexOf(this)];
if (socket != null) {
if (!dragging) {
transform.position += (socket.position - transform.position) * 0.1f;
}
transform.rotation = Quaternion.Slerp(transform.rotation, socket.rotation, 0.1f);
}
}
}