Elin Modding Docs Doc
Loading...
Searching...
No Matches
MeshPass.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using UnityEngine;
5using UnityEngine.Rendering;
6
7// Token: 0x0200012B RID: 299
8public class MeshPass : ScriptableObject
9{
10 // Token: 0x060007FE RID: 2046 RVA: 0x00033AFC File Offset: 0x00031CFC
11 public void Init()
12 {
13 this.batchSize = ((this.batches.Count > 0) ? this.batches[0].size : 1023);
14 if (!this.initialized || this.mesh == null)
15 {
16 if (this.subPass)
17 {
18 this.subPass.Init();
19 }
20 if (this.snowPass)
21 {
22 this.snowPass.Init();
23 }
24 if (this.shadowPass)
25 {
26 this.shadowPass.Init();
27 }
28 this.batches.Add(new MeshBatch(this));
29 this._Refresh();
30 this.initialized = true;
31 }
32 this.idx = (this.batchIdx = 0);
33 }
34
35 // Token: 0x060007FF RID: 2047 RVA: 0x00033BC4 File Offset: 0x00031DC4
36 public unsafe void Add(Point point, float tile = 0f, float color = 0f)
37 {
38 Vector3 vector = *point.Position();
39 this._batch = this.batches[this.batchIdx];
40 this._batch.matrices[this.idx].m03 = vector.x;
41 this._batch.matrices[this.idx].m13 = vector.y;
42 this._batch.matrices[this.idx].m23 = vector.z;
43 this._batch.tiles[this.idx] = tile;
44 if (this.setColor)
45 {
46 this._batch.colors[this.idx] = color;
47 }
48 this.idx++;
49 if (this.idx == this.batchSize)
50 {
51 this.NextBatch();
52 }
53 }
54
55 // Token: 0x06000800 RID: 2048 RVA: 0x00033CA8 File Offset: 0x00031EA8
56 public void Add(ref Vector3 v, float tile = 0f, float color = 0f)
57 {
58 this._batch = this.batches[this.batchIdx];
59 this._batch.matrices[this.idx].m03 = v.x;
60 this._batch.matrices[this.idx].m13 = v.y;
61 this._batch.matrices[this.idx].m23 = v.z;
62 this._batch.tiles[this.idx] = tile;
63 if (this.setColor)
64 {
65 this._batch.colors[this.idx] = color;
66 }
67 this.idx++;
68 if (this.idx == this.batchSize)
69 {
70 this.NextBatch();
71 }
72 }
73
74 // Token: 0x06000801 RID: 2049 RVA: 0x00033D80 File Offset: 0x00031F80
75 public void Add(float x, float y, float z, float tile = 0f, float color = 0f)
76 {
77 this._batch = this.batches[this.batchIdx];
78 this._batch.matrices[this.idx].m03 = x;
79 this._batch.matrices[this.idx].m13 = y;
80 this._batch.matrices[this.idx].m23 = z;
81 this._batch.tiles[this.idx] = tile;
82 if (this.setColor)
83 {
84 this._batch.colors[this.idx] = color;
85 }
86 this.idx++;
87 if (this.idx == this.batchSize)
88 {
89 this.NextBatch();
90 }
91 }
92
93 // Token: 0x06000802 RID: 2050 RVA: 0x00033E4C File Offset: 0x0003204C
94 public void AddWithScale(float x, float y, float z, int tile, float scale)
95 {
96 this._batch = this.batches[this.batchIdx];
97 Matrix4x4[] matrices = this._batch.matrices;
98 float num = -scale / 2f + 0.5f;
99 matrices[this.idx].m03 = x + num;
100 matrices[this.idx].m13 = y + num;
101 matrices[this.idx].m23 = z;
102 matrices[this.idx].m00 = scale;
103 matrices[this.idx].m11 = scale;
104 this._batch.tiles[this.idx] = (float)tile;
105 this.idx++;
106 if (this.idx == this.batchSize)
107 {
108 this.NextBatch();
109 }
110 }
111
112 // Token: 0x06000803 RID: 2051 RVA: 0x00033F24 File Offset: 0x00032124
113 public void AddShadow(MeshPassParam p, ref Vector3 fix)
114 {
115 this._batch = this.batches[this.batchIdx];
116 this._batch.matrices[this.idx].SetTRS(Vector3.zero, Quaternion.Euler(0f, 0f, 0f), Vector3.one);
117 this._batch.matrices[this.idx].m03 = p.x + fix.x;
118 this._batch.matrices[this.idx].m13 = p.y + fix.y;
119 this._batch.matrices[this.idx].m23 = p.z + fix.z;
120 if (this.setTile)
121 {
122 this._batch.tiles[this.idx] = p.tile;
123 }
124 this.idx++;
125 if (this.idx == this.batchSize)
126 {
127 this.NextBatch();
128 }
129 }
130
131 // Token: 0x06000804 RID: 2052 RVA: 0x0003403C File Offset: 0x0003223C
132 public void AddShadow(float x, float y, float z, ShadowData.Item s, SourcePref pref, int dir = 0, bool snow = false)
133 {
134 int angle = s.angle;
135 float num = (float)s.scaleX * 0.01f;
136 float num2 = (float)s.scaleY * 0.01f;
137 bool flag = dir % 2 == 1;
138 int num3 = flag ? 1 : -1;
139 this._batch = this.batches[this.batchIdx];
140 Matrix4x4[] matrices = this._batch.matrices;
141 matrices[this.idx].m03 = x - 0.01f * (float)((dir >= 2) ? (flag ? pref.shadowBRX : pref.shadowBX) : (flag ? pref.shadowRX : pref.shadowX)) + ((0.7f * -num + 0.7f) * (float)num3 + (float)s.x * 0.01f) * (float)num3;
142 matrices[this.idx].m13 = y - 0.01f * (float)((dir >= 2) ? (flag ? pref.shadowBRY : pref.shadowBY) : (flag ? pref.shadowRY : pref.shadowY)) + 0.6f * -num2 + 0.6f + (float)s.y * 0.01f;
143 matrices[this.idx].m23 = z;
144 matrices[this.idx].m00 = num;
145 matrices[this.idx].m11 = num2;
146 if (angle == 0)
147 {
148 matrices[this.idx].m00 = num;
149 matrices[this.idx].m01 = 0f;
150 matrices[this.idx].m10 = 0f;
151 matrices[this.idx].m11 = num2;
152 }
153 else
154 {
155 this.tempV.z = (float)(-(float)angle);
156 Quaternion quaternion = Quaternion.Euler(0f, 0f, (float)(-(float)angle));
157 this.tempE.x = 1f - quaternion.z * quaternion.z * 2f;
158 this.tempE.y = -quaternion.w * quaternion.z * 2f;
159 matrices[this.idx].m00 = this.tempE.x * num;
160 matrices[this.idx].m01 = this.tempE.y * num2;
161 matrices[this.idx].m10 = -this.tempE.y * num;
162 matrices[this.idx].m11 = this.tempE.x * num2;
163 }
164 this._batch.tiles[this.idx] = (float)((s.tile + (snow ? 1000 : 0)) * num3);
165 this.idx++;
166 if (this.idx == this.batchSize)
167 {
168 this.NextBatch();
169 }
170 }
171
172 // Token: 0x06000805 RID: 2053 RVA: 0x00034340 File Offset: 0x00032540
173 public void AddWithRotation(float x, float y, float z, float sx, float sy, int tile, float angle, bool flip)
174 {
175 float num = 1f;
176 float num2 = 1f;
177 int num3 = flip ? -1 : 1;
178 this._batch = this.batches[this.batchIdx];
179 Matrix4x4[] matrices = this._batch.matrices;
180 matrices[this.idx].m03 = x + ((0.7f * -num + 0.7f) * (float)num3 + sx * 0.01f) * (float)num3;
181 matrices[this.idx].m13 = y + 0.6f * -num2 + 0.6f + sy * 0.01f;
182 matrices[this.idx].m23 = z;
183 matrices[this.idx].m00 = num;
184 matrices[this.idx].m11 = num2;
185 this.tempV.z = -angle;
186 Quaternion quaternion = Quaternion.Euler(0f, 0f, -angle);
187 this.tempE.x = 1f - quaternion.z * quaternion.z * 2f;
188 this.tempE.y = -quaternion.w * quaternion.z * 2f;
189 matrices[this.idx].m00 = this.tempE.x * num;
190 matrices[this.idx].m01 = this.tempE.y * num2;
191 matrices[this.idx].m10 = -this.tempE.y * num;
192 matrices[this.idx].m11 = this.tempE.x * num2;
193 this._batch.tiles[this.idx] = (float)(tile * num3);
194 this.idx++;
195 if (this.idx == this.batchSize)
196 {
197 this.NextBatch();
198 }
199 }
200
201 // Token: 0x06000806 RID: 2054 RVA: 0x0003452C File Offset: 0x0003272C
202 public void Add(MeshPassParam p)
203 {
204 this._batch = this.batches[this.batchIdx];
205 this._batch.matrices[this.idx].m03 = p.x;
206 this._batch.matrices[this.idx].m13 = p.y;
207 this._batch.matrices[this.idx].m23 = p.z;
208 if (this.setTile)
209 {
210 this._batch.tiles[this.idx] = p.tile;
211 }
212 if (this.setColor)
213 {
214 this._batch.colors[this.idx] = p.color;
215 }
216 if (this.setMatColor)
217 {
218 this._batch.matColors[this.idx] = p.matColor;
219 }
220 this.idx++;
221 if (this.idx == this.batchSize)
222 {
223 this.NextBatch();
224 }
225 }
226
227 // Token: 0x06000807 RID: 2055 RVA: 0x00034638 File Offset: 0x00032838
228 public void Add(float x, float y, float z, float tile, float color, float matColor = 0f)
229 {
230 this._batch = this.batches[this.batchIdx];
231 this._batch.matrices[this.idx].m03 = x;
232 this._batch.matrices[this.idx].m13 = y;
233 this._batch.matrices[this.idx].m23 = z;
234 this._batch.tiles[this.idx] = tile;
235 if (this.setColor)
236 {
237 this._batch.colors[this.idx] = color;
238 }
239 if (this.setMatColor)
240 {
241 this._batch.matColors[this.idx] = matColor;
242 }
243 this.idx++;
244 if (this.idx == this.batchSize)
245 {
246 this.NextBatch();
247 }
248 }
249
250 // Token: 0x06000808 RID: 2056 RVA: 0x00034720 File Offset: 0x00032920
251 public void Add(MeshPassParam p, float tile, float color, float matColor = 0f)
252 {
253 this._batch = this.batches[this.batchIdx];
254 this._batch.matrices[this.idx].m03 = p.x;
255 this._batch.matrices[this.idx].m13 = p.y;
256 this._batch.matrices[this.idx].m23 = p.z;
257 this._batch.tiles[this.idx] = tile;
258 if (this.setColor)
259 {
260 this._batch.colors[this.idx] = color;
261 }
262 if (this.setMatColor)
263 {
264 this._batch.matColors[this.idx] = matColor;
265 }
266 this.idx++;
267 if (this.idx == this.batchSize)
268 {
269 this.NextBatch();
270 }
271 }
272
273 // Token: 0x06000809 RID: 2057 RVA: 0x00034814 File Offset: 0x00032A14
274 public void Draw()
275 {
276 if (this.haveSnowPass)
277 {
278 this.snowPass.Draw();
279 }
280 if (this.haveSubPass)
281 {
282 this.subPass.Draw();
283 }
284 if (this.haveShadowPass)
285 {
286 this.shadowPass.Draw();
287 }
288 if (this.idx == 0 && this.batchIdx == 0)
289 {
290 return;
291 }
292 for (int i = 0; i < this.batchIdx + 1; i++)
293 {
294 int num = (i == this.batchIdx) ? this.idx : this.batches[i].size;
295 if (num == 0)
296 {
297 break;
298 }
299 if (this.setTile)
300 {
301 this.batches[i].mpb.SetFloatArray("_Tiles", this.batches[i].tiles);
302 }
303 if (this.setColor)
304 {
305 this.batches[i].mpb.SetFloatArray("_Color", this.batches[i].colors);
306 }
307 if (this.setMatColor)
308 {
309 this.batches[i].mpb.SetFloatArray("_MatColor", this.batches[i].matColors);
310 }
311 if (this.renderQueue != 0)
312 {
313 if (this.batches[i].mat == null)
314 {
315 this.batches[i].mat = new Material(this.mat);
316 }
317 this.batches[i].mat.renderQueue = this.renderQueue + i;
318 Graphics.DrawMeshInstanced(this.mesh, 0, this.batches[i].mat, this.batches[i].matrices, num, this.batches[i].mpb, ShadowCastingMode.Off, false, 0, Camera.main);
319 }
320 else
321 {
322 Graphics.DrawMeshInstanced(this.mesh, 0, this.mat, this.batches[i].matrices, num, this.batches[i].mpb, ShadowCastingMode.Off, false, 0, Camera.main);
323 }
324 }
325 this.lastBatchCount = this.batchIdx;
326 this.lastCount = this.batchIdx * this.batchSize + this.idx;
327 this.idx = (this.batchIdx = 0);
328 if (this.resize)
329 {
330 Debug.Log("#pass Resize Pass:" + base.name);
331 this.resize = false;
332 this.batches[0] = new MeshBatch(this);
333 }
334 }
335
336 // Token: 0x0600080A RID: 2058 RVA: 0x00034A9C File Offset: 0x00032C9C
337 public void DrawEmpty()
338 {
339 this.idx = (this.batchIdx = 0);
340 }
341
342 // Token: 0x0600080B RID: 2059 RVA: 0x00034ABC File Offset: 0x00032CBC
343 public void NextBatch()
344 {
345 this.idx = 0;
346 this.batchIdx++;
347 if (this.batchIdx >= this.batches.Count)
348 {
349 if (this.batchSize != 1023)
350 {
351 this.batchSize = 1023;
352 this.resize = true;
353 }
354 this.batches.Add(new MeshBatch(this));
355 }
356 }
357
358 // Token: 0x0600080C RID: 2060 RVA: 0x00034B24 File Offset: 0x00032D24
359 private Mesh SpriteToMesh(Sprite sprite)
360 {
361 Mesh mesh = new Mesh();
362 mesh.SetVertices(Array.ConvertAll<Vector2, Vector3>(sprite.vertices, (Vector2 c) => c).ToList<Vector3>());
363 mesh.uv = sprite.uv;
364 mesh.SetTriangles(Array.ConvertAll<ushort, int>(sprite.triangles, (ushort c) => (int)c), 0);
365 return mesh;
366 }
367
368 // Token: 0x0600080D RID: 2061 RVA: 0x00034BA8 File Offset: 0x00032DA8
369 public override string ToString()
370 {
371 return base.name;
372 }
373
374 // Token: 0x0600080E RID: 2062 RVA: 0x00034BB0 File Offset: 0x00032DB0
375 public void Refresh()
376 {
377 if (!Application.isPlaying)
378 {
379 return;
380 }
381 UnityEngine.Object.DestroyImmediate(this.mesh);
382 foreach (MeshPass meshPass in Core.Instance.scene.passes)
383 {
384 meshPass.initialized = false;
385 meshPass.batches.Clear();
386 meshPass.Init();
387 }
388 }
389
390 // Token: 0x170001C6 RID: 454
391 // (get) Token: 0x0600080F RID: 2063 RVA: 0x00034C08 File Offset: 0x00032E08
392 // (set) Token: 0x06000810 RID: 2064 RVA: 0x00034C1A File Offset: 0x00032E1A
393 public float meshX
394 {
395 get
396 {
397 return this.pmesh.size.x;
398 }
399 set
400 {
401 this.pmesh.size.x = value;
402 }
403 }
404
405 // Token: 0x06000811 RID: 2065 RVA: 0x00034C2D File Offset: 0x00032E2D
406 public void OnValidate()
407 {
408 this.Refresh();
409 }
410
411 // Token: 0x06000812 RID: 2066 RVA: 0x00034C38 File Offset: 0x00032E38
412 public void _Refresh()
413 {
414 this.haveSubPass = this.subPass;
415 this.haveShadowPass = this.shadowPass;
416 this.haveSnowPass = this.snowPass;
417 if (!this.mesh)
418 {
419 if (this.pmesh)
420 {
421 this.mesh = this.pmesh.GetMesh();
422 }
423 else if (this.sprite)
424 {
425 this.mesh = this.SpriteToMesh(this.sprite);
426 }
427 }
428 if (this.haveSnowPass)
429 {
430 this.snowPass.mesh = this.mesh;
431 }
432 if (this.haveSubPass)
433 {
434 this.subPass.mesh = this.mesh;
435 }
436 if (this.haveShadowPass)
437 {
438 this.shadowPass.mesh = this.mesh;
439 }
440 }
441
442 // Token: 0x04000841 RID: 2113
443 public const int TokenLiquid = 10000;
444
445 // Token: 0x04000842 RID: 2114
446 public const int TokenLowWall = 1000000;
447
448 // Token: 0x04000843 RID: 2115
449 public const int TokenLowWallDefault = 3000000;
450
451 // Token: 0x04000844 RID: 2116
452 public MeshPass subPass;
453
454 // Token: 0x04000845 RID: 2117
455 public MeshPass snowPass;
456
457 // Token: 0x04000846 RID: 2118
458 public MeshPass shadowPass;
459
460 // Token: 0x04000847 RID: 2119
461 public Material mat;
462
463 // Token: 0x04000848 RID: 2120
464 public Mesh mesh;
465
466 // Token: 0x04000849 RID: 2121
467 public ProceduralMesh pmesh;
468
469 // Token: 0x0400084A RID: 2122
470 public Sprite sprite;
471
472 // Token: 0x0400084B RID: 2123
473 public bool setTile;
474
475 // Token: 0x0400084C RID: 2124
476 public bool setColor;
477
478 // Token: 0x0400084D RID: 2125
479 public bool setMatColor;
480
481 // Token: 0x0400084E RID: 2126
482 public bool setExtra;
483
484 // Token: 0x0400084F RID: 2127
485 public int renderQueue;
486
487 // Token: 0x04000850 RID: 2128
488 public MeshPassParam _p = new MeshPassParam();
489
490 // Token: 0x04000851 RID: 2129
491 public FilterMode filter;
492
493 // Token: 0x04000852 RID: 2130
494 public int lastCount;
495
496 // Token: 0x04000853 RID: 2131
497 public int lastBatchCount;
498
499 // Token: 0x04000854 RID: 2132
500 [NonSerialized]
501 public bool haveSubPass;
502
503 // Token: 0x04000855 RID: 2133
504 [NonSerialized]
505 public bool haveShadowPass;
506
507 // Token: 0x04000856 RID: 2134
508 [NonSerialized]
509 public bool haveSnowPass;
510
511 // Token: 0x04000857 RID: 2135
512 [NonSerialized]
513 public int idx;
514
515 // Token: 0x04000858 RID: 2136
516 [NonSerialized]
517 public int batchIdx;
518
519 // Token: 0x04000859 RID: 2137
520 [NonSerialized]
521 public int batchSize = 1023;
522
523 // Token: 0x0400085A RID: 2138
524 [NonSerialized]
525 public List<MeshBatch> batches = new List<MeshBatch>();
526
527 // Token: 0x0400085B RID: 2139
528 [NonSerialized]
529 private bool initialized;
530
531 // Token: 0x0400085C RID: 2140
532 [NonSerialized]
533 private bool resize;
534
535 // Token: 0x0400085D RID: 2141
536 [NonSerialized]
537 public Texture preserveTex;
538
539 // Token: 0x0400085E RID: 2142
540 private MeshBatch _batch;
541
542 // Token: 0x0400085F RID: 2143
543 private Vector3 tempV = Vector3.zero;
544
545 // Token: 0x04000860 RID: 2144
546 private Vector2 tempE = Vector2.zero;
547
548 // Token: 0x04000861 RID: 2145
549 [NonSerialized]
550 private bool first = true;
551}
Definition Point.cs:11