1
1
using System . Collections . Generic ;
2
+ using SaberFactory . Helpers ;
2
3
using SaberFactory . Misc ;
3
4
using UnityEngine ;
4
5
@@ -7,9 +8,11 @@ namespace SaberFactory.Instances.Trail
7
8
internal class SFTrail : MonoBehaviour
8
9
{
9
10
public static bool CapFps ;
11
+
10
12
protected float TrailWidth => ( PointStart . position - PointEnd . position ) . magnitude ;
11
13
12
14
public Vector3 CurHeadPos => ( PStartPos + PEndPos ) / 2f ;
15
+
13
16
public Color Color = Color . white ;
14
17
public int Granularity = 60 ;
15
18
public int SamplingFrequency = 20 ;
@@ -31,9 +34,11 @@ internal class SFTrail : MonoBehaviour
31
34
protected VertexPool . VertexSegment _vertexSegment ;
32
35
33
36
private readonly int _skipFirstFrames = 4 ;
37
+
34
38
private int _frameNum ;
35
39
private float _time ;
36
40
private bool _relativeMode ;
41
+ private ImmediateDrawer _immediateDrawer ;
37
42
38
43
public bool RelativeMode
39
44
{
@@ -60,6 +65,56 @@ private Vector3 GetPlayerOffset()
60
65
return PlayerTransforms . transform . position ;
61
66
}
62
67
68
+ private void OnEnable ( )
69
+ {
70
+ _vertexPool ? . SetMeshObjectActive ( true ) ;
71
+ }
72
+
73
+ private void OnDisable ( )
74
+ {
75
+ _vertexPool ? . SetMeshObjectActive ( false ) ;
76
+ }
77
+
78
+ private void OnDestroy ( )
79
+ {
80
+ if ( ! _inited || _vertexPool == null )
81
+ {
82
+ return ;
83
+ }
84
+
85
+ _vertexPool . Destroy ( ) ;
86
+ }
87
+
88
+ public void Setup ( TrailInitData initData , Transform pointStart , Transform pointEnd , Material material , bool editor )
89
+ {
90
+ PointStart = pointStart ;
91
+ PointEnd = pointEnd ;
92
+ Material = material ;
93
+ Granularity = initData . Granularity ;
94
+ TrailLength = initData . TrailLength ;
95
+ Whitestep = initData . Whitestep ;
96
+ SamplingFrequency = initData . SamplingFrequency ;
97
+
98
+ #if DEBUG
99
+ _immediateDrawer = new ImmediateDrawer ( ) ;
100
+ #endif
101
+
102
+ gameObject . layer = 12 ;
103
+ if ( editor )
104
+ {
105
+ SortingOrder = 3 ;
106
+ }
107
+
108
+ _elemPool = new ElementPool ( TrailLength ) ;
109
+ _vertexPool = new VertexPool ( Material , this ) ;
110
+ _vertexSegment = _vertexPool . GetVertices ( Granularity * 3 , ( Granularity - 1 ) * 12 ) ;
111
+ UpdateIndices ( ) ;
112
+
113
+ _vertexPool . SetMeshObjectActive ( false ) ;
114
+
115
+ _inited = true ;
116
+ }
117
+
63
118
private void LateUpdate ( )
64
119
{
65
120
// if (PlayerTransforms)
@@ -124,58 +179,12 @@ private void LateUpdate()
124
179
_snapshotList [ 1 ] . PointStart -= offset ;
125
180
_snapshotList [ 1 ] . PointEnd -= offset ;
126
181
}
127
-
182
+
128
183
RefreshSpline ( ) ;
129
184
UpdateVertex ( ) ;
130
185
_vertexPool . LateUpdate ( ) ;
131
186
}
132
187
133
- private void OnEnable ( )
134
- {
135
- _vertexPool ? . SetMeshObjectActive ( true ) ;
136
- }
137
-
138
- private void OnDisable ( )
139
- {
140
- _vertexPool ? . SetMeshObjectActive ( false ) ;
141
- }
142
-
143
- private void OnDestroy ( )
144
- {
145
- if ( ! _inited || _vertexPool == null )
146
- {
147
- return ;
148
- }
149
-
150
- _vertexPool . Destroy ( ) ;
151
- }
152
-
153
- public void Setup ( TrailInitData initData , Transform pointStart , Transform pointEnd , Material material , bool editor )
154
- {
155
- PointStart = pointStart ;
156
- PointEnd = pointEnd ;
157
- Material = material ;
158
- Granularity = initData . Granularity ;
159
- TrailLength = initData . TrailLength ;
160
- Whitestep = initData . Whitestep ;
161
- SamplingFrequency = initData . SamplingFrequency ;
162
-
163
- gameObject . layer = 12 ;
164
- if ( editor )
165
- {
166
- SortingOrder = 3 ;
167
- }
168
-
169
- _elemPool = new ElementPool ( TrailLength ) ;
170
- _vertexPool = new VertexPool ( Material , this ) ;
171
- _vertexSegment = _vertexPool . GetVertices ( Granularity * 3 , ( Granularity - 1 ) * 12 ) ;
172
- UpdateIndices ( ) ;
173
-
174
- _vertexPool . SetMeshObjectActive ( false ) ;
175
-
176
- _inited = true ;
177
- }
178
-
179
188
public void SetMaterialBlock ( MaterialPropertyBlock block )
180
189
{
181
190
if ( _vertexPool == null || ! _vertexPool . MeshRenderer )
@@ -191,6 +200,9 @@ private void RefreshSpline()
191
200
for ( var i = 0 ; i < _snapshotList . Count ; i ++ )
192
201
{
193
202
_spline . ControlPoints [ i ] . Position = _snapshotList [ i ] . Pos ;
203
+ #if DEBUG
204
+ _immediateDrawer . DrawSmallBall ( _spline . ControlPoints [ i ] . Position ) ;
205
+ #endif
194
206
_spline . ControlPoints [ i ] . Normal = _snapshotList [ i ] . PointEnd - _snapshotList [ i ] . PointStart ;
195
207
}
196
208
@@ -249,10 +261,14 @@ private void UpdateVertex()
249
261
uvCoord . x = 1f ;
250
262
uvCoord . y = uvSegment ;
251
263
pool . UVs [ baseIdx + 2 ] = uvCoord ;
264
+
265
+ #if DEBUG
266
+ _immediateDrawer . DrawSmallBall ( pos0 , Color . green ) ;
267
+ _immediateDrawer . DrawSmallBall ( pos1 , Color . green ) ;
268
+ #endif
252
269
}
253
270
254
271
_vertexSegment . Pool . UVChanged = true ;
255
- _vertexSegment . Pool . VertChanged = true ;
256
272
_vertexSegment . Pool . ColorChanged = true ;
257
273
}
258
274
0 commit comments