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


C# Bounds.Contains方法代码示例

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


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

示例1: getDesiredPositionDelta

        public Vector3 getDesiredPositionDelta( Bounds targetBounds, Vector3 basePosition, Vector3 targetAvgVelocity )
        {
            var desiredOffset = Vector3.zero;
            var hasHorizontal = ( axis & CameraAxis.Horizontal ) == CameraAxis.Horizontal;
            var hasVertical = ( axis & CameraAxis.Vertical ) == CameraAxis.Vertical;
            var bounds = new Bounds( basePosition, new Vector3( width, height, 5f ) );

            if( !bounds.Contains( targetBounds.max ) || !bounds.Contains( targetBounds.min ) )
            {
                // figure out the minimum distance we need to move to get the player back in our bounds
                // x-axis
                if( hasHorizontal && bounds.min.x > targetBounds.min.x )
                {
                    desiredOffset.x = targetBounds.min.x - bounds.min.x;
                }
                else if( hasHorizontal && bounds.max.x < targetBounds.max.x )
                {
                    desiredOffset.x = targetBounds.max.x - bounds.max.x;
                }

                // y-axis. disregard movement above the trap when in platform snap mode
                if( hasVertical && bounds.min.y > targetBounds.min.y )
                {
                    desiredOffset.y = targetBounds.min.y - bounds.min.y;
                }
                else if( /*!inPlatformSnapMode &&*/ hasVertical && bounds.max.y < targetBounds.max.y )
                {
                    desiredOffset.y = targetBounds.max.y - bounds.max.y;
                }
            }

            return desiredOffset;
        }
开发者ID:WondermSwift,项目名称:CameraKit2D,代码行数:33,代码来源:CameraWindow.cs

示例2: FixedUpdate

        protected override void FixedUpdate()
        {
            base.FixedUpdate();

            _realDetectionBlock = DetectionBlock;
            _realDetectionBlock.center = DetectionBlock.center + this.transform.position;

            if (IsFreeToMove && !IsDead && !IsHurt) {

                if (!IsAttacking && !IsHurt && ValidateDetection()) {

                    if (AlwaysFollow) {
                        _following = true;
                    }

                    if (!IsAttacking && !IsHurt
                        && this.transform.position.x - RangeOfAttack <= ProtaController.transform.position.x
                        && this.transform.position.x + RangeOfAttack >= ProtaController.transform.position.x
                        && _realDetectionBlock.Contains(ProtaController.transform.position)) {

                        _delayToAttackCounter += Time.deltaTime;

                        if (_delayToAttackCounter >= DelayToAttack) {
                            if (!IsAttacking && !IsHurt && this.transform.position.x > ProtaController.transform.position.x) {
                                this.ChangePlayerDirection("left");
                                this.ChangePlayerState(PlayerState.Attacking);
                            } else if (!IsAttacking && !IsHurt) {
                                this.ChangePlayerDirection("right");
                                this.ChangePlayerState(PlayerState.Attacking);
                            }

                            _delayToAttackCounter = 0.0f;
                        } else {
                            this.ChangePlayerState(PlayerState.Idle);
                        }
                    } else if (!IsAttacking && !IsHurt && ( _realDetectionBlock.Contains(ProtaController.transform.position) || _following )) {
                        // At Left
                        if (!IsAttacking && !IsHurt && this.transform.position.x - RangeOfAttack > ProtaController.transform.position.x) {
                            this.HorizontalMovement("left");
                        } else if (!IsAttacking && !IsHurt && this.transform.position.x + RangeOfAttack < ProtaController.transform.position.x) {
                            this.HorizontalMovement("right");
                        } else {
                            this.ChangePlayerState(PlayerState.Idle);
                        }
                    } else if (!IsAttacking && !IsHurt) {
                        this.ChangePlayerState(PlayerState.Idle);
                    }
                } else if (!IsAttacking && !IsHurt) {
                    this.ChangePlayerState(PlayerState.Idle);
                }
            }
        }
开发者ID:SpoonmanGames,项目名称:Descend-Into-Heaven,代码行数:52,代码来源:BadGuy.cs

示例3: BoundsInBoundsCheck

    public static Vector3 BoundsInBoundsCheck( Bounds bigB, Bounds lilB, BoundsTest test = BoundsTest.onScreen)
    {
        Vector3 pos = lilB.center;
        Vector3 off = Vector3.zero;
        switch (test) {

        case BoundsTest.center:
            if (bigB.Contains(pos)){
                return(Vector3.zero);
            }

            if(pos.x > bigB.max.x){
                off.x = pos.x - bigB.max.x;
            } else if (pos.x < bigB.min.x){
                off.x = pos.x - bigB.min.x;
            }

            if(pos.y > bigB.max.y){
                off.y = pos.y - bigB.max.y;
            } else if (pos.y < bigB.min.y){
                off.y = pos.y - bigB.min.y;
            }

            if(pos.z > bigB.max.z){
                off.z = pos.z - bigB.max.z;
            } else if (pos.z < bigB.min.z){
                off.z = pos.z - bigB.min.z;
            }
            return(off);
        }
        return(Vector3.zero);
    }
开发者ID:CwExist,项目名称:spacesmup,代码行数:32,代码来源:Utils.cs

示例4: setScope

 public static void setScope(Bounds pBounds, Transform pParent,NetworkPlayer pPlayer)
 {
     foreach (Transform lTransform in pParent)
     {
         lTransform.networkView.SetScope(pPlayer,pBounds.Contains(lTransform.position));
     }
 }
开发者ID:Seraphli,项目名称:TheInsectersWar,代码行数:7,代码来源:BoundNetworkScope.cs

示例5: DynamicSetupList

    private List<Vector3> DynamicSetupList(float minX, float maxX, float minZ, float maxZ, Bounds bR, Bounds bM)
    {
        List<Vector3> checkList = new List<Vector3>();
        float Tilesize = Pathfinder.Instance.Tilesize;

        for (float i = minZ; i < maxZ; i += Tilesize / 2)
        {
            for (float j = minX; j < maxX; j += Tilesize / 2)
            {
                for (float k = bR.min.y; k < bR.max.y; k += Tilesize)
                {
                    if (k > lowestY)
                    {
                        Vector3 local = transform.InverseTransformPoint(new Vector3(j, k, i));

                        if (bM.Contains(local))
                        {
                            checkList.Add(new Vector3(j, k, i));
                        }
                    }
                }
            }
        }
        return checkList;
    }
开发者ID:erinwalker,项目名称:PersonalWork,代码行数:25,代码来源:DynamicTDGridObject.cs

示例6: LookForTrackedUserInRegion

 ZigTrackedUser LookForTrackedUserInRegion(ZigInput zig, Bounds region) {
     foreach (ZigTrackedUser trackedUser in zig.TrackedUsers.Values) {
         if (trackedUser.SkeletonTracked && region.Contains(trackedUser.Position) && trackedUser != leftTrackedUser && trackedUser != rightTrackedUser) {
             return trackedUser;
         }
     }
     return null;
 }
开发者ID:guozanhua,项目名称:kinect-oculus-demo,代码行数:8,代码来源:ZigEngageSplitScreen.cs

示例7: existsBetweenOrInside

 //Checks for containment first, then for intersection
 public static bool existsBetweenOrInside(Bounds box, Triangle3 triangle)
 {
     foreach (Vector3 p in triangle.ABC)
     {
         if(box.Contains(p))
             return true;
     }
     return existsBetween(box, triangle);
 }
开发者ID:polycular,项目名称:oekogotschi,代码行数:10,代码来源:Intersection3.cs

示例8: AreaContainsClick

		public static bool AreaContainsClick(Bounds area , Vector2 mousePosition)
		{
			if (Input.GetMouseButton(0))
			{
				if (area.Contains(mousePosition))
				{
					return true;
				}
			}
			return false;
		}
开发者ID:DutchBeastman,项目名称:ProefProeveAdventureClick,代码行数:11,代码来源:ClickUtils.cs

示例9: BoundsWithinPoints

    // BoundsWithinPoints                                                                                      //
    // Cchecks if passed bounds contains either point (return false)                                           //
    // Then Fires rays between both points to check if the bounds are contained within both rays (return true) //
    public static bool BoundsWithinPoints( Vector3 point_a, Vector3 point_b, Bounds bounds )
    {
        // If the start or end point are within the object, do nothing
        if( bounds.Contains( point_a ) || bounds.Contains( point_b ) )
        {
            return false;
        }

        // If the object is fully on both rays
        Ray ray_forward = new Ray( point_a, point_b - point_a );
        Ray ray_backward = new Ray( point_b, point_a - point_b );
        if( bounds.IntersectRay( ray_forward ) && bounds.IntersectRay( ray_backward ))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
开发者ID:tomob95,项目名称:Portfolio,代码行数:23,代码来源:TiCuttingUtilities.cs

示例10: Update

        protected override void Update()
        {
            base.Update();

            if (EditorDebugMode) {
                if (!ShootAlways) {
                    DebugExtension.DebugBounds(_realDetectionBlock, Color.red);
                }
                DebugExtension.DebugBounds(_realShootRangeBlock, Color.green);
            }

            _realDetectionBlock = DetectionBlock;
            _realDetectionBlock.center = DetectionBlock.center + this.transform.position;
            _realShootRangeBlock = ShootRangeBlock;
            _realShootRangeBlock.center = ShootRangeBlock.center + this.transform.position;

            if (!IsDead && (ShootAlways || _realDetectionBlock.Contains(PlayerController.transform.position)) ) {

                _attackDelayCounter += Time.deltaTime;

                if (_attackDelayCounter >= AttackDelay) {

                    _attackDelayCounter = 0;
                    ChangePlayerState(PlayerState.Attacking);

                    if (ShootAtTarget) {
                        _BulletToSpawn = Instantiate(BulletToSpawn, this.transform.position + _upSpawnPosition, this.transform.rotation) as GameObject;
                        _BulletToSpawn.GetComponent<BulletController>().TargetPosition = PlayerController.transform.position;
                        _BulletToSpawn.GetComponent<BulletController>().SetVelocity();
                    } else {
                        if (!ChooseShootDirections || ShootLeft) {
                            _BulletToSpawn = Instantiate(BulletToSpawn, this.transform.position + _leftSpawnPosition, this.transform.rotation) as GameObject;
                            _BulletToSpawn.GetComponent<BulletController>().TargetPosition = new Vector2(_realShootRangeBlock.min.x, _BulletToSpawn.transform.position.y);
                            _BulletToSpawn.GetComponent<BulletController>().SetVelocity();
                        }

                        if (!ChooseShootDirections || ShootUp) {
                            _BulletToSpawn = Instantiate(BulletToSpawn, this.transform.position + _upSpawnPosition, this.transform.rotation) as GameObject;
                            _BulletToSpawn.GetComponent<BulletController>().TargetPosition = new Vector2(_BulletToSpawn.transform.position.x, _realShootRangeBlock.max.y);
                            _BulletToSpawn.GetComponent<BulletController>().SetVelocity();
                        }

                        if (!ChooseShootDirections || ShootRight) {
                            _BulletToSpawn = Instantiate(BulletToSpawn, this.transform.position + _rightSpawnPosition, this.transform.rotation) as GameObject;
                            _BulletToSpawn.GetComponent<BulletController>().TargetPosition = new Vector2(_realShootRangeBlock.max.x, _BulletToSpawn.transform.position.y);
                            _BulletToSpawn.GetComponent<BulletController>().SetVelocity();
                        }
                    }
                }
            }
        }
开发者ID:SpoonmanGames,项目名称:Descend-Into-Heaven,代码行数:51,代码来源:CrossEnemy.cs

示例11: ApplyForce

    public void ApplyForce(Transform transObj, float maxForce = 1, float radius = 0)
    {
        //radius = 0;
        //Debug.Log("Cube hit!");

        var b = new Bounds(FinalPosition, transform.localScale);
        b.Expand(radius * 2);

        // Why does radius need to be multiplied by 2?
        //var falloffBounds =new Bounds( new Bounds(FinalPosition, transform.localScale + (Vector3.one * Falloff) + (Vector3.one * radius * 2));

        var falloffBounds = new Bounds(FinalPosition, transform.localScale);
        falloffBounds.Expand(radius * 2 + Falloff * 2);
        if (falloffBounds.Contains(transObj.position))
        {
            //Debug.Log("Object in falloff");

            // inside the obstacle!
            if (b.Contains(transObj.position))
            {
                //Debug.Log("Object has enter bounds!");

                transObj.position = GetClosestBorderFromInsidePoint(b, transObj.position, 0.01f);
            }
            // in the fallout area
            else
            {
                var falloutClosePoint = falloffBounds.ClosestPoint(transObj.position);
                Helpers.DrawDebugPoint(falloutClosePoint, 1, Color.cyan);

                var objClosePoint = b.ClosestPoint(transObj.position);
                Helpers.DrawDebugPoint(objClosePoint, 1, Color.magenta);

                Debug.DrawLine(falloutClosePoint, objClosePoint, Color.yellow);

                var mag = (falloutClosePoint - objClosePoint).magnitude;

                var frac = Mathf.Max(1 - mag / Falloff, 0);

                //Debug.Log("mag = " + mag + " (" + frac + ")");

                var forceVector = (falloutClosePoint - objClosePoint).normalized * frac * maxForce;
                transObj.position += forceVector * Time.deltaTime;
            }
        }
    }
开发者ID:talford2,项目名称:FirstPersonExperiment,代码行数:46,代码来源:CubeObstackeAvoidence.cs

示例12: GetPosition

 public override Vector3 GetPosition(MBParticle PT)
 {
     int runs = 0;
     Bounds r = new Bounds(Vector3.zero,Scale);
     Vector3 hrs=Scale;
     hrs.Scale(Hollow);
     Bounds hr = new Bounds(Vector3.zero, hrs);
     Vector3 v = Vector3.zero;
     while (runs++ < 100) {
         v.x = Random.Range(r.min.x, r.max.x);
         v.y = Random.Range(r.min.y, r.max.y);
         v.z = Random.Range(r.min.z, r.max.z);
         if (!hr.Contains(v))
             return v;
     }
     return new Vector3(r.min.x, r.min.y, r.min.z);
 }
开发者ID:rstaewen,项目名称:Pharos,代码行数:17,代码来源:MBHollowBoxEmitter.cs

示例13: FixedUpdate

	void FixedUpdate(){
		Vector3 delta = _player.transform.position - transform.position;
			
		if(delta.x > targetDistance.x || delta.x < -targetDistance.x){
			if(movementEnabled){
				delta.Normalize();
				_unit.Move(delta.x);
			}
		}

		if(!movementEnabled){
			Bounds bounds = new Bounds(transform.position, wakeDistance);
			if(bounds.Contains(_player.transform.position)){
				movementEnabled = true;
			}
		}
	}
开发者ID:zendar,项目名称:gamejam2016,代码行数:17,代码来源:EnemyAI.cs

示例14: ClosestPoint

    public static Vector2 ClosestPoint(Bounds bounds, Vector2 point) {
        if (bounds.Contains(point)) {
            return point;
        } else {
            float x = point.x;
            float y = point.y;

            if (x < bounds.min.x) {
                x = bounds.min.x;
            } else if (x > bounds.max.x) {
                x = bounds.max.x;
            }

            if (y < bounds.min.y) {
                y = bounds.min.y;
            } else if (y > bounds.max.y) {
                y = bounds.max.y;
            }

            return new Vector2(x, y);
        }
    }
开发者ID:tng2903,项目名称:game1,代码行数:22,代码来源:MadMath.cs

示例15: updateScope

 public void updateScope(Bounds pBounds)
 {
     //Scope Transform中的子物体
     foreach (Transform lNetworkPlayerRoot in networkPlayerRoots)
     {
         setScope(pBounds, lNetworkPlayerRoot, networkPlayer);
     }
     //Scope 自定义物体
     var lNetworkViewNode = networkViewList.First;
     while (lNetworkViewNode != null)
     {
         var lNetworkView = lNetworkViewNode.Value;
         var lNextNode = lNetworkViewNode.Next;
         if (lNetworkView)
         {
             lNetworkView.SetScope(networkPlayer,
                 pBounds.Contains(lNetworkView.transform.position));
         }
         else
             networkViewList.Remove(lNetworkViewNode);
         lNetworkViewNode = lNextNode;
     }
 }
开发者ID:Seraphli,项目名称:TheInsectersWar,代码行数:23,代码来源:BoundNetworkScope.cs


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