public async Task <IActionResult> Create([Bind("Id,Name,Description")] SustainableChemistryWeb.Models.Reactant reactant) { try { Reactant appReactant = new Reactant() { Name = reactant.Name, Description = reactant.Description, Temp2 = string.Empty, }; if (string.IsNullOrEmpty(appReactant.Description)) { appReactant.Description = string.Empty; } if (ModelState.IsValid) { _context.Add(appReactant); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public void SpawnWater(float width, float height) { //Add Color trigger for player collision GameObject colorTrigger = new GameObject("Color Trigger"); colorTrigger.layer = LayerMask.NameToLayer("Player"); colorTrigger.transform.SetParent(transform); colorTrigger.transform.localPosition = Vector2.zero; if (deadly) { colorTrigger.AddComponent <Death>(); } // Set the collision for the color trigger BoxCollider2D box = colorTrigger.AddComponent <BoxCollider2D>(); box.offset = new Vector2(0, height / 4); box.size = new Vector2(width, height / 2); box.isTrigger = true; colorTrigger.AddComponent <PlayerColor>(); colorTrigger.GetComponent <PlayerColor>().colorInPool = poolSubstance.particleColor; //calculate no of edges and nodes we have int edgecount = Mathf.RoundToInt(width) * 5; //five per unit width to give smoothness and lower the performance impact int nodecount = edgecount + 1; //for floating add a box collider edge = gameObject.AddComponent <EdgeCollider2D>(); edge.points = new Vector2[edgecount]; edge.edgeRadius = .5f; edge.offset = new Vector2(0f, -.6f); //Add our line renderer and set it up; Color poolColor = poolSubstance.particleColor; Body = gameObject.AddComponent <LineRenderer>(); Material bodyMaterial = new Material(baseMaterial); bodyMaterial.color = poolColor; Body.material = bodyMaterial; Body.material.renderQueue = 1000; Body.positionCount = nodecount; Body.startWidth = 0.1f; Body.endWidth = 0.1f; //Declare our physics arrays xpositions = new float[nodecount]; ypositions = new float[nodecount]; velocities = new float[nodecount]; accelerations = new float[nodecount]; //Declare our mesh arrays meshobjects = new GameObject[edgecount]; meshes = new Mesh[edgecount]; colliders = new GameObject[edgecount]; //Set the variables BOTTOM = transform.position.y; TOP = BOTTOM + height; LEFT = transform.position.x - width / 2; //for each node, set the line renderer and physics arrays for (int i = 0; i < nodecount; i++) { ypositions[i] = TOP; xpositions[i] = (LEFT + width * i / edgecount); Body.SetPosition(i, new Vector3(xpositions[i], BOTTOM, z)); accelerations[i] = 0; velocities[i] = 0; } //set the meshes for (int i = 0; i < edgecount; i++) { //make the mesh meshes[i] = new Mesh(); //mesh corners Vector3[] Vertices = new Vector3[4]; //each mesh has 4 corners Vertices[0] = new Vector3(xpositions[i], ypositions[i], z); //top part is variable where the waves are Vertices[1] = new Vector3(xpositions[i + 1], ypositions[i + 1], z); //top part is variable where the waves are Vertices[2] = new Vector3(xpositions[i], BOTTOM, z); //mesh bottom is flat Vertices[3] = new Vector3(xpositions[i + 1], BOTTOM, z); //mesh bottom is flat //UVs of the mesh's texture Vector2[] UVs = new Vector2[4]; UVs[0] = new Vector2(0, 1); UVs[1] = new Vector2(1, 1); UVs[2] = new Vector2(0, 0); UVs[3] = new Vector2(1, 0); //Set where the triangles should be. int[] tris = new int[6] { 0, 1, 3, 3, 2, 0 }; //Add all this data to the mesh. meshes[i].vertices = Vertices; meshes[i].uv = UVs; meshes[i].triangles = tris; //Create a holder for the mesh, set it to be the manager's child meshobjects[i] = Instantiate(watermesh, Vector3.zero, Quaternion.identity) as GameObject; meshobjects[i].GetComponent <MeshFilter>().mesh = meshes[i]; meshobjects[i].GetComponent <MeshRenderer>().material = bodyMaterial; meshobjects[i].transform.parent = transform; //Create our colliders, set them be our child. colliders[i] = new GameObject(); colliders[i].name = "Trigger"; colliders[i].AddComponent <BoxCollider2D>(); colliders[i].transform.parent = meshobjects[i].transform; //set the pos and scale to the correct dimes colliders[i].transform.position = new Vector3(LEFT + width * (i + 0.5f) / edgecount, TOP - .5f, 0); colliders[i].transform.localScale = new Vector3(width / edgecount, 1, 1); //add WaterDetector and make sure they're triggers colliders[i].GetComponent <BoxCollider2D>().isTrigger = true; colliders[i].AddComponent <LiquidDetector>(); Reactant reactant = GetComponent <Reactant>(); Reactant newReactant = colliders[i].AddComponent <Reactant>(); newReactant.reactantSubstance = poolSubstance; } }