13 this.batchSize = ((this.batches.Count > 0) ? this.batches[0].size : 1023);
14 if (!this.initialized || this.mesh ==
null)
26 this.shadowPass.Init();
30 this.initialized =
true;
32 this.idx = (this.batchIdx = 0);
36 public unsafe
void Add(
Point point,
float tile = 0f,
float color = 0f)
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;
46 this._batch.colors[this.idx] = color;
49 if (this.idx == this.batchSize)
56 public void Add(ref Vector3 v,
float tile = 0f,
float color = 0f)
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;
65 this._batch.colors[this.idx] = color;
68 if (this.idx == this.batchSize)
75 public void Add(
float x,
float y,
float z,
float tile = 0f,
float color = 0f)
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;
84 this._batch.colors[this.idx] = color;
87 if (this.idx == this.batchSize)
94 public void AddWithScale(
float x,
float y,
float z,
int tile,
float scale)
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;
106 if (this.idx == this.batchSize)
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;
122 this._batch.tiles[this.idx] = p.tile;
125 if (this.idx == this.batchSize)
132 public void AddShadow(
float x,
float y,
float z,
ShadowData.
Item s,
SourcePref pref,
int dir = 0,
bool snow =
false)
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;
148 matrices[this.idx].m00 = num;
149 matrices[this.idx].m01 = 0f;
150 matrices[this.idx].m10 = 0f;
151 matrices[this.idx].m11 = num2;
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;
164 this._batch.tiles[this.idx] = (float)((s.tile + (snow ? 1000 : 0)) * num3);
166 if (this.idx == this.batchSize)
173 public void AddWithRotation(
float x,
float y,
float z,
float sx,
float sy,
int tile,
float angle,
bool flip)
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);
195 if (this.idx == this.batchSize)
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;
210 this._batch.tiles[this.idx] = p.tile;
214 this._batch.colors[this.idx] = p.color;
216 if (this.setMatColor)
218 this._batch.matColors[this.idx] = p.matColor;
221 if (this.idx == this.batchSize)
228 public void Add(
float x,
float y,
float z,
float tile,
float color,
float matColor = 0f)
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;
237 this._batch.colors[this.idx] = color;
239 if (this.setMatColor)
241 this._batch.matColors[this.idx] = matColor;
244 if (this.idx == this.batchSize)
251 public void Add(
MeshPassParam p,
float tile,
float color,
float matColor = 0f)
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;
260 this._batch.colors[this.idx] = color;
262 if (this.setMatColor)
264 this._batch.matColors[this.idx] = matColor;
267 if (this.idx == this.batchSize)
276 if (this.haveSnowPass)
278 this.snowPass.Draw();
280 if (this.haveSubPass)
284 if (this.haveShadowPass)
286 this.shadowPass.Draw();
288 if (this.idx == 0 && this.batchIdx == 0)
292 for (
int i = 0; i < this.batchIdx + 1; i++)
294 int num = (i == this.batchIdx) ? this.idx : this.batches[i].size;
301 this.batches[i].mpb.SetFloatArray(
"_Tiles", this.batches[i].tiles);
305 this.batches[i].mpb.SetFloatArray(
"_Color", this.batches[i].colors);
307 if (this.setMatColor)
309 this.batches[i].mpb.SetFloatArray(
"_MatColor", this.batches[i].matColors);
311 if (this.renderQueue != 0)
313 if (this.batches[i].mat ==
null)
315 this.batches[i].mat =
new Material(this.mat);
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);
322 Graphics.DrawMeshInstanced(this.mesh, 0, this.mat, this.batches[i].matrices, num, this.batches[i].mpb, ShadowCastingMode.Off,
false, 0, Camera.main);
325 this.lastBatchCount = this.batchIdx;
326 this.lastCount = this.batchIdx * this.batchSize + this.idx;
327 this.idx = (this.batchIdx = 0);
330 Debug.Log(
"#pass Resize Pass:" + base.name);
337 public void DrawEmpty()
339 this.idx = (this.batchIdx = 0);
343 public void NextBatch()
347 if (this.batchIdx >= this.batches.Count)
349 if (this.batchSize != 1023)
351 this.batchSize = 1023;
359 private Mesh SpriteToMesh(Sprite sprite)
361 Mesh mesh =
new Mesh();
362 mesh.SetVertices(Array.ConvertAll<Vector2, Vector3>(sprite.vertices, (Vector2 c) => c).ToList<Vector3>());
364 mesh.SetTriangles(Array.ConvertAll<ushort,
int>(sprite.triangles, (ushort c) => (
int)c), 0);
369 public override string ToString()
375 public void Refresh()
377 if (!Application.isPlaying)
381 UnityEngine.Object.DestroyImmediate(this.mesh);
382 foreach (
MeshPass meshPass
in Core.Instance.scene.passes)
384 meshPass.initialized =
false;
385 meshPass.batches.Clear();
397 return this.pmesh.size.x;
401 this.pmesh.size.x = value;
406 public void OnValidate()
412 public void _Refresh()
414 this.haveSubPass = this.subPass;
415 this.haveShadowPass = this.shadowPass;
416 this.haveSnowPass = this.snowPass;
421 this.mesh = this.pmesh.GetMesh();
423 else if (this.sprite)
425 this.mesh = this.SpriteToMesh(this.sprite);
428 if (this.haveSnowPass)
430 this.snowPass.mesh = this.mesh;
432 if (this.haveSubPass)
434 this.subPass.mesh = this.mesh;
436 if (this.haveShadowPass)
438 this.shadowPass.mesh = this.mesh;
443 public const int TokenLiquid = 10000;
446 public const int TokenLowWall = 1000000;
449 public const int TokenLowWallDefault = 3000000;
470 public Sprite sprite;
476 public bool setColor;
479 public bool setMatColor;
482 public bool setExtra;
485 public int renderQueue;
491 public FilterMode filter;
494 public int lastCount;
497 public int lastBatchCount;
501 public bool haveSubPass;
505 public bool haveShadowPass;
509 public bool haveSnowPass;
521 public int batchSize = 1023;
525 public List<MeshBatch> batches =
new List<MeshBatch>();
529 private bool initialized;
537 public Texture preserveTex;
543 private Vector3 tempV = Vector3.zero;
546 private Vector2 tempE = Vector2.zero;
550 private bool first =
true;