public void OnDisable() { GraphwayConnection graphwayConnection = (GraphwayConnection)target; if (graphwayConnection != null) { GraphwayEditor.DisableRenderers(graphwayConnection.transform); } }
private void CreateSubnodeObject(Vector3 subnodePosition) { // Create new subnode object GraphwayConnection graphwayConnection = (GraphwayConnection)target; GameObject subnodeObject = Instantiate(Resources.Load("Prefabs/GraphwaySubnode")) as GameObject; subnodeObject.name = graphwayConnection.editorSubnodeCounter.ToString(); subnodeObject.transform.position = subnodePosition; subnodeObject.transform.parent = graphwayConnection.transform; subnodeObject.AddComponent <GraphwayObject>(); // Register undo operation Undo.RegisterCreatedObjectUndo(subnodeObject, "Created Subnode"); graphwayConnection.editorSubnodeCounter++; }
public void OnSceneGUI() { GraphwayConnection graphwayConnection = (GraphwayConnection)target; if (subnodePlacementEnabled) { // Disable left click selection on other game objects HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); // Place subnodes // NOTE - objects must have colliders attached! if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); RaycastHit hit; if (Physics.Raycast(worldRay, out hit)) { // Create subnode at position CreateSubnodeObject(hit.point); // Mark scene as dirty to trigger 'Save Changes' prompt EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } // Use up event Event.current.Use(); } } else { // Re-enable left click selection on other game objects HandleUtility.Repaint(); } // Update graph GraphwayEditor.DrawGraph(graphwayConnection.transform); }
void Start() { // Create new list to store pathfinding jobs jobs = new List <GwJob>(); // Convert GameObject structure to class objects for efficiency // Check game objects exist if (!transform.Find("Nodes")) { Debug.LogError("Missing Graphway child object 'Nodes'."); } else if (!transform.Find("Connections")) { Debug.LogError("Missing Graphway child object 'Connections'."); } else { Transform nodesParent = transform.Find("Nodes").transform; Transform connectionsParent = transform.Find("Connections").transform; // Create dictionary of NODES nodes = new Dictionary <int, GwNode>(); foreach (Transform node in nodesParent.transform) { GraphwayNode nodeData = node.GetComponent <GraphwayNode>(); nodes[nodeData.nodeID] = new GwNode(nodeData.nodeID, node.position); } // Add CONNECTION structure foreach (Transform connection in connectionsParent.transform) { GraphwayConnection connectionData = connection.GetComponent <GraphwayConnection>(); // Check if connection uses SUBNODES Vector3[] subnodesAB = null; Vector3[] subnodesBA = null; if (connection.childCount > 0) { // Read positions of child objects into array subnodesAB = new Vector3[connection.childCount]; int i = 0; foreach (Transform subnode in connection.transform) { subnodesAB[i] = subnode.position; i++; } // Clone & Reverse subnodes fron A->B to B->A subnodesBA = (Vector3[])subnodesAB.Clone(); Array.Reverse(subnodesBA); } // Add connection A->B if (connectionData.connectionType == GraphwayConnectionTypes.Bidirectional || connectionData.connectionType == GraphwayConnectionTypes.UnidirectionalAToB) { nodes[connectionData.nodeIDA].AddConnection(connectionData.nodeIDB, connectionData.disabled, connectionData.speedWeight, subnodesAB); } // Add connection B->A if (connectionData.connectionType == GraphwayConnectionTypes.Bidirectional || connectionData.connectionType == GraphwayConnectionTypes.UnidirectionalBToA) { nodes[connectionData.nodeIDB].AddConnection(connectionData.nodeIDA, connectionData.disabled, connectionData.speedWeight, subnodesBA); } } // Remove graphway child gameobjects as they are no longer needed during runtime Destroy(nodesParent.gameObject); Destroy(connectionsParent.gameObject); } }