Layers

From Unify Community Wiki
Revision as of 09:51, 7 February 2007 by KeliHlodversson (Talk | contribs)

Jump to: navigation, search

by Ray Nothnagel

Description

A static class designed to ease layer usage.

Usage

<javascript> //set the layer to 2 (ignore raycast) gameObject.layer = Layers.ignoreRaycast; //make the camera render only objects in the ignore raycast layer camera.cullingMask = Layers.CreateInclusiveMask([Layers.ignoreRaycast]); //make the camera render everyting but that layer camera.cullingMask = Layers.CreateExclusiveMask([Layers.ignoreRaycast]); </javascript>

If you add more layers, this becomes even more handy as you no longer need to think about bitwise math to create complex masks. <javascript> //this assumes you've added "player" and "landscape" layer variables to Layers.js //the camera will render only objects in those two layers camera.cullingMask = Layers.CreateInclusiveMask([Layers.player, Layers.landscape]); </javascript>

Layers.js

<javascript> static var ignoreRaycast = 2; //any other layers you would like to access can go here //static var player = 8;

static function CreateInclusiveMask(layers : int[]) : LayerMask{ var m : int = 0; for (l=0;l<layers.length;l++) { m |= (1<<layers[l]); } return m; }

static function CreateExclusiveMask(layers : int[]) : LayerMask{ var m : int = 0; for (l=0;l<layers.length;l++) { m |= (1<<layers[l]); } return ~m; }</javascript>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox