protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); simulator = new WaveSimulator(GraphicsDevice, spriteBatch, GraphicsDevice.Viewport.Width / scale, GraphicsDevice.Viewport.Height / scale, Content.Load <Effect>("SimulationEffect"), Content.Load <Effect>("DrawingEffect")); Pixel = new Texture2D(GraphicsDevice, 1, 1); Pixel.SetData <Color>(new Color[] { Color.White }); Background = Content.Load <Texture2D>("Pebbles"); GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp; }
protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); simulator = new WaveSimulator(GraphicsDevice, spriteBatch, 500, 500, Content.Load <Effect>("simulation"), Content.Load <Effect>("drawing")); Pixel = new Texture2D(GraphicsDevice, 1, 1); Pixel.SetData <Color>(new Color[] { Color.White }); Circle = Content.Load <Texture2D>("circle"); Picture = Content.Load <Texture2D>("pic"); keyboard = new KeyboardObject(); mouse = new MouseObject(Content, "mouse"); GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp; }
void Start() { //Generating Mesh mf = GetComponent <MeshFilter>(); mesh = new Mesh(); mf.mesh = mesh; //Generates the the surface using var i, then generates the bottom using var oo int oo = SurfaceVertices - 1; for (int i = 0; i <= VertexCount - 1; i++) { if (i < SurfaceVertices) { vertices[i] = new Vector3(StartX + (VertexSpacing * i), YSurface, 0); } else if (i >= SurfaceVertices) { vertices[i] = new Vector3(vertices[oo].x, YBottom, 0); oo += -1; } } mesh.vertices = vertices; //Connecting the dots. :) //Setting the Triangles. I got this part working by lots of trial and error. I am sure there could be a better solution but anyways for now this doesnt affect the gameplay peformance and it works. int tt; tt = SurfaceVertices; for (int t = SurfaceVertices - 1; t > 0 / 2; t += -1) { TriangulateRectangle(t, t - 1, tt, tt + 1); tt++; } mesh.triangles = triangle; //Setting the Normals Vector3[] normals = new Vector3[VertexCount]; for (int n = 0; n <= VertexCount - 1; n++) { normals[n] = -Vector3.forward; } mesh.normals = normals; //Setting the UVS int nVertices = mesh.vertices.Length; var uvs = new Vector2[nVertices]; for (int r = 0; r < nVertices; r++) { uvs[r] = mesh.vertices[r]; } mesh.uv = uvs; //Mesh Generation Done //Generating Springs and saving each of Spring's Scripts into the array for refrence later. Also setting the properties of it. for (int sprngs = 0; sprngs < SurfaceVertices; sprngs++) { Transform TransformHolder; TransformHolder = Instantiate(SpringPrefab, vertices[sprngs], Quaternion.identity) as Transform; SpringList[sprngs] = TransformHolder.GetComponent <SpringScript>(); SpringList[sprngs].MaxIncrease = MaxIncrease; SpringList[sprngs].MaxDecrease = MaxDecrease; SpringList[sprngs].TargetY = YSurface; SpringList[sprngs].Damping = Damping; SpringList[sprngs].Tension = Tension; SpringList[sprngs].ID = sprngs; SpringList[sprngs].Water = this; var boxCollider = TransformHolder.GetComponent <BoxCollider>() as BoxCollider; boxCollider.size = new Vector3(VertexSpacing, 0, 2); SpringList[sprngs].transform.parent = this.transform; } //Wave Simulator WaveSimulatorPrefab = Instantiate(WaveSimulatorPrefab, new Vector3(0, 0, 0), Quaternion.identity) as Transform; WaveSimulator = WaveSimulatorPrefab.GetComponent <WaveSimulator>(); WaveSimulator.WaveHeight = WaveSimHeight; WaveSimulator.WaveSpeed = WaveSimSpeed; //StartCoroutine(ChangeWaterHeight(5,2)); }