171 lines
5.7 KiB
C#
171 lines
5.7 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace LOS
|
|
{
|
|
// Token: 0x02000100 RID: 256
|
|
[RequireComponent(typeof(Camera))]
|
|
public class AttackShapes : MonoBehaviour
|
|
{
|
|
// Token: 0x1700001C RID: 28
|
|
// (get) Token: 0x060015BD RID: 5565 RVA: 0x0019BC9A File Offset: 0x00199E9A
|
|
public static Plane[] CameraFrustumPlanes
|
|
{
|
|
get
|
|
{
|
|
return AttackShapes.m_CameraFrustumPlanes;
|
|
}
|
|
}
|
|
|
|
// Token: 0x060015BE RID: 5566 RVA: 0x0019BCA1 File Offset: 0x00199EA1
|
|
private void Awake()
|
|
{
|
|
this.m_Camera = base.GetComponent<Camera>();
|
|
this.CreateTextures();
|
|
}
|
|
|
|
// Token: 0x060015BF RID: 5567 RVA: 0x0019BCB5 File Offset: 0x00199EB5
|
|
private void OnEnable()
|
|
{
|
|
LOSHelper.ExtractFrustumPlanes(AttackShapes.m_CameraFrustumPlanes, this.m_Camera);
|
|
}
|
|
|
|
// Token: 0x060015C0 RID: 5568 RVA: 0x0019BCC8 File Offset: 0x00199EC8
|
|
private void CreateTextures()
|
|
{
|
|
if (this.textures.Length > 1 && this.textures[1] != null)
|
|
{
|
|
this.textures[1].Release();
|
|
}
|
|
if (this.textures[0] != null)
|
|
{
|
|
this.textures[0].Release();
|
|
}
|
|
this.textures = new RenderTexture[2];
|
|
bool flag = false;
|
|
RenderTexture renderTexture = new RenderTexture(this.texSize, this.texSize, 16, RenderTextureFormat.RGHalf);
|
|
renderTexture.name = "rt0";
|
|
this.textures[0] = renderTexture;
|
|
renderTexture.useMipMap = flag;
|
|
renderTexture.filterMode = FilterMode.Trilinear;
|
|
RenderTexture renderTexture2 = new RenderTexture(this.texSize, this.texSize, 16, RenderTextureFormat.RGHalf);
|
|
renderTexture.name = "rt1";
|
|
this.textures[1] = renderTexture2;
|
|
renderTexture2.useMipMap = flag;
|
|
renderTexture2.filterMode = FilterMode.Trilinear;
|
|
}
|
|
|
|
// Token: 0x060015C1 RID: 5569 RVA: 0x0019BD98 File Offset: 0x00199F98
|
|
private void OnDisable()
|
|
{
|
|
}
|
|
|
|
// Token: 0x060015C2 RID: 5570 RVA: 0x0019BD9C File Offset: 0x00199F9C
|
|
private void OnPreRender()
|
|
{
|
|
if (this.m_Camera == null)
|
|
{
|
|
return;
|
|
}
|
|
if (this.textures[0] == null)
|
|
{
|
|
this.CreateTextures();
|
|
}
|
|
if (base.transform.hasChanged)
|
|
{
|
|
LOSHelper.ExtractFrustumPlanes(AttackShapes.m_CameraFrustumPlanes, this.m_Camera);
|
|
base.transform.hasChanged = false;
|
|
}
|
|
}
|
|
|
|
// Token: 0x060015C3 RID: 5571 RVA: 0x0019BDF8 File Offset: 0x00199FF8
|
|
[ImageEffectOpaque]
|
|
private void OnRenderImage(RenderTexture source, RenderTexture destination)
|
|
{
|
|
if (!this.m_Camera)
|
|
{
|
|
return;
|
|
}
|
|
Matrix4x4 matrix4x;
|
|
Matrix4x4 matrix4x2;
|
|
LOSHelper.CalculateViewVectors(this.m_Camera, out matrix4x, out matrix4x2);
|
|
Materials.Mask.SetMatrix(ShaderID.FrustumRays, matrix4x);
|
|
Materials.Mask.SetMatrix(ShaderID.FrustumOrigins, matrix4x2);
|
|
Materials.Mask.SetMatrix(ShaderID.WorldToCameraMatrix, this.m_Camera.worldToCameraMatrix);
|
|
Material skybox = RenderSettings.skybox;
|
|
RenderSettings.skybox = Materials.SkyBox;
|
|
this.RenderSourceToMask(this.caster, 0, this.caster.gameObject.transform.position);
|
|
if (this.cameraNumber > 1f)
|
|
{
|
|
this.RenderSourceToMask(this.caster2, 1, this.caster2.gameObject.transform.position);
|
|
}
|
|
RenderSettings.skybox = skybox;
|
|
if (!this.combineMaterial)
|
|
{
|
|
this.combineMaterial = new Material(this.coneShader);
|
|
}
|
|
if (this.caster)
|
|
{
|
|
this.combineMaterial.SetFloat("cameraLengthConeAttack", this.caster.SourceCamera.farClipPlane);
|
|
this.combineMaterial.SetFloat("minVarianceConeAttack", this.caster.MinVariance);
|
|
this.combineMaterial.SetFloat("backfaceFadeAttack", this.caster.BackfacesFade);
|
|
this.combineMaterial.SetFloat("sphereRadius", this.sphereRadius);
|
|
this.combineMaterial.SetFloat("cameraNumber", this.cameraNumber);
|
|
}
|
|
Graphics.Blit(source, destination, this.combineMaterial, 0);
|
|
}
|
|
|
|
// Token: 0x060015C4 RID: 5572 RVA: 0x0019BF80 File Offset: 0x0019A180
|
|
private void RenderSourceToMask(LOSSource losSource, int num, Vector3 center)
|
|
{
|
|
Camera sourceCamera = losSource.SourceCamera;
|
|
Materials.SkyBox.SetVector(ShaderID.FarPlane, new Vector4(sourceCamera.farClipPlane, sourceCamera.farClipPlane, sourceCamera.farClipPlane, sourceCamera.farClipPlane));
|
|
sourceCamera.targetTexture = this.textures[num];
|
|
sourceCamera.RenderWithShader(Shaders.DepthCone, null);
|
|
if (num == 0)
|
|
{
|
|
Shader.SetGlobalVector("_SourcePosConeAttack", center);
|
|
Shader.SetGlobalVector("_LosPosConeAttack", losSource.gameObject.transform.position + losSource.gameObject.transform.forward);
|
|
Shader.SetGlobalMatrix("_SourceWorldProjConeAttack", sourceCamera.projectionMatrix * sourceCamera.worldToCameraMatrix);
|
|
Shader.SetGlobalMatrix("_Source_CamToWorldConeAttack", sourceCamera.cameraToWorldMatrix);
|
|
Shader.SetGlobalTexture("_SourceDepthTexConeAttack", this.textures[num]);
|
|
return;
|
|
}
|
|
Shader.SetGlobalVector("_SourcePosConeAttack1", center);
|
|
Shader.SetGlobalVector("_LosPosConeAttack1", losSource.gameObject.transform.position + losSource.gameObject.transform.forward);
|
|
Shader.SetGlobalMatrix("_SourceWorldProjConeAttack1", sourceCamera.projectionMatrix * sourceCamera.worldToCameraMatrix);
|
|
Shader.SetGlobalTexture("_SourceDepthTexConeAttack1", this.textures[num]);
|
|
}
|
|
|
|
// Token: 0x04002600 RID: 9728
|
|
public int texSize = 1024;
|
|
|
|
// Token: 0x04002601 RID: 9729
|
|
public static Plane[] m_CameraFrustumPlanes = new Plane[6];
|
|
|
|
// Token: 0x04002602 RID: 9730
|
|
public LOSSource caster;
|
|
|
|
// Token: 0x04002603 RID: 9731
|
|
public LOSSource caster2;
|
|
|
|
// Token: 0x04002604 RID: 9732
|
|
private Camera m_Camera;
|
|
|
|
// Token: 0x04002605 RID: 9733
|
|
public RenderTexture[] textures = new RenderTexture[1];
|
|
|
|
// Token: 0x04002606 RID: 9734
|
|
private Material combineMaterial;
|
|
|
|
// Token: 0x04002607 RID: 9735
|
|
public float sphereRadius;
|
|
|
|
// Token: 0x04002608 RID: 9736
|
|
public float cameraNumber = 1f;
|
|
|
|
// Token: 0x04002609 RID: 9737
|
|
public Shader coneShader;
|
|
}
|
|
}
|