public void SaveSettings() { GridPainterSettings.Default.CellSize = CellSize; GridPainterSettings.Default.ShowRulers = ShowRulers; GridPainterSettings.Default.ShowLines = showLines; // Save field value here instead fo calculable property GridPainterSettings.Default.PaintMode = PaintMode.ToString(); GridPainterSettings.Default.LineArgb = System.Drawing.Color.FromArgb(LineArgb); GridPainterSettings.Default.Line10Argb = System.Drawing.Color.FromArgb(Line10Argb); GridPainterSettings.Default.NumbersArgb = System.Drawing.Color.FromArgb(NumbersArgb); GridPainterSettings.Default.Save(); }
void Update() { if (Input.GetKey(KeyCode.Mouse0)) { var foundNode = MouseSelect(); if (foundNode != null) { if (Input.GetKeyDown(KeyCode.Mouse0)) // If pressed down this frame { if (currentPaintMode == PaintMode.Start) { foundNode.SetNodeType(Node.NodeType.Empty); start = foundNode; vis.ColorStartNode(start); } else if (currentPaintMode == PaintMode.End) { foundNode.SetNodeType(Node.NodeType.Empty); end = foundNode; vis.ColorEndNode(end); } } else { if (currentPaintMode == PaintMode.Empty) { if (foundNode == start || foundNode == end || foundNode.type != Node.NodeType.Empty) { foundNode.SetNodeType(Node.NodeType.Empty); vis.ColorNodeByType(foundNode); } } else if (currentPaintMode == PaintMode.Block && foundNode.type != Node.NodeType.Block) { foundNode.SetNodeType(Node.NodeType.Block); vis.ColorNodeByType(foundNode); if (pm != null && pm.path != null && pm.path.Contains(foundNode)) { //pm.recalculate = true; } } } } } // Finalize grid and search if (Input.GetKeyDown(KeyCode.Space)) { vis.ResetAllColors(start, end); bool canSearch = true; if (start == null) { UnityEngine.Debug.LogError("NO START NODE"); canSearch = false; } if (end == null) { UnityEngine.Debug.LogError("NO END NODE"); canSearch = false; } if (!canSearch) { return; } Stopwatch sw = new Stopwatch(); sw.Start(); if (useMethod == SearchMethod.BFS) { path = bfs.Search(start, end); processed = bfs.processed; } else if (useMethod == SearchMethod.DFS) { path = dfs.Search(start, end); processed = dfs.processed; } else if (useMethod == SearchMethod.AStar) { path = astar.Search(start, end); processed = astar.processed; } sw.Stop(); processedCount.text = "Processed: " + processed.Count; pathCount.text = "Path: " + path.Count; methodType.text = "Method: " + useMethod.ToString(); time.text = "Time: " + sw.Elapsed; } if (Input.GetKeyDown(KeyCode.F)) { var d = FindObjectOfType <Grid>().diagonalNeighbours; foreach (Node n in Grid.nodes) { n.FindNeighbours(d); } } if (Input.GetKeyDown(KeyCode.Q)) { vis.VisualizeVisited(processed); } if (Input.GetKeyDown(KeyCode.W)) { vis.VisualizePath(path); } if (Input.GetKeyDown(KeyCode.E)) { vis.ResetAllColors(start, end); } // PaintMode if (Input.GetKeyDown(KeyCode.Alpha1)) { currentPaintMode = PaintMode.Empty; paintMode.text = "Paint Mode: " + currentPaintMode.ToString() + " <color=white>[ ]</color>"; } if (Input.GetKeyDown(KeyCode.Alpha2)) { currentPaintMode = PaintMode.Block; paintMode.text = "Paint Mode: " + currentPaintMode.ToString() + " <color=black>[ ]</color>"; } if (Input.GetKeyDown(KeyCode.Alpha3)) { currentPaintMode = PaintMode.Start; paintMode.text = "Paint Mode: " + currentPaintMode.ToString() + " <color=cyan>[ ]</color>"; } if (Input.GetKeyDown(KeyCode.Alpha4)) { currentPaintMode = PaintMode.End; paintMode.text = "Paint Mode: " + currentPaintMode.ToString() + " <color=red>[ ]</color>"; } }