using System;
using UnityEngine;

namespace LOS
{
	// Token: 0x02000107 RID: 263
	[ExecuteInEditMode]
	[RequireComponent(typeof(Camera))]
	[AddComponentMenu("Line of Sight/LOS Layer Excluder")]
	public class LOSLayerExcluder : MonoBehaviour
	{
		// Token: 0x060015FD RID: 5629 RVA: 0x0019CEF7 File Offset: 0x0019B0F7
		private void OnEnable()
		{
			if (base.GetComponent<Camera>().actualRenderingPath == RenderingPath.DeferredShading)
			{
				Debug.LogError("The LOS Layer Excluder script component does not support Deferred Rendering!\nPlease use the LOS Stencil Mask script component instead.");
				base.enabled = false;
			}
		}

		// Token: 0x060015FE RID: 5630 RVA: 0x0019CF18 File Offset: 0x0019B118
		private void Start()
		{
			this.m_ExcludeCamera = this.CreateExcludeCamera();
		}

		// Token: 0x060015FF RID: 5631 RVA: 0x0019CF26 File Offset: 0x0019B126
		private void LateUpdate()
		{
			if (this.m_ExcludeCamera)
			{
				this.SyncCamera(this.m_ExcludeCamera);
			}
		}

		// Token: 0x06001600 RID: 5632 RVA: 0x0019CF44 File Offset: 0x0019B144
		private Camera CreateExcludeCamera()
		{
			GameObject gameObject = null;
			Transform transform = base.transform.Find("Exclude Camera");
			if (null != transform)
			{
				gameObject = transform.gameObject;
			}
			if (null == gameObject)
			{
				gameObject = new GameObject("Exclude Camera");
				gameObject.transform.parent = base.gameObject.transform;
				gameObject.transform.localPosition = Vector3.zero;
				gameObject.transform.localRotation = Quaternion.identity;
				gameObject.transform.localScale = Vector3.one;
			}
			Camera camera = gameObject.GetComponent<Camera>();
			if (null == camera)
			{
				camera = gameObject.AddComponent<Camera>();
			}
			return camera;
		}

		// Token: 0x06001601 RID: 5633 RVA: 0x0019CFE8 File Offset: 0x0019B1E8
		private void SyncCamera(Camera excludeCamera)
		{
			excludeCamera.CopyFrom(base.GetComponent<Camera>());
			excludeCamera.cullingMask = this.m_ExcludeLayers.value;
			excludeCamera.clearFlags = CameraClearFlags.Nothing;
			excludeCamera.depth += 1f;
			base.GetComponent<Camera>().cullingMask = base.GetComponent<Camera>().cullingMask & ~this.m_ExcludeLayers.value;
		}

		// Token: 0x0400261A RID: 9754
		[Tooltip("Selects which layers to exclude from the line of sight")]
		[SerializeField]
		private LayerMask m_ExcludeLayers;

		// Token: 0x0400261B RID: 9755
		private Camera m_ExcludeCamera;
	}
}
