本文整理汇总了C#中LayerMask类的典型用法代码示例。如果您正苦于以下问题:C# LayerMask类的具体用法?C# LayerMask怎么用?C# LayerMask使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LayerMask类属于命名空间,在下文中一共展示了LayerMask类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LayerMaskField
private LayerMask LayerMaskField( string label, LayerMask layerMask) {
List<string> layers = new List<string>();
List<int> layerNumbers = new List<int>();
for (int i = 0; i < 32; i++) {
string layerName = LayerMask.LayerToName(i);
if (layerName != "") {
layers.Add(layerName);
layerNumbers.Add(i);
}
}
int maskWithoutEmpty = 0;
for (int i = 0; i < layerNumbers.Count; i++) {
if (((1 << layerNumbers[i]) & layerMask.value) > 0)
maskWithoutEmpty |= (1 << i);
}
maskWithoutEmpty = EditorGUILayout.MaskField( label, maskWithoutEmpty, layers.ToArray());
int mask = 0;
for (int i = 0; i < layerNumbers.Count; i++) {
if ((maskWithoutEmpty & (1 << i)) > 0)
mask |= (1 << layerNumbers[i]);
}
layerMask.value = mask;
return layerMask;
}
示例2: Awake
void Awake()
{
pubbleLayerMask = 1 << (LayerMask.NameToLayer("PlayObject"));//实例化mask到cube这个自定义的层级之上。
//此处手动修改layer ,因为NGUI的layer 默认初始化为UI,一定要写在Awake函数
gameObject.layer = ConstantValue.PubbleMaskLayer;
defaultLayer = 1 << (LayerMask.NameToLayer("Default"));
}
示例3: HorizontalCollisions
void HorizontalCollisions (ref Vector3 velocity, LayerMask cMask) {
float dirX = Mathf.Sign (velocity.x); // direction of velocity in the x component
float rayLength = Mathf.Abs (velocity.x) + skinWidth; // length of raycast ray, equal to velocity in the x component
for (int i = 0; i < horRayCount; i++) {
Vector2 rayOrigin = (dirX == -1)?rayCastOrigins.botLeft:rayCastOrigins.botRight; // checks direction of velocity in the x component and assigns an origin respectively
rayOrigin += Vector2.up * (horRaySpacing * i); // adds origin for each ray along boundry
RaycastHit2D hit = Physics2D.Raycast (rayOrigin, Vector2.right * dirX, rayLength, cMask); // creates ray at each ray origin in the direction of velocity with the length of velocity while ignoring objects not in the layer mask collisionMask
Debug.DrawRay(rayOrigin, Vector2.right * dirX * rayLength, Color.red);
if (hit) { // if ray collides with object in layer mask collisionMask
float slopeAngle = Vector2.Angle(hit.normal, Vector2.up);
if (i == 0 && slopeAngle <= maxClimbAngle){
float distanceToSlopeStart = 0; // temp variable for distance to slope
if (slopeAngle != collisionsInfo.slopeAngleOld) { // checks change in slope
distanceToSlopeStart = hit.distance - skinWidth; // assigns distance minus skin width to temp variable
velocity.x -= distanceToSlopeStart * dirX; // subtracts temp value from velocity in the x axis with respect to direction
}
ClimbSlope (ref velocity, slopeAngle); // calls ClimbSlope () method which checks collisions on slopes
velocity.x += distanceToSlopeStart * dirX; // adds temp value to velocity in the x axis with respect to direction
}
if (!collisionsInfo.climbingSlope || slopeAngle > maxClimbAngle){
velocity.x = (hit.distance - skinWidth) * dirX; // if hit assigns distance from boundry to object collided to velocity in the x component
rayLength = hit.distance; // assigns distance from boundry to object collided to rayLegth, as to not get confused if not all rays are colliding with same object distance
if (collisionsInfo.climbingSlope){
velocity.y = Mathf.Tan (collisionsInfo.slopeAngle * Mathf.Deg2Rad) * Mathf.Abs(velocity.x); // Trig!
}
collisionsInfo.left = dirX == -1;
collisionsInfo.right = dirX == 1;
}
}
}
}
示例4: NetBehaviour
public NetBehaviour(GameObject gameObject, LayerMask interActable)
{
this.gameObject = gameObject;
this.range = 2.5f;
this.interActable = interActable;
lastTimeFire = 0;
}
示例5: ChangeObjectLayermask
public void ChangeObjectLayermask(LayerMask newMask)
{
foreach (Transform trans in gameObject.GetComponentsInChildren<Transform>(true))
{
trans.gameObject.layer = (int)Mathf.Log(newMask.value, 2);
}
}
示例6: Start
void Start()
{
zeroMask = LayerMask.NameToLayer("ZeroView");
oneMask = LayerMask.NameToLayer("OneView");
zeroMaskBack = LayerMask.NameToLayer ("ZeroViewBack");
oneMaskBack = LayerMask.NameToLayer ("OneViewBack");
}
示例7: Initialize
public void Initialize (LayerMask terrainMask, LayerMask objectMask, Transform foliageContainer, float newYearLength)
{
terrainLayerMask = terrainMask;
objectLayerMask = objectMask;
container = foliageContainer;
yearLength = newYearLength;
}
示例8: Awake
protected override void Awake()
{
base.Awake();
_controller = GetComponent<CharacterController>();
_groundLayers = 1 << LayerMask.NameToLayer("Environment") | 1 << LayerMask.NameToLayer("StickingWall");
}
示例9: Start
// Use this for initialization
void Start()
{
drag = GetComponent<DragableBlock>();
blocks = LayerMask.GetMask("Blocks");
rotBy90 = Quaternion.Euler(0, 90, 0);
rotByNeg90 = Quaternion.Euler(0, -90, 0);
}
示例10: Setup
private void Setup(Vector2 heading, LayerMask layer)
{
Heading = heading;
Layer = layer;
StartCoroutine(Timer());
}
示例11: ChanceToHit
public override float ChanceToHit(GameObject target)
{
if (Vector3.Distance(this.transform.position, target.transform.position) > range)
{
//out of range
return 0;
}
Ray ray = new Ray(this.transform.position, target.transform.position - this.transform.position);
RaycastHit hit;
LayerMask layerMask = new LayerMask();
layerMask = layerMask << LayerMask.NameToLayer("Avoid");
if (Physics.Raycast(ray, out hit, range, layerMask))
{
if (hit.collider.gameObject != target)
{
//not aimed at target
return 0;
}
}
Vector3 direction = target.transform.position - this.transform.position;
direction.Normalize();
float chance = Vector3.Dot(this.transform.forward, direction);
return chance;
}
示例12: Reset
public void Reset()
{
Awake();
// UnityChan2DController
maxSpeed = 10f;
jumpPower = 1000;
backwardForce = new Vector2(-4.5f, 5.4f);
whatIsGround = 1 << LayerMask.NameToLayer("Ground");
// Transform
transform.localScale = new Vector3(1, 1, 1);
// Rigidbody2D
m_rigidbody2D.gravityScale = 3.5f;
m_rigidbody2D.fixedAngle = true;
// BoxCollider2D
m_boxcollier2D.size = new Vector2(1, 2.5f);
m_boxcollier2D.offset = new Vector2(0, -0.25f);
// Animator
m_animator.applyRootMotion = false;
speedlevel = 1;
gameflg = true;
bonusflg = false;
jumpconstraint = 0;
bonusJump = 0;
GameSC = 0;
Score.bonusgauge = 0;
gamed = true;
}
示例13: SetWallAvoidanceProperties
public void SetWallAvoidanceProperties(float strengthMultiplier, float avoidanceForce, float maxViewDistance, LayerMask obstacleLayer)
{
wallAvoidance.strengthMultiplier = strengthMultiplier;
wallAvoidance.avoidanceForce = avoidanceForce;
wallAvoidance.maxViewDistance = maxViewDistance;
wallAvoidance.obstacleLayer = obstacleLayer;
}
示例14: Awake
void Awake()
{
playerController = GameObject.FindGameObjectWithTag ("Player").GetComponent<PlayerController> ();
ShotSpawnPos = GameObject.FindGameObjectWithTag("ShotSpawn");
ShootableMask = LayerMask.GetMask ("Shootable"); // get a reference to the shootable mask
ShotLine = ShotSpawnPos.GetComponent<LineRenderer> (); // get reference to the line AKA bullet
}
示例15: Awake
void Awake ()
{
tipsBlockLayerMask = 1 << gameObject.layer;
maskedLayer = 1 << ISSCLayerManager.blockLayer;
}