public virtual GameObject CreatePickedUpRef(string prefabname, GameObject starObj) { StarVertex starVertex = starObj.GetComponent <StarPickup>().thisStarVertex; GameObject pickedUpStar = Instantiate((GameObject)Resources.Load("prefabs/" + prefabname + "pickedup", typeof(GameObject)), starObj.transform.position, Quaternion.identity); pickedUpStar.transform.parent = powerUpGroup; pickedUpStar.transform.localScale = pickedUpStar.transform.localScale * scaleAmount; return(pickedUpStar); }
public void CheckAndDrawLines(StarVertex thisSV) { foreach (StarVertex sv in starsConnectedTo) { if (sv.IsInPlace && thisSV.isInPlace) { DrawLine(thisSV, sv); } } }
private void DrawLine(StarVertex start, StarVertex end) { GameObject starLine = new GameObject(); starLine.name = "GeneratedLine"; starLine.transform.parent = transform; GameObject starLineCollider = new GameObject(); starLineCollider.AddComponent <BoxCollider>().size = new Vector3(10.0f, 10.0f, 10.0f); starLineCollider.GetComponent <BoxCollider>().isTrigger = true; starLineCollider.AddComponent <LineRendererSpeedBoost>(); starLineCollider.GetComponent <LineRendererSpeedBoost>().starRaySoundPrefab = starRaySoundObj; starLineCollider.transform.parent = starLine.transform; starLine.AddComponent <LineRenderer>(); starLine.GetComponent <LineRenderer>().material = starRayMaterial; LineRenderer lineRenderer = starLine.GetComponent <LineRenderer>(); EnhancedLineRenderer enhancedLineRenderer = new EnhancedLineRenderer(lineRenderer, start, end); enhancedLineRenderers.Add(enhancedLineRenderer); IEnumerator starTravel = LineToTarget(enhancedLineRenderer.thisLineRenderer, enhancedLineRenderer.start.starRef.transform.position, enhancedLineRenderer.end.starRef.transform.position, starLineCollider.GetComponent <BoxCollider>()); StartCoroutine(starTravel); }
public void FillStarsBuffers() { Random random = new Random(7); StarVertex[] array = new StarVertex[600]; for (int i = 0; i < 150; i++) { Vector3 v; do { v = new Vector3(random.Float(-1f, 1f), random.Float(-1f, 1f), random.Float(-1f, 1f)); }while (v.LengthSquared() > 1f); v = Vector3.Normalize(v); float s = 9f * random.NormalFloat(1f, 0.1f); float w = MathUtils.Saturate(random.NormalFloat(0.6f, 0.4f)); Color color = new Color(new Vector4(random.Float(0.6f, 1f), 0.7f, random.Float(0.8f, 1f), w)); Vector3 v2 = 900f * v; Vector3 vector = Vector3.Normalize(Vector3.Cross((v.X > v.Y) ? Vector3.UnitY : Vector3.UnitX, v)); Vector3 v3 = Vector3.Normalize(Vector3.Cross(vector, v)); Vector3 position = v2 + s * (-vector - v3); Vector3 position2 = v2 + s * (vector - v3); Vector3 position3 = v2 + s * (vector + v3); Vector3 position4 = v2 + s * (-vector + v3); StarVertex starVertex = array[i * 4] = new StarVertex { Position = position, TextureCoordinate = new Vector2(0f, 0f), Color = color }; starVertex = (array[i * 4 + 1] = new StarVertex { Position = position2, TextureCoordinate = new Vector2(1f, 0f), Color = color }); starVertex = (array[i * 4 + 2] = new StarVertex { Position = position3, TextureCoordinate = new Vector2(1f, 1f), Color = color }); starVertex = (array[i * 4 + 3] = new StarVertex { Position = position4, TextureCoordinate = new Vector2(0f, 1f), Color = color }); } m_starsVertexBuffer.SetData(array, 0, array.Length); ushort[] array2 = new ushort[900]; for (int j = 0; j < 150; j++) { array2[j * 6] = (ushort)(j * 4); array2[j * 6 + 1] = (ushort)(j * 4 + 1); array2[j * 6 + 2] = (ushort)(j * 4 + 2); array2[j * 6 + 3] = (ushort)(j * 4 + 2); array2[j * 6 + 4] = (ushort)(j * 4 + 3); array2[j * 6 + 5] = (ushort)(j * 4); } m_starsIndexBuffer.SetData(array2, 0, array2.Length); }
private static Submesh GetStarfieldMesh(StarfieldNode node, RenderContext context) { // The mesh is cached in the scene node. var mesh = node.RenderData as Submesh; if (mesh == null) { mesh = new Submesh { PrimitiveType = PrimitiveType.TriangleList }; node.RenderData = mesh; } if (mesh.VertexBuffer == null || mesh.VertexBuffer.IsDisposed) { int numberOfStars = node.Stars.Count; // The total number of stars is limited by the graphics device max primitives per call limit. var graphicsDevice = context.GraphicsService.GraphicsDevice; int maxNumberOfStars = graphicsDevice.GetMaxPrimitivesPerCall() / 2; if (numberOfStars > maxNumberOfStars) throw new GraphicsException("The number of stars must be less than " + maxNumberOfStars); // Create a vertex buffer with a quad for each star. // 1--2 // | /| // |/ | // 0--3 mesh.VertexCount = numberOfStars * 4; var vertices = new StarVertex[numberOfStars * 4]; for (int i = 0; i < numberOfStars; i++) { var star = node.Stars[i]; var positionAndSize = new HalfVector4(star.Position.X, star.Position.Y, star.Position.Z, star.Size); var color = new HalfVector4(star.Color.X, star.Color.Y, star.Color.Z, 1); vertices[i * 4 + 0].PositionAndSize = positionAndSize; vertices[i * 4 + 0].Color = color; vertices[i * 4 + 0].Texture = new Vector2(0, 1); vertices[i * 4 + 1].PositionAndSize = positionAndSize; vertices[i * 4 + 1].Color = color; vertices[i * 4 + 1].Texture = new Vector2(0, 0); vertices[i * 4 + 2].PositionAndSize = positionAndSize; vertices[i * 4 + 2].Color = color; vertices[i * 4 + 2].Texture = new Vector2(1, 0); vertices[i * 4 + 3].PositionAndSize = positionAndSize; vertices[i * 4 + 3].Color = color; vertices[i * 4 + 3].Texture = new Vector2(1, 1); } mesh.VertexBuffer = new VertexBuffer(graphicsDevice, typeof(StarVertex), vertices.Length, BufferUsage.None); mesh.VertexBuffer.SetData(vertices); // Create index buffer for quad (= two triangles, clockwise). var indices = new ushort[numberOfStars * 6]; for (int i = 0; i < numberOfStars; i++) { indices[i * 6 + 0] = (ushort)(i * 4 + 0); indices[i * 6 + 1] = (ushort)(i * 4 + 1); indices[i * 6 + 2] = (ushort)(i * 4 + 2); indices[i * 6 + 3] = (ushort)(i * 4 + 0); indices[i * 6 + 4] = (ushort)(i * 4 + 2); indices[i * 6 + 5] = (ushort)(i * 4 + 3); } mesh.IndexBuffer = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, indices.Length, BufferUsage.None); mesh.IndexBuffer.SetData(indices); mesh.PrimitiveCount = numberOfStars * 2; } return mesh; }
public EnhancedLineRenderer(LineRenderer thisLineRenderer, StarVertex start, StarVertex end) { this.thisLineRenderer = thisLineRenderer; this.start = start; this.end = end; }
private static Submesh GetStarfieldMesh(StarfieldNode node, RenderContext context) { // The mesh is cached in the scene node. var mesh = node.RenderData as Submesh; if (mesh == null) { mesh = new Submesh { PrimitiveType = PrimitiveType.TriangleList }; node.RenderData = mesh; } if (mesh.VertexBuffer == null || mesh.VertexBuffer.IsDisposed) { int numberOfStars = node.Stars.Count; // The total number of stars is limited by the graphics device max primitives per call limit. var graphicsDevice = context.GraphicsService.GraphicsDevice; int maxNumberOfStars = graphicsDevice.GetMaxPrimitivesPerCall() / 2; if (numberOfStars > maxNumberOfStars) { throw new GraphicsException("The number of stars must be less than " + maxNumberOfStars); } // Create a vertex buffer with a quad for each star. // 1--2 // | /| // |/ | // 0--3 mesh.VertexCount = numberOfStars * 4; var vertices = new StarVertex[numberOfStars * 4]; for (int i = 0; i < numberOfStars; i++) { var star = node.Stars[i]; var positionAndSize = new HalfVector4(star.Position.X, star.Position.Y, star.Position.Z, star.Size); var color = new HalfVector4(star.Color.X, star.Color.Y, star.Color.Z, 1); vertices[i * 4 + 0].PositionAndSize = positionAndSize; vertices[i * 4 + 0].Color = color; vertices[i * 4 + 0].Texture = new Vector2(0, 1); vertices[i * 4 + 1].PositionAndSize = positionAndSize; vertices[i * 4 + 1].Color = color; vertices[i * 4 + 1].Texture = new Vector2(0, 0); vertices[i * 4 + 2].PositionAndSize = positionAndSize; vertices[i * 4 + 2].Color = color; vertices[i * 4 + 2].Texture = new Vector2(1, 0); vertices[i * 4 + 3].PositionAndSize = positionAndSize; vertices[i * 4 + 3].Color = color; vertices[i * 4 + 3].Texture = new Vector2(1, 1); } mesh.VertexBuffer = new VertexBuffer(graphicsDevice, typeof(StarVertex), vertices.Length, BufferUsage.None); mesh.VertexBuffer.SetData(vertices); // Create index buffer for quad (= two triangles, clockwise). var indices = new ushort[numberOfStars * 6]; for (int i = 0; i < numberOfStars; i++) { indices[i * 6 + 0] = (ushort)(i * 4 + 0); indices[i * 6 + 1] = (ushort)(i * 4 + 1); indices[i * 6 + 2] = (ushort)(i * 4 + 2); indices[i * 6 + 3] = (ushort)(i * 4 + 0); indices[i * 6 + 4] = (ushort)(i * 4 + 2); indices[i * 6 + 5] = (ushort)(i * 4 + 3); } mesh.IndexBuffer = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, indices.Length, BufferUsage.None); mesh.IndexBuffer.SetData(indices); mesh.PrimitiveCount = numberOfStars * 2; } return(mesh); }