Ejemplo n.º 1
0
 protected override void UpdateTrail(PCTrail trail, float deltaTime)
 {
     if (_clampPosition && trail.Points.Count > 0)
     {
         trail.Points[0].Position = _clampPosition.position;
     }
 }
Ejemplo n.º 2
0
 private void CheckEmitChange()
 {
     if (this._emit != this.Emit)
     {
         this._emit = this.Emit;
         if (this._emit)
         {
             if (this._activeTrail == null || this._activeTrail.NumPoints != this.GetMaxNumberOfPoints())
             {
                 if (this._activeTrail != null)
                 {
                     this._activeTrail.Dispose();
                 }
                 this._activeTrail = new PCTrail(this.GetMaxNumberOfPoints());
             }
             else
             {
                 this._activeTrail.Points.Clear();
             }
             this._activeTrail.IsActiveTrail = true;
             this.OnStartEmit();
         }
         else
         {
             this.OnStopEmit();
             this._activeTrail.IsActiveTrail = false;
             this._fadingTrails.Add(this._activeTrail);
         }
     }
 }
Ejemplo n.º 3
0
 public void Translate(Vector3 t)
 {
     if (this._activeTrail != null)
     {
         for (int i = 0; i < this._activeTrail.Points.Count; i++)
         {
             PCTrailPoint local1 = this._activeTrail.Points[i];
             local1.Position += t;
         }
     }
     if (this._fadingTrails != null)
     {
         for (int j = 0; j < this._fadingTrails.Count; j++)
         {
             PCTrail trail = this._fadingTrails[j];
             if (trail != null)
             {
                 for (int k = 0; k < trail.Points.Count; k++)
                 {
                     PCTrailPoint local2 = trail.Points[k];
                     local2.Position += t;
                 }
             }
         }
     }
     this.OnTranslate(t);
 }
Ejemplo n.º 4
0
        protected virtual void OnDestroy()
        {
            OnDisable();

            if (_activeTrail != null)
            {
                _activeTrail.Dispose();
                _activeTrail = null;
            }

            if (_fadingTrails != null)
            {
                {
                    var __list3      = _fadingTrails;
                    var __listCount3 = __list3.Count;
                    for (int __i3 = 0; __i3 < __listCount3; ++__i3)
                    {
                        var fadingTrail = (PCTrail)__list3[__i3];
                        {
                            if (fadingTrail != null)
                            {
                                fadingTrail.Dispose();
                            }
                        }
                    }
                }
                _fadingTrails.Clear();
            }
        }
Ejemplo n.º 5
0
 protected override void UpdateTrail(PCTrail trail, float deltaTime)
 {
     foreach (PCTrailPoint point in trail.Points)
     {
         point.Position += ConstantForce * deltaTime;
     }
 }
        /// <summary>
        /// Clears all active trails from the system.
        /// </summary>
        /// <param name="emitState">Desired emit state after clearing</param>
        public void ClearSystem(bool emitState)
        {
            if (_activeTrail != null)
            {
                _activeTrail.Dispose();
                _activeTrail = null;
            }

            if (_fadingTrails != null)
            {
                foreach (PCTrail fadingTrail in _fadingTrails)
                {
                    if (fadingTrail != null)
                    {
                        fadingTrail.Dispose();
                    }
                }

                _fadingTrails.Clear();
            }

            Emit  = emitState;
            _emit = !emitState;

            CheckEmitChange();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Clears all active trails from the system.
        /// </summary>
        /// <param name="emitState">Desired emit state after clearing</param>
        public void ClearSystem(bool emitState)
        {
            if (_activeTrail != null)
            {
                _activeTrail.MeshUpdated = false;
                _activeTrail.Dispose();
                _activeTrail = null;
            }

            if (_fadingTrails != null)
            {
                {
                    var __list5      = _fadingTrails;
                    var __listCount5 = __list5.Count;
                    for (int __i5 = 0; __i5 < __listCount5; ++__i5)
                    {
                        var fadingTrail = (PCTrail)__list5[__i5];
                        {
                            if (fadingTrail != null)
                            {
                                fadingTrail.Dispose();
                            }
                        }
                    }
                }
                _fadingTrails.Clear();
            }

            Emit  = emitState;
            _emit = !emitState;

            CheckEmitChange();
        }
 private void UpdatePoints(PCTrail line, float deltaTime)
 {
     for (int i = 0; i < line.Points.Count; i++)
     {
         line.Points[i].Update(_noDecay ? 0 : deltaTime);
     }
 }
Ejemplo n.º 9
0
 public void Translate(Vector3 t)
 {
     if (this._activeTrail != null)
     {
         for (int i = 0; i < this._activeTrail.Points.Count; i++)
         {
             this._activeTrail.Points[i].Position += t;
         }
     }
     if (this._fadingTrails != null)
     {
         for (int j = 0; j < this._fadingTrails.Count; j++)
         {
             PCTrail pCTrail = this._fadingTrails[j];
             if (pCTrail != null)
             {
                 for (int k = 0; k < pCTrail.Points.Count; k++)
                 {
                     pCTrail.Points[k].Position += t;
                 }
             }
         }
     }
     this.OnTranslate(t);
 }
Ejemplo n.º 10
0
        public void CreateTrail(Vector3 from, Vector3 to, float distanceBetweenPoints)
        {
            float   num        = Vector3.Distance(from, to);
            Vector3 normalized = (to - from).normalized;
            float   num2       = 0f;
            CircularBuffer <PCTrailPoint> circularBuffer = new CircularBuffer <PCTrailPoint>(this.GetMaxNumberOfPoints());
            int num3 = 0;

            while (num2 < num)
            {
                PCTrailPoint pCTrailPoint = new PCTrailPoint();
                pCTrailPoint.PointNumber = num3;
                pCTrailPoint.Position    = from + normalized * num2;
                circularBuffer.Add(pCTrailPoint);
                this.InitialiseNewPoint(pCTrailPoint);
                num3++;
                if (distanceBetweenPoints <= 0f)
                {
                    break;
                }
                num2 += distanceBetweenPoints;
            }
            PCTrailPoint pCTrailPoint2 = new PCTrailPoint();

            pCTrailPoint2.PointNumber = num3;
            pCTrailPoint2.Position    = to;
            circularBuffer.Add(pCTrailPoint2);
            this.InitialiseNewPoint(pCTrailPoint2);
            PCTrail pCTrail = new PCTrail(this.GetMaxNumberOfPoints());

            pCTrail.Points = circularBuffer;
            this._fadingTrails.Add(pCTrail);
        }
Ejemplo n.º 11
0
 private void UpdatePoints(PCTrail line, float deltaTime)
 {
     for (int i = 0; i < line.Points.Count; i++)
     {
         line.Points[i].Update((!this._noDecay) ? deltaTime : 0f);
     }
 }
Ejemplo n.º 12
0
 public void CreateTrail(Vector3 from, Vector3 to, float distanceBetweenPoints)
 {
     float num = Vector3.Distance(from, to);
     Vector3 normalized = (to - from).normalized;
     float num2 = 0f;
     CircularBuffer<PCTrailPoint> circularBuffer = new CircularBuffer<PCTrailPoint>(this.GetMaxNumberOfPoints());
     int num3 = 0;
     while (num2 < num)
     {
         PCTrailPoint pCTrailPoint = new PCTrailPoint();
         pCTrailPoint.PointNumber = num3;
         pCTrailPoint.Position = from + normalized * num2;
         circularBuffer.Add(pCTrailPoint);
         this.InitialiseNewPoint(pCTrailPoint);
         num3++;
         if (distanceBetweenPoints <= 0f)
         {
             break;
         }
         num2 += distanceBetweenPoints;
     }
     PCTrailPoint pCTrailPoint2 = new PCTrailPoint();
     pCTrailPoint2.PointNumber = num3;
     pCTrailPoint2.Position = to;
     circularBuffer.Add(pCTrailPoint2);
     this.InitialiseNewPoint(pCTrailPoint2);
     PCTrail pCTrail = new PCTrail(this.GetMaxNumberOfPoints());
     pCTrail.Points = circularBuffer;
     this._fadingTrails.Add(pCTrail);
 }
Ejemplo n.º 13
0
 private void UpdatePoints(float deltaTime, PCTrail line)
 {
     for (int i = 0; i < line.Points.Count; i++)
     {
         line.Points[i].Update(deltaTime);
         UpdatePoint(line.Points[i], deltaTime);
     }
 }
Ejemplo n.º 14
0
        protected override void UpdateTrail(PCTrail trail, float deltaTime)
        {
            if (_noDecay)
                return;

            foreach (PCTrailPoint point in trail.Points)
            {
                point.Position += ConstantForce * deltaTime;
            }
        }
Ejemplo n.º 15
0
 protected override void UpdateTrail(PCTrail trail, float deltaTime)
 {
     if (this._noDecay)
     {
         return;
     }
     foreach (PCTrailPoint current in trail.Points)
     {
         current.Position += this.ConstantForce * deltaTime;
     }
 }
Ejemplo n.º 16
0
        private int NumberOfActivePoints(PCTrail line)
        {
            int num = 0;

            for (int i = 0; i < line.Points.Count; i++)
            {
                if (line.Points[i].TimeActive() < this.TrailData.Lifetime)
                {
                    num++;
                }
            }
            return(num);
        }
        private int NumberOfActivePoints(PCTrail line)
        {
            int count = 0;

            for (int index = 0; index < line.Points.Count; index++)
            {
                if (line.Points[index].TimeActive() < TrailData.Lifetime)
                {
                    count++;
                }
            }
            return(count);
        }
Ejemplo n.º 18
0
        protected virtual void Awake()
        {
            GlobalTrailRendererCount++;

            if (GlobalTrailRendererCount == 1)
            {
                _matToTrailList = new Dictionary <Material, List <PCTrail> >();
                _toClean        = new List <Mesh>();
            }

            _activeTrail  = new PCTrail(MaxNumberOfPoints);
            _fadingTrails = new List <PCTrail>();
            _t            = transform;
            _emit         = Emit;
        }
Ejemplo n.º 19
0
 protected override void UpdateTrail(PCTrail trail, float deltaTime)
 {
     if (this._noDecay)
     {
         return;
     }
     using (IEnumerator <PCTrailPoint> enumerator = trail.Points.GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             PCTrailPoint current = enumerator.get_Current();
             current.Position += this.ConstantForce * deltaTime;
         }
     }
 }
        /// <summary>
        /// Insert a trail into this trail renderer.
        /// </summary>
        /// <param name="from">The start position of the trail.</param>
        /// <param name="to">The end position of the trail.</param>
        /// <param name="distanceBetweenPoints">Distance between each point on the trail</param>
        public void CreateTrail(Vector3 from, Vector3 to, float distanceBetweenPoints)
        {
            float distanceBetween = Vector3.Distance(from, to);

            Vector3 dirVector = to - from;

            dirVector = dirVector.normalized;

            float currentLength = 0;

            CircularBuffer <PCTrailPoint> newLine = new CircularBuffer <PCTrailPoint>(GetMaxNumberOfPoints());
            int pointNumber = 0;

            while (currentLength < distanceBetween)
            {
                PCTrailPoint newPoint = new PCTrailPoint();
                newPoint.PointNumber = pointNumber;
                newPoint.Position    = from + dirVector * currentLength;
                newLine.Add(newPoint);
                InitialiseNewPoint(newPoint);

                pointNumber++;

                if (distanceBetweenPoints <= 0)
                {
                    break;
                }
                else
                {
                    currentLength += distanceBetweenPoints;
                }
            }

            PCTrailPoint lastPoint = new PCTrailPoint();

            lastPoint.PointNumber = pointNumber;
            lastPoint.Position    = to;
            newLine.Add(lastPoint);
            InitialiseNewPoint(lastPoint);

            PCTrail newTrail = new PCTrail(GetMaxNumberOfPoints());

            newTrail.Points = newLine;

            _fadingTrails.Add(newTrail);
        }
        protected virtual void OnDestroy()
        {
            GlobalTrailRendererCount--;

            if (GlobalTrailRendererCount == 0)
            {
                if (_toClean != null && _toClean.Count > 0)
                {
                    foreach (Mesh mesh in _toClean)
                    {
                        if (Application.isEditor)
                        {
                            DestroyImmediate(mesh, true);
                        }
                        else
                        {
                            Destroy(mesh);
                        }
                    }
                }

                _toClean = null;
                _matToTrailList.Clear();
                _matToTrailList = null;
            }

            if (_activeTrail != null)
            {
                _activeTrail.Dispose();
                _activeTrail = null;
            }

            if (_fadingTrails != null)
            {
                foreach (PCTrail fadingTrail in _fadingTrails)
                {
                    if (fadingTrail != null)
                    {
                        fadingTrail.Dispose();
                    }
                }

                _fadingTrails.Clear();
            }
        }
Ejemplo n.º 22
0
 protected virtual void OnDestroy()
 {
     TrailRenderer_Base.GlobalTrailRendererCount--;
     if (TrailRenderer_Base.GlobalTrailRendererCount == 0)
     {
         if (TrailRenderer_Base._toClean != null && TrailRenderer_Base._toClean.Count > 0)
         {
             for (int i = 0; i < TrailRenderer_Base._toClean.Count; i++)
             {
                 Mesh mesh = TrailRenderer_Base._toClean[i];
                 if (mesh != null)
                 {
                     if (Application.isEditor)
                     {
                         Object.DestroyImmediate(mesh, true);
                     }
                     else
                     {
                         Object.Destroy(mesh);
                     }
                 }
             }
         }
         TrailRenderer_Base._toClean = null;
         TrailRenderer_Base._matToTrailList.Clear();
         TrailRenderer_Base._matToTrailList = null;
     }
     if (this._activeTrail != null)
     {
         this._activeTrail.Dispose();
         this._activeTrail = null;
     }
     if (this._fadingTrails != null)
     {
         for (int j = 0; j < this._fadingTrails.Count; j++)
         {
             PCTrail pCTrail = this._fadingTrails[j];
             if (pCTrail != null)
             {
                 pCTrail.Dispose();
             }
         }
         this._fadingTrails.Clear();
     }
 }
Ejemplo n.º 23
0
 protected virtual void OnDestroy()
 {
     GlobalTrailRendererCount--;
     if (GlobalTrailRendererCount == 0)
     {
         if ((_toClean != null) && (_toClean.Count > 0))
         {
             for (int i = 0; i < _toClean.Count; i++)
             {
                 Mesh mesh = _toClean[i];
                 if (mesh != null)
                 {
                     if (Application.isEditor)
                     {
                         UnityEngine.Object.DestroyImmediate(mesh, true);
                     }
                     else
                     {
                         UnityEngine.Object.Destroy(mesh);
                     }
                 }
             }
         }
         _toClean = null;
         _matToTrailList.Clear();
         _matToTrailList = null;
     }
     if (this._activeTrail != null)
     {
         this._activeTrail.Dispose();
         this._activeTrail = null;
     }
     if (this._fadingTrails != null)
     {
         for (int j = 0; j < this._fadingTrails.Count; j++)
         {
             PCTrail trail = this._fadingTrails[j];
             if (trail != null)
             {
                 trail.Dispose();
             }
         }
         this._fadingTrails.Clear();
     }
 }
Ejemplo n.º 24
0
 protected virtual void Awake()
 {
     TrailRenderer_Base.GlobalTrailRendererCount++;
     if (TrailRenderer_Base.GlobalTrailRendererCount == 1)
     {
         TrailRenderer_Base._matToTrailList = new DictionaryView <Material, ListView <PCTrail> >();
         TrailRenderer_Base._toClean        = new ListView <Mesh>();
     }
     this._fadingTrails = new ListView <PCTrail>();
     this._t            = base.transform;
     this._emit         = this.Emit;
     if (this._emit)
     {
         this._activeTrail = new PCTrail(this.GetMaxNumberOfPoints());
         this._activeTrail.IsActiveTrail = true;
         this.OnStartEmit();
     }
 }
Ejemplo n.º 25
0
 protected override void UpdateTrail(PCTrail trail, float deltaTime)
 {
     if (_noDecay)
     {
         return;
     }
     {
         // foreach(var point in trail.Points)
         var __enumerator1 = (trail.Points).GetEnumerator();
         while (__enumerator1.MoveNext())
         {
             var point = (PCTrailPoint)__enumerator1.Current;
             {
                 point.Position += ConstantForce * deltaTime;
             }
         }
     }
 }
Ejemplo n.º 26
0
 private void CheckEmitChange()
 {
     if (_emit != Emit)
     {
         _emit = Emit;
         if (_emit)
         {
             OnStartEmit();
             _activeTrail = new PCTrail(MaxNumberOfPoints);
         }
         else
         {
             OnStopEmit();
             _fadingTrails.Add(_activeTrail);
             _activeTrail = null;
         }
     }
 }
Ejemplo n.º 27
0
 public void ClearSystem(bool emitState)
 {
     if (this._fadingTrails != null)
     {
         for (int i = 0; i < this._fadingTrails.Count; i++)
         {
             PCTrail pCTrail = this._fadingTrails[i];
             if (pCTrail != null && pCTrail != this._activeTrail)
             {
                 pCTrail.Dispose();
             }
         }
         this._fadingTrails.Clear();
     }
     this.Emit  = emitState;
     this._emit = !emitState;
     this.CheckEmitChange();
 }
        private void CheckEmitChange()
        {
            if (_emit != Emit)
            {
                _emit = Emit;
                if (_emit)
                {
                    _activeTrail = new PCTrail(GetMaxNumberOfPoints());
                    _activeTrail.IsActiveTrail = true;

                    OnStartEmit();
                }
                else
                {
                    OnStopEmit();
                    _activeTrail.IsActiveTrail = false;
                    _fadingTrails.Add(_activeTrail);
                    _activeTrail = null;
                }
            }
        }
Ejemplo n.º 29
0
 public void ClearSystem(bool emitState)
 {
     if (this._activeTrail != null)
     {
         this._activeTrail.Dispose();
         this._activeTrail = null;
     }
     if (this._fadingTrails != null)
     {
         foreach (PCTrail current in this._fadingTrails)
         {
             if (current != null)
             {
                 current.Dispose();
             }
         }
         this._fadingTrails.Clear();
     }
     this.Emit = emitState;
     this._emit = !emitState;
     this.CheckEmitChange();
 }
Ejemplo n.º 30
0
        protected virtual void Awake()
        {
            GlobalTrailRendererCount++;

            if (GlobalTrailRendererCount == 1)
            {
                _matToTrailList = new Dictionary <Material, List <PCTrail> > ();
                _toClean        = new List <Mesh> ();
            }

            combineList   = new List <CombineInstance>();
            _fadingTrails = new List <PCTrail> ();
            _t            = transform;
            _emit         = Emit;

            if (_emit)
            {
                _activeTrail = new PCTrail(GetMaxNumberOfPoints());
                _activeTrail.IsActiveTrail = true;
                OnStartEmit();
            }
        }
        protected virtual void Awake()
        {
            GlobalTrailRendererCount++;

            if(GlobalTrailRendererCount == 1)
            {
                _matToTrailList = new Dictionary<Material, List<PCTrail>>();
                _toClean = new List<Mesh>();
            }

            
            _fadingTrails = new List<PCTrail>();
            _t = transform;
            _emit = Emit;

            if (_emit)
            {
                _activeTrail = new PCTrail(GetMaxNumberOfPoints());
                _activeTrail.IsActiveTrail = true;
                OnStartEmit();
            }
        }
Ejemplo n.º 32
0
        public void CreateTrail(Vector3 from, Vector3 to, float distanceBetweenPoints)
        {
            float   num        = Vector3.Distance(from, to);
            Vector3 normalized = to - from;

            normalized = normalized.normalized;
            float num2 = 0f;
            CircularBuffer <PCTrailPoint> buffer = new CircularBuffer <PCTrailPoint>(this.GetMaxNumberOfPoints());
            int num3 = 0;

            while (num2 < num)
            {
                PCTrailPoint point = new PCTrailPoint {
                    PointNumber = num3,
                    Position    = from + ((Vector3)(normalized * num2))
                };
                buffer.Add(point);
                this.InitialiseNewPoint(point);
                num3++;
                if (distanceBetweenPoints <= 0f)
                {
                    break;
                }
                num2 += distanceBetweenPoints;
            }
            PCTrailPoint item = new PCTrailPoint {
                PointNumber = num3,
                Position    = to
            };

            buffer.Add(item);
            this.InitialiseNewPoint(item);
            PCTrail trail = new PCTrail(this.GetMaxNumberOfPoints())
            {
                Points = buffer
            };

            this._fadingTrails.Add(trail);
        }
Ejemplo n.º 33
0
 protected override void UpdateTrail(PCTrail trail, float deltaTime)
 {
     if (!base._noDecay)
     {
         IEnumerator <PCTrailPoint> enumerator = trail.Points.GetEnumerator();
         try
         {
             while (enumerator.MoveNext())
             {
                 PCTrailPoint current = enumerator.Current;
                 current.Position += (Vector3)(this.ConstantForce * deltaTime);
             }
         }
         finally
         {
             if (enumerator == null)
             {
             }
             enumerator.Dispose();
         }
     }
 }
Ejemplo n.º 34
0
 private void GenerateMesh(PCTrail trail)
 {
     trail.Mesh.Clear(false);
     Vector3 vector = (!(Camera.main != null)) ? Vector3.forward : Camera.main.transform.forward;
     if (this.TrailData.UseForwardOverride)
     {
         vector = this.TrailData.ForwardOverride.normalized;
     }
     trail.activePointCount = this.NumberOfActivePoints(trail);
     if (trail.activePointCount < 2)
     {
         return;
     }
     int num = 0;
     for (int i = 0; i < trail.Points.Count; i++)
     {
         PCTrailPoint pCTrailPoint = trail.Points[i];
         float num2 = pCTrailPoint.TimeActive() / this.TrailData.Lifetime;
         if (pCTrailPoint.TimeActive() <= this.TrailData.Lifetime)
         {
             if (this.TrailData.UseForwardOverride && this.TrailData.ForwardOverrideRelative)
             {
                 vector = pCTrailPoint.Forward;
             }
             Vector3 a = Vector3.zero;
             if (i < trail.Points.Count - 1)
             {
                 a = Vector3.Cross((trail.Points[i + 1].Position - pCTrailPoint.Position).normalized, vector).normalized;
             }
             else
             {
                 a = Vector3.Cross((pCTrailPoint.Position - trail.Points[i - 1].Position).normalized, vector).normalized;
             }
             Color color = (!this.TrailData.StretchColorToFit) ? ((!this.TrailData.UsingSimpleColor) ? this.TrailData.ColorOverLife.Evaluate(num2) : Color.Lerp(this.TrailData.SimpleColorOverLifeStart, this.TrailData.SimpleColorOverLifeEnd, num2)) : ((!this.TrailData.UsingSimpleColor) ? this.TrailData.ColorOverLife.Evaluate(1f - (float)num / (float)trail.activePointCount / 2f) : Color.Lerp(this.TrailData.SimpleColorOverLifeStart, this.TrailData.SimpleColorOverLifeEnd, 1f - (float)num / (float)trail.activePointCount / 2f));
             float d = (!this.TrailData.StretchSizeToFit) ? ((!this.TrailData.UsingSimpleSize) ? this.TrailData.SizeOverLife.Evaluate(num2) : Mathf.Lerp(this.TrailData.SimpleSizeOverLifeStart, this.TrailData.SimpleSizeOverLifeEnd, num2)) : ((!this.TrailData.UsingSimpleSize) ? this.TrailData.SizeOverLife.Evaluate(1f - (float)num / (float)trail.activePointCount / 2f) : Mathf.Lerp(this.TrailData.SimpleSizeOverLifeStart, this.TrailData.SimpleSizeOverLifeEnd, 1f - (float)num / (float)trail.activePointCount / 2f));
             trail.verticies[num] = pCTrailPoint.Position + a * d;
             if (this.TrailData.MaterialTileLength <= 0f)
             {
                 trail.uvs[num] = new Vector2((float)num / (float)trail.activePointCount / 2f, 0f);
             }
             else
             {
                 trail.uvs[num] = new Vector2(pCTrailPoint.GetDistanceFromStart() / this.TrailData.MaterialTileLength, 0f);
             }
             trail.normals[num] = vector;
             trail.colors[num] = color;
             num++;
             trail.verticies[num] = pCTrailPoint.Position - a * d;
             if (this.TrailData.MaterialTileLength <= 0f)
             {
                 trail.uvs[num] = new Vector2((float)num / (float)trail.activePointCount / 2f, 1f);
             }
             else
             {
                 trail.uvs[num] = new Vector2(pCTrailPoint.GetDistanceFromStart() / this.TrailData.MaterialTileLength, 1f);
             }
             trail.normals[num] = vector;
             trail.colors[num] = color;
             num++;
         }
     }
     Vector2 v = trail.verticies[num - 1];
     for (int j = num; j < trail.verticies.Length; j++)
     {
         trail.verticies[j] = v;
     }
     int num3 = 0;
     for (int k = 0; k < 2 * (trail.activePointCount - 1); k++)
     {
         if (k % 2 == 0)
         {
             trail.indicies[num3] = k;
             num3++;
             trail.indicies[num3] = k + 1;
             num3++;
             trail.indicies[num3] = k + 2;
         }
         else
         {
             trail.indicies[num3] = k + 2;
             num3++;
             trail.indicies[num3] = k + 1;
             num3++;
             trail.indicies[num3] = k;
         }
         num3++;
     }
     int num4 = trail.indicies[num3 - 1];
     for (int l = num3; l < trail.indicies.Length; l++)
     {
         trail.indicies[l] = num4;
     }
     trail.Mesh.vertices = trail.verticies;
     trail.Mesh.SetIndices(trail.indicies, MeshTopology.Triangles, 0);
     trail.Mesh.uv = trail.uvs;
     trail.Mesh.normals = trail.normals;
     trail.Mesh.colors = trail.colors;
 }
Ejemplo n.º 35
0
 private int NumberOfActivePoints(PCTrail line)
 {
     int num = 0;
     for (int i = 0; i < line.Points.Count; i++)
     {
         if (line.Points[i].TimeActive() < this.TrailData.Lifetime)
         {
             num++;
         }
     }
     return num;
 }
Ejemplo n.º 36
0
 private void UpdatePoints(PCTrail line, float deltaTime)
 {
     for (int i = 0; i < line.Points.Count; i++)
     {
         line.Points[i].Update((!this._noDecay) ? deltaTime : 0f);
     }
 }
        protected virtual void UpdateTrail(PCTrail trail, float deltaTime)
        {

        }
        private void GenerateMesh(PCTrail trail)
        {
            trail.Mesh.Clear(false);

            Vector3 camForward = Camera.main != null ? Camera.main.transform.forward : Vector3.forward;

            if (TrailData.UseForwardOverride)
            {
                camForward = TrailData.ForwardOverride.normalized;
            }

            trail.activePointCount = NumberOfActivePoints(trail);

            if (trail.activePointCount < 2)
            {
                return;
            }


            int vertIndex = 0;

            for (int i = 0; i < trail.Points.Count; i++)
            {
                PCTrailPoint p         = trail.Points[i];
                float        timeAlong = p.TimeActive() / TrailData.Lifetime;

                if (p.TimeActive() > TrailData.Lifetime)
                {
                    continue;
                }

                if (TrailData.UseForwardOverride && TrailData.ForwardOverrideRelative)
                {
                    camForward = p.Forward;
                }

                Vector3 cross = Vector3.zero;

                if (i < trail.Points.Count - 1)
                {
                    cross =
                        Vector3.Cross((trail.Points[i + 1].Position - p.Position).normalized, camForward).
                        normalized;
                }
                else
                {
                    cross =
                        Vector3.Cross((p.Position - trail.Points[i - 1].Position).normalized, camForward).
                        normalized;
                }


                //yuck! lets move these into their own functions some time
                Color c = TrailData.StretchColorToFit ?
                          (TrailData.UsingSimpleColor ? Color.Lerp(TrailData.SimpleColorOverLifeStart, TrailData.SimpleColorOverLifeEnd, 1 - ((float)vertIndex / (float)trail.activePointCount / 2f)) : TrailData.ColorOverLife.Evaluate(1 - ((float)vertIndex / (float)trail.activePointCount / 2f))) :
                          (TrailData.UsingSimpleColor ? Color.Lerp(TrailData.SimpleColorOverLifeStart, TrailData.SimpleColorOverLifeEnd, timeAlong) : TrailData.ColorOverLife.Evaluate(timeAlong));

                float s = TrailData.StretchSizeToFit ?
                          (TrailData.UsingSimpleSize ? Mathf.Lerp(TrailData.SimpleSizeOverLifeStart, TrailData.SimpleSizeOverLifeEnd, 1 - ((float)vertIndex / (float)trail.activePointCount / 2f)) : TrailData.SizeOverLife.Evaluate(1 - ((float)vertIndex / (float)trail.activePointCount / 2f))) :
                          (TrailData.UsingSimpleSize ? Mathf.Lerp(TrailData.SimpleSizeOverLifeStart, TrailData.SimpleSizeOverLifeEnd, timeAlong) : TrailData.SizeOverLife.Evaluate(timeAlong));


                trail.verticies[vertIndex] = p.Position + cross * s;

                if (TrailData.MaterialTileLength <= 0)
                {
                    trail.uvs[vertIndex] = new Vector2((float)vertIndex / (float)trail.activePointCount / 2f, 0);
                }
                else
                {
                    trail.uvs[vertIndex] = new Vector2(p.GetDistanceFromStart() / TrailData.MaterialTileLength, 0);
                }

                trail.normals[vertIndex] = camForward;
                trail.colors[vertIndex]  = c;
                vertIndex++;
                trail.verticies[vertIndex] = p.Position - cross * s;

                if (TrailData.MaterialTileLength <= 0)
                {
                    trail.uvs[vertIndex] = new Vector2((float)vertIndex / (float)trail.activePointCount / 2f, 1);
                }
                else
                {
                    trail.uvs[vertIndex] = new Vector2(p.GetDistanceFromStart() / TrailData.MaterialTileLength, 1);
                }

                trail.normals[vertIndex] = camForward;
                trail.colors[vertIndex]  = c;

                vertIndex++;
            }

            Vector2 finalPosition = trail.verticies[vertIndex - 1];

            for (int i = vertIndex; i < trail.verticies.Length; i++)
            {
                trail.verticies[i] = finalPosition;
            }

            int indIndex = 0;

            for (int pointIndex = 0; pointIndex < 2 * (trail.activePointCount - 1); pointIndex++)
            {
                if (pointIndex % 2 == 0)
                {
                    trail.indicies[indIndex] = pointIndex;
                    indIndex++;
                    trail.indicies[indIndex] = pointIndex + 1;
                    indIndex++;
                    trail.indicies[indIndex] = pointIndex + 2;
                }
                else
                {
                    trail.indicies[indIndex] = pointIndex + 2;
                    indIndex++;
                    trail.indicies[indIndex] = pointIndex + 1;
                    indIndex++;
                    trail.indicies[indIndex] = pointIndex;
                }

                indIndex++;
            }

            int finalIndex = trail.indicies[indIndex - 1];

            for (int i = indIndex; i < trail.indicies.Length; i++)
            {
                trail.indicies[i] = finalIndex;
            }

            trail.Mesh.vertices = trail.verticies;
            trail.Mesh.SetIndices(trail.indicies, MeshTopology.Triangles, 0);
            trail.Mesh.uv      = trail.uvs;
            trail.Mesh.normals = trail.normals;
            trail.Mesh.colors  = trail.colors;
        }
        /// <summary>
        /// Clears all active trails from the system.
        /// </summary>
        /// <param name="emitState">Desired emit state after clearing</param>
        public void ClearSystem(bool emitState)
        {
            if(_activeTrail != null)
            {
                _activeTrail.Dispose();
                _activeTrail = null;
            }

            if (_fadingTrails != null)
            {
                foreach (PCTrail fadingTrail in _fadingTrails)
                {
                    if (fadingTrail != null)
                        fadingTrail.Dispose();
                }

                _fadingTrails.Clear();
            }

            Emit = emitState;
            _emit = !emitState;

            CheckEmitChange();
        }
Ejemplo n.º 40
0
 protected virtual void Awake()
 {
     TrailRenderer_Base.GlobalTrailRendererCount++;
     if (TrailRenderer_Base.GlobalTrailRendererCount == 1)
     {
         TrailRenderer_Base._matToTrailList = new Dictionary<Material, List<PCTrail>>();
         TrailRenderer_Base._toClean = new List<Mesh>();
     }
     this._fadingTrails = new List<PCTrail>();
     this._t = base.transform;
     this._emit = this.Emit;
     if (this._emit)
     {
         this._activeTrail = new PCTrail(this.GetMaxNumberOfPoints());
         this._activeTrail.IsActiveTrail = true;
         this.OnStartEmit();
     }
 }
 private void UpdatePoints(PCTrail line, float deltaTime)
 {
     for (int i = 0; i < line.Points.Count; i++)
     {
         line.Points[i].Update(_noDecay ? 0 : deltaTime);
     }
 }
 private void CheckEmitChange()
 {
     if (_emit != Emit)
     {
         _emit = Emit;
         if (_emit)
         {
             _activeTrail = new PCTrail(GetMaxNumberOfPoints());
             _activeTrail.IsActiveTrail = true;
             
             OnStartEmit();
         }
         else
         {
             OnStopEmit();
             _activeTrail.IsActiveTrail = false;
             _fadingTrails.Add(_activeTrail);
             _activeTrail = null;
         }
     }
 }
Ejemplo n.º 43
0
        protected override void UpdateTrail(PCTrail trail, float deltaTime)
        {
            if (trail.IsActiveTrail == false)
                return;

            //TODO Must optimize this further, I don't need to keep recalculating point positions unless we are
            //dealng with the points between the last and 2nd last CP (+ the last CP itself)
            int trailPointIndex = 0;
            for (int i = 0; i < _controlPoints.Count; i++)
            {
                trail.Points[trailPointIndex].Position = _controlPoints[i].p;

                if (TrailData.UseForwardOverride)
                {
                    trail.Points[trailPointIndex].Forward = _controlPoints[i].forward;
                }

                trailPointIndex++;

                if (i < _controlPoints.Count - 1)
                {
                    Vector3 Handle1, Handle2;
                    float distanceBetween = Vector3.Distance(_controlPoints[i].p, _controlPoints[i + 1].p) / 2;
                    if (i == 0)
                    {
                        Handle1 = _controlPoints[i].p + (_controlPoints[i + 1].p - _controlPoints[i].p).normalized * distanceBetween;
                    }
                    else
                    {
                        Handle1 = _controlPoints[i].p + (_controlPoints[i + 1].p - _controlPoints[i - 1].p).normalized * distanceBetween;
                    }

                    int nextI = i + 1;

                    if (nextI == _controlPoints.Count - 1)
                    {
                        Handle2 = _controlPoints[nextI].p + (_controlPoints[nextI - 1].p - _controlPoints[nextI].p).normalized * distanceBetween;
                    }
                    else
                    {
                        Handle2 = _controlPoints[nextI].p + (_controlPoints[nextI - 1].p - _controlPoints[nextI + 1].p).normalized * distanceBetween;
                    }

                    PCTrailPoint currentHandle = trail.Points[trailPointIndex-1];
                    PCTrailPoint nextHandle = trail.Points[(trailPointIndex-1) + PointsBetweenControlPoints+1];

                    
                    for (int pointBetween = 0; pointBetween < PointsBetweenControlPoints; pointBetween++)
                    {
                        float t= (((float)pointBetween + 1f) / ((float)PointsBetweenControlPoints + 1f));
                        trail.Points[trailPointIndex].Position = GetPointAlongCurve(_controlPoints[i].p, Handle1, _controlPoints[i + 1].p, Handle2, t, 0.3f);
                        trail.Points[trailPointIndex].SetTimeActive(Mathf.Lerp(currentHandle.TimeActive(), nextHandle.TimeActive(), t));

                        if (TrailData.UseForwardOverride)
                        {
                            trail.Points[trailPointIndex].Forward = Vector3.Lerp(currentHandle.Forward, nextHandle.Forward, t);
                        }


                        trailPointIndex++;
                    }

                }
            }

            int lastControlPointPointIndex = ((_controlPoints.Count - 1) + ((_controlPoints.Count - 1) * PointsBetweenControlPoints));
            int prevControlPointPointIndex = lastControlPointPointIndex - PointsBetweenControlPoints - 1;
            int activePointCount = lastControlPointPointIndex + 1;
            

            /*
             * 
             * This is that optimisation mentioned above..sort of works, but smoothing isn't working right so i am leaving it out for now
             * 
             * 
             
            int lastControlPointIndex = _controlPoints.Count - 1;
            int prevControlPointIndex = _controlPoints.Count - 2;

            Vector3 Handle1, Handle2;
            float distanceBetween = Vector3.Distance(_controlPoints[lastControlPointIndex].p, _controlPoints[prevControlPointIndex].p) / 2;

            if (prevControlPointIndex == 0)
                Handle1 = _controlPoints[prevControlPointIndex].p + (_controlPoints[lastControlPointIndex].p - _controlPoints[prevControlPointIndex].p).normalized * distanceBetween;
            else
                Handle1 = _controlPoints[prevControlPointIndex].p + (_controlPoints[lastControlPointIndex].p - _controlPoints[prevControlPointIndex - 1].p).normalized * distanceBetween;
           

            Handle2 = _controlPoints[lastControlPointIndex].p + (_controlPoints[prevControlPointIndex].p - _controlPoints[lastControlPointIndex].p).normalized * distanceBetween;


            float timeActiveLastControlPoint = trail.Points[lastControlPointPointIndex].TimeActive();
            float timeActivePrevControlPoint = trail.Points[prevControlPointPointIndex].TimeActive();

            for (int pointBetween = 0; pointBetween < PointsBetweenControlPoints; pointBetween++)
            {
                float t= (((float)pointBetween + 1f) / ((float)PointsBetweenControlPoints + 1f));
                trail.Points[prevControlPointPointIndex + pointBetween + 1].Position = GetPointAlongCurve(_controlPoints[prevControlPointIndex].p, Handle1, _controlPoints[lastControlPointIndex].p, Handle2, t, 0.3f);
                trail.Points[prevControlPointPointIndex + pointBetween + 1].SetTimeActive(Mathf.Lerp(timeActivePrevControlPoint, timeActiveLastControlPoint, t));
            }
            trail.Points[lastControlPointPointIndex].Position = _controlPoints[lastControlPointIndex].p;
            */

            float distanceFromStart = trail.Points[prevControlPointPointIndex].GetDistanceFromStart();
            for (int i = prevControlPointPointIndex + 1; i < activePointCount; i++)
            {
                distanceFromStart += Vector3.Distance(trail.Points[i - 1].Position, trail.Points[i].Position);
                trail.Points[i].SetDistanceFromStart(distanceFromStart);
            }

        }
Ejemplo n.º 44
0
 protected override void UpdateTrail(PCTrail trail, float deltaTime)
 {
     if (!trail.IsActiveTrail)
     {
         return;
     }
     int num = 0;
     for (int i = 0; i < this._controlPoints.Count; i++)
     {
         trail.Points[num].Position = this._controlPoints[i].p;
         if (this.TrailData.UseForwardOverride)
         {
             trail.Points[num].Forward = this._controlPoints[i].forward;
         }
         num++;
         if (i < this._controlPoints.Count - 1)
         {
             float d = Vector3.Distance(this._controlPoints[i].p, this._controlPoints[i + 1].p) / 2f;
             Vector3 curveStartHandle;
             if (i == 0)
             {
                 curveStartHandle = this._controlPoints[i].p + (this._controlPoints[i + 1].p - this._controlPoints[i].p).normalized * d;
             }
             else
             {
                 curveStartHandle = this._controlPoints[i].p + (this._controlPoints[i + 1].p - this._controlPoints[i - 1].p).normalized * d;
             }
             int num2 = i + 1;
             Vector3 curveEndHandle;
             if (num2 == this._controlPoints.Count - 1)
             {
                 curveEndHandle = this._controlPoints[num2].p + (this._controlPoints[num2 - 1].p - this._controlPoints[num2].p).normalized * d;
             }
             else
             {
                 curveEndHandle = this._controlPoints[num2].p + (this._controlPoints[num2 - 1].p - this._controlPoints[num2 + 1].p).normalized * d;
             }
             PCTrailPoint pCTrailPoint = trail.Points[num - 1];
             PCTrailPoint pCTrailPoint2 = trail.Points[num - 1 + this.PointsBetweenControlPoints + 1];
             for (int j = 0; j < this.PointsBetweenControlPoints; j++)
             {
                 float t = ((float)j + 1f) / ((float)this.PointsBetweenControlPoints + 1f);
                 trail.Points[num].Position = this.GetPointAlongCurve(this._controlPoints[i].p, curveStartHandle, this._controlPoints[i + 1].p, curveEndHandle, t, 0.3f);
                 trail.Points[num].SetTimeActive(Mathf.Lerp(pCTrailPoint.TimeActive(), pCTrailPoint2.TimeActive(), t));
                 if (this.TrailData.UseForwardOverride)
                 {
                     trail.Points[num].Forward = Vector3.Lerp(pCTrailPoint.Forward, pCTrailPoint2.Forward, t);
                 }
                 num++;
             }
         }
     }
     int num3 = this._controlPoints.Count - 1 + (this._controlPoints.Count - 1) * this.PointsBetweenControlPoints;
     int num4 = num3 - this.PointsBetweenControlPoints - 1;
     int num5 = num3 + 1;
     float num6 = trail.Points[num4].GetDistanceFromStart();
     for (int k = num4 + 1; k < num5; k++)
     {
         num6 += Vector3.Distance(trail.Points[k - 1].Position, trail.Points[k].Position);
         trail.Points[k].SetDistanceFromStart(num6);
     }
 }
 private int NumberOfActivePoints(PCTrail line)
 {
     int count = 0;
     for (int index = 0; index < line.Points.Count; index++)
     {
         if (line.Points[index].TimeActive() < TrailData.Lifetime) count++;
     }
     return count;
 }
Ejemplo n.º 46
0
 private void CheckEmitChange()
 {
     if (this._emit != this.Emit)
     {
         this._emit = this.Emit;
         if (this._emit)
         {
             this._activeTrail = new PCTrail(this.GetMaxNumberOfPoints());
             this._activeTrail.IsActiveTrail = true;
             this.OnStartEmit();
         }
         else
         {
             this.OnStopEmit();
             this._activeTrail.IsActiveTrail = false;
             this._fadingTrails.Add(this._activeTrail);
             this._activeTrail = null;
         }
     }
 }
        private void GenerateMesh(PCTrail trail)
        {
            trail.Mesh.Clear(false);

            Vector3 camForward = Camera.main != null ? Camera.main.transform.forward : Vector3.forward;

            if(TrailData.UseForwardOverride)
            {
                camForward = TrailData.ForwardOverride.normalized;
            }

            trail.activePointCount = NumberOfActivePoints(trail);

            if (trail.activePointCount < 2)
                return;


            int vertIndex = 0;
            for (int i = 0; i < trail.Points.Count; i++)
            {
                PCTrailPoint p = trail.Points[i];
                float timeAlong = p.TimeActive()/TrailData.Lifetime;

                if(p.TimeActive() > TrailData.Lifetime)
                {
                    continue;
                }

                if (TrailData.UseForwardOverride && TrailData.ForwardOverrideRelative)
                    camForward = p.Forward;

                Vector3 cross = Vector3.zero;

                if (i < trail.Points.Count - 1)
                {
                    cross =
                        Vector3.Cross((trail.Points[i + 1].Position - p.Position).normalized, camForward).
                            normalized;
                }
                else
                {
                    cross =
                        Vector3.Cross((p.Position - trail.Points[i - 1].Position).normalized, camForward).
                            normalized;
                }


                //yuck! lets move these into their own functions some time
                Color c = TrailData.StretchColorToFit ?
                    (TrailData.UsingSimpleColor ? Color.Lerp(TrailData.SimpleColorOverLifeStart, TrailData.SimpleColorOverLifeEnd, 1 - ((float)vertIndex / (float)trail.activePointCount / 2f)) : TrailData.ColorOverLife.Evaluate(1 - ((float)vertIndex / (float)trail.activePointCount / 2f))) :
                    (TrailData.UsingSimpleColor ? Color.Lerp(TrailData.SimpleColorOverLifeStart,TrailData.SimpleColorOverLifeEnd,timeAlong) : TrailData.ColorOverLife.Evaluate(timeAlong));
                
                float s = TrailData.StretchSizeToFit ? 
                    (TrailData.UsingSimpleSize ? Mathf.Lerp(TrailData.SimpleSizeOverLifeStart,TrailData.SimpleSizeOverLifeEnd,1 - ((float)vertIndex / (float)trail.activePointCount / 2f)) : TrailData.SizeOverLife.Evaluate(1 - ((float)vertIndex / (float)trail.activePointCount / 2f))) : 
                    (TrailData.UsingSimpleSize ? Mathf.Lerp(TrailData.SimpleSizeOverLifeStart,TrailData.SimpleSizeOverLifeEnd, timeAlong) : TrailData.SizeOverLife.Evaluate(timeAlong));
                
                
                trail.verticies[vertIndex] = p.Position + cross * s;

                if(TrailData.MaterialTileLength <= 0)
                {
                    trail.uvs[vertIndex] = new Vector2((float)vertIndex / (float)trail.activePointCount / 2f, 0);
                }
                else
                {
                    trail.uvs[vertIndex] = new Vector2(p.GetDistanceFromStart() / TrailData.MaterialTileLength, 0);
                }

                trail.normals[vertIndex] = camForward;
                trail.colors[vertIndex] = c;
                vertIndex++;
                trail.verticies[vertIndex] = p.Position - cross * s;

                if (TrailData.MaterialTileLength <= 0)
                {
                    trail.uvs[vertIndex] = new Vector2((float)vertIndex / (float)trail.activePointCount / 2f, 1);
                }
                else
                {
                    trail.uvs[vertIndex] = new Vector2(p.GetDistanceFromStart() / TrailData.MaterialTileLength, 1);
                }

                trail.normals[vertIndex] = camForward;
                trail.colors[vertIndex] = c;

                vertIndex++;
            }

            Vector2 finalPosition = trail.verticies[vertIndex-1];
            for(int i = vertIndex; i < trail.verticies.Length; i++)
            {
                trail.verticies[i] = finalPosition;
            }

            int indIndex = 0;
            for (int pointIndex = 0; pointIndex < 2 * (trail.activePointCount - 1); pointIndex++)
            {
                if(pointIndex%2==0)
                {
                    trail.indicies[indIndex] = pointIndex;
                    indIndex++;
                    trail.indicies[indIndex] = pointIndex + 1;
                    indIndex++;
                    trail.indicies[indIndex] = pointIndex + 2;
                }
                else
                {
                    trail.indicies[indIndex] = pointIndex + 2;
                    indIndex++;
                    trail.indicies[indIndex] = pointIndex + 1;
                    indIndex++;
                    trail.indicies[indIndex] = pointIndex;
                }

                indIndex++;
            }

            int finalIndex = trail.indicies[indIndex-1];
            for (int i = indIndex; i < trail.indicies.Length; i++)
            {
                trail.indicies[i] = finalIndex;
            }

            trail.Mesh.vertices = trail.verticies;
            trail.Mesh.SetIndices(trail.indicies, MeshTopology.Triangles, 0);
            trail.Mesh.uv = trail.uvs;
            trail.Mesh.normals = trail.normals;
            trail.Mesh.colors = trail.colors;
        }
Ejemplo n.º 48
0
 protected virtual void OnDestroy()
 {
     TrailRenderer_Base.GlobalTrailRendererCount--;
     if (TrailRenderer_Base.GlobalTrailRendererCount == 0)
     {
         if (TrailRenderer_Base._toClean != null && TrailRenderer_Base._toClean.Count > 0)
         {
             foreach (Mesh current in TrailRenderer_Base._toClean)
             {
                 if (Application.isEditor)
                 {
                     UnityEngine.Object.DestroyImmediate(current, true);
                 }
                 else
                 {
                     UnityEngine.Object.Destroy(current);
                 }
             }
         }
         TrailRenderer_Base._toClean = null;
         TrailRenderer_Base._matToTrailList.Clear();
         TrailRenderer_Base._matToTrailList = null;
     }
     if (this._activeTrail != null)
     {
         this._activeTrail.Dispose();
         this._activeTrail = null;
     }
     if (this._fadingTrails != null)
     {
         foreach (PCTrail current2 in this._fadingTrails)
         {
             if (current2 != null)
             {
                 current2.Dispose();
             }
         }
         this._fadingTrails.Clear();
     }
 }
 protected virtual void UpdateTrail(PCTrail trail, float deltaTime)
 {
 }
        protected virtual void OnDestroy()
        {
            GlobalTrailRendererCount--;

            if(GlobalTrailRendererCount == 0)
            {
                if(_toClean != null && _toClean.Count > 0)
                {
                    foreach (Mesh mesh in _toClean)
                    {
                        if (Application.isEditor)
                            DestroyImmediate(mesh, true);
                        else
                            Destroy(mesh);
                    }
                }

                _toClean = null;
                _matToTrailList.Clear();
                _matToTrailList = null;
            }

            if (_activeTrail != null)
            {
                _activeTrail.Dispose();
                _activeTrail = null;
            }

            if (_fadingTrails != null)
            {
                foreach (PCTrail fadingTrail in _fadingTrails)
                {
                    if (fadingTrail != null)
                        fadingTrail.Dispose();
                }

                _fadingTrails.Clear();
            }
        }
        /// <summary>
        /// Insert a trail into this trail renderer. 
        /// </summary>
        /// <param name="from">The start position of the trail.</param>
        /// <param name="to">The end position of the trail.</param>
        /// <param name="distanceBetweenPoints">Distance between each point on the trail</param>
        public void CreateTrail(Vector3 from, Vector3 to, float distanceBetweenPoints)
        {
            float distanceBetween = Vector3.Distance(from, to);

            Vector3 dirVector = to - from;
            dirVector = dirVector.normalized;

            float currentLength = 0;

            CircularBuffer<PCTrailPoint> newLine = new CircularBuffer<PCTrailPoint>(GetMaxNumberOfPoints());
            int pointNumber = 0;
            while (currentLength < distanceBetween) 
            {
                PCTrailPoint newPoint = new PCTrailPoint();
                newPoint.PointNumber = pointNumber;
                newPoint.Position = from + dirVector*currentLength;
                newLine.Add(newPoint);
                InitialiseNewPoint(newPoint);

                pointNumber++;

                if (distanceBetweenPoints <= 0)
                    break;
                else
                    currentLength += distanceBetweenPoints;
            }

            PCTrailPoint lastPoint = new PCTrailPoint();
            lastPoint.PointNumber = pointNumber;
            lastPoint.Position = to;
            newLine.Add(lastPoint);
            InitialiseNewPoint(lastPoint);

            PCTrail newTrail = new PCTrail(GetMaxNumberOfPoints());
            newTrail.Points = newLine;

            _fadingTrails.Add(newTrail);
        }