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


C# UnityEngine.Bounds类代码示例

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


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

示例1: Start

 public void Start()
 {
     Factories = new GameObject[10];
     Factories = Resources.LoadAll<GameObject>("Prefabs/Factories/Food");
     ThisBounds = gameObject.GetComponent<Renderer>().bounds;
     Global = GameObject.FindGameObjectWithTag("GLOBALS").GetComponent<Globals>();
 }
开发者ID:wjbdev,项目名称:Rv2,代码行数:7,代码来源:Food.cs

示例2: existsBetween

            //from http://stackoverflow.com/a/17503268/931669
            public static bool existsBetween(Bounds box, Triangle3 triangle)
            {
                double triangleMin, triangleMax;
                double boxMin, boxMax;

                // Test the box normals (x-, y- and z-axes)
                var boxNormals = new Vector3[] {
                    new Vector3(1,0,0),
                    new Vector3(0,1,0),
                    new Vector3(0,0,1)
                };

                //Get the box vertices as array for project()
                var boxVertices = new Vector3[] {
                    box.center + new Vector3(box.extents.x, box.extents.y, box.extents.z),
                    box.center + new Vector3(box.extents.x, -box.extents.y, box.extents.z),
                    box.center + new Vector3(-box.extents.x, -box.extents.y, box.extents.z),
                    box.center + new Vector3(-box.extents.x, box.extents.y, box.extents.z),
                    box.center + new Vector3(box.extents.x, box.extents.y, -box.extents.z),
                    box.center + new Vector3(box.extents.x, -box.extents.y, -box.extents.z),
                    box.center + new Vector3(-box.extents.x, -box.extents.y, -box.extents.z),
                    box.center + new Vector3(-box.extents.x, box.extents.y, -box.extents.z),
                };


                for (int i = 0; i < 3; i++)
                {
                    project(triangle.ABC, boxNormals[i], out triangleMin, out triangleMax);
                    if (triangleMax < box.min[i] || triangleMin > box.max[i])
                        return false; // No intersection possible.
                }

                // Test the triangle normal
                double triangleOffset = Vector3.Dot(triangle.Normal, triangle.A);
                project(boxVertices, triangle.Normal, out boxMin, out boxMax);
                if (boxMax < triangleOffset || boxMin > triangleOffset)
                    return false; // No intersection possible.

                // Test the nine edge cross-products
                Vector3[] triangleEdges = new Vector3[] {
                    triangle.A - (triangle.B),
                    triangle.B - (triangle.C),
                    triangle.C - (triangle.A)
                };
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        // The box normals are the same as it's edge tangents
                        Vector3 axis = Vector3.Cross(triangleEdges[i], boxNormals[j]);
                        project(boxVertices, axis, out boxMin, out boxMax);
                        project(triangle.ABC, axis, out triangleMin, out triangleMax);
                        if (boxMax <= triangleMin || boxMin >= triangleMax)
                            return false; // No intersection possible
                    }
                }

                // No separating axis found.
                return true;
            }
开发者ID:polycular,项目名称:oekogotschi,代码行数:61,代码来源:Intersection3.cs

示例3: DrawBounds

 public static void DrawBounds(Bounds bounds)
 {
     DrawLine(bounds.min, new Vector2(bounds.min.x, bounds.max.y));
     DrawLine(bounds.min, new Vector2(bounds.max.x, bounds.min.y));
     DrawLine(bounds.max, new Vector2(bounds.min.x, bounds.max.y));
     DrawLine(bounds.max, new Vector2(bounds.max.x, bounds.min.y));
 }
开发者ID:chrismcmath,项目名称:Ent2D,代码行数:7,代码来源:DebugUtils.cs

示例4: GetAllInBounds

		/** Fills the buffer with all RecastMeshObjs which intersect the specified bounds */
		public static void GetAllInBounds (List<RecastMeshObj> buffer, Bounds bounds) {
			if (!Application.isPlaying){
				RecastMeshObj[] objs = FindObjectsOfType(typeof(RecastMeshObj)) as RecastMeshObj[];
				for (int i=0;i<objs.Length;i++) {
					objs[i].RecalculateBounds();
					if (objs[i].GetBounds ().Intersects (bounds)) {
						buffer.Add(objs[i]);
					}
				}
				return;
			} else if (Time.timeSinceLevelLoad == 0) {
				//Is is not guaranteed that all RecastMeshObj OnEnable functions have been called, so if it is the first frame since loading a new level
				//try to initialize all RecastMeshObj objects.
				RecastMeshObj[] objs = FindObjectsOfType(typeof(RecastMeshObj)) as RecastMeshObj[];
				for (int i=0;i<objs.Length;i++) objs[i].Register();
			}
			
			for (int q=0;q<dynamicMeshObjs.Count;q++) {
				if (dynamicMeshObjs[q].GetBounds ().Intersects (bounds)) {
					buffer.Add (dynamicMeshObjs[q]);
				}
			}
			
			Rect r = Rect.MinMaxRect (bounds.min.x, bounds.min.z, bounds.max.x, bounds.max.z);
			
			tree.QueryInBounds (r, buffer);
		}
开发者ID:westernknight,项目名称:RVO,代码行数:28,代码来源:RecastMeshObj.cs

示例5: DrawBounds

		public static void DrawBounds(Bounds bounds, Color color)
		{
			var size = bounds.size;

			var points = new Vector3[8];
			points[0] = bounds.center-bounds.extents;
			points[1] = points[0]+new Vector3(size.x, 0, 0);
			points[2] = points[0]+new Vector3(0, size.y, 0);
			points[3] = points[0]+new Vector3(0, 0, size.z);
			points[4] = bounds.center+bounds.extents;
			points[5] = points[4]-new Vector3(size.x, 0, 0);
			points[6] = points[4]-new Vector3(0, size.y, 0);
			points[7] = points[4]-new Vector3(0, 0, size.z);

			Debug.DrawLine(points[0], points[1], color);
			Debug.DrawLine(points[0], points[2], color);
			Debug.DrawLine(points[0], points[3], color);
			Debug.DrawLine(points[4], points[5], color);
			Debug.DrawLine(points[4], points[6], color);
			Debug.DrawLine(points[4], points[7], color);
			Debug.DrawLine(points[1], points[6], color);
			Debug.DrawLine(points[1], points[7], color);
			Debug.DrawLine(points[2], points[5], color);
			Debug.DrawLine(points[2], points[7], color);
			Debug.DrawLine(points[3], points[5], color);
			Debug.DrawLine(points[3], points[6], color);
		}
开发者ID:siwenRen,项目名称:Wolf,代码行数:27,代码来源:DebugUtils.cs

示例6: onDrawGizmos

        public void onDrawGizmos( Vector3 basePosition )
        {
            Gizmos.color = new Color( 1f, 0f, 0.6f );

            var hasHorizontal = ( axis & CameraAxis.Horizontal ) == CameraAxis.Horizontal;
            var hasVertical = ( axis & CameraAxis.Vertical ) == CameraAxis.Vertical;
            var hasBothAxis = hasHorizontal && hasVertical;
            var bounds = new Bounds( basePosition, new Vector3( width, height ) );
            var lineWidth = Camera.main.orthographicSize;

            // expand our bounds to have larger lines if we only have a single axis
            if( hasVertical && !hasBothAxis )
            {
                bounds.Expand( new Vector3( lineWidth - bounds.size.x, 0f ) );
            }

            if( hasHorizontal && !hasBothAxis )
            {
                bounds.Expand( new Vector3( 0f, lineWidth - bounds.size.y ) );
            }

            if( hasVertical || hasBothAxis )
            {
                Gizmos.DrawLine( bounds.min, bounds.min + new Vector3( bounds.size.x, 0f ) );
                Gizmos.DrawLine( bounds.max, bounds.max - new Vector3( bounds.size.x, 0f ) );
            }

            if( hasHorizontal || hasBothAxis )
            {
                Gizmos.DrawLine( bounds.min, bounds.min + new Vector3( 0f, bounds.size.y ) );
                Gizmos.DrawLine( bounds.max, bounds.max - new Vector3( 0f, bounds.size.y ) );
            }
        }
开发者ID:WondermSwift,项目名称:CameraKit2D,代码行数:33,代码来源:CameraWindow.cs

示例7: MaxBoundsExtent

        public static float MaxBoundsExtent(Transform obj, bool includeEffects)
        {
            // get the maximum bounds extent of object, including all child renderers,
            // but excluding particles and trails, for FOV zooming effect.

            var renderers = obj.GetComponentsInChildren<Renderer>();

            Bounds bounds = new Bounds();
            bool initBounds = false;
            foreach (Renderer r in renderers)
            {
                if (!((r is TrailRenderer) || (r is ParticleRenderer) || (r is ParticleSystemRenderer)))
                {
                    if (!initBounds)
                    {
                        initBounds = true;
                        bounds = r.bounds;
                    }
                    else
                    {
                        bounds.Encapsulate(r.bounds);
                    }
                }
            }
            float max = Mathf.Max(bounds.extents.x, bounds.extents.y, bounds.extents.z);
            return max;
        }
开发者ID:oatssss,项目名称:McGill-Once-McGill-Twice,代码行数:27,代码来源:TargetFieldOfView.cs

示例8: DistanceToBounds

 public static float DistanceToBounds(Direction dir, Vector3 pos, Bounds liveable)
 {
     switch(dir)
     {
         case Direction.NORTH:
             return liveable.max.y - pos.y;
         case Direction.NORTHEAST:
             return Mathf.Min(liveable.max.y - pos.y, liveable.max.z - pos.z);
         case Direction.EAST:
             return liveable.max.z - pos.z;
         case Direction.SOUTHEAST:
             return Mathf.Min(pos.y - liveable.min.y, liveable.max.z - pos.z);
         case Direction.SOUTH:
             return pos.y - liveable.min.y;
         case Direction.SOUTHWEST:
             return Mathf.Min(pos.y - liveable.min.y, pos.z - liveable.min.z);
         case Direction.WEST:
             return pos.z - liveable.min.z;
         case Direction.NORTHWEST:
             return Mathf.Min(liveable.max.y - pos.y, pos.z - liveable.min.z);
         default:
         case Direction.CENTER:
             break;
     }
     return 99999f;
 }
开发者ID:threeup,项目名称:threefish,代码行数:26,代码来源:Utils.cs

示例9: loadBattleTileArray

        //Battle Tile Array uses 32x32 px tiles.  Also includes tileSpriteLookup metadata object
        private void loadBattleTileArray(GameObject tileMapGameObject)
        {

            string strTileArray = "";

            Bounds mapBounds = tileMapGameObject.GetComponentInChildren<Renderer>().bounds;

            int tileWidth = (int)Math.Ceiling(mapBounds.size.x );
            int tileHeight = (int)Math.Ceiling(mapBounds.size.y );

            battleTileArray = new Tile[tileWidth, tileHeight];
            for (int y = 0; y < tileHeight; y++)
            {
                for (int x = 0; x < tileWidth; x++)
                {
                 
                    Vector3 center = new Vector3(x + Tile.TILE_SIZE, -y + Tile.TILE_SIZE,0);
                    Vector3 size = new Vector3(Tile.TILE_SIZE, Tile.TILE_SIZE);
                    Bounds tileBounds = new Bounds(center, size);
                    bool empty = !checkCollision(tileBounds);

                    battleTileArray[x, y] = new Tile(x, y, empty);

                    //Extra metadata on tile
                    battleTileArray[x, y].tileSpriteLookup = getTileSpriteLookup(tileBounds, x, y, empty);

                    strTileArray += empty ? "." : "#";
                }
                strTileArray += System.Environment.NewLine;
            }
            int i = 1;
        }
开发者ID:mengtest,项目名称:UnityRPG,代码行数:33,代码来源:TileMapData.cs

示例10: DoRenderPreview

 private void DoRenderPreview(bool shaded)
 {
     BillboardAsset target = this.target as BillboardAsset;
     Bounds bounds = new Bounds(new Vector3(0f, (this.m_Height.floatValue + this.m_Bottom.floatValue) * 0.5f, 0f), new Vector3(this.m_Width.floatValue, this.m_Height.floatValue, this.m_Width.floatValue));
     float magnitude = bounds.extents.magnitude;
     float num2 = 8f * magnitude;
     Quaternion quaternion = Quaternion.Euler(-this.m_PreviewDir.y, -this.m_PreviewDir.x, 0f);
     this.m_PreviewUtility.m_Camera.transform.rotation = quaternion;
     this.m_PreviewUtility.m_Camera.transform.position = (Vector3) (quaternion * (-Vector3.forward * num2));
     this.m_PreviewUtility.m_Camera.nearClipPlane = num2 - (magnitude * 1.1f);
     this.m_PreviewUtility.m_Camera.farClipPlane = num2 + (magnitude * 1.1f);
     this.m_PreviewUtility.m_Light[0].intensity = 1.4f;
     this.m_PreviewUtility.m_Light[0].transform.rotation = quaternion * Quaternion.Euler(40f, 40f, 0f);
     this.m_PreviewUtility.m_Light[1].intensity = 1.4f;
     Color ambient = new Color(0.1f, 0.1f, 0.1f, 0f);
     InternalEditorUtility.SetCustomLighting(this.m_PreviewUtility.m_Light, ambient);
     if (shaded)
     {
         target.MakeRenderMesh(this.m_ShadedMesh, 1f, 1f, 0f);
         target.MakeMaterialProperties(this.m_ShadedMaterialProperties, this.m_PreviewUtility.m_Camera);
         ModelInspector.RenderMeshPreviewSkipCameraAndLighting(this.m_ShadedMesh, bounds, this.m_PreviewUtility, target.material, null, this.m_ShadedMaterialProperties, new Vector2(0f, 0f), -1);
     }
     else
     {
         target.MakePreviewMesh(this.m_GeometryMesh);
         ModelInspector.RenderMeshPreviewSkipCameraAndLighting(this.m_GeometryMesh, bounds, this.m_PreviewUtility, this.m_GeometryMaterial, this.m_WireframeMaterial, null, new Vector2(0f, 0f), -1);
     }
     InternalEditorUtility.RemoveCustomLighting();
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:29,代码来源:BillboardAssetInspector.cs

示例11: Start

 public void Start()
 {
     Global = GameObject.FindGameObjectWithTag("GLOBALS").GetComponent<Globals>();
     ThisBounds = gameObject.GetComponent<Renderer>().bounds;
     Level = 1;
     InvokeRepeating("Mine", 3f, 3f);
 }
开发者ID:wjbdev,项目名称:Rv2,代码行数:7,代码来源:Fac_Metal.cs

示例12: Move

        public Vector2 Move(float deltaX, float deltaY)
        {
            //Update bounds
            m_BoundsWithSkin = m_BoxCollider.bounds;
            m_BoundsWithSkin.Expand(-2.0f * m_SkinWidth);

            m_IsGrounded = false;
            m_IsGoingUpSlope = false;

            Vector2 deltaMovement = new Vector2(deltaX * Time.deltaTime, deltaY * Time.deltaTime);

            //Move horizontally
            HandleHorizontalMovement(ref deltaMovement);
            
            //Move vertically
            HandleVerticalMovement(ref deltaMovement);

            //Do the actual movement in world space
            transform.Translate(new Vector3(deltaMovement.x, deltaMovement.y, 0.0f), Space.World);

            //Return the current velocity
            Vector2 velocity = new Vector2(0.0f, 0.0f);

            if (Time.deltaTime > 0.0f)
                velocity = deltaMovement / Time.deltaTime;

            return velocity;
        }
开发者ID:stijndelaruelle,项目名称:sjabloon,代码行数:28,代码来源:CharacterController2D.cs

示例13: DoEditModeInspectorModeButton

 public static void DoEditModeInspectorModeButton(SceneViewEditMode mode, string label, GUIContent icon, Bounds bounds, Editor caller)
 {
     if (!EditorUtility.IsPersistent(caller.target))
     {
         DetectMainToolChange();
         if (s_EditColliderButtonStyle == null)
         {
             s_EditColliderButtonStyle = new GUIStyle("Button");
             s_EditColliderButtonStyle.padding = new RectOffset(0, 0, 0, 0);
             s_EditColliderButtonStyle.margin = new RectOffset(0, 0, 0, 0);
         }
         Rect rect = EditorGUILayout.GetControlRect(true, 23f, new GUILayoutOption[0]);
         Rect position = new Rect(rect.xMin + EditorGUIUtility.labelWidth, rect.yMin, 33f, 23f);
         GUIContent content = new GUIContent(label);
         Vector2 vector = GUI.skin.label.CalcSize(content);
         Rect rect3 = new Rect(position.xMax + 5f, rect.yMin + ((rect.height - vector.y) * 0.5f), vector.x, rect.height);
         int instanceID = caller.GetInstanceID();
         bool flag = (editMode == mode) && (ownerID == instanceID);
         EditorGUI.BeginChangeCheck();
         bool flag2 = GUI.Toggle(position, flag, icon, s_EditColliderButtonStyle);
         GUI.Label(rect3, label);
         if (EditorGUI.EndChangeCheck())
         {
             ChangeEditMode(!flag2 ? SceneViewEditMode.None : mode, bounds, caller);
         }
     }
 }
开发者ID:demelev,项目名称:projectHL,代码行数:27,代码来源:EditMode.cs

示例14: GetBoundDiag

        //-----------------------------------------------------
        //Renvoie la diagonale de la bounding box
        public static float GetBoundDiag(Bounds bbox)
        {
            Vector3 dim = bbox.size;
               // Calculer la taille idéale du champ de vision de la caméra (+projecteur) : la plus petite possible contenant l'objet

            float  bigDim = 0, bigDim2=0, bigI=0;
               for(int i=0; i<3; i++)      // Récupérer la dimension la plus grande
               {
                   if( (dim[i]>0 ? dim[i] : -dim[i]) > bigDim)
                   {
                       bigDim = (dim[i]>0 ? dim[i] : -dim[i]);
                       bigI = i;
                   }
               }
               for(int i=0; i<3; i++)      // Récupérer la 2e dimension la plus grande
               {
                   if( (dim[i]>0 ? dim[i] : -dim[i]) > bigDim2 && i!=bigI)
                       bigDim2 = (dim[i]>0 ? dim[i] : -dim[i]);
               }

            //       Debug.Log("IOSBigDim = "+bigDim+", BigDim2="+bigDim2);
               bigDim = bigDim/2;// * scl;
               bigDim2 = bigDim2/2;// * scl;

               return Mathf.Sqrt(bigDim*bigDim + bigDim2*bigDim2);
        }
开发者ID:gviaud,项目名称:OS-unity-5,代码行数:28,代码来源:_3Dutils.cs

示例15: GetBounds

        // Compute bounding box
        //
        public Bounds GetBounds()
        {
            float xmin = Mathf.Infinity;
            float ymin = Mathf.Infinity;
            float xmax = -Mathf.Infinity;
            float ymax = -Mathf.Infinity;
            Point v;
            float vx, vy;

            for (int i = this.halfEdges.Count - 1; i >= 0; i--)
            {
                v = this.halfEdges[i].GetStartPoint();
                vx = v.x;
                vy = v.y;
                if (vx < xmin) { xmin = vx; }
                if (vy < ymin) { ymin = vy; }
                if (vx > xmax) { xmax = vx; }
                if (vy > ymax) { ymax = vy; }
                // we dont need to take into account end point,
                // since each end point matches a start point
            }

            // TODO: verify y
            Bounds bounds = new Bounds();
            bounds.SetMinMax(new Vector3(xmin, 0, xmax), new Vector3(ymin, 0, ymax));

            return bounds;
        }
开发者ID:jesta88,项目名称:Unity-Voronoi,代码行数:30,代码来源:Cell.cs


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