using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;

// Token: 0x02000084 RID: 132
public class Culling : MonoBehaviour
{
	// Token: 0x06000CD7 RID: 3287 RVA: 0x000F90F0 File Offset: 0x000F72F0
	public void Setup(SceneCamera sceneCam)
	{
		this.sceneCamera = sceneCam;
		if (this.centerSphere)
		{
			this.centerSphere.SetActive(false);
		}
		int count = this.grass.Count;
		if (!this.sceneCamera.perspectiveShot && this.sceneCamera.index == 0)
		{
			this.art.gameObject.transform.localScale = new Vector3(22.6001f, 22.6001f, 1f);
		}
		if (!this.sceneCamera.perspectiveShot && this.sceneCamera.index == 1)
		{
			if (this.art.gameObject.transform.localScale.x > 20f)
			{
				this.art.gameObject.transform.localScale = new Vector3(22.6001f, 22.6001f, 1f);
			}
			else
			{
				this.art.gameObject.transform.localScale = new Vector3(11.3002f, 11.3002f, 1f);
			}
		}
		if (!this.first)
		{
			if (this.art)
			{
				this.art.gameObject.layer = 2;
				if (this.art.sharedMaterial && !this.art.sharedMaterial.shader.name.Contains("Lit"))
				{
					this.art.sharedMaterial.shader = Links.x.quadShader;
				}
			}
			this.first = true;
		}
		if (Links.x)
		{
			Links.x.AddQuad(this);
		}
		if (this.art)
		{
			this.min = this.art.bounds.min;
			this.max = this.art.bounds.max;
		}
		this.culling = this;
		if (Links.x)
		{
			this.ChangeState(false, false);
		}
		base.enabled = false;
	}

	// Token: 0x06000CD8 RID: 3288 RVA: 0x000F92F4 File Offset: 0x000F74F4
	public void ChangeState(bool on, bool quadForceOff)
	{
		int num = this.lights.Count;
		for (int i = 0; i < num; i++)
		{
			if (this.lights[i])
			{
				this.lights[i].enabled = on;
				if (on)
				{
					this.lights[i].EnableRevealer();
				}
			}
		}
		num = this.losBlockers.Count;
		for (int j = 0; j < num; j++)
		{
			this.losBlockers[j].enabled = on;
		}
		num = this.grass.Count;
		for (int k = 0; k < num; k++)
		{
			this.grass[k].enabled = on;
		}
		num = this.audioSources.Count;
		for (int l = 0; l < num; l++)
		{
			this.audioSources[l].enabled = on;
			if (on)
			{
				this.audioSources[l].audioSource.volume = Links.x.options.soundVolume;
			}
		}
		num = this.hannahAnimators.Count;
		for (int m = 0; m < num; m++)
		{
			this.hannahAnimators[m].enabled = on;
			if (on && this.hannahAnimators[m])
			{
				this.hannahAnimators[m].enabled = on;
			}
		}
		this.camParams.enabled = on;
		this.art.enabled = on;
		if (quadForceOff)
		{
			this.art.enabled = false;
			this.camParams.enabled = false;
		}
		this.isOn = on;
	}

	// Token: 0x06000CD9 RID: 3289 RVA: 0x000F9494 File Offset: 0x000F7694
	public void SetVolume()
	{
		int count = this.audioSources.Count;
		for (int i = 0; i < count; i++)
		{
			this.audioSources[i].audioSource.volume = Links.x.options.soundVolume;
		}
	}

	// Token: 0x06000CDA RID: 3290 RVA: 0x000F94DE File Offset: 0x000F76DE
	public void ArtOn()
	{
		this.camParams.enabled = true;
		this.art.enabled = true;
	}

	// Token: 0x06000CDB RID: 3291 RVA: 0x000F94F8 File Offset: 0x000F76F8
	public void MultiCameraChange(bool on)
	{
	}

	// Token: 0x06000CDC RID: 3292 RVA: 0x000F94FC File Offset: 0x000F76FC
	public void CreateWallRenderers()
	{
		for (int i = 0; i < this.losBlockers.Count; i++)
		{
			if (this.losBlockers[i])
			{
				Object.DestroyImmediate(this.losBlockers[i].gameObject);
			}
		}
		this.losBlockers.Clear();
		int count = this.colliders.Count;
		for (int j = 0; j < count; j++)
		{
			if (this.colliders[j].gameObject.layer == 9)
			{
				this.CreateMeshRenderer(this.colliders[j]);
			}
		}
	}

	// Token: 0x06000CDD RID: 3293 RVA: 0x000F9598 File Offset: 0x000F7798
	public void CreateFloorRenderer(Collider collider)
	{
		GameObject gameObject = collider.gameObject;
		if (gameObject.GetComponent<MeshCollider>())
		{
			GameObject gameObject2 = new GameObject("Line of Sight Blocker Mesh " + gameObject.name);
			Transform transform = gameObject.transform;
			gameObject2.transform.position = transform.position - this.ySubtract;
			gameObject2.transform.rotation = transform.rotation;
			gameObject2.AddComponent<MeshFilter>().mesh = gameObject.GetComponent<MeshFilter>().sharedMesh;
			gameObject2.AddComponent<MeshRenderer>().sharedMaterial = Links.x.lineOfSightBlockerMaterial;
			gameObject2.layer = 29;
			gameObject2.transform.parent = transform;
			gameObject2.transform.localScale = Vector3.one;
			return;
		}
		BoxCollider component = gameObject.GetComponent<BoxCollider>();
		if (component)
		{
			GameObject gameObject3 = new GameObject("Line of Sight Blocker");
			Transform transform2 = gameObject.transform;
			gameObject3.transform.position = transform2.TransformPoint(component.center);
			gameObject3.transform.rotation = transform2.rotation;
			gameObject3.transform.localScale = new Vector3(component.size.x * transform2.localScale.x, component.size.y * transform2.localScale.y, component.size.z * transform2.localScale.z);
			gameObject3.AddComponent<MeshFilter>().mesh = Links.x.cubeMesh;
			gameObject3.AddComponent<MeshRenderer>().sharedMaterial = Links.x.lineOfSightBlockerMaterial;
			gameObject3.layer = 29;
			gameObject3.transform.parent = transform2;
			return;
		}
		SphereCollider component2 = gameObject.GetComponent<SphereCollider>();
		if (component2)
		{
			GameObject gameObject4 = new GameObject("Line of Sight Blocker Sphere");
			Transform transform3 = gameObject.transform;
			gameObject4.transform.position = transform3.TransformPoint(component2.center);
			gameObject4.transform.rotation = transform3.rotation;
			gameObject4.transform.localScale = new Vector3(component2.radius * transform3.localScale.x * 2f, component2.radius * transform3.localScale.x * 2f, component2.radius * transform3.localScale.z * 2f);
			gameObject4.AddComponent<MeshFilter>().mesh = Links.x.sphereMesh;
			gameObject4.AddComponent<MeshRenderer>().sharedMaterial = Links.x.lineOfSightBlockerMaterial;
			gameObject4.layer = 29;
			gameObject4.transform.parent = transform3;
			return;
		}
		CapsuleCollider component3 = gameObject.GetComponent<CapsuleCollider>();
		if (component3)
		{
			GameObject gameObject5 = new GameObject("Line of Sight Blocker Capsule");
			Transform transform4 = gameObject.transform;
			gameObject5.transform.position = transform4.TransformPoint(component3.center);
			gameObject5.transform.rotation = transform4.rotation;
			gameObject5.transform.localScale = new Vector3(component3.radius * transform4.localScale.x * 2f, component3.height * transform4.localScale.y / 2f, component3.radius * transform4.localScale.z * 2f);
			gameObject5.AddComponent<MeshFilter>().mesh = Links.x.capsuleMesh;
			gameObject5.AddComponent<MeshRenderer>().sharedMaterial = Links.x.lineOfSightBlockerMaterial;
			gameObject5.layer = 29;
			gameObject5.transform.parent = transform4;
		}
	}

	// Token: 0x06000CDE RID: 3294 RVA: 0x000F990C File Offset: 0x000F7B0C
	public void CreateMeshRenderer(Collider collider)
	{
		GameObject gameObject = collider.gameObject;
		BoxCollider component = gameObject.GetComponent<BoxCollider>();
		if (component)
		{
			GameObject gameObject2 = new GameObject("Line of Sight Blocker");
			Transform transform = gameObject.transform;
			gameObject2.transform.position = transform.TransformPoint(component.center);
			gameObject2.transform.rotation = transform.rotation;
			gameObject2.transform.localScale = new Vector3(component.size.x * transform.localScale.x, component.size.y * transform.localScale.y, component.size.z * transform.localScale.z);
			gameObject2.AddComponent<MeshFilter>().mesh = Resources.GetBuiltinResource<Mesh>("Cube.fbx");
			MeshRenderer meshRenderer = gameObject2.AddComponent<MeshRenderer>();
			meshRenderer.sharedMaterial = Resources.Load<Material>("Crawl/LineOfSightBlockers");
			gameObject2.layer = 29;
			gameObject2.transform.parent = transform;
			this.losBlockers.Add(meshRenderer);
			meshRenderer.enabled = false;
			return;
		}
		CapsuleCollider component2 = gameObject.GetComponent<CapsuleCollider>();
		if (component2)
		{
			GameObject gameObject3 = new GameObject("Line of Sight Blocker Capsule");
			Transform transform2 = gameObject.transform;
			gameObject3.transform.position = transform2.TransformPoint(component2.center);
			gameObject3.transform.rotation = transform2.rotation;
			gameObject3.transform.localScale = new Vector3(component2.radius * transform2.localScale.x * 2f, component2.height * transform2.localScale.y / 2f, component2.radius * transform2.localScale.z * 2f);
			gameObject3.AddComponent<MeshFilter>().mesh = Resources.GetBuiltinResource<Mesh>("Capsule.fbx");
			MeshRenderer meshRenderer2 = gameObject3.AddComponent<MeshRenderer>();
			meshRenderer2.sharedMaterial = Resources.Load<Material>("Crawl/LineOfSightBlockers");
			gameObject3.layer = 29;
			gameObject3.transform.parent = transform2;
			this.losBlockers.Add(meshRenderer2);
			meshRenderer2.enabled = false;
			return;
		}
		SphereCollider component3 = gameObject.GetComponent<SphereCollider>();
		if (component3)
		{
			GameObject gameObject4 = new GameObject("Line of Sight Blocker Sphere");
			Transform transform3 = gameObject.transform;
			gameObject4.transform.position = transform3.TransformPoint(component3.center);
			gameObject4.transform.rotation = transform3.rotation;
			gameObject4.transform.localScale = new Vector3(component3.radius * transform3.localScale.x * 2f, component3.radius * transform3.localScale.x * 2f, component3.radius * transform3.localScale.z * 2f);
			gameObject4.AddComponent<MeshFilter>().mesh = Resources.GetBuiltinResource<Mesh>("Sphere.fbx");
			MeshRenderer meshRenderer3 = gameObject4.AddComponent<MeshRenderer>();
			meshRenderer3.sharedMaterial = Resources.Load<Material>("Crawl/LineOfSightBlockers");
			gameObject4.layer = 29;
			gameObject4.transform.parent = transform3;
			this.losBlockers.Add(meshRenderer3);
			meshRenderer3.enabled = false;
			return;
		}
	}

	// Token: 0x06000CDF RID: 3295 RVA: 0x000F9C21 File Offset: 0x000F7E21
	public void ClearColliders()
	{
		this.colliders.Clear();
	}

	// Token: 0x06000CE0 RID: 3296 RVA: 0x000F9C2E File Offset: 0x000F7E2E
	public void AddCollider(Collider coll)
	{
		if (coll.gameObject.name.Contains("amera"))
		{
			return;
		}
		this.colliders.Add(coll);
	}

	// Token: 0x06000CE1 RID: 3297 RVA: 0x000F9C54 File Offset: 0x000F7E54
	public void ClearGrass()
	{
		this.grass.Clear();
	}

	// Token: 0x06000CE2 RID: 3298 RVA: 0x000F9C61 File Offset: 0x000F7E61
	public void ClearAudio()
	{
		this.audioSources.Clear();
	}

	// Token: 0x06000CE3 RID: 3299 RVA: 0x000F9C6E File Offset: 0x000F7E6E
	public void AddGrass(MeshRenderer renderer)
	{
		if (renderer.shadowCastingMode == ShadowCastingMode.ShadowsOnly)
		{
			return;
		}
		this.grass.Add(renderer);
	}

	// Token: 0x06000CE4 RID: 3300 RVA: 0x000F9C86 File Offset: 0x000F7E86
	public void ClearLights()
	{
		this.lights.Clear();
	}

	// Token: 0x06000CE5 RID: 3301 RVA: 0x000F9C93 File Offset: 0x000F7E93
	public void ClearHannahAnimators()
	{
		this.hannahAnimators.Clear();
	}

	// Token: 0x06000CE6 RID: 3302 RVA: 0x000F9CA0 File Offset: 0x000F7EA0
	public void AddSource(CoolAudioSource source)
	{
		this.audioSources.Add(source);
	}

	// Token: 0x06000CE7 RID: 3303 RVA: 0x000F9CAE File Offset: 0x000F7EAE
	public void AddLight(Moonlight light)
	{
		this.lights.Add(light);
	}

	// Token: 0x06000CE8 RID: 3304 RVA: 0x000F9CBC File Offset: 0x000F7EBC
	public void AddHannahAnimator(HannahAnimatorSimple anim)
	{
		this.hannahAnimators.Add(anim);
	}

	// Token: 0x0400147E RID: 5246
	public bool isOn;

	// Token: 0x0400147F RID: 5247
	public MeshRenderer art;

	// Token: 0x04001480 RID: 5248
	public List<Moonlight> lights = new List<Moonlight>();

	// Token: 0x04001481 RID: 5249
	public List<Collider> colliders = new List<Collider>();

	// Token: 0x04001482 RID: 5250
	public List<MeshRenderer> grass = new List<MeshRenderer>();

	// Token: 0x04001483 RID: 5251
	public List<RandomAnimationStart> animatorsRandom = new List<RandomAnimationStart>();

	// Token: 0x04001484 RID: 5252
	public List<HannahAnimatorSimple> hannahAnimators = new List<HannahAnimatorSimple>();

	// Token: 0x04001485 RID: 5253
	public List<MeshRenderer> losBlockers = new List<MeshRenderer>();

	// Token: 0x04001486 RID: 5254
	public List<Item> items = new List<Item>();

	// Token: 0x04001487 RID: 5255
	public Vector3 center;

	// Token: 0x04001488 RID: 5256
	public Vector3 min;

	// Token: 0x04001489 RID: 5257
	public Vector3 max;

	// Token: 0x0400148A RID: 5258
	public CameraParams camParams;

	// Token: 0x0400148B RID: 5259
	private Culling culling;

	// Token: 0x0400148C RID: 5260
	private Material[] mat;

	// Token: 0x0400148D RID: 5261
	private Vector3 ySubtract = new Vector3(0f, 0.1f, 0f);

	// Token: 0x0400148E RID: 5262
	public GameObject centerSphere;

	// Token: 0x0400148F RID: 5263
	public SceneCamera sceneCamera;

	// Token: 0x04001490 RID: 5264
	public List<CoolAudioSource> audioSources = new List<CoolAudioSource>();

	// Token: 0x04001491 RID: 5265
	private bool first;
}
