/// <summary> /// Attempt to latch a graph onto a given simulation /// </summary> public void AttachToSimulation(NDLineGraph graph, NDSimulation simulation, RaycastHit hit) { int vertIndex = simulation.GetNearestPoint(hit); // Check for duplicates if (!VertIsAvailable(vertIndex, simulation)) { Destroy(graph.gameObject); return; } graph.vert = vertIndex; graphs.Add(graph); }
/// <summary> /// Looks for NDSimulation instance and adds neuronClamp object if possible /// </summary> /// <param name="hit"></param> public void InstantiateGraph(RaycastHit hit) { // Make sure we have a valid prefab and simulation if (graphPrefab == null) { Debug.LogError("No Clamp prefab found"); } NDSimulation sim = hit.collider.GetComponentInParent <NDSimulation>(); // If there is no NDSimulation, don't try instantiating a clamp if (sim == null) { return; } var graphObj = Instantiate(graphPrefab); NDLineGraph graph = graphObj.GetComponent <NDLineGraph>(); graph.manager = this; AttachToSimulation(graph, sim, hit); }