public void Test_NodeSpawningWillNotCauseErrors() { //Prepare var reflectedNodeTypes = GetAllNonAbstractNodeModelTypes(); //Act NodeSpawner.SpawnAllNodeModelsInGraph(GraphModel); //Validate var spawnedNodeTypes = GetAllSpawnedNodeTypes(); var missingSpawnedNode = reflectedNodeTypes.Except(spawnedNodeTypes).ToList(); if (missingSpawnedNode.Any()) { string errorMessage = "The following types have not been spawned in the SpawnAllNodeModelsInGraph():\n\n"; StringBuilder builder = new StringBuilder(errorMessage); foreach (var missingNode in missingSpawnedNode) { builder.AppendLine(missingNode.ToString()); } Debug.LogError(builder.ToString()); } Assert.That(missingSpawnedNode, Is.Empty); }
private void Path() { NodeSpawner nManager = GameObject.Find("NodeGenerator").GetComponent <NodeSpawner>(); foreach (var node in nManager.grid) { node.GScore = 0; node.HScore = 0; node.FScore = 0; node.previous = null; } List <Node> open = new List <Node>(); List <Node> closed = new List <Node>(); Node current = currentOn; open.Add(current); while (open.Count > 0) { // If the destination node is actually in our closed list... if (closed.Exists(check => destination == check)) { break; } // Set current to open's first, then remove it from open, adding it to closed. current = open[0]; open.RemoveAt(0); closed.Add(current); foreach (var n in current.connections) { // If the node doesn't already exist in the closed list... if (!closed.Exists(check => n == check)) { // If it's not already in open, add it, and calculate the G Score/previous. if (!open.Exists(check => n == check)) { n.GScore = current.GScore + n.costToMove; n.HScore = (int)Mathf.Abs(current.transform.position.x + destination.transform.position.x) + (int)Mathf.Abs(current.transform.position.z + destination.transform.position.z); n.FScore = n.GScore + n.HScore; n.previous = current; open.Add(n); } else { // If it IS in open, and the new cost is lower... if (n.GScore > current.GScore + n.costToMove) { // Calculate the G Score and previous connection. n.GScore = current.GScore + n.costToMove; n.previous = current; } } } } SortNodes(ref open); } // This will be hit when the while ends naturally or when it hits the break. if (closed.Exists(check => destination == check)) { // We've found the shortest path! // Clear out the old path. finalPath.Clear(); Node temp = destination; finalPath.Insert(0, destination); // Add the previous of each node until we reach the start (start is null). while (temp.previous != null) { finalPath.Insert(0, temp.previous); temp = temp.previous; } // Remove the node we're currently on as we don't need to seek to // something we're already at. finalPath.Remove(currentOn); } }
public NodeMenuGenerator() { root = new MenuItem("root"); root.AddChild(new MenuItem("other")); root.AddChild(new MenuItem("filters")); root.AddChild(new MenuItem("noise")); root.AddChild(new MenuItem("pattern")); root.AddChild(new MenuItem("mix")); root.AddChild(new MenuItem("adjustment")); root.AddChild(new MenuItem("transform")); root["adjustment"].AddChild(new MenuItem("gain", delegate { NodeSpawner.Spawn(new TextureProcessors.Adjustment.ProcessorGain()); })); //root["adjustment"].AddChild(new MenuItem("gamma", delegate { NodeSpawner.Spawn(new TextureProcessors.Adjustment.ProcessorGamma()); } )); root["adjustment"].AddChild(new MenuItem("contrast", delegate { NodeSpawner.Spawn(new TextureProcessors.Adjustment.ProcessorContrast()); })); root["adjustment"].AddChild(new MenuItem("invert", delegate { NodeSpawner.Spawn(new TextureProcessors.Adjustment.ProcessorInvert()); })); root["adjustment"].AddChild(new MenuItem("levels", delegate { NodeSpawner.Spawn(new TextureProcessors.Adjustment.ProcessorLevels()); })); root["transform"].AddChild(new MenuItem("twirl", delegate { NodeSpawner.Spawn(new TextureProcessors.Adjustment.ProcessorTwirl()); })); root["transform"].AddChild(new MenuItem("push", delegate { NodeSpawner.Spawn(new TextureProcessors.Adjustment.ProcessorPush()); })); root["other"].AddChild(new MenuItem("RGB", delegate { NodeSpawner.Spawn(new TextureProcessors.Other.ProcessorRGB()); })); root["other"].AddChild(new MenuItem("HSB", delegate { NodeSpawner.Spawn(new TextureProcessors.Other.ProcessorHSB()); })); root ["other"].AddChild(new MenuItem("dither", delegate { NodeSpawner.Spawn(new TextureProcessors.Other.ProcessorDither()); })); root["filters"].AddChild(new MenuItem("gaussian blur", delegate { NodeSpawner.Spawn(new TextureProcessors.Filters.ProcessorGaussianBlur()); })); root["filters"].AddChild(new MenuItem("motion blur", delegate { NodeSpawner.Spawn(new TextureProcessors.Filters.ProcessorMotionBlur()); })); root["filters"].AddChild(new MenuItem("bokeh", delegate { NodeSpawner.Spawn(new TextureProcessors.Filters.ProcessorBokeh()); })); root["filters"].AddChild(new MenuItem("curl", delegate { NodeSpawner.Spawn(new TextureProcessors.Filters.ProcessorCurlFilter()); })); root["filters"].AddChild(new MenuItem("bloom", delegate { NodeSpawner.Spawn(new TextureProcessors.Filters.ProcessorBloom()); })); root["filters"].AddChild(new MenuItem("diffuse", delegate { NodeSpawner.Spawn(new TextureProcessors.Filters.ProcessorDiffuse()); })); root["filters"].AddChild(new MenuItem("normal map", delegate { NodeSpawner.Spawn(new TextureProcessors.Filters.ProcessorNormalMap()); })); root["filters"].AddChild(new MenuItem("ambient occlusion", delegate { NodeSpawner.Spawn(new TextureProcessors.Filters.ProcessorAmbientOcclusion()); })); //root["filter"].AddChild(new MenuItem("emboss")); //root["filter"].AddChild(new MenuItem("sharpen")); //root["filter"].AddChild(new MenuItem("custom matrix")); //root["filter"].AddChild(new MenuItem("radial blur")); root["pattern"].AddChild(new MenuItem("lines", delegate { NodeSpawner.Spawn(new TextureProcessors.Pattern.ProcessorLines()); })); root["pattern"].AddChild(new MenuItem("circles", delegate { NodeSpawner.Spawn(new TextureProcessors.Pattern.ProcessorCircles()); })); root["pattern"].AddChild(new MenuItem("bricks", delegate { NodeSpawner.Spawn(new TextureProcessors.Pattern.ProcessorBricks()); })); //root["pattern"].AddChild(new MenuItem("knitting", delegate { NodeSpawner.Spawn(new TextureProcessors.Pattern.ProcessorKnitting()); })); root["pattern"].AddChild(new MenuItem("herringbone", delegate { NodeSpawner.Spawn(new TextureProcessors.Pattern.ProcessorParquet()); })); root["noise"].AddChild(new MenuItem("wavelet", delegate { NodeSpawner.Spawn(new TextureProcessors.Noise.ProcessorWaveletNoise()); })); root["noise"].AddChild(new MenuItem("perlin", delegate { NodeSpawner.Spawn(new TextureProcessors.Noise.ProcessorPerlinNoise()); })); root["noise"].AddChild(new MenuItem("simplex", delegate { NodeSpawner.Spawn(new TextureProcessors.Noise.ProcessorSimplexNoise()); })); root["noise"].AddChild(new MenuItem("white", delegate { NodeSpawner.Spawn(new TextureProcessors.Noise.ProcessorWhiteNoise()); })); root["noise"].AddChild(new MenuItem("billow", delegate { NodeSpawner.Spawn(new TextureProcessors.Noise.ProcessorBillowNoise()); })); root ["noise"].AddChild(new MenuItem("cellular")); root ["noise"] ["cellular"].AddChild(new MenuItem("generator", delegate { NodeSpawner.Spawn(new TextureProcessors.Noise.ProcessorCellularNoise()); })); root ["noise"] ["cellular"].AddChild(new MenuItem("seeder", delegate { NodeSpawner.Spawn(new TextureProcessors.Noise.ProcessorCellularNoiseSeeder()); })); root["mix"].AddChild(new MenuItem("add", delegate { NodeSpawner.Spawn(new TextureProcessors.Mix.ProcessorAdd()); })); root["mix"].AddChild(new MenuItem("blend", delegate { NodeSpawner.Spawn(new TextureProcessors.Mix.ProcessorBlend()); })); root["mix"].AddChild(new MenuItem("screen", delegate { NodeSpawner.Spawn(new TextureProcessors.Mix.ProcessorScreen()); })); root["mix"].AddChild(new MenuItem("multiply", delegate { NodeSpawner.Spawn(new TextureProcessors.Mix.ProcessorMultiply()); })); root["mix"].AddChild(new MenuItem("overlay", delegate { NodeSpawner.Spawn(new TextureProcessors.Mix.ProcessorOverlay()); })); root["mix"].AddChild(new MenuItem("subtract", delegate { NodeSpawner.Spawn(new TextureProcessors.Mix.ProcessorSubtract()); })); root["mix"].AddChild(new MenuItem("min", delegate { NodeSpawner.Spawn(new TextureProcessors.Mix.ProcessorMin()); })); root["mix"].AddChild(new MenuItem("max", delegate { NodeSpawner.Spawn(new TextureProcessors.Mix.ProcessorMax()); })); //root["blend"].AddChild(new MenuItem("max")); //root["blend"].AddChild(new MenuItem("min")); root.Sort(); }
public static void Load(ProjectSaveInfo projectSaveInfo) { Reset(); NodeController.used_ids = projectSaveInfo.used_node_ids; Globals.instance.resolutionIndex_preview = projectSaveInfo.resolutionIndex_preview; Globals.instance.resolutionIndex_export = projectSaveInfo.resolutionIndex_export; Globals.instance.realtimeUpdatePreview = projectSaveInfo.realtime_update_preview; Dictionary <ulong, NodeController> loaded_nodes = new Dictionary <ulong, NodeController> (); foreach (ProjectSaveInfo.SavedNodeInfo node in projectSaveInfo.Nodes) { NodeController ctrl = NodeSpawner.Spawn( (TextureProcessors.TextureProcessor)System.Activator.CreateInstance(System.Type.GetType(node.processorType)), node.ID ); loaded_nodes.Add(node.ID, ctrl); (ctrl.gameObject.transform as RectTransform).anchoredPosition = node.position; foreach (string pname in node.properties.Keys) { ctrl.processor [pname] = node.properties [pname]; } } foreach (ProjectSaveInfo.SavedNodeInfo node in projectSaveInfo.Nodes) { NodeController ctrl = loaded_nodes [node.ID]; for (int i = 0; i < node.input_IDs.Count; i++) { ulong input_id = node.input_IDs [i]; if (input_id == 0) { continue; } NodeController input_ctrl = loaded_nodes [input_id]; ctrl.inputs [i].connectedOutputButton = input_ctrl.output; } } if (projectSaveInfo.albedo_ID != 0) { Globals.instance.components.outputNode.inputButtonController_albedo.connectedOutputButton = loaded_nodes [projectSaveInfo.albedo_ID].output; } if (projectSaveInfo.normal_ID != 0) { Globals.instance.components.outputNode.inputButtonController_normalMap.connectedOutputButton = loaded_nodes [projectSaveInfo.normal_ID].output; } if (projectSaveInfo.smooth_id != 0) { Globals.instance.components.outputNode.inputButtonController_smoothness.connectedOutputButton = loaded_nodes [projectSaveInfo.smooth_id].output; } if (projectSaveInfo.metallic_ID != 0) { Globals.instance.components.outputNode.inputbuttonController_metallic.connectedOutputButton = loaded_nodes [projectSaveInfo.metallic_ID].output; } if (projectSaveInfo.occlusion_id != 0) { Globals.instance.components.outputNode.inputbuttonController_occlusion.connectedOutputButton = loaded_nodes [projectSaveInfo.occlusion_id].output; } if (projectSaveInfo.parallax_id != 0) { Globals.instance.components.outputNode.inputbuttonController_parallax.connectedOutputButton = loaded_nodes [projectSaveInfo.parallax_id].output; } if (projectSaveInfo.emission_id != 0) { Globals.instance.components.outputNode.inputbuttonController_emission.connectedOutputButton = loaded_nodes [projectSaveInfo.emission_id].output; } }