IEnumerator DrawTrail(GameObject ball, LW_Polyline3D trail) { Transform ballTransform = ball.transform; float lifeSpan = ballLifeSpan; Vector3 lastPos = Vector3.zero; while (lifeSpan > 0) { Vector3 currPos = linework.gameObject.transform.InverseTransformPoint(ballTransform.position); if ((currPos - lastPos).sqrMagnitude > sqrMinMove) { ShiftAndAddPoint(currPos, trail); lastPos = currPos; } lifeSpan -= Time.deltaTime; yield return(null); } ball.SetActive(false); m_BallPool.Push(ball); while (trail.points.Count > 0) { ShiftAndRemovePoint(trail); yield return(null); } if (linework != null) { linework.graphic.Remove(trail); } }
// Use this for initialization void Start() { canvas = LW_Canvas.Create(new GameObject(), "ImpactRings", false); //linework = LW_Canvas.Create(gameObject, "ImpactRings", false); canvas.blendMode = BlendMode.AlphaBlend; canvas.featureMode = FeatureMode.Advanced; canvas.strokeDrawMode = StrokeDrawMode.Draw2D; canvas.joinsAndCapsMode = JoinsAndCapsMode.Shader; canvas.gradientsMode = GradientsMode.Vertex; canvas.antiAliasingMode = AntiAliasingMode.On; masterStroke = LW_Stroke.Create(Color.white, 0.05f); masterStroke.paintMode = PaintMode.RadialGradient; masterStroke.gradientUnits = GradientUnits.userSpaceOnUse; masterStroke.presizeVBO = 100; lines = new LW_Polyline3D[1000]; LW_Stroke stroke = LW_Stroke.Create(Color.white, 1f); stroke.linejoin = Linejoin.Break; canvas.graphic.styles.Add(stroke); linePoints = new Vector3[lines.Length][]; for (int i = 0; i < lines.Length; i++) { linePoints[i] = new Vector3[2]; lines[i] = LW_Polyline3D.Create(linePoints[i], false); canvas.graphic.Add(lines[i]); } }
public void setProps(PCLSkeleton skel, Transform lookAtTarget, string text, float time, int jointIndex, Vector3 dir, float fontSize, float posSmooth, float circleSize) { this.skel = skel; this.lookAtTarget = lookAtTarget; this.jointIndex = jointIndex; this.text = text; this.posSmooth = posSmooth; Invoke("kill", time); // Create the LineWorks Components and Scriptable Objects. linework = GetComponent <LW_Canvas>(); linework.segmentation = 20; linework.featureMode = FeatureMode.Advanced; linework.strokeDrawMode = StrokeDrawMode.Draw3D; linework.joinsAndCapsMode = JoinsAndCapsMode.Shader; circle = LW_Circle.Create(Vector2.zero, .15f / transform.localScale.x); circleStroke = LW_Stroke.Create(Color.white, .2f); circleStroke.linejoin = Linejoin.Round; circle.styles.Add(circleStroke); linework.graphic.Add(circle); Vector3[] points = new Vector3[3]; points[0] = Vector3.zero; points[1] = Vector3.Scale(Vector3.one, dir) / transform.localScale.x; points[2] = points[1] + (Vector3.right * dir.x * lineSizeFactor) / transform.localScale.x; line = LW_Polyline3D.Create(points); lineStroke = LW_Stroke.Create(Color.white, .2f); line.styles.Add(lineStroke); linework.graphic.Add(line); line.isVisible = false; tm.transform.localPosition = points[2]; tm.anchor = dir.x > 0 ? TextAnchor.LowerRight : TextAnchor.LowerLeft; tm.alignment = dir.x > 0 ? TextAlignment.Right : TextAlignment.Left; tm.characterSize = fontSize / 100; text = "Super cool dis-donc"; seq = DOTween.Sequence(); //seq.Pause(); //blink circle seq.AppendCallback(() => blinkShape(circle, .5f)).AppendInterval(.3f); // reduce circle seq.AppendCallback(() => reduceCircle(circleSize / transform.localScale.x)).AppendInterval(.2f); //reveal line seq.AppendCallback(() => blinkShape(line, .5f)).AppendInterval(.3f); seq.AppendCallback(() => revealText(1)); if (skel != null) { transform.position = skel.joints[jointIndex]; } transform.LookAt(lookAtTarget.position); }
public void ShiftAndRemovePoint(LW_Polyline3D shape) { Vector3[] oldPoints = shape.points.ToArray(); int newNumberOfPoints = Mathf.Clamp(oldPoints.Length - 1, 0, numberOfPoints); Vector3[] newPoints = new Vector3[newNumberOfPoints]; for (int i = 0; i < newNumberOfPoints; i++) { newPoints[i] = oldPoints[i]; } shape.points = new List <Vector3>(newPoints); }
void Start() { stroke = LW_Stroke.Create(Color.red, 1.0f); strokeOutline = LW_Stroke.Create(Color.red, 1.4f); //testLine = LW_Stroke.Create (Color.magenta, 1.0f); chordShapeLine = LW_Polyline3D.Create(new Vector2[0], false); chordShapeLineOutline = LW_Polyline3D.Create(new Vector2[0], false); //stroke.verticalOffset = 0.1f; // Adjust the segmenetation to get a smoother looking line. linework.segmentation = 20; // If you want to use any of the advanced shader features you have to set featureMode to Advanced. linework.featureMode = FeatureMode.Advanced; // If you would like the stroke to be 3D. ie. always face the camera. linework.strokeDrawMode = StrokeDrawMode.Draw2D; // If you would like to have the shader provide anti-aliasing linework.antiAliasingMode = AntiAliasingMode.On; // It is recommended for 3D lines to use the 'Round' Linejoin. linework.joinsAndCapsMode = JoinsAndCapsMode.Shader; stroke.linejoin = Linejoin.Round; stroke.linecap = Linecap.Round; strokeOutline.linejoin = Linejoin.Round; strokeOutline.linecap = Linecap.Round; //testLine.linejoin = Linejoin.Round; //testLine.linecap = Linecap.Round; stroke.opacity = 0.6f; strokeOutline.opacity = 0.8f; for (int i = 0; i < 15; i++) // creating a chordshape for each of the 5 CAGED shapes { chordShapeLines[i] = LW_Polyline3D.Create(new Vector2[0], false); chordShapeLines[i].styles.Add(stroke); chordShapeOutlines[i] = LW_Polyline3D.Create(new Vector2[0], false); chordShapeOutlines[i].styles.Add(strokeOutline); linework.graphic.Add(chordShapeOutlines [i]); linework.graphic.Add(chordShapeLines [i]); } // chordShapeLine.styles.Add (testLine); // chordShapeLineOutline.styles.Add (strokeOutline); // // linework.graphic.Add (chordShapeLine); // // linework.graphic.Add (chordShapeLineOutline); }
public void ShiftAndAddPoint(Vector3 point, LW_Polyline3D shape) { Vector3[] oldPoints = shape.points.ToArray(); int newNumberOfPoints = Mathf.Clamp(oldPoints.Length + 1, 1, numberOfPoints); Vector3[] newPoints = new Vector3[newNumberOfPoints]; for (int i = 0; i < oldPoints.Length; i++) { if (i < newNumberOfPoints - 1) { newPoints[i + 1] = oldPoints[i]; } } newPoints[0] = point; shape.points = new List <Vector3>(newPoints); }
void LaunchBall() { if (linework != null) { GameObject ball; if (m_BallPool.Count == 0) { ball = (GameObject)Instantiate(ballPrefab, transform.position, Quaternion.identity); } else { ball = m_BallPool.Pop(); ball.SetActive(true); ball.transform.position = transform.position; } Vector3 launchVector = transform.up + new Vector3(Random.Range(-0.2f, 0.2f), 0, Random.Range(-0.2f, 0.2f)); ball.GetComponent <Rigidbody>().AddForce(launchVector * (force * Random.Range(1f, 1.1f)), ForceMode.Impulse); LW_Polyline3D trail = LW_Polyline3D.Create(new Vector3[0], false); linework.graphic.Add(trail); StartCoroutine(DrawTrail(ball, trail)); } }
void Start() { vectorCanvas = LW_Canvas.Create(null, "BallOfLines", false); vectorCanvas.blendMode = BlendMode.AdditiveSoft; vectorCanvas.featureMode = FeatureMode.Advanced; vectorCanvas.strokeDrawMode = StrokeDrawMode.Draw3D; vectorCanvas.joinsAndCapsMode = JoinsAndCapsMode.Vertex; vectorCanvas.gradientsMode = GradientsMode.Vertex; vectorCanvas.antiAliasingMode = AntiAliasingMode.Off; vectorCanvas.mainTexture = texture; LW_Stroke stroke = LW_Stroke.Create(Color.white, 1f); stroke.linejoin = Linejoin.Break; vectorCanvas.graphic.styles.Add(stroke); lines = LW_Polyline3D.Create(new Vector3[0], false); vectorCanvas.graphic.Add(lines); SetWidth(width); SetColor(color); SetPoints(numberOfPoints); MakeLine(numberOfPoints); }