public void GenerateLotsOfLines() { for (int i = 0; i < 10; i++) { if (UseUnityLineRendererToggle != null && UseUnityLineRendererToggle.isOn && UnityLineRenderer != null) { for (int j = 0; j < FastLineRenderer.MaxLinesPerMesh; j++) { Vector3 pos = new Vector3(UnityEngine.Random.Range(0.0f, Screen.width), UnityEngine.Random.Range(0.0f, Screen.height), UnityEngine.Random.Range(-400.0f, 400.0f)); UnityLineRendererPositions.Add(pos); } UnityLineRenderer.positionCount = UnityLineRendererPositions.Count; UnityLineRenderer.SetPositions(UnityLineRendererPositions.ToArray()); } else if (lotsOfLinesRenderer != null) { // fast clone, just re-use the mesh! const float range = 1000.0f; FastLineRenderer r = FastLineRenderer.CreateWithParent(null, LineRenderer); r.Material.EnableKeyword("DISABLE_CAPS"); r.Mesh = lotsOfLinesRenderer.Mesh; r.transform.Translate(UnityEngine.Random.Range(-range, range), UnityEngine.Random.Range(-range, range), UnityEngine.Random.Range(-range, range)); } else { FastLineRenderer r = FastLineRenderer.CreateWithParent(null, LineRenderer); r.Material.EnableKeyword("DISABLE_CAPS"); r.SetCapacity(FastLineRenderer.MaxLinesPerMesh * FastLineRenderer.VerticesPerLine); FastLineRendererProperties props = new FastLineRendererProperties(); for (int j = 0; j < FastLineRenderer.MaxLinesPerMesh; j++) { Color32 randColor = new Color32(RandomByte(), RandomByte(), RandomByte(), RandomByte()); // Vector3 pos = new Vector3(UnityEngine.Random.Range(0.0f, Screen.width), UnityEngine.Random.Range(0.0f, Screen.height), UnityEngine.Random.Range(-400.0f, 400.0f)); Vector3 pos = new Vector3(UnityEngine.Random.Range(0.0f, Screen.width), UnityEngine.Random.Range(0.0f, Screen.height), 0); props.Start = pos; props.End = Vector3.zero; props.Color = randColor; props.Radius = UnityEngine.Random.Range(1.0f, 4.0f); props.SetLifeTime(float.MaxValue); // props.AngularVelocity = UnityEngine.Random.Range(-6.0f, 6.0f); // props.Velocity = RandomVelocity(50.0f); r.AppendLine(props); } r.Apply(); lotsOfLinesRenderer = r; } LineCountLabel.text = "Lines: " + (lineCount += FastLineRenderer.MaxLinesPerMesh); } }
void DrawGeometry(Geometry geo) { wkbGeometryType t = Ogr.GT_Flatten(geo.GetGeometryType()); switch (t) { case wkbGeometryType.wkbUnknown: break; case wkbGeometryType.wkbPoint: break; case wkbGeometryType.wkbPolygon: { Geometry linestring = geo.GetGeometryRef(0); if (Ogr.GT_Flatten(linestring.GetGeometryType()) == wkbGeometryType.wkbLineString) { DrawGeometry(linestring); } } break; case wkbGeometryType.wkbLineString: { int count = geo.GetPointCount(); if (count >= 2) { double[] pt = new double[2]; for (int i = 0; i < count - 1; i++) { geo.GetPoint(i, pt); props.Start = new Vector2((float)pt[0], (float)pt[1]); lineRenderer.AppendLine(props); } geo.GetPoint(count - 1, pt); props.Start = new Vector2((float)pt[0], (float)pt[1]); lineRenderer.EndLine(props); } } break; default: break; } }
void DrawLineString(Geometry geo) { int count = geo.GetPointCount(); if (count >= 2) { double[] pt = new double[2]; for (int i = 0; i < count - 1; i++) { geo.GetPoint(i, pt); props.Start = new Vector3((float)pt[0], (float)pt[1], 0); lineRenderer.AppendLine(props); } geo.GetPoint(count - 1, pt); props.Start = new Vector3((float)pt[0], (float)pt[1], 0); lineRenderer.EndLine(props); } }
private void AddCurvesAndSpline() { if (ShowCurves) { const float animationTime = 0.025f; ShowCurves = false; FastLineRendererProperties props = new FastLineRendererProperties(); props.GlowIntensityMultiplier = 0.5f; props.Radius = 4.0f; props.Color = UnityEngine.Color.white; // props.Start = new Vector3(Screen.width * 0.1f, Screen.height * 0.1f, 0.0f); // props.End = new Vector3(Screen.width * 1.1f, Screen.height * 1.0f, 0.0f); // LineRenderer.AppendCurve(props, // new Vector3(Screen.width * 0.33f, Screen.height * 0.67f, 0.0f), // control point 1 // new Vector3(Screen.width * 0.67f, Screen.height * 0.33f, 0.0f), // control point 2 // 16, true, true, animationTime); // props.Color = UnityEngine.Color.red; // props.Start = new Vector3(0.0f, Screen.height * 0.2f, 0.0f); // props.End = new Vector3(Screen.width * 1.2f, Screen.height * 0.2f, 0.0f); // Vector3[] spline = new Vector3[] // { // props.Start, // new Vector3(Screen.width * 0.2f, Screen.height * 0.8f, 0.0f), // new Vector3(Screen.width * 0.4f, Screen.height * 0.2f, 0.0f), // new Vector3(Screen.width * 0.6f, Screen.height * 0.8f, 0.0f), // new Vector3(Screen.width * 0.8f, Screen.height * 0.2f, 0.0f), // new Vector3(Screen.width, Screen.height * 0.8f, 0.0f), // props.End // }; LineRenderer.AppendLine(props); // LineRenderer.AppendSpline(props, spline, 128, FastLineRendererSplineFlags.StartCap | FastLineRendererSplineFlags.EndCap, animationTime); // add a circle and arc // props.Color = Color.green; // LineRenderer.AppendCircle(props, new Vector3(Screen.width * 0.5f, Screen.height * 0.5f, 0.0f), 100.0f, 64, Vector3.forward, animationTime); // LineRenderer.AppendArc(props, new Vector3(Screen.width * 0.25f, Screen.height * 0.5f, 0.0f), 100.0f, 270.0f, 90.0f, 32, Vector3.forward, false, animationTime); // LineRenderer.AppendArc(props, new Vector3(Screen.width * 0.75f, Screen.height * 0.5f, 0.0f), 100.0f, 0.0f, 360.0f, 32, Vector3.forward, false, animationTime); LineRenderer.Apply(); } }
void Update() { float inputX = Input.GetAxis("Horizontal"); float inputY = Input.GetAxis("Vertical"); float rtaxis = Input.GetAxis("Fire"); if (rtaxis > 0.5) { is_drawing = true; } else { is_drawing = false; } movement = new Vector2(speed.x * inputX, speed.y * inputY); GetComponent <Rigidbody2D>().velocity = movement; crnt_pos = GetComponent <Transform>().position; if (System.Math.Abs(inputX) > 0.5 && System.Math.Abs(inputY) < 0.5) { if (inputX > 0) { GetComponent <SpriteRenderer>().sprite = right; } else { GetComponent <SpriteRenderer>().sprite = left; } } if (System.Math.Abs(inputY) > 0.5 && System.Math.Abs(inputX) < 0.5) { GetComponent <SpriteRenderer>().sprite = front; } // Draw line if (dist(crnt_pos, prev_pos) >= 5) { if (is_drawing != last) { if (last == true) { FLR.EndLine(FLRP); } else { crnt_edge_collider_OBJ = new GameObject(); crnt_edge_collider_OBJ.layer = 8; crnt_edge_collider_OBJ.transform.position = crnt_pos; crnt_edge_collider = crnt_edge_collider_OBJ.AddComponent <EdgeCollider2D>(); EC_points.Add(new List <Vector2>()); EC_count++; } } if (is_drawing) { EC_points[EC_count].Add(new Vector2(crnt_pos.x - crnt_edge_collider.transform.position.x, crnt_pos.y - crnt_edge_collider.transform.position.y)); crnt_edge_collider.points = EC_points[EC_count].ToArray(); FLRP.Start = crnt_pos; FLR.AppendLine(FLRP); FLR.Apply(); prev_pos = crnt_pos; } last = is_drawing; } }