public static void ResetTransform() { foreach (var selected in Selection.gameObjects) { NodeSystem s = selected.GetComponent <NodeSystem>(); if (s != null) { ResetTransformRecursively(s, s.rootNode); } } }
public static void RemoveNode() { foreach (var selected in Selection.gameObjects) { NodeSystem ns = selected.GetComponent <NodeSystem>(); if (ns != null && ns.selectedNode != null) { ns.RemoveSelected(); } } }
static void ResetTransformRecursively(NodeSystem nodeSystem, Node curNode) { curNode.pos = nodeSystem.transform.InverseTransformPoint(curNode.pos); foreach (Node child in curNode.children) { if (child != null) { ResetTransformRecursively(nodeSystem, child); } } }
public static void ClearNodes() { foreach (var selected in Selection.gameObjects) { NodeSystem nodeSystem = selected.GetComponent <NodeSystem>(); if (nodeSystem != null) { nodeSystem.allNodes = new List <Node>(); nodeSystem.rootNode = null; nodeSystem.Initialize(); } } }
void OnSceneGUI() { // get the chosen game object NodeSystem t = target as NodeSystem; if (sv == null || sceneViewCam == null) { sv = EditorWindow.GetWindow <SceneView>(); sceneViewCam = sv.camera; } if (t == null || t.rootNode == null) { return; } Event current = Event.current; int controlID = GUIUtility.GetControlID(t.GetHashCode(), FocusType.Passive); Node nodeToSelect = NodeToSelect(t); if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { if (nodeToSelect != null) { t.selectedNode = nodeToSelect; Event.current.Use(); } } if (current.type == EventType.Layout) { if (nodeToSelect != null) { HandleUtility.AddDefaultControl(controlID); } } DrawLinesRecursively(t, t.rootNode); EditorGUI.BeginChangeCheck(); Vector3 newPosition = t.transform.TransformPoint(t.selectedNode.pos); if (t.selectedNode != null) { newPosition = Handles.PositionHandle(t.transform.TransformPoint(t.selectedNode.pos), t.transform.rotation); } if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(t, "Change node position"); t.selectedNode.pos = t.transform.InverseTransformPoint(newPosition); } }
void DrawLinesRecursively(NodeSystem system, Node curNode) { foreach (Node child in curNode.children) { if (child != null) { Handles.DrawLine( system.transform.TransformPoint(curNode.pos), system.transform.TransformPoint(child.pos) ); DrawLinesRecursively(system, child); } } }
Node NodeToSelect(NodeSystem t) { Vector2 guiPosition = Event.current.mousePosition; Ray ray = HandleUtility.GUIPointToWorldRay(guiPosition); foreach (Node node in t.GetAllNodes()) { if (HitGizmoSphere(t.transform.TransformPoint(node.pos), ray)) { return(node); } } return(null); }
public static void AddChild() { foreach (var selected in Selection.gameObjects) { NodeSystem ns = selected.GetComponent <NodeSystem>(); if (ns != null && ns.selectedNode != null) { Node newNode = ns.AddNewChildToSelected(); // Make it easy to do staircases: if (ns.buildAsStaircase) { newNode.pos += 0.5f * (temp ? ns.staircaseDirection1 : ns.staircaseDirection2); } temp = !temp; } } }
public static void MirrorAcrossZ() { foreach (var selected in Selection.gameObjects) { NodeSystem s = selected.GetComponent <NodeSystem>(); if (s != null) { for (int i = 0; i < s.serializedNodes.Count; i++) { SerializableNode thisNode = s.serializedNodes[i]; thisNode.pos.z *= -1f; s.serializedNodes[i] = thisNode; } for (int i = 0; i < s.allNodes.Count; i++) { s.allNodes[i].pos.z *= -1f; } } } }