//Created by Neodrop
//neodrop@unity3d.ru
using UnityEngine;
using System.Collections;
//#pragma warning disable

[RequireComponent(typeof(Camera))]
public class CameraLayersDistance : MonoBehaviour
{
    public float[] layerCullDistances;

    void Awake()
    {
        UpdateLayers();
    }

    public void UpdateLayers()
    {
        if (layerCullDistances != null) camera.layerCullDistances = layerCullDistances;
    }

    LayerMask CampareLayers(LayerMask mask)
    {
        LayerMask currentMask = camera.cullingMask;
        for (int i = 0; i < 32; i++)
        {
            if (mask == (mask | (1 << i)))
            {
                if (currentMask != (currentMask | (1 << i)))
                {
                    currentMask += (int)(Mathf.Pow(2, i));
                }
            }
            else if (currentMask == (currentMask | (1 << i)))
            {
                currentMask -= (int)(Mathf.Pow(2, i));
            }
        }

        return currentMask;
    }

    public bool HasLayer(int layerID)
    {
        return camera.cullingMask == (camera.cullingMask | (1 << layerID));
    }

    public bool HasLayer(string layerName)
    {
        int layerID = LayerMask.NameToLayer(layerName);
        return camera.cullingMask == (camera.cullingMask | (1 << layerID));
    }
}
