当前位置: 首页>>代码示例>>C#>>正文


C# LayerMask类代码示例

本文整理汇总了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;
	}
开发者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


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