public void Setup(TrailInitData initData, Transform pointStart, Transform pointEnd, Material material, bool editor) { PointStart = pointStart; PointEnd = pointEnd; Material = material; Granularity = initData.Granularity; TrailLength = initData.TrailLength; Whitestep = initData.Whitestep; SamplingFrequency = initData.SamplingFrequency; gameObject.layer = 12; if (editor) { SortingOrder = 3; } _elemPool = new ElementPool(TrailLength); _vertexPool = new VertexPool(Material, this); _vertexSegment = _vertexPool.GetVertices(Granularity * 3, (Granularity - 1) * 12); UpdateIndices(); _vertexPool.SetMeshObjectActive(false); _inited = true; }
private void LateUpdate() { if (!_inited) { return; } if (CapFps) { _time += Time.deltaTime; if (_time < 1f / 90) { return; } _time = 0; } _frameNum++; if (_frameNum == _skipFirstFrames + 1) { _vertexPool.SetMeshObjectActive(true); _spline.Granularity = Granularity; _spline.Clear(); for (int i = 0; i < TrailLength; i++) { _spline.AddControlPoint(CurHeadPos, PointStart.position - PointEnd.position); } _snapshotList.Clear(); _snapshotList.Add(new Element(PointStart.position, PointEnd.position)); _snapshotList.Add(new Element(PointStart.position, PointEnd.position)); } else if (_frameNum < _skipFirstFrames + 1) { return; } UpdateHeadElem(); RecordCurElem(); RefreshSpline(); UpdateVertex(); _vertexPool.LateUpdate(); }
public void Setup(TrailInitData initData, Transform pointStart, Transform pointEnd, Material material) { PointStart = pointStart; PointEnd = pointEnd; MyMaterial = material; Granularity = initData.Granularity; TrailLength = initData.TrailLength; Whitestep = initData.Whitestep; _elemPool = new ElementPool(TrailLength); _trailWidth = (PointStart.position - PointEnd.position).magnitude; _vertexPool = new VertexPool(MyMaterial, this); _vertexSegment = _vertexPool.GetVertices(Granularity * 3, (Granularity - 1) * 12); UpdateIndices(); _vertexPool.SetMeshObjectActive(false); _inited = true; }
private void OnDisable() { _vertexPool?.SetMeshObjectActive(false); }