public void Update() { foreach (var b in toRemove) { behaviours.Remove(b); } foreach (var b in toAdd) { behaviours.Add(b); } toAdd.Clear(); toRemove.Clear(); foreach (var b in behaviours) { b.__InitializeUpdate(); } PRun.Split(behaviours.Count, (left, right) => { for (int i = left; i < right; i++) { behaviours[i].__FastUpdate(); } }); foreach (var b in behaviours) { b.__SlowUpdate(); } }
public void UpdateMesh() { int t_count = toRemove.Count; int t_i; for (int i = 0; i < t_count; i++) { t_i = toRemove[i]; count--; var t = shots[t_i]; shots[t_i] = shots[count]; shots[count] = t; } toRemove.Clear(); tris = arrayPool.GetArray(count); camPos = Camera.main.transform.position; deltaTime = Time.deltaTime; PRun.Split(count, UpdateShots); mesh.vertices = verts; mesh.SetTriangles(tris, 0, false); mesh.uv = uvs; mesh.bounds = new Bounds(Vector3.zero, new Vector3(float.MaxValue, float.MaxValue, float.MaxValue)); for (int i = 0; i < count; i++) { if (shots[i].dead < Time.time) { toRemove.Add(i); } else { RaycastHit hit; if (CheckHits(Physics.RaycastNonAlloc(shots[i].back, shots[i].pos - shots[i].back, hits, shots[i].distance, Constants.shotMask), shots[i], out hit)) { shots[i].shot.Hit(hit); toRemove.Add(i); } } } }
public void UpdateMesh() { foreach (var i in toRemove) { count--; var t = shots[i]; shots[i] = shots[count]; shots[count] = t; } toRemove.Clear(); int ntris = count * 6; if (tris.Length != ntris) { tris = new int[ntris]; } Vector3 camPos = camera.position; //PRun.For(count, i => PRun.Split(count, (left, right) => { for (int i = left; i < right; i++) { int n = i * 4; int n1 = n + 1; int n2 = n + 2; int n3 = n + 3; Vector3 up = Vector3.Cross(shots[i].back - camPos, shots[i].dir); up.Normalize(); up *= shots[i].width; switch (shots[i].type) { case SizeType.Dynamic: verts[n] = shots[i].back - up; verts[n1] = shots[i].pos - up; verts[n2] = shots[i].back + up; verts[n3] = shots[i].pos + up; break; case SizeType.Static: var back = shots[i].pos - shots[i].dir * shots[i].length; verts[n] = back - up; verts[n1] = shots[i].pos - up; verts[n2] = back + up; verts[n3] = shots[i].pos + up; break; } int nuv = i * 4; uvs[nuv] = shots[i].uvRect.leftBot; uvs[nuv + 1] = shots[i].uvRect.rightBot; uvs[nuv + 2] = shots[i].uvRect.leftTop; uvs[nuv + 3] = shots[i].uvRect.rightTop; int nt = i * 6; tris[nt] = n; tris[nt + 1] = n2; tris[nt + 2] = n1; tris[nt + 3] = n2; tris[nt + 4] = n3; tris[nt + 5] = n1; } }); mesh.vertices = verts; mesh.SetTriangles(tris, 0, false); //mesh.triangles = tris; mesh.uv = uvs; mesh.bounds = new Bounds(Vector3.zero, new Vector3(float.MaxValue, float.MaxValue, float.MaxValue)); for (int i = 0; i < count; i++) { if (shots[i].dead < Time.time) { toRemove.Add(i); } else { shots[i].back = shots[i].pos; float distance = shots[i].speed * Time.deltaTime; shots[i].pos += shots[i].dir * distance; RaycastHit hit; if (Physics.Raycast(shots[i].back, shots[i].pos - shots[i].back, out hit, distance)) { if (hit.transform.IsOne(shots[i].friend)) { continue; } shots[i].shot.Hit(hit); toRemove.Add(i); } } } }