Exemplo n.º 1
0
        //create a new linerenderer
        GameObject NewLine(LineTrace tracer, Transform parent, Vector3 position)
        {
            GameObject go = new GameObject();

            go.name = "line";
            //go.transform.position = position;
            go.transform.SetParent(parent);

            //go.hideFlags = HideFlags.HideInHierarchy;
            LineRenderer line = go.AddComponent <LineRenderer>();

            line.useWorldSpace = false;
            //lineMat = new Material(Shader.Find("Particles/Additive"));
            //Debug.Log("Creating line with material: " + tracer.lineMat);
            line.material = tracer.lineMat;
            line.SetColors(tracer.startColor, tracer.endColor);
            line.SetWidth(tracer.startWidth, tracer.endWidth);
            line.SetVertexCount(tracer.lineSegments);

            for (int i = 0; i < tracer.lineSegments; i++)
            {
                line.SetPosition(i, position);
            }

            return(go);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Animates the drawing.
        /// Draw the line, starting at startTime and ending at endTime.
        /// </summary>
        /// <returns>The drawing.</returns>
        /// <param name="tracer">Tracer.</param>
        IEnumerator AnimateDrawing(LineTrace tracer)
        {
            float timer     = 0;
            float stepTimer = 0f;
            float stepSize  = tracer.endTime / tracer.lineSegments;
            int   index     = 0;

            //Debug.Log("Drawing: " + edges.Length + " lines");
            while (timer <= tracer.endTime || index < tracer.lineSegments)
            {
                if (stepTimer >= stepSize)
                {
                    //Debug.Log("Drawing index: " + index);

                    for (int c = 0; c < edges.Length; c++)
                    {
                        int          row     = lineTracers.IndexOf(tracer);
                        GameObject   lineObj = tracerMatrix[row, c];
                        LineRenderer line    = lineObj.GetComponent <LineRenderer>();

                        Edge edge = edges[c];
                        //get the points in space we need
                        Vector3 a         = transform.TransformPoint(verticies[edge.vertexIndex[0]]);
                        Vector3 b         = transform.TransformPoint(verticies[edge.vertexIndex[1]]);
                        Vector3 aToB      = b - a;
                        Vector3 offsetDir = GetNormalDirection(edge);

                        //Debug.Log("Drawing tracer: " + index + " from " + a + " to " + b + " vec: " + aToB) ;
                        float   percent = (float)index / tracer.lineSegments;
                        Vector3 offset  = offsetDir * tracer.curve.Evaluate(percent) * tracer.amplitude;
                        //Debug.Log("%: " + percent);
                        Vector3 pos = a + aToB * percent + offset;
                        line.SetPosition(index, pos);
                    }

                    index++;
                    stepTimer = 0;
                }

                float delta = Time.deltaTime;
                timer     += delta;
                stepTimer += delta;
                yield return(null);
            }

            if (tracer == lastTracer)
            {
                if (OnFinish != null)
                {
                    OnFinish.Invoke();
                }
            }
            //Debug.Log ("done drawing edges");
        }
Exemplo n.º 3
0
        //similar to Invoke but using the tracer parameter
        IEnumerator delayedStart(LineTrace tracer)
        {
            float timer = 0;

            while (timer < tracer.startTime)
            {
                timer += Time.deltaTime;
                yield return(null);
            }
            StartCoroutine(AnimateDrawing(tracer));
        }
Exemplo n.º 4
0
        LineRenderer line;             // the line itself.

        //constructor
        public LineTrace(LineTrace prefab, Transform parent)
        {
            name         = prefab.name;
            curve        = prefab.curve;
            startColor   = prefab.startColor;
            endColor     = prefab.endColor;
            startWidth   = prefab.startWidth;
            endWidth     = prefab.endWidth;
            lineSegments = prefab.lineSegments;
            amplitude    = prefab.amplitude;
            //line = NewLine(prefab, parent);
        }
Exemplo n.º 5
0
        private LineTrace lastTracer;        // the last tracer to finish it's draw animation. After this tracer (line) is done drawing, we invoke the "OnFinish()" event(s);

        // Use this for initialization
        void Start()
        {
            mesh = this.GetComponent <MeshFilter> ().mesh;
            if (hideMesh)
            {
                this.GetComponent <MeshRenderer>().enabled = false;
            }
            verticies = mesh.vertices;
            triangles = mesh.triangles;
            if (useOutline)
            {
                edges = BuildManifoldEdges(mesh);
            }
            else
            {
                edges = GetAllEdges(mesh);
            }
            FillTracerMatrix();

            //get the last linetracer
            if (lineTracers.Count > 0)            //initialize to the first tracer
            {
                lastTracer = lineTracers[0];
            }
            //find the line tracer with the latest end time
            float endTime = 0;

            foreach (LineTrace tracer in lineTracers)
            {
                if (tracer.endTime > endTime)
                {
                    endTime    = tracer.endTime;
                    lastTracer = tracer;
                }
            }

            //if the onstart option is selected
            if (onStart)
            {
                //insta draw or animated draw
                if (instantDraw)
                {
                    InstantDraw();
                }
                else
                {
                    AnimatedDraw();
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Instantantly draw all of the lines.
        /// </summary>
        public void InstantDraw()
        {
            //Debug.Log("Drawing: " + edges.Length + " lines");
            for (int r = 0; r < lineTracers.Count; r++)
            {
                for (int c = 0; c < edges.Length; c++)
                {
                    int          index   = r * edges.Length + c;
                    LineTrace    tracer  = lineTracers[r];
                    GameObject   lineObj = tracerMatrix[r, c];
                    LineRenderer line    = lineObj.GetComponent <LineRenderer>();

                    Edge edge = edges[c];
                    //get the points in space we need
                    Vector3 a         = transform.TransformPoint(verticies[edge.vertexIndex[0]]);
                    Vector3 b         = transform.TransformPoint(verticies[edge.vertexIndex[1]]);
                    Vector3 aToB      = b - a;
                    Vector3 offsetDir = GetNormalDirection(edge);

                    //Debug.Log("Drawing tracer: " + index + " from " + a + " to " + b + " vec: " + aToB) ;
                    //place all of the points on the line
                    for (int seg = 0; seg < tracer.lineSegments; seg++)
                    {
                        float   percent = (float)seg / tracer.lineSegments;
                        Vector3 offset  = offsetDir * tracer.curve.Evaluate(percent) * tracer.amplitude;
                        //Debug.Log("%: " + percent);
                        Vector3 pos = a + aToB * percent + offset;
                        line.SetPosition(seg, pos);
                    }
                }
            }

            if (OnFinish != null)
            {
                OnFinish.Invoke();
            }
        }