private void DoShowEffects()
        {
            FastLineRendererProperties props = new FastLineRendererProperties();
            FastLineRenderer           r     = FastLineRenderer.CreateWithParent(null, LineRenderer);

            r.Material.EnableKeyword("DISABLE_CAPS");
            r.SetCapacity(8192 * FastLineRenderer.VerticesPerLine);
            r.Turbulence  = 350.0f;
            r.BoundsScale = new Vector3(4.0f, 4.0f, 4.0f);
            //r.JitterMultiplier = UnityEngine.Random.Range(0.25f, 1.5f);

            const float maxLifeTimeSeconds = 1.5f;

            for (int i = 0; i < 32; i++)
            {
                Vector3 pos  = new Vector3(10.0f, Screen.height * 0.5f);
                Vector3 pos2 = new Vector3(10.0f + (UnityEngine.Random.Range(50.0f, 150.0f)), Screen.height * 0.5f + (UnityEngine.Random.Range(-15.0f, 15.0f)));
                props.Start  = pos;
                props.End    = pos2;
                props.Radius = UnityEngine.Random.Range(8.0f, 16.0f);
                float s = UnityEngine.Random.Range(1.0f, maxLifeTimeSeconds);
                props.SetLifeTime(s, s * UnityEngine.Random.Range(0.1f, 0.2f));
                props.Color           = new Color32(RandomByte(), RandomByte(), RandomByte(), RandomByte());
                props.Velocity        = RandomVelocity(20.0f);
                props.Velocity.z      = 0.0f;
                props.AngularVelocity = UnityEngine.Random.Range(-0.1f, 0.1f);
                r.AddLine(props);
            }
            r.Apply();

            // send the script back into the cache, freeing up resources after max lifetime seconds.
            r.SendToCacheAfter(TimeSpan.FromSeconds(maxLifeTimeSeconds));
        }
Exemple #2
0
 public void Init(FastLineRenderer parent, float radius)
 {
     Assert.IsNotNull(parent);
     lineRenderer = FastLineRenderer.CreateWithParent(null, parent);
     lineRenderer.Material.EnableKeyword("DISABLE_CAPS");
     lineRenderer.SetCapacity(FastLineRenderer.MaxLinesPerMesh * FastLineRenderer.VerticesPerLine);
     props        = new FastLineRendererProperties();
     props.Radius = radius;
 }
        private void UpdateDynamicLines()
        {
            if (!Input.GetKeyDown(KeyCode.Space) || LineRenderer == null)
            {
                return;
            }
            else if (ShowEffects)
            {
                DoShowEffects();
                return;
            }

            const float maxLifeTimeSeconds   = 5.0f;
            FastLineRendererProperties props = new FastLineRendererProperties();
            FastLineRenderer           r     = FastLineRenderer.CreateWithParent(null, LineRenderer);

            r.Material.EnableKeyword("DISABLE_CAPS");
            r.SetCapacity(8192 * FastLineRenderer.VerticesPerLine);
            r.Turbulence  = 150.0f;
            r.BoundsScale = new Vector3(4.0f, 4.0f, 4.0f);
            props.GlowIntensityMultiplier = 0.1f;
            props.GlowWidthMultiplier     = 4.0f;

            for (int i = 0; i < 8192; i++)
            {
                Vector3 pos;
                if (Camera.main.orthographic)
                {
                    pos    = UnityEngine.Random.insideUnitCircle;
                    pos.x *= Screen.width * UnityEngine.Random.Range(0.1f, 0.4f);
                    pos.y *= Screen.height * UnityEngine.Random.Range(0.1f, 0.4f);
                }
                else
                {
                    pos    = UnityEngine.Random.insideUnitSphere;
                    pos.x *= Screen.width * UnityEngine.Random.Range(0.5f, 2.0f);
                    pos.y *= Screen.height * UnityEngine.Random.Range(0.5f, 2.0f);
                    pos.z *= UnityEngine.Random.Range(-200.0f, 200.0f);
                }
                props.End    = pos;
                props.Radius = UnityEngine.Random.Range(1.0f, 4.0f);
                float s = UnityEngine.Random.Range(1.0f, maxLifeTimeSeconds);
                props.SetLifeTime(s, s * 0.15f);
                props.Color           = new Color32(RandomByte(), RandomByte(), RandomByte(), RandomByte());
                props.Velocity        = RandomVelocity(100.0f);
                props.AngularVelocity = UnityEngine.Random.Range(-6.0f, 6.0f);
                r.AddLine(props);
            }
            r.Apply();
            r.SendToCacheAfter(TimeSpan.FromSeconds(maxLifeTimeSeconds));
        }
Exemple #4
0
        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);
            }
        }