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


C# Bounds.Encapsulate方法代码示例

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


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

示例1: GetBoundWithChildren

        /// <summary>
        /// Gets the rendering bounds of the transform.
        /// </summary>
        /// <param name="transform">The game object to get the bounding box for.</param>
        /// <param name="pBound">The bounding box reference that will </param>
        /// <param name="encapsulate">Used to determine if the first bounding box to be 
        /// calculated should be encapsulated into the <see cref="pBound"/> argument.</param>
        /// <returns>Returns true if at least one bounding box was calculated.</returns>
        public static bool GetBoundWithChildren(Transform transform, ref Bounds pBound, ref bool encapsulate)
        {
            var didOne = false;

            // get 'this' bound
            if (transform.gameObject.renderer != null)
            {
                var bound = transform.gameObject.renderer.bounds;
                if (encapsulate)
                {
                    pBound.Encapsulate(bound.min);
                    pBound.Encapsulate(bound.max);
                }
                else
                {
                    pBound.min = bound.min; 
                    pBound.max = bound.max; 
                    encapsulate = true;
                }

                didOne = true;
            }

            // union with bound(s) of any/all children
            foreach (Transform child in transform)
            {
                if (GetBoundWithChildren(child, ref pBound, ref encapsulate))
                {
                    didOne = true;
                }
            }

            return didOne;
        }
开发者ID:Skybladev2,项目名称:TacticalRPG,代码行数:42,代码来源:Helpers.cs

示例2: DrawSkeleton

 public static void DrawSkeleton(Transform reference, Dictionary<Transform, bool> actualBones, AvatarSetupTool.BoneWrapper[] bones)
 {
   if ((Object) reference == (Object) null || actualBones == null)
     return;
   AvatarSkeletonDrawer.sPoseError = false;
   Bounds bounds = new Bounds();
   Renderer[] componentsInChildren = reference.root.GetComponentsInChildren<Renderer>();
   if (componentsInChildren != null)
   {
     foreach (Renderer renderer in componentsInChildren)
     {
       bounds.Encapsulate(renderer.bounds.min);
       bounds.Encapsulate(renderer.bounds.max);
     }
   }
   Quaternion orientation = Quaternion.identity;
   if (bones != null)
     orientation = AvatarSetupTool.AvatarComputeOrientation(bones);
   AvatarSkeletonDrawer.DrawSkeletonSubTree(actualBones, bones, orientation, reference, bounds);
   Camera current = Camera.current;
   if (!AvatarSkeletonDrawer.sPoseError || !((Object) current != (Object) null))
     return;
   GUIStyle style = new GUIStyle(GUI.skin.label);
   style.normal.textColor = Color.red;
   style.wordWrap = false;
   style.alignment = TextAnchor.MiddleLeft;
   style.fontSize = 20;
   GUIContent content = new GUIContent("Character is not in T pose");
   Rect rect = GUILayoutUtility.GetRect(content, style);
   rect.x = 30f;
   rect.y = 30f;
   Handles.BeginGUI();
   GUI.Label(rect, content, style);
   Handles.EndGUI();
 }
开发者ID:BlakeTriana,项目名称:unity-decompiled,代码行数:35,代码来源:AvatarSkeletonDrawer.cs

示例3: AddBreastColliders

 private void AddBreastColliders()
 {
     if ((this.middleSpine != null) && (this.pelvis != null))
     {
         Bounds bounds = this.Clip(this.GetBreastBounds(this.pelvis), this.pelvis, this.middleSpine, false);
         BoxCollider collider = this.pelvis.gameObject.AddComponent<BoxCollider>();
         collider.center = bounds.center;
         collider.size = bounds.size;
         bounds = this.Clip(this.GetBreastBounds(this.middleSpine), this.middleSpine, this.middleSpine, true);
         collider = this.middleSpine.gameObject.AddComponent<BoxCollider>();
         collider.center = bounds.center;
         collider.size = bounds.size;
     }
     else
     {
         Bounds bounds2 = new Bounds();
         bounds2.Encapsulate(this.pelvis.InverseTransformPoint(this.leftHips.position));
         bounds2.Encapsulate(this.pelvis.InverseTransformPoint(this.rightHips.position));
         bounds2.Encapsulate(this.pelvis.InverseTransformPoint(this.leftArm.position));
         bounds2.Encapsulate(this.pelvis.InverseTransformPoint(this.rightArm.position));
         Vector3 size = bounds2.size;
         size[SmallestComponent(bounds2.size)] = size[LargestComponent(bounds2.size)] / 2f;
         BoxCollider collider2 = this.pelvis.gameObject.AddComponent<BoxCollider>();
         collider2.center = bounds2.center;
         collider2.size = size;
     }
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:27,代码来源:RagdollBuilder.cs

示例4: GetBoundWithChildren

    static bool GetBoundWithChildren( Transform parent, ref Bounds pBound, ref bool initBound )
    {
        Bounds bound = new Bounds();
        bool didOne = false;

        if( parent.gameObject.renderer != null )
        {
            bound = parent.gameObject.renderer.bounds;
            if( initBound )
            {
                pBound.Encapsulate( bound.min );
                pBound.Encapsulate( bound.max );
            }
            else
            {
                pBound.min = new Vector3( bound.min.x, bound.min.y, bound.min.z );
                pBound.max = new Vector3( bound.max.x, bound.max.y, bound.max.z );
                initBound = true;
            }
            didOne = true;
        }

        foreach( Transform child in parent )
        {
            if( GetBoundWithChildren( child, ref pBound, ref initBound ))
                didOne = true;
        }

        return didOne;
    }
开发者ID:pchernev,项目名称:Zombayo,代码行数:30,代码来源:GetBBox.cs

示例5: GetPartColliderBoundsInBasis

        public static Bounds GetPartColliderBoundsInBasis(this Part part, Matrix4x4 worldToBasisMatrix, int excessiveVerts = 2500)
        {
            Transform[] transforms = part.FindModelComponents<Transform>();
            Bounds bounds = new Bounds();
            for (int i = 0; i < transforms.Length; i++)
            {
                Transform t = transforms[i];

                MeshCollider mc = t.GetComponent<MeshCollider>();
                Mesh m;
                Matrix4x4 matrix = worldToBasisMatrix * t.localToWorldMatrix;

                if (mc == null)
                {
                    BoxCollider bc = t.GetComponent<BoxCollider>();
                    if (bc != null)
                    {
                        bounds.Encapsulate(matrix.MultiplyPoint3x4(bc.bounds.min));
                        bounds.Encapsulate(matrix.MultiplyPoint3x4(bc.bounds.max));
                    }
                    continue;
                }
                else
                    m = mc.sharedMesh;

                if (m == null)
                    continue;

                bounds.Encapsulate(matrix.MultiplyPoint3x4(m.bounds.min));
                bounds.Encapsulate(matrix.MultiplyPoint3x4(m.bounds.max));

            }
            return bounds;
        }
开发者ID:khr15714n,项目名称:Ferram-Aerospace-Research,代码行数:34,代码来源:PartGeometryExtensions.cs

示例6: EditPageBounds

        void EditPageBounds()
        {
            Page t = target as Page;
            Vector3 pos = t.transform.position;

            Vector3[] verts = new Vector3[4];
            verts[0] = new Vector3(pos.x + t.pageBounds.min.x, pos.y + t.pageBounds.min.y, 0);
            verts[1] = new Vector3(pos.x + t.pageBounds.min.x, pos.y + t.pageBounds.max.y, 0);
            verts[2] = new Vector3(pos.x + t.pageBounds.max.x, pos.y + t.pageBounds.max.y, 0);
            verts[3] = new Vector3(pos.x + t.pageBounds.max.x, pos.y + t.pageBounds.min.y, 0);

            Handles.DrawSolidRectangleWithOutline(verts, new Color(1,1,1,0.2f), new Color(0,0,0,1));

            for(int i = 0; i < 4; ++i)
            {
                Vector3 vert = verts[i];
                Vector3 newPos = Handles.FreeMoveHandle(vert,
                                                        Quaternion.identity,
                                                        HandleUtility.GetHandleSize(pos) * 0.1f,
                                                        Vector3.zero,
                                                        Handles.CubeCap);
                newPos.z = 0;
                verts[i] = newPos;

                if (vert != newPos)
                {
                    switch(i)
                    {
                    case 0:
                        verts[1].x = newPos.x;
                        verts[3].y = newPos.y;
                        break;
                    case 1:
                        verts[0].x = newPos.x;
                        verts[2].y = newPos.y;
                        break;
                    case 2:
                        verts[3].x = newPos.x;
                        verts[1].y = newPos.y;
                        break;
                    case 3:
                        verts[2].x = newPos.x;
                        verts[0].y = newPos.y;
                        break;
                    }
                    break;
                }
            }

            Bounds newBounds = new Bounds(verts[0], Vector3.zero);
            newBounds.Encapsulate(verts[1]);
            newBounds.Encapsulate(verts[2]);
            newBounds.Encapsulate(verts[3]);

            t.transform.position = newBounds.center;
            newBounds.center = Vector3.zero;

            t.pageBounds = newBounds;
        }
开发者ID:Toast3y,项目名称:Trials-Of-The-Dolphin-King,代码行数:59,代码来源:PageEditor.cs

示例7: Voxelize

	public void Voxelize (Transform root)
	{
		var meshFilters = root.GetComponentsInChildren<MeshFilter>();
		
		var objectBounds = new List<BoundHierarchy>();
		foreach (var filter in meshFilters)
		{
			var mesh = filter.sharedMesh;
			var vertices = mesh.vertices;
			var tris = mesh.triangles;
			var triangleBounds = new List<BoundHierarchy>();
			for(int i = 0; i < tris.Length; i += 3)
			{
				var vert1 = vertices[tris[i + 0]];
				var vert2 = vertices[tris[i + 1]];
				var vert3 = vertices[tris[i + 2]];
				vert1 = filter.transform.TransformPoint(vert1);
				vert2 = filter.transform.TransformPoint(vert2);
				vert3 = filter.transform.TransformPoint(vert3);
				
				var u = vert2 - vert3;
				var v = vert3 - vert1;
				var triNormal = Vector3.Cross(u, v);
				triNormal = triNormal.normalized;
				
				var triBounds = new Bounds(vert1, Vector3.zero);
				triBounds.Encapsulate(vert2);
				triBounds.Encapsulate(vert3);
				
				var tri = new Triangle {
					vertA = vert1,
					vertB = vert2,
					vertC = vert3,
					normal = triNormal,
					bound = triBounds,
				};
				
				triangleBounds.Add(new BoundHierarchy() { 
					bound = triBounds, 
					subBounds = null, 
					triList = tri 
				});
			}
			
			objectBounds.Add(new BoundHierarchy() { 
				bound = filter.GetComponent<Renderer>().bounds,  
				subBounds = triangleBounds.ToArray() 
			});
		}
		
		var rootNode = new BoundHierarchy() { 
			bound = _bounds, 
			subBounds = objectBounds.ToArray() 
		};
		
		GenerateBlockArray ();
		GenerateVoxelData (rootNode);
	}
开发者ID:ArieLeo,项目名称:unity-voxelizer,代码行数:58,代码来源:Voxeliser.cs

示例8: GetBounds

 public static Bounds GetBounds(this GameObject obj)
 {
     var renderers = obj.GetComponentsInChildren<Renderer>();
     var bounds = new Bounds(renderers.Length > 0 ? renderers.First().bounds.center : obj.transform.position,
         Vector3.zero);
     renderers.ToList().ForEach(r => bounds.Encapsulate(r.bounds));
     obj.GetComponentsInChildren<Collider>().ForEach(
         c =>
             bounds.Encapsulate(new Bounds(obj.transform.TransformPoint(c.bounds.center),
                 obj.transform.TransformPoint(c.bounds.size))));
     return bounds;
 }
开发者ID:fatiguedartist,项目名称:Sisyphus,代码行数:12,代码来源:RDGameObjectExtensions.cs

示例9: GetMapBoundingBox

    // --------------
    private Rect GetMapBoundingBox()
    {
        Matrix4x4	mat = this.GetMapTargetMatrix();

        Bounds		box = new Bounds(
            mat.MultiplyPoint3x4(new Vector3(0,	0, 0)), Vector3.zero);

        box.Encapsulate(mat.MultiplyPoint3x4(new Vector3(this.mapWidth,	0,				0)));
        box.Encapsulate(mat.MultiplyPoint3x4(new Vector3(0,				this.mapHeight,	0)));
        box.Encapsulate(mat.MultiplyPoint3x4(new Vector3(this.mapWidth,	this.mapHeight,	0)));

        return new Rect(box.min.x, box.min.y, box.size.x, box.size.y);
    }
开发者ID:perrysham,项目名称:2DDemo,代码行数:14,代码来源:DemoMapCS.cs

示例10: GetBounds

    public static Bounds GetBounds(List<Vector3> vals)
    {
        Bounds b = new Bounds(Vector3.zero, Vector3.zero);

        if ( vals != null && vals.Count > 0 )
        {
            b.Encapsulate(vals[0]);

            for ( int i = 1; i < vals.Count; i++ )
                b.Encapsulate(vals[i]);
        }

        return b;
    }
开发者ID:mobeid,项目名称:NP_SIMULATOR,代码行数:14,代码来源:MegaCacheUtils.cs

示例11: BoundsUnion

//============================ Bounds Functions ============================\
	
	// Creates bounds that encapsulate of the two Bounds passed in.
	public static Bounds BoundsUnion( Bounds b0, Bounds b1 ) {
		// If the size of one of the bounds is Vector3.zero, ignore that one
		if ( b0.size==Vector3.zero && b1.size!=Vector3.zero ) {
			return( b1 );
		} else if ( b0.size!=Vector3.zero && b1.size==Vector3.zero ) {
			return( b0 );
		} else if ( b0.size==Vector3.zero && b1.size==Vector3.zero ) {
			return( b0 );
		}
		// Stretch b0 to include the b1.min and b1.max
		b0.Encapsulate(b1.min);
		b0.Encapsulate(b1.max);
		return( b0 );
	}
开发者ID:ITIGameDesign,项目名称:QuickSnap,代码行数:17,代码来源:Utils.cs

示例12: BoundsColliders

	public static Bounds BoundsColliders(GameObject obj) {
		var bounds = new Bounds(obj.transform.position, Vector3.zero);

		var colliders = obj.GetComponentsInChildren<Collider2D>();
		foreach(var c in colliders) {
			var blocal =BoundsOf(c);
			var t = c.transform;
			var max = t.TransformPoint(blocal.max);
			bounds.Encapsulate(max);
			var min = t.TransformPoint(blocal.min);
			bounds.Encapsulate(min);
		}

		return bounds;
	}
开发者ID:josejaime14,项目名称:ocdc_ggj16,代码行数:15,代码来源:CameraFollow.cs

示例13: calculateWorldBounds

	public static Bounds calculateWorldBounds(GameObject go)
	{
		if (null == go) { return new Bounds(Vector3.zero, Vector3.zero); }

		Vector2 min = new Vector2(float.MaxValue, float.MaxValue);
		Vector2 max = new Vector2(float.MinValue, float.MinValue);
		Vector3 v;

		RectTransform[] rts = go.GetComponentsInChildren<RectTransform>();
		if (rts.Length == 0) return new Bounds(go.transform.position, Vector3.zero);

		for (int i = 0, imax = rts.Length; i < imax; ++i)
		{
			RectTransform t = rts[i];
			if (!t.gameObject.activeSelf) { continue; }

			Vector3[] corners = new Vector3[4];
			t.GetWorldCorners(corners);

			for (int j = 0; j < 4; ++j)
			{
				v = corners[j];
				if (v.x > max.x) max.x = v.x;
				if (v.y > max.y) max.y = v.y;

				if (v.x < min.x) min.x = v.x;
				if (v.y < min.y) min.y = v.y;
			}
		}

		Bounds b = new Bounds(min, Vector3.zero);
		b.Encapsulate(max);

		return b;
	}
开发者ID:oathx,项目名称:Six,代码行数:35,代码来源:UGUIMath.cs

示例14: Start

 private void Start()
 {
     if (this.template != null)
     {
         int num = 0;
         Bounds bounds = new Bounds();
         for (int i = 0; i < this.maxRows; i++)
         {
             for (int j = 0; j < this.maxColumns; j++)
             {
                 GameObject obj2 = NGUITools.AddChild(base.gameObject, this.template);
                 obj2.transform.localPosition = new Vector3(this.padding + ((j + 0.5f) * this.spacing), -this.padding - ((i + 0.5f) * this.spacing), 0f);
                 UIStorageSlot component = obj2.GetComponent<UIStorageSlot>();
                 if (component != null)
                 {
                     component.storage = this;
                     component.slot = num;
                 }
                 bounds.Encapsulate(new Vector3((this.padding * 2f) + ((j + 1) * this.spacing), (-this.padding * 2f) - ((i + 1) * this.spacing), 0f));
                 if (++num >= this.maxItemCount)
                 {
                     if (this.background != null)
                     {
                         this.background.transform.localScale = bounds.size;
                     }
                     return;
                 }
             }
         }
         if (this.background != null)
         {
             this.background.transform.localScale = bounds.size;
         }
     }
 }
开发者ID:Lessica,项目名称:Something-of-SHIPWAR-GAMES,代码行数:35,代码来源:UIItemStorage.cs

示例15: Awake

 void Awake()
 {
     propBounds = new Bounds( transform.position, Vector3.zero );
     foreach( var c in GetComponents<Collider>() ) {
         propBounds.Encapsulate( c.bounds );
     }
 }
开发者ID:johnsietsma,项目名称:eons,代码行数:7,代码来源:GazePickPoint.cs


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