public void SpawnOrConnectGraphNode() { RaycastHit hit; var ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); if (Physics.Raycast(ray.origin, ray.direction, out hit, Mathf.Infinity)) { GraphNode newNode = null; GraphNode[] objects = GameObject.FindObjectsOfType <GraphNode>(); for (int i = 0; i < objects.Length; i++) { if (Vector3.Distance(hit.point, objects[i].transform.position) < 3f) { newNode = objects[i]; break; } } if (newNode == null) { GameObject newGo = new GameObject("GraphNode", typeof(GraphNode)); newNode = newGo.GetComponent <GraphNode>(); newGo.transform.position = hit.point + Vector3.up; newGo.transform.SetParent(node.Transform.parent); newNode.MaxSpeed = node.MaxSpeed; } if (node.LinksBezierHelpers == null) { node.LinksBezierHelpers = new List <Vector3>(); } if (node.ConnectedNodes == null) { node.ConnectedNodes = new List <GraphNode>(); } node.LinksBezierHelpers.Add(Bezier.CenterOf(newNode.transform.position, node.transform.position)); node.ConnectedNodes.Add(newNode); if (node.SelectCreatedNodeOnSpawn) { newNode.SelectCreatedNodeOnSpawn = true; newSelected = newNode.gameObject; } } }
public static Vector3 GetPointPosition(Vector3 start, Vector3 end, float t, float multiply) { Vector3 additionalPoint = Bezier.CenterOf(start, end) - new Vector3(0, multiply * Vector3.Distance(start, end) / 2, 0); return(Bezier.Calculate(start, additionalPoint, end, t)); }
public void VizualizeRoadLinks(RoadNode node, Vector3 transformPosition, List <RoadNode> nodes, List <Vector3> helpers) { for (int i = 0; i < nodes.Count; i++) { if (i + 1 <= helpers.Count) { for (int j = 1; j < node.IterationsCount[i] + 1; j++) { if (nodes[i] != null && helpers[i] != null) { Gizmos.color = Color.white; Gizmos.DrawLine( Bezier.GetPointPosition(transformPosition, (nodes[i]).transform.position, helpers[i], (float)(j - 1) / (float)node.IterationsCount[i]), Bezier.GetPointPosition(transformPosition, (nodes[i]).transform.position, helpers[i], ((float)j / (float)node.IterationsCount[i])) ); move = (Bezier.GetPointPosition(transformPosition, (nodes[i]).transform.position, helpers[i], (float)(j - 1) / (float)node.IterationsCount[i]) - Bezier.GetPointPosition(transformPosition, (nodes[i]).transform.position, helpers[i], (float)(j) / (float)node.IterationsCount[i])).normalized * 6f; Gizmos.DrawLine( Rotate( Bezier.GetPointPosition(transformPosition, (nodes[i]).transform.position, helpers[i], (float)(j) / (float)node.IterationsCount[i]), move, 90, 1), Rotate( Bezier.GetPointPosition(transformPosition, (nodes[i]).transform.position, helpers[i], (float)(j) / (float)node.IterationsCount[i]), move, -90, 1)); } } } else { for (int j = 1; j < node.IterationsCount[i] + 1; j++) { if (nodes[i] != null) { Gizmos.DrawLine( Bezier.GetPointPosition(transformPosition, (nodes[i]).transform.position, Bezier.CenterOf(transformPosition, (nodes[i]).transform.position), (float)(j - 1) / (float)node.IterationsCount[i]), Bezier.GetPointPosition(transformPosition, (nodes[i]).transform.position, Bezier.CenterOf(transformPosition, (nodes[i]).transform.position), (float)j / (float)node.IterationsCount[i]) ); move = (Bezier.GetPointPosition(transformPosition, (nodes[i]).transform.position, helpers[i], (float)(j - 1) / (float)node.IterationsCount[i]) - Bezier.GetPointPosition(transformPosition, (nodes[i]).transform.position, helpers[i], (float)(j) / (float)node.IterationsCount[i])).normalized * 6f; Gizmos.DrawLine( Rotate( Bezier.GetPointPosition(transformPosition, (nodes[i]).transform.position, helpers[i], (float)(j) / (float)node.IterationsCount[i]), move, 90, 1), Rotate( Bezier.GetPointPosition(transformPosition, (nodes[i]).transform.position, helpers[i], (float)(j) / (float)node.IterationsCount[i]), move, -90, 1)); } } } } }
public void VizualizeGraphLinks(Vector3 transformPosition, List <GraphNode> nodes, List <Vector3> helpers) { for (int i = 0; i < nodes.Count; i++) { int definition = (nodes[i].OverrideDefinition ? nodes[i].OverrideDefinitionValue : Bezier.BezierIterationsCount); if (i + 1 <= helpers.Count) { for (int j = 1; j < definition + 1; j++) { if (nodes[i] != null && helpers[i] != null) { if (nodes[i].MaxSpeed != 0) { Handles.color = Color.Lerp(Color.red, Color.green, (nodes[i].MaxSpeed / 35f) > 1f ? ((nodes[i].MaxSpeed / 35f) < 2 ? (nodes[i].MaxSpeed / 35f) - 1f : 0) : (nodes[i].MaxSpeed / 35f)); Gizmos.color = Handles.color; } else { Handles.color = Color.red; Gizmos.color = Handles.color; } if (!((helpers[i].y >= transformPosition.y - 1f && helpers[i].y <= (nodes[i]).transform.position.y + 1f) || (helpers[i].y <= transformPosition.y + 1f && helpers[i].y >= (nodes[i]).transform.position.y - 1f))) { Gizmos.color = orange; Handles.color = Color.red; } //Arrows if (j > 0) { Handles.ArrowCap(0, Bezier.GetPointPosition(transformPosition, (nodes[i]).transform.position, helpers[i], (float)(j - 1) / (float)definition), Quaternion.LookRotation(( Bezier.GetPointPosition(transformPosition, (nodes[i]).transform.position, helpers[i], ((float)j / (float)definition)) - Bezier.GetPointPosition(transformPosition, (nodes[i]).transform.position, helpers[i], (float)(j - 1) / (float)definition) ).normalized), 2f ); } Gizmos.DrawLine( Bezier.GetPointPosition(transformPosition, (nodes[i]).transform.position, helpers[i], (float)(j - 1) / (float)definition), Bezier.GetPointPosition(transformPosition, (nodes[i]).transform.position, helpers[i], ((float)j / (float)definition)) ); } } } else { for (int j = 1; j < definition + 1; j++) { if (nodes[i] != null) { Gizmos.DrawLine( Bezier.GetPointPosition(transformPosition, (nodes[i]).transform.position, Bezier.CenterOf(transformPosition, (nodes[i]).transform.position), (float)(j - 1) / (float)definition), Bezier.GetPointPosition(transformPosition, (nodes[i]).transform.position, Bezier.CenterOf(transformPosition, (nodes[i]).transform.position), (float)j / (float)definition) ); } } } } }