• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# LayerMask类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中LayerMask的典型用法代码示例。如果您正苦于以下问题:C# LayerMask类的具体用法?C# LayerMask怎么用?C# LayerMask使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



LayerMask类属于命名空间,在下文中一共展示了LayerMask类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
	}
开发者ID:CarsonRoscoe,项目名称:DefendAman,代码行数:25,代码来源:SettingsWindow.cs


示例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"));
 }
开发者ID:Blavtes,项目名称:JsonConfigForUnity,代码行数:7,代码来源:PubbleObject.cs


示例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;
				} 
			}		
		}
	}
开发者ID:HardlyConsideredGames,项目名称:Project-Universus,代码行数:31,代码来源:CollisionsController.cs


示例4: NetBehaviour

 public NetBehaviour(GameObject gameObject, LayerMask interActable)
 {
     this.gameObject = gameObject;
     this.range = 2.5f;
     this.interActable = interActable;
     lastTimeFire = 0;
 }
开发者ID:spytroll33,项目名称:SuperApeEscape,代码行数:7,代码来源:NetBehaviour.cs


示例5: ChangeObjectLayermask

 public void ChangeObjectLayermask(LayerMask newMask)
 {
     foreach (Transform trans in gameObject.GetComponentsInChildren<Transform>(true))
     {
         trans.gameObject.layer = (int)Mathf.Log(newMask.value, 2);
     }
 }
开发者ID:Catchouli-old,项目名称:SuperShooterGuy3D,代码行数:7,代码来源:OldLayer.cs


示例6: Start

 void Start()
 {
     zeroMask = LayerMask.NameToLayer("ZeroView");
     oneMask = LayerMask.NameToLayer("OneView");
     zeroMaskBack = LayerMask.NameToLayer ("ZeroViewBack");
     oneMaskBack = LayerMask.NameToLayer ("OneViewBack");
 }
开发者ID:g-bunny,项目名称:InterPlay,代码行数:7,代码来源:CameraMovement.cs


示例7: Initialize

	public void Initialize (LayerMask terrainMask, LayerMask objectMask, Transform foliageContainer, float newYearLength)
	{
		terrainLayerMask = terrainMask;
		objectLayerMask = objectMask;
		container = foliageContainer;
		yearLength = newYearLength;
	}
开发者ID:TheMasonX,项目名称:Project-True-Forest,代码行数:7,代码来源:TerrainObjectType.cs


示例8: Awake

    protected override void Awake()
    {
        base.Awake();
        _controller = GetComponent<CharacterController>();

        _groundLayers = 1 << LayerMask.NameToLayer("Environment") | 1 << LayerMask.NameToLayer("StickingWall");
    }
开发者ID:Rirols,项目名称:Theater,代码行数:7,代码来源:CharacterMotor.cs


示例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);
 }
开发者ID:jslone,项目名称:Jenga,代码行数:8,代码来源:AlignBlock.cs


示例10: Setup

	private void Setup(Vector2 heading, LayerMask layer)
	{
		Heading = heading;
		Layer = layer;

		StartCoroutine(Timer());
	}
开发者ID:KyleMassacre,项目名称:PlanetServer,代码行数:7,代码来源:Shot.cs


示例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;
    }
开发者ID:sean-h,项目名称:spacegame,代码行数:28,代码来源:LaserCannon.cs


示例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;
    }
开发者ID:akihasakura,项目名称:RunningGame,代码行数:33,代码来源:UnityChan2DController.cs


示例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;
 }
开发者ID:FeedJonathanFoundation,项目名称:ubisoft-game-lab,代码行数:7,代码来源:MoveClosestWaypoint.cs


示例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
 }
开发者ID:mrkennyschafer,项目名称:Meditational_Gaming,代码行数:7,代码来源:FireWeapons.cs


示例15: Awake

	void Awake ()
	{

		tipsBlockLayerMask = 1 << gameObject.layer;

		maskedLayer = 1 << ISSCLayerManager.blockLayer;
	}
开发者ID:LingJiJian,项目名称:Smashy-Cars,代码行数:7,代码来源:SelectTipBlockEffect.cs


示例16: setHoming

 public void setHoming(float turn, float maxDist, float maxAngle, LayerMask voituresLayer)
 {
     this.turn = turn;
     this.maxDistance = maxDist;
     this.maxAngle = maxAngle;
     this.voituresLayer = voituresLayer;
 }
开发者ID:SeevenDev,项目名称:LOG4715_Lab2,代码行数:7,代码来源:ProjectileBehavior.cs


示例17: WithinSight

 public static Transform WithinSight(Transform transform, Vector3 positionOffset, float fieldOfViewAngle, float viewDistance, LayerMask objectLayerMask)
 {
     Transform objectFound = null;
     var hitColliders = Physics.OverlapSphere(transform.position, viewDistance, objectLayerMask);
     if (hitColliders != null)
     {
         float minAngle = Mathf.Infinity;
         for (int i = 0; i < hitColliders.Length; ++i)
         {
             float angle;
             Transform obj;
             // Call the WithinSight function to determine if this specific object is within sight
             if ((obj = WithinSight(transform, positionOffset, fieldOfViewAngle, viewDistance, hitColliders[i].transform, false, out angle)) != null)
             {
                 // This object is within sight. Set it to the objectFound GameObject if the angle is less than any of the other objects
                 if (angle < minAngle)
                 {
                     minAngle = angle;
                     objectFound = obj;
                 }
             }
         }
     }
     return objectFound;
 }
开发者ID:seenen,项目名称:BehaviorTree_Seenen,代码行数:25,代码来源:BDUtility.cs


示例18: VerticalCollisions

	void VerticalCollisions(ref Vector3 velocity, LayerMask cMask){
		float dirY 		= Mathf.Sign (velocity.y);																		        // direction of velocity in the y component
		float rayLength = Mathf.Abs(velocity.y) + skinWidth;															        // length of raycast ray, equal to velocity in the y component
		for (int i = 0; i < vertRayCount; i++) {
			Vector2 	 rayOrigin = (dirY == -1)?rayCastOrigins.botLeft:rayCastOrigins.topLeft;						        // checks direction of velocity in the y component and assigns an origin respectively 
			rayOrigin 	     	  += Vector2.right * (vertRaySpacing * i + velocity.x);									        // adds origin for each ray along boundry 
			RaycastHit2D hit 	   = Physics2D.Raycast(rayOrigin,Vector2.up * dirY,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.up * dirY * rayLength,Color.red);
			if (hit) {																									        // if ray collides with object in layer mask collisionMask
				velocity.y 	= (hit.distance - skinWidth) * dirY;												                // if hit assigns distance from boundry to object collided to velocity in the y 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.x = velocity.y / Mathf.Tan (collisionsInfo.slopeAngle * Mathf.Deg2Rad) * Mathf.Sign(velocity.x);   // more Trig!
				}
				collisionsInfo.below = dirY == -1;
				collisionsInfo.above = dirY == 1;
				if( timeStamp <= Time.time) {                                                                                   
					timeStamp = Time.time + jumpCoolDown;
				}
			}
		}
		if (collisionsInfo.climbingSlope){
			float directionX    = Mathf.Sign (velocity.x);
			rayLength           = Mathf.Abs (velocity.x) + skinWidth;
			Vector2 rayOrigin   = ((directionX == -1)?rayCastOrigins.botLeft:rayCastOrigins.botRight) + Vector2.up * velocity.y;
			RaycastHit2D hit    = Physics2D.Raycast(rayOrigin, Vector2.right * directionX, rayLength, cMask);
			if (hit) {
				float slopeAngle = Vector2.Angle (hit.normal, Vector2.up);
				if (slopeAngle  != collisionsInfo.slopeAngle){
					velocity.x   = (hit.distance - skinWidth) * directionX;
					collisionsInfo.slopeAngle = slopeAngle;
				}
			}			
		}
	}		
开发者ID:HardlyConsideredGames,项目名称:Project-Universus,代码行数:35,代码来源:CollisionsController.cs


示例19: setLayerMask

	public void setLayerMask(){
		#if UNITY_EDITOR
		if(!Application.isPlaying && Layer.value <= 0){
			Layer = 1<< LayerMask.NameToLayer("ShadowLayer");
		}
		#endif
	}
开发者ID:SpacesAdventure,项目名称:Kio-2,代码行数:7,代码来源:DynamicLight.cs


示例20: Start

 void Start()
 {
     navAgent = GetComponent<NavMeshAgent> ();
     myTransform = transform;
     raycastLayer = 1 << LayerMask.NameToLayer ("Player");
     StartCoroutine (DoCheck ());
 }
开发者ID:tpai,项目名称:unitygame-fpsgame2,代码行数:7,代码来源:ZombieMovement.cs



注:本文中的LayerMask类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# LayerType类代码示例发布时间:2022-05-24
下一篇:
C# Layer类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap