wiki.sine.space | sinespace

Scripting/SLayerMask

From wiki.sine.space
Revision as of 13:00, 10 June 2019 by JoshuaMay (Talk | contribs) (Properties)

Jump to: navigation, search

The SLayerMask class provides a wrapper around the Unity LayerMask class for filtering physics hits.

SLayerMask will ignore any layer names that are passed into it that are unknown layers. If your layer mask isn't working as you expect it to, verify that you're using accurate layer names.

You can use the .Layers property to see what layers got accepted by the SLayerMask object.

Members

New

SLayerMask New (table layerNames);

Static function that creators a new layer mask from a table of layer names.

-- Let's create a new layer mask to filter out other avatars and vehicles:

local mask = LayerMask.New({"Avatars", "Vehicles"});

local hit = Space.Physics.RaycastSingle(Space.Host.ExecutingObject.WorldPosition, Space.Host.ExecutingObject.Forward, 500.0, mask)


New

SLayerMask New (params string[] layerNames);

Static function that creators a new layer mask from one or more string parameters.

-- Let's create a new layer mask to filter out other avatars and vehicles:

local mask = LayerMask.New("Avatars");
or
local mask = LayerMask.New("Avatars", "Vehicles", "UI");

local hit = Space.Physics.RaycastSingle(Space.Host.ExecutingObject.WorldPosition, Space.Host.ExecutingObject.Forward, 500.0, mask)


SetLayers

void SetLayers (table layerNames);

Function that changes an existing layer mask using a table of layer names.

-- Let's create a new layer mask to filter out other avatars, then overwrite it to be vehicles instead:

local mask = LayerMask.New({"Avatars"});
mask.SetLayers({"Vehicles"});

local hit = Space.Physics.RaycastSingle(Space.Host.ExecutingObject.WorldPosition, Space.Host.ExecutingObject.Forward, 500.0, mask)


SetLayers

void SetLayers (params string[] layerNames);

Function that changes an existing layer mask using one or more string parameters.

-- Let's create a new layer mask to filter out other avatars, then overwrite it to be vehicles instead:

local mask = LayerMask.New("Avatars");
mask.SetLayers("Vehicles");

local hit = Space.Physics.RaycastSingle(Space.Host.ExecutingObject.WorldPosition, Space.Host.ExecutingObject.Forward, 500.0, mask)


AddLayer

void AddLayer (string layerName);

Add a new layer to an existing layer mask.

-- Let's create a new layer mask to filter out other avatars, then add vehicles:

local mask = LayerMask.New("Avatars");
mask.AddLayer("Vehicles");

local hit = Space.Physics.RaycastSingle(Space.Host.ExecutingObject.WorldPosition, Space.Host.ExecutingObject.Forward, 500.0, mask)


RemoveLayer

void RemoveLayer (string layerName);

Remove a new layer from an existing layer mask.

-- Let's create a new layer mask, then remove vehicles:

local mask = LayerMask.New("Avatars", "Vehicles", "UI");
mask.RemoveLayer("Vehicles");

local hit = Space.Physics.RaycastSingle(Space.Host.ExecutingObject.WorldPosition, Space.Host.ExecutingObject.Forward, 500.0, mask)


Properties

Layers

[[Scripting/string[]|string[]]] Layers { get; set; }

The layer names represented in this layer mask

local mask = LayerMask.New("Avatars");

-- Get
local layers = mask.Layers;
-- Set
local layers = {"Vehicles", "UI"};

mask.Layers = layers;


Inverted

bool Inverted { get; set; }

Is the mask exclusionary or not.

-- Create an inclusionary mask that gets ONLY Avatars.

local mask = LayerMask.New("Avatars");
-- Now change it to be an exclusionary mask that gets everything EXCEPT Avatars.'

mask.inverted = true;