Esempio n. 1
0
        void UpdateLine()
        {
            float t;

            if (duration == 0)
            {
                t = 1.0f;
            }
            else
            {
                t = (Time.time - startTime) / duration;
            }
            if (t >= 1.0f)
            {
                t = 1.0f;
                if (autoFadeAfter == 0)
                {
                    Destroy(this);                      // will destroy this behaviour at the end of the frame
                }
                else
                {
                    startAutoFadeTime = Time.time;
                }
            }

            // pass current vertices
            float vertexIndex   = 1 + (vertices.Length - 2) * t;
            int   currentVertex = (int)(vertexIndex);

            lr.SetVertexCount(currentVertex + 1);
            for (int k = 0; k < currentVertex; k++)
            {
                lr.SetPosition(k, vertices [k]);
            }
            // adjust last segment
            Vector3 nextVertex = vertices [currentVertex];
            float   subt       = vertexIndex - currentVertex;
            Vector3 progress   = Vector3.Lerp(vertices [currentVertex], nextVertex, subt);

            lr.SetPosition(currentVertex, progress);
        }
Esempio n. 2
0
        // Use this for initialization
        void Start()
        {
            // Create the line mesh
            if (numPoints < 2)
            {
                numPoints = 2;
            }
            vertices  = new Vector3[numPoints];
            startTime = Time.time;
            lr        = transform.GetComponent <LineRenderer2> ();
            if (lr == null)
            {
                lr = gameObject.AddComponent <LineRenderer2> ();
            }
            lr.SetVertexBufferSize(vertices.Length);
            lr.SetVertexCount(vertices.Length);
            lr.useWorldSpace = false;
            lr.SetWidth(lineWidth, lineWidth);
            if (!reuseMaterial)
            {
                lineMaterial = Instantiate(lineMaterial);
            }
            lineMaterial.color = color;
            lr.material        = lineMaterial;      // needs to instantiate to preserve individual color so can't use sharedMaterial
            lr.SetColors(color, color);

            vertices = new Vector3[numPoints];
            for (int s = 0; s < numPoints; s++)
            {
                float   t         = (float)s / (numPoints - 1);
                float   elevation = Mathf.Sin(t * Mathf.PI) * arcElevation;
                Vector3 sPos;
                if (earthInvertedMode)
                {
                    sPos = Vector3.Lerp(start, end, t).normalized * 0.5f * (1.0f - elevation);
                }
                else
                {
                    sPos = Vector3.Lerp(start, end, t).normalized * 0.5f * (1.0f + elevation);
                }
                vertices [s] = sPos;
                lr.SetPosition(s, sPos);
            }
            startAutoFadeTime = float.MaxValue;
            colorTransparent  = new Color(color.r, color.g, color.b, 0);

            if (duration == 0)
            {
                lr.Update();
                UpdateLine();
            }
        }