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


C# Rect.Overlaps方法代码示例

本文整理汇总了C#中UnityEngine.Rect.Overlaps方法的典型用法代码示例。如果您正苦于以下问题:C# Rect.Overlaps方法的具体用法?C# Rect.Overlaps怎么用?C# Rect.Overlaps使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Rect的用法示例。


在下文中一共展示了Rect.Overlaps方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FixedUpdate

    void FixedUpdate()
    {
        ball.localPosition += new Vector3(velocityX, velocityY, 0);
        Debug.Log(ball.localPosition);
        Debug.Log(ball.localPosition + (Vector3.up * ballRadius));
        if (velocityY > 0)
        {
            if (!area.rect.Contains(ball.localPosition + new Vector3(0, ballRadius, 0)))
            {
                velocityY = -velocityY;
            }
        }
        else
        {
            if (!area.rect.Contains(ball.localPosition + new Vector3(0, -ballRadius, 0)))
            {
                velocityY = -velocityY;
            }
        }

        Rect ball2Rect = new Rect(ball.localPosition.x - ballRadius, ball.localPosition.y - ballRadius, ballRadius * 2, ballRadius * 2);
        Rect paddle1Rect = new Rect(paddle1.localPosition.x - 5, paddle1.localPosition.y - 25, 10, 50);
        Rect paddle2Rect = new Rect(paddle2.localPosition.x - 5, paddle2.localPosition.y - 25, 10, 50);
        if (velocityX > 0 && ball2Rect.Overlaps(paddle2Rect))
        {
            velocityX = -velocityX;
        }
        else if (velocityX < 0 && ball2Rect.Overlaps(paddle1Rect))
        {
            velocityX = -velocityX;
        }
    }
开发者ID:Absor,项目名称:RoadTo5k,代码行数:32,代码来源:PongMatchScript.cs

示例2: TestOverlop

 static void TestOverlop()
 {
     var rect = new Rect(0, 0, 100, 100);
     Assert(true, rect.Overlaps(new Rect(-1, -1, 101, 101)));
     Assert(true, rect.Overlaps(new Rect(1, 1, 50, 50)));
     Assert(true, rect.Overlaps(new Rect(50, 50, 200, 200)));
     Assert(false, rect.Overlaps(new Rect(150, 150, 200, 200)));
 }
开发者ID:pureivan,项目名称:UIBatchSorting,代码行数:8,代码来源:UIBatchSortingTest.cs

示例3: IsInRegion

	/// <summary>
	/// Gets whether any part of this object is touching the given region of world space.
	/// </summary>
	public bool IsInRegion(Rect region)
	{
		Bounds myBounds3D = MyCollider.bounds;
		Rect myBounds = new Rect(myBounds3D.min.x, myBounds3D.min.y,
								 myBounds3D.size.x, myBounds3D.size.y);

		return region.Overlaps(myBounds, true);
	}
开发者ID:heyx3,项目名称:PointAndClick,代码行数:11,代码来源:PhotographableObject.cs

示例4: Intersects

 public static bool Intersects(Rect r1, Rect r2)
 {
     if (!r1.Overlaps(r2) && !r2.Overlaps(r1))
     {
         return false;
     }
     return true;
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:8,代码来源:RectUtils.cs

示例5: Overlaps

        public static bool Overlaps(Rect screenRect, Renderer renderer)
        {
            if (!renderer)
                return false;

            Rect boundsRect = BoundsToScreenRect(renderer.bounds);
            return screenRect.Overlaps(boundsRect);
        }
开发者ID:devmelon,项目名称:Answers,代码行数:8,代码来源:SelectionUtil.cs

示例6: Intersection

 public static bool Intersection(Rect r1, Rect r2, out Rect intersection)
 {
     if (!r1.Overlaps(r2) && !r2.Overlaps(r1))
     {
         intersection = new Rect(0f, 0f, 0f, 0f);
         return false;
     }
     float x = Mathf.Max(r1.xMin, r2.xMin);
     float y = Mathf.Max(r1.yMin, r2.yMin);
     float num3 = Mathf.Min(r1.xMax, r2.xMax);
     float num4 = Mathf.Min(r1.yMax, r2.yMax);
     intersection = new Rect(x, y, num3 - x, num4 - y);
     return true;
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:14,代码来源:RectUtils.cs

示例7: Update

    void Update()
    {
        Rect PlayerRect = new Rect(Player.transform.position.x - Player.sprite.bounds.extents.x, Player.transform.position.y - Player.sprite.bounds.extents.y, Player.sprite.bounds.extents.x * 2, Player.sprite.bounds.extents.y * 2),
             BuildingRect = new Rect(_buildingBoxCollider.transform.position.x - _buildingBoxCollider.bounds.extents.x, _buildingBoxCollider.transform.position.y - _buildingBoxCollider.bounds.extents.y, _buildingBoxCollider.bounds.extents.x * 2, _buildingBoxCollider.bounds.extents.y * 2);

        if (PlayerRect.Overlaps(BuildingRect))
        {
            if (_buildingRenderer.color.a > 0.1)
                _buildingRenderer.color = new Color(_buildingRenderer.color.r, _buildingRenderer.color.g, _buildingRenderer.color.b, _buildingRenderer.color.a - Time.deltaTime);
        }
        else
        {
            if(_buildingRenderer.color.a < 1)
                _buildingRenderer.color = new Color(_buildingRenderer.color.r, _buildingRenderer.color.g, _buildingRenderer.color.b, _buildingRenderer.color.a + Time.deltaTime);
        }
    }
开发者ID:GameChangerChicago,项目名称:TheTest,代码行数:16,代码来源:BuildingFadeManager.cs

示例8: Intersect

        /// <summary>
        /// Find the intersection of two rectangles, returns the amount of overlap as a Rectangle.
        /// </summary>
        /// <param name="one">One.</param>
        /// <param name="two">Two.</param>
        public static Rect Intersect(Rect one, Rect two)
        {
            if (one.Overlaps(two))
            {
               	float left, right, top, bottom;

               	if (one.xMin > two.xMin)
               	{
               		left = one.xMin;
               	} else {
               		left = two.xMin;
               	}

               	if (one.xMax < two.xMax)
               	{
               		right = one.xMax;
               	} else{
               		right = two.xMax;
               	}

               	if (one.yMax < two.yMax)
               	{
               		top = one.yMax;
               	} else {
               		top = two.yMax;
               	}

               	if (one.yMin > two.yMin)
               	{
               		bottom = one.yMin;
               	} else {
               		bottom = two.yMin;
               	}

                return new Rect(left, top, right - left, top - bottom);
            } else {
                return new Rect(0, 0, 0, 0);
            }
        }
开发者ID:bfollington,项目名称:Bolt,代码行数:44,代码来源:Rect.cs

示例9: getLimbHit

    int getLimbHit(OmniObject player, Rect r, ref Vector2 pos)
    {
        if (player.skeleton == null)
            return -1;

        Rect b = new Rect();

                for (int i = 0; i < player.skeleton.Length; i++)
                {
                    if (player.skeleton[i].name == "bounds")
                        continue;

                    b.x = player.bounds.x;
                    b.y = player.bounds.y;
                    b.x += player.skeleton[i].bounds.x * player.item.Size;
                    b.y += player.skeleton[i].bounds.y * player.item.Size;
                    b.width = player.skeleton[i].bounds.width * player.item.Size;
                    b.height = player.skeleton[i].bounds.height * player.item.Size;
                    if (r.Overlaps(b))
                    {
                        pos = new Vector2(r.x - b.x, r.y - b.y);
                        return i;
                    }
                }

        return -1;
    }
开发者ID:jwatsn,项目名称:OmniDigUnity,代码行数:27,代码来源:OmniItemType.cs

示例10: SelectWindowsInRect

		public void SelectWindowsInRect(Rect rect, System.Func<FlowWindow, bool> predicate = null) {

			//this.selectionRect = rect;

			this.selected.Clear();
			foreach (var window in this.windows) {

				if (window.IsContainer() == false && rect.Overlaps(window.rect, true) == true && (predicate == null || predicate(window) == true)) {

					this.selected.Add(window.id);

				}

			}

		}
开发者ID:cg0206,项目名称:Unity3d.UI.Windows,代码行数:16,代码来源:FlowData.cs

示例11: Update

 // Update is called once per frame
 void Update()
 {
     if (playerTime.playTime > 0 && !lost)
     {
         for (int i = arrows.Count - 1; i >= 0; i--)
         {
             GameObject obj = arrows[i];
             obj.transform.Translate(-speed, 0, 0);
             Rect rectObj, rectZone;
             rectObj = new Rect(obj.transform.position.x - obj.GetComponent<RectTransform>().rect.width,
                 obj.transform.position.y - obj.GetComponent<RectTransform>().rect.height,
                 obj.GetComponent<RectTransform>().rect.width, obj.GetComponent<RectTransform>().rect.height);
             rectZone = new Rect(pointZone.transform.position.x - pointZone.GetComponent<RectTransform>().rect.width,
                pointZone.transform.position.y - pointZone.GetComponent<RectTransform>().rect.height,
                pointZone.GetComponent<RectTransform>().rect.width, pointZone.GetComponent<RectTransform>().rect.height);
             bool hit = false;
             if (rectObj.Overlaps(rectZone))
             {
                 Debug.Log("Obj " + rectObj + rectObj.size.x * rectObj.size.y);
                 Debug.Log("Zone " + rectZone + rectZone.size.x * rectZone.size.y);
                 Rect inter = new Rect(rectObj.xMin, rectObj.yMin, Mathf.Abs(rectObj.xMin - rectZone.xMax),
                     Mathf.Abs(rectObj.yMin - rectZone.yMax));
                 Debug.Log("inter " + inter + inter.size.x * inter.size.y);
                 int image = 0;
                 for (int j = 0; j < images.Length; j++)
                 {
                     if (obj.GetComponent<Image>().sprite == images[j])
                     {
                         image = j;
                     }
                 }
                 switch (image)
                 {
                     case 0:
                         if (Input.GetKeyDown("up"))
                         {
                             Debug.Log("Acertado");
                             hit = true;
                             Debug.Log("Obj " + rectObj + rectObj.size.x * rectObj.size.y);
                             Debug.Log("Zone " + rectZone + rectZone.size.x * rectZone.size.y);
                             inter = new Rect(rectObj.xMin, rectObj.yMin, Mathf.Abs(rectObj.xMin - rectZone.xMax),
                                 Mathf.Abs(rectObj.yMin - rectZone.yMax));
                             Debug.Log("inter " + inter + inter.size.x * inter.size.y);
                         }
                         break;
                     case 1:
                         if (Input.GetKeyDown("right"))
                         {
                             Debug.Log("Acertado");
                             hit = true;
                             Debug.Log("Obj " + rectObj + rectObj.size.x * rectObj.size.y);
                             Debug.Log("Zone " + rectZone + rectZone.size.x * rectZone.size.y);
                             inter = new Rect(rectObj.xMin, rectObj.yMin, Mathf.Abs(rectObj.xMin - rectZone.xMax),
                                 Mathf.Abs(rectObj.yMin - rectZone.yMax));
                             Debug.Log("inter " + inter + inter.size.x * inter.size.y);
                         }
                         break;
                     case 2:
                         if (Input.GetKeyDown("left"))
                         {
                             Debug.Log("Acertado");
                             hit = true;
                             Debug.Log("Obj " + rectObj + rectObj.size.x * rectObj.size.y);
                             Debug.Log("Zone " + rectZone + rectZone.size.x * rectZone.size.y);
                             inter = new Rect(rectObj.xMin, rectObj.yMin, Mathf.Abs(rectObj.xMin - rectZone.xMax),
                                 Mathf.Abs(rectObj.yMin - rectZone.yMax));
                             Debug.Log("inter " + inter + inter.size.x * inter.size.y);
                         }
                         break;
                     case 3:
                         if (Input.GetKeyDown("down"))
                         {
                             Debug.Log("Acertado");
                             hit = true;
                             Debug.Log("Obj " + rectObj + rectObj.size.x * rectObj.size.y);
                             Debug.Log("Zone " + rectZone + rectZone.size.x * rectZone.size.y);
                             inter = new Rect(rectObj.xMin, rectObj.yMin, Mathf.Abs(rectObj.xMin - rectZone.xMax),
                                 Mathf.Abs(rectObj.yMin - rectZone.yMax));
                             Debug.Log("inter " + inter + inter.size.x * inter.size.y);
                         }
                         break;
                     default:
                         break;
                 }
             }
             if (obj.transform.position.x <= 0 || hit)
             {
                 arrows.Remove(obj);
                 Destroy(obj);
                 lost = !hit;
             }
             if (lost)
             {
                 defeatBanner.SetActive(true);
             }
         }
         separation -= speed;
         if (separation <= 0)
         {
//.........这里部分代码省略.........
开发者ID:MegaTuks,项目名称:GlobalGameJam,代码行数:101,代码来源:Arrows.cs

示例12: FindNearestCellsToARect

				public List<Cell> FindNearestCellsToARect (Rect bbox)
				{
						List<Cell> foundCells = new List<Cell> ();

						// Automatically abort if the range does not collide with this quad
						if (!BoundingBox.Contains (new Vector2 (bbox.xMin, bbox.yMin)) && !BoundingBox.Contains (new Vector2 (bbox.xMin, bbox.yMax)) &&
								!BoundingBox.Contains (new Vector2 (bbox.xMax, bbox.yMin)) && !BoundingBox.Contains (new Vector2 (bbox.xMax, bbox.yMax))
								&& !BoundingBox.Overlaps (bbox))
								return foundCells;
			
						// Check objects at this quad level
						if (bbox.Overlaps (BoundingBox)
								|| bbox.Contains (new Vector2 (BoundingBox.xMin, BoundingBox.yMin))
								|| bbox.Contains (new Vector2 (BoundingBox.xMin, BoundingBox.yMax))
								|| bbox.Contains (new Vector2 (BoundingBox.xMax, BoundingBox.yMin))
								|| bbox.Contains (new Vector2 (BoundingBox.xMax, BoundingBox.yMax)) 
								|| bbox.Contains (BoundingBox.center)) {
								if (Cells.Count > 0) {
										foreach (Cell c in Cells) {
												foundCells.Add (c);
										}
								}
						}

						// Terminate here, if there are no children
						if (Children == null)
								return foundCells;

						// Otherwise, add the points from the children
						foundCells.AddRange (Children [0].FindNearestCellsToARect (bbox));
						foundCells.AddRange (Children [1].FindNearestCellsToARect (bbox));
						foundCells.AddRange (Children [2].FindNearestCellsToARect (bbox));
						foundCells.AddRange (Children [3].FindNearestCellsToARect (bbox));
			
						return foundCells;
				}
开发者ID:kristafervale,项目名称:MapEditor,代码行数:36,代码来源:QuadTreeNode.cs

示例13: CalcCollision

		//chamto noUsed function !!
		//chamto need Optimization !!
		public MonoDrop CalcCollision(MonoDrop srcDrop)
		{


			const float BOX_WIDTH = 0.57f;
			const float BOX_HEIGHT = 0.57f;
			if(null == srcDrop) return null;

			Rect srcBox = new Rect();
			Rect dstBox = new Rect();
			srcBox.width = BOX_WIDTH;
			srcBox.height = BOX_HEIGHT;
			srcBox.center = new Vector2(srcDrop.transform.position.x,srcDrop.transform.position.y);
			dstBox = srcBox;
			foreach(MonoDrop dstDrop in m_mapDrop.DtnrId.Values)
			{
				//self exclusion
				if(srcDrop == dstDrop) continue;

				//dstBox.center = new Vector2(dstDrop.transform.position.x,dstDrop.transform.position.y);
				dstBox.center = new Vector2(dstDrop.gotoWorldPosition.x , dstDrop.gotoWorldPosition.y);

				if(true == srcBox.Overlaps(dstBox,true)) //include allowInverse
				{
					return dstDrop;
				}

			}

			return null;
		}
开发者ID:chamto,项目名称:pudPractice,代码行数:33,代码来源:CDropManager.cs

示例14: Attack

    public void Attack()
    {
        if (animator.GetInteger("dolphin_int") != 2)
        {
            animator.SetInteger("dolphin_int", 2);
            transform.Translate(0f, -0.5f, 0f);
            transform.Rotate(0f, 0f, 180f);

            AttackCounter = Time.time + AttackTimer;
            splashEvent(new Vector3(gameObject.transform.position.x,gameObject.transform.position.y + 0.2f, gameObject.transform.position.z));

        }

        transform.Rotate(Vector3.forward * (0.5f));

        dolphin.transform.Rotate(0f, 0f, -300.0f * Time.deltaTime);
        transform.Translate(new Vector3(1 * 11f * Time.deltaTime, 0f, 0f));

        //hit test
        pr = getRect(playerHitArea);
        //rg = getRect(objectMesh);

        if (pr.Overlaps(rg))
        {
            if(!playerAttacked)
            {
                DolphinAttackEvent(12f);
                playerAttacked = true;
            }

        }

        if (Time.time > AttackCounter)
        {
            currentState = dolphinStates.escaping;
        }
    }
开发者ID:kingofraytown,项目名称:BOAB,代码行数:37,代码来源:DolphinController.cs

示例15: doRoomsOverlapCorridor

	bool doRoomsOverlapCorridor(Corridor alreadyPlaced, Room toBePlaced)
	{
		bool doesOverlap = false;
		//finds the direction of the corridor and makes the correct rectangle
		switch(alreadyPlaced.direction)
		{
		case Direction.North:
			alreadyPlacedRect = new Rect (alreadyPlaced.startXPos, alreadyPlaced.startYPos, alreadyPlaced.corridorWidth+2, alreadyPlaced.corridorLength);
			break;
		case Direction.East:
			alreadyPlacedRect = new Rect (alreadyPlaced.startXPos, alreadyPlaced.startYPos, alreadyPlaced.corridorLength, alreadyPlaced.corridorWidth+2);
			break;
		case Direction.South:
			alreadyPlacedRect = new Rect (alreadyPlaced.startXPos, alreadyPlaced.EndPositionY, alreadyPlaced.corridorWidth+2, alreadyPlaced.corridorLength);
			break;
		case Direction.West:
			alreadyPlacedRect = new Rect (alreadyPlaced.EndPositionX, alreadyPlaced.startYPos, alreadyPlaced.corridorLength, alreadyPlaced.corridorWidth+2);
			break;
		}

		//makes the room rectangle
		toBePlacedRect = new Rect (toBePlaced.xPos-2, toBePlaced.yPos-2, toBePlaced.roomWidth+3, toBePlaced.roomHeight+3);

		//checks to see if the toBePlaced rectangle overlaps the already placed
		if (alreadyPlacedRect.Overlaps (toBePlacedRect)) 
		{
			doesOverlap = true;
		}
		//if previous did not register then checks vise versa
		else if (toBePlacedRect.Overlaps (alreadyPlacedRect)) 
		{
			doesOverlap = true;
		} 
		else 
		{
			//Lastly if code gets here then it individually checks each tile and checks if it is within the other rect
			for (float i = toBePlacedRect.x; i <= toBePlacedRect.x + toBePlacedRect.width; i++) {
				for (float j = toBePlacedRect.y; j <= toBePlacedRect.y + toBePlacedRect.height; j++) {
					if (alreadyPlacedRect.Contains (new Vector2 (i, j))) {
						doesOverlap = true;
						break;
					}
				}
			}
		}
		return doesOverlap;
	}
开发者ID:technicalvgda,项目名称:Adagio,代码行数:47,代码来源:BoardCreator.cs


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