public static void EnsureGraphicsExist() { if (singleton == null) { GameObject obj2 = GameObject.Find("__LASER_GRAPHICS__"); if (obj2 == null) { obj2 = new GameObject { hideFlags = HideFlags.NotEditable | HideFlags.DontSave, name = "__LASER_GRAPHICS__" }; singleton = obj2.AddComponent <LaserGraphics>(); singleton.hideFlags = HideFlags.NotEditable | HideFlags.DontSave; } else { singleton = obj2.GetComponent <LaserGraphics>(); if (singleton == null) { singleton = obj2.AddComponent <LaserGraphics>(); singleton.hideFlags = HideFlags.NotEditable | HideFlags.DontSave; } } } }
private void OnPreCull() { if (base.enabled) { LaserGraphics.RenderLasersOnCamera(this.camera); } }
public static void EnsureGraphicsExist() { if (!LaserGraphics.singleton) { GameObject gameObject = GameObject.Find("__LASER_GRAPHICS__"); if (gameObject) { LaserGraphics.singleton = gameObject.GetComponent <LaserGraphics>(); if (!LaserGraphics.singleton) { LaserGraphics.singleton = gameObject.AddComponent <LaserGraphics>(); LaserGraphics.singleton.hideFlags = HideFlags.DontSave | HideFlags.NotEditable; } } else { GameObject gameObject1 = new GameObject() { hideFlags = HideFlags.DontSave | HideFlags.NotEditable, name = "__LASER_GRAPHICS__" }; gameObject = gameObject1; LaserGraphics.singleton = gameObject.AddComponent <LaserGraphics>(); LaserGraphics.singleton.hideFlags = HideFlags.DontSave | HideFlags.NotEditable; } } }
private void OnEnable() { g.allActiveBeams.Add(this); LaserGraphics.EnsureGraphicsExist(); }
private void RenderLasers(Camera camera) { Vector3 vector3 = new Vector3(); Vector3 vector31 = new Vector3(); Vector3 vector32 = new Vector3(); Vector3 vector33 = new Vector3(); float single; if (!this.madeLists) { this.beams = new List <LaserBeam>(); this.willRender = new List <LaserBeam>(); this.madeLists = true; } int num = camera.cullingMask; if (this.beams != null) { this.beams.Clear(); this.beams.AddRange(LaserBeam.Collect()); } else { this.beams = new List <LaserBeam>(LaserBeam.Collect()); } LaserGraphics.allBeamsMask = 0; foreach (LaserBeam beam in this.beams) { LaserGraphics.UpdateBeam(ref beam.frame, beam); } if ((num & LaserGraphics.allBeamsMask) != 0 && this.beams.Count > 0) { Plane[] planeArray = GeometryUtility.CalculateFrustumPlanes(camera); foreach (LaserBeam laserBeam in this.beams) { if (!laserBeam.isViewModel && ((num & laserBeam.frame.beamsLayer) != laserBeam.frame.beamsLayer || !GeometryUtility.TestPlanesAABB(planeArray, laserBeam.frame.bounds))) { continue; } this.willRender.Add(laserBeam); } if (this.willRender.Count > 0) { LaserGraphics.world2Cam = camera.worldToCameraMatrix; LaserGraphics.cam2World = camera.cameraToWorldMatrix; LaserGraphics.camProj = camera.projectionMatrix; try { foreach (LaserBeam laserBeam1 in this.willRender) { LaserGraphics.RenderBeam(planeArray, camera, laserBeam1, ref laserBeam1.frame); } foreach (LaserGraphics.MeshBuffer meshBuffer in LaserGraphics.Computation.beams) { bool flag = meshBuffer.Resize(); int num1 = 0; LaserGraphics.VertexBuffer vertexBuffer = meshBuffer.buffer; float single1 = Single.PositiveInfinity; single = single1; vector3.z = single1; float single2 = single; single = single2; vector3.y = single2; vector3.x = single; float single3 = Single.NegativeInfinity; single = single3; vector31.z = single3; float single4 = single; single = single4; vector31.y = single4; vector31.x = single; foreach (LaserBeam beam1 in meshBuffer.beams) { int num2 = num1; num1 = num2 + 1; int num3 = num2; int num4 = num1; num1 = num4 + 1; int num5 = num4; int num6 = num1; num1 = num6 + 1; int num7 = num6; int num8 = num1; num1 = num8 + 1; int num9 = num8; vertexBuffer.v[num3] = beam1.frame.beamVertices.m0; vertexBuffer.v[num5] = beam1.frame.beamVertices.m1; vertexBuffer.v[num9] = beam1.frame.beamVertices.m2; vertexBuffer.v[num7] = beam1.frame.beamVertices.m3; vertexBuffer.n[num3] = beam1.frame.beamNormals.m0; vertexBuffer.n[num5] = beam1.frame.beamNormals.m1; vertexBuffer.n[num9] = beam1.frame.beamNormals.m2; vertexBuffer.n[num7] = beam1.frame.beamNormals.m3; vertexBuffer.c[num3] = beam1.frame.beamColor.m0; vertexBuffer.c[num5] = beam1.frame.beamColor.m1; vertexBuffer.c[num9] = beam1.frame.beamColor.m2; vertexBuffer.c[num7] = beam1.frame.beamColor.m3; vertexBuffer.t[num3] = beam1.frame.beamUVs.m0; vertexBuffer.t[num5] = beam1.frame.beamUVs.m1; vertexBuffer.t[num9] = beam1.frame.beamUVs.m2; vertexBuffer.t[num7] = beam1.frame.beamUVs.m3; for (int i = num3; i <= num7; i++) { if (vertexBuffer.v[i].x < vector3.x) { vector3.x = vertexBuffer.v[i].x; } if (vertexBuffer.v[i].x > vector31.x) { vector31.x = vertexBuffer.v[i].x; } if (vertexBuffer.v[i].y < vector3.y) { vector3.y = vertexBuffer.v[i].y; } if (vertexBuffer.v[i].y > vector31.y) { vector31.y = vertexBuffer.v[i].y; } if (vertexBuffer.v[i].z < vector3.z) { vector3.z = vertexBuffer.v[i].z; } if (vertexBuffer.v[i].z > vector31.z) { vector31.z = vertexBuffer.v[i].z; } } beam1.frame.bufBeam = null; } meshBuffer.beams.Clear(); meshBuffer.BindMesh(flag, vector3, vector31); Graphics.DrawMesh(meshBuffer.mesh, Matrix4x4.identity, meshBuffer.material, 1, camera, 0, null, false, false); } foreach (LaserGraphics.MeshBuffer dot in LaserGraphics.Computation.dots) { bool flag1 = dot.Resize(); int num10 = 0; LaserGraphics.VertexBuffer vertexBuffer1 = dot.buffer; float single5 = Single.PositiveInfinity; single = single5; vector32.z = single5; float single6 = single; single = single6; vector32.y = single6; vector32.x = single; float single7 = Single.NegativeInfinity; single = single7; vector33.z = single7; float single8 = single; single = single8; vector33.y = single8; vector33.x = single; foreach (LaserBeam beam2 in dot.beams) { int num11 = num10; num10 = num11 + 1; int num12 = num11; int num13 = num10; num10 = num13 + 1; int num14 = num13; int num15 = num10; num10 = num15 + 1; int num16 = num15; int num17 = num10; num10 = num17 + 1; int num18 = num17; vertexBuffer1.v[num12] = beam2.frame.dotVertices1.m0; vertexBuffer1.v[num14] = beam2.frame.dotVertices1.m1; vertexBuffer1.v[num18] = beam2.frame.dotVertices1.m2; vertexBuffer1.v[num16] = beam2.frame.dotVertices1.m3; vertexBuffer1.n[num12] = beam2.frame.beamNormals.m0; vertexBuffer1.n[num14] = beam2.frame.beamNormals.m1; vertexBuffer1.n[num18] = beam2.frame.beamNormals.m2; vertexBuffer1.n[num16] = beam2.frame.beamNormals.m3; vertexBuffer1.c[num12] = beam2.frame.dotColor1.m0; vertexBuffer1.c[num14] = beam2.frame.dotColor1.m1; vertexBuffer1.c[num18] = beam2.frame.dotColor1.m2; vertexBuffer1.c[num16] = beam2.frame.dotColor1.m3; vertexBuffer1.t[num12] = LaserGraphics.uv[0]; vertexBuffer1.t[num14] = LaserGraphics.uv[1]; vertexBuffer1.t[num18] = LaserGraphics.uv[2]; vertexBuffer1.t[num16] = LaserGraphics.uv[3]; for (int j = num12; j <= num16; j++) { if (vertexBuffer1.v[j].x < vector32.x) { vector32.x = vertexBuffer1.v[j].x; } if (vertexBuffer1.v[j].x > vector33.x) { vector33.x = vertexBuffer1.v[j].x; } if (vertexBuffer1.v[j].y < vector32.y) { vector32.y = vertexBuffer1.v[j].y; } if (vertexBuffer1.v[j].y > vector33.y) { vector33.y = vertexBuffer1.v[j].y; } if (vertexBuffer1.v[j].z < vector32.z) { vector32.z = vertexBuffer1.v[j].z; } if (vertexBuffer1.v[j].z > vector33.z) { vector33.z = vertexBuffer1.v[j].z; } } int num19 = num10; num10 = num19 + 1; num12 = num19; int num20 = num10; num10 = num20 + 1; num14 = num20; int num21 = num10; num10 = num21 + 1; num16 = num21; int num22 = num10; num10 = num22 + 1; num18 = num22; vertexBuffer1.v[num12] = beam2.frame.dotVertices2.m0; vertexBuffer1.v[num14] = beam2.frame.dotVertices2.m1; vertexBuffer1.v[num18] = beam2.frame.dotVertices2.m2; vertexBuffer1.v[num16] = beam2.frame.dotVertices2.m3; vertexBuffer1.n[num12] = beam2.frame.beamNormals.m0; vertexBuffer1.n[num14] = beam2.frame.beamNormals.m1; vertexBuffer1.n[num18] = beam2.frame.beamNormals.m2; vertexBuffer1.n[num16] = beam2.frame.beamNormals.m3; vertexBuffer1.c[num12] = beam2.frame.dotColor2.m0; vertexBuffer1.c[num14] = beam2.frame.dotColor2.m1; vertexBuffer1.c[num18] = beam2.frame.dotColor2.m2; vertexBuffer1.c[num16] = beam2.frame.dotColor2.m3; vertexBuffer1.t[num12] = LaserGraphics.uv[0]; vertexBuffer1.t[num14] = LaserGraphics.uv[1]; vertexBuffer1.t[num18] = LaserGraphics.uv[2]; vertexBuffer1.t[num16] = LaserGraphics.uv[3]; for (int k = num12; k <= num16; k++) { if (vertexBuffer1.v[k].x < vector32.x) { vector32.x = vertexBuffer1.v[k].x; } if (vertexBuffer1.v[k].x > vector33.x) { vector33.x = vertexBuffer1.v[k].x; } if (vertexBuffer1.v[k].y < vector32.y) { vector32.y = vertexBuffer1.v[k].y; } if (vertexBuffer1.v[k].y > vector33.y) { vector33.y = vertexBuffer1.v[k].y; } if (vertexBuffer1.v[k].z < vector32.z) { vector32.z = vertexBuffer1.v[k].z; } if (vertexBuffer1.v[k].z > vector33.z) { vector33.z = vertexBuffer1.v[k].z; } } beam2.frame.bufDot = null; } dot.beams.Clear(); if (!flag1) { dot.mesh.vertices = vertexBuffer1.v; dot.mesh.normals = vertexBuffer1.n; dot.mesh.colors = vertexBuffer1.c; dot.mesh.uv = vertexBuffer1.t; } else { dot.mesh.Clear(false); dot.mesh.vertices = vertexBuffer1.v; dot.mesh.normals = vertexBuffer1.n; dot.mesh.colors = vertexBuffer1.c; dot.mesh.uv = vertexBuffer1.t; dot.mesh.SetIndices(vertexBuffer1.i, MeshTopology.Quads, 0); } dot.BindMesh(flag1, vector32, vector33); Graphics.DrawMesh(dot.mesh, Matrix4x4.identity, dot.material, 1, camera, 0, null, false, false); } } finally { this.willRender.Clear(); LaserGraphics.Computation.beams.Clear(); LaserGraphics.Computation.dots.Clear(); LaserGraphics.MeshBuffer.Reset(); } } } }
private static void RenderBeam(Plane[] frustum, Camera camera, LaserBeam beam, ref LaserBeam.FrameData frame) { Vector3 vector3 = LaserGraphics.world2Cam.MultiplyPoint(frame.origin); Vector3 vector31 = LaserGraphics.world2Cam.MultiplyPoint(frame.point); Vector3 vector32 = vector31 - vector3; vector32.Normalize(); float single = 1f - (1f - Mathf.Abs(vector32.z)) * beam.beamOutput; Quaternion quaternion = Quaternion.LookRotation(vector32, vector31); Quaternion quaternion1 = Quaternion.LookRotation(vector32, vector3); Vector3 vector33 = quaternion1 * new Vector3(frame.originWidth, 0f, 0f); Vector3 vector34 = quaternion * new Vector3(frame.pointWidth, 0f, 0f); frame.beamVertices.m0 = LaserGraphics.cam2World.MultiplyPoint((vector33 * 0.5f) + vector3); frame.beamVertices.m2 = LaserGraphics.cam2World.MultiplyPoint((vector34 * 0.5f) + vector31); frame.beamVertices.m1 = LaserGraphics.cam2World.MultiplyPoint((vector33 * -0.5f) + vector3); frame.beamVertices.m3 = LaserGraphics.cam2World.MultiplyPoint((vector34 * -0.5f) + vector31); frame.beamNormals.m0.x = frame.originWidth; frame.beamNormals.m2.x = frame.pointWidth; frame.beamNormals.m1.x = -frame.originWidth; frame.beamNormals.m3.x = -frame.pointWidth; frame.beamNormals.m0.y = -frame.distance; frame.beamNormals.m1.y = -frame.distance; frame.beamNormals.m2.y = -frame.distance; frame.beamNormals.m3.y = -frame.distance; float single1 = 0f; float single2 = single1; frame.beamNormals.m1.z = single1; frame.beamNormals.m0.z = single2; float single3 = frame.distanceFraction; single2 = single3; frame.beamNormals.m3.z = single3; frame.beamNormals.m2.z = single2; Color color = LaserGraphics.RangeBeamColor(beam.beamColor * single); Color color1 = color; frame.beamColor.m3 = (T)color; Color color2 = color1; color1 = color2; frame.beamColor.m2 = (T)color2; Color color3 = color1; color1 = color3; frame.beamColor.m1 = (T)color3; frame.beamColor.m0 = color1; frame.beamUVs.m0 = LaserGraphics.uv[0]; frame.beamUVs.m0.x = frame.beamUVs.m0.x * frame.distanceFraction; frame.beamUVs.m1 = LaserGraphics.uv[1]; frame.beamUVs.m1.x = frame.beamUVs.m1.x * frame.distanceFraction; frame.beamUVs.m2 = LaserGraphics.uv[2]; frame.beamUVs.m2.x = frame.beamUVs.m2.x * frame.distanceFraction; frame.beamUVs.m3 = LaserGraphics.uv[3]; frame.beamUVs.m3.x = frame.beamUVs.m3.x * frame.distanceFraction; frame.bufBeam = LaserGraphics.MeshBuffer.ForBeamMaterial(beam.beamMaterial); if (!LaserGraphics.Computation.beams.Add(frame.bufBeam)) { LaserGraphics.MeshBuffer meshBuffer = frame.bufBeam; meshBuffer.measureSize = meshBuffer.measureSize + 1; } else { frame.bufBeam.measureSize = 1; } frame.bufBeam.beams.Add(beam); if (!frame.didHit) { frame.bufDot = null; frame.drawDot = false; } else { Vector3 vector35 = LaserGraphics.world2Cam.MultiplyVector(-frame.hitNormal); if (vector35.z >= 0f) { frame.bufDot = null; frame.drawDot = false; } else { Vector3 vector36 = LaserGraphics.cam2World.MultiplyPoint(Vector3.zero); if (Physics.Linecast(vector36, Vector3.Lerp(vector36, frame.point, 0.95f), beam.cullLayers)) { frame.bufDot = null; frame.drawDot = false; } else { Vector3 vector37 = LaserGraphics.world2Cam.MultiplyPoint(frame.point); Quaternion quaternion2 = Quaternion.LookRotation(vector37, Vector3.up); frame.dotVertices1.m0 = LaserGraphics.cam2World.MultiplyPoint(vector37 + (quaternion2 * new Vector3(frame.dotRadius, -frame.dotRadius, 0f))); frame.dotVertices1.m1 = LaserGraphics.cam2World.MultiplyPoint(vector37 + (quaternion2 * new Vector3(frame.dotRadius, frame.dotRadius, 0f))); frame.dotVertices1.m2 = LaserGraphics.cam2World.MultiplyPoint(vector37 + (quaternion2 * new Vector3(-frame.dotRadius, -frame.dotRadius, 0f))); frame.dotVertices1.m3 = LaserGraphics.cam2World.MultiplyPoint(vector37 + (quaternion2 * new Vector3(-frame.dotRadius, frame.dotRadius, 0f))); quaternion2 = Quaternion.LookRotation(vector35, Vector3.up); frame.dotVertices2.m0 = LaserGraphics.cam2World.MultiplyPoint(vector37 + (quaternion2 * new Vector3(frame.dotRadius, -frame.dotRadius, -0.01f))); frame.dotVertices2.m1 = LaserGraphics.cam2World.MultiplyPoint(vector37 + (quaternion2 * new Vector3(frame.dotRadius, frame.dotRadius, -0.01f))); frame.dotVertices2.m2 = LaserGraphics.cam2World.MultiplyPoint(vector37 + (quaternion2 * new Vector3(-frame.dotRadius, -frame.dotRadius, -0.01f))); frame.dotVertices2.m3 = LaserGraphics.cam2World.MultiplyPoint(vector37 + (quaternion2 * new Vector3(-frame.dotRadius, frame.dotRadius, -0.01f))); Color color4 = LaserGraphics.RangeDotColor(beam.dotColor); color1 = color4; frame.dotColor2.m3 = (T)color4; Color color5 = color1; color1 = color5; frame.dotColor2.m2 = (T)color5; Color color6 = color1; color1 = color6; frame.dotColor2.m1 = (T)color6; Color color7 = color1; color1 = color7; frame.dotColor2.m0 = (T)color7; Color color8 = color1; color1 = color8; frame.dotColor1.m3 = (T)color8; Color color9 = color1; color1 = color9; frame.dotColor1.m2 = (T)color9; Color color10 = color1; color1 = color10; frame.dotColor1.m1 = (T)color10; frame.dotColor1.m0 = color1; frame.bufDot = LaserGraphics.MeshBuffer.ForDotMaterial(beam.dotMaterial); if (!LaserGraphics.Computation.dots.Add(frame.bufDot)) { LaserGraphics.MeshBuffer meshBuffer1 = frame.bufDot; meshBuffer1.measureSize = meshBuffer1.measureSize + 2; } else { frame.bufDot.measureSize = 2; } frame.bufDot.beams.Add(beam); frame.drawDot = true; } } } }