local Layer = {}
local rawget = rawget
local setmetatable = setmetatable
local LayerMask = {}
local unity_layermask = CS.UnityEngine.LayerMask

function LayerMask.__index(t, k)
  return rawget(LayerMask, k)
end

function LayerMask.__call(t, v)
  return setmetatable({
    value = value or 0
  }, LayerMask)
end

function LayerMask.New(value)
  return setmetatable({
    value = value or 0
  }, LayerMask)
end

function LayerMask:Get()
  return self.value
end

function LayerMask.NameToLayer(name)
  local layer = Layer[name]
  if layer == nil then
    Layer[name] = unity_layermask.NameToLayer(name)
  end
  return Layer[name]
end

function LayerMask.GetMask(...)
  local arg = {
    ...
  }
  local value = 0
  for i = 1, #arg do
    local n = LayerMask.NameToLayer(arg[i])
    if n ~= nil then
      value = value | 1 << n
    end
  end
  return value
end

LayerMask.unity_layermask = CS.UnityEngine.LayerMask
setmetatable(LayerMask, LayerMask)
return LayerMask
