//Gets the total bounds of this tank model and its equipped decorations for viewport fitting in the main menu. public Bounds GetTankBounds() { Bounds?objectBounds = null; foreach (Renderer rend in GetComponentsInChildren <MeshRenderer>()) { if (rend.enabled && rend.gameObject.activeInHierarchy) { Bounds rendBounds = rend.bounds; // Only on bounds with volume if (rendBounds.size.x > 0 && rendBounds.size.y > 0 && rendBounds.size.z > 0) { if (objectBounds.HasValue) { Bounds boundVal = objectBounds.Value; boundVal.Encapsulate(rendBounds); objectBounds = boundVal; } else { objectBounds = rend.bounds; } } } } return(objectBounds.Value); }
static Bounds?CalculateMeshRendererSizes(Transform objectTransform) { var thisFilter = objectTransform.GetComponent <Renderer>(); var childFilters = objectTransform.GetComponentsInChildren <Renderer>(true).ToList(); if (thisFilter != null) { childFilters.Insert(0, thisFilter); } Bounds?result = null; foreach (var filter in childFilters) { var bounds = filter.bounds; if (result == null) { result = bounds; } else { result.Value.Encapsulate(bounds.min); result.Value.Encapsulate(bounds.max); } } return(result); }
// re-calculate m_RoomBoundsPointsCached and m_RoomBoundsAabbCached private void RefreshRoomBoundsCache() { Vector3[] points_RS = null; if (App.Config.m_SdkMode == SdkMode.Oculus) { #if OCULUS_SUPPORTED // N points, clockwise winding (but axis is undocumented), undocumented convexity // In practice, it's clockwise looking along Y- points_RS = OVRManager.boundary.GetGeometry(OVRBoundary.BoundaryType.OuterBoundary) .Select(v => UnityFromOculus(v)).ToArray(); #endif // OCULUS_SUPPORTED } if (points_RS == null) { points_RS = new Vector3[0]; } // We could use points_RS to expose a raw-points-based API, and currently // we can offer the guarantee that the points are clockwise (looking along Y-), // and convex. So far, nobody needs it. // Debug.Assert(IsClockwiseConvex(points_RS)); // m_RoomBoundsPointsCached = points_RS. m_RoomBoundsAabbCached = FromPoints(points_RS); }
public void Reset() { avatarName = null; polyCount = null; aabb = null; skinnedMeshCount = null; meshCount = null; materialCount = null; animatorCount = null; boneCount = null; lightCount = null; particleSystemCount = null; particleTotalCount = null; particleMaxMeshPolyCount = null; particleTrailsEnabled = null; particleCollisionEnabled = null; trailRendererCount = null; lineRendererCount = null; dynamicBoneComponentCount = null; dynamicBoneSimulatedBoneCount = null; dynamicBoneColliderCount = null; dynamicBoneCollisionCheckCount = null; clothCount = null; clothMaxVertices = null; physicsColliderCount = null; physicsRigidbodyCount = null; audioSourceCount = null; downloadSize = null; for (int i = 0; i < (int)AvatarPerformanceCategory.AvatarPerformanceCategoryCount; i++) { _performanceRatingCache[i] = PerformanceRating.None; } }
internal Drawable(XTexture2D texture, Bounds?source = null, float rotation = 0.0f, int offset = 0) { Texture = texture; Source = source; Rotation = Math.Clamp(rotation, 0.0f, MathF.PI * 2.0f); Offset = offset; }
static private Bounds?BoxAbs(GameObject rootGameObject) { if (rootGameObject.transform.childCount == 0) { return(rootGameObject.GetComponent <Renderer>()?.bounds); } bool hasBounds = false; Bounds bounds = new Bounds(Vector3.zero, Vector3.zero); for (int i = 0; i < rootGameObject.transform.childCount; ++i) { Bounds?childBounds = BoxAbs(rootGameObject.transform.GetChild(i).gameObject); if (childBounds.HasValue) { if (hasBounds) { bounds.Encapsulate(childBounds.Value); } else { bounds = childBounds.Value; hasBounds = true; } } } return(hasBounds ? bounds : (Bounds?)null); }
public Bounds GetBounds() { Bounds?b = null; if (Nodes.IsNullOrEmpty()) { return(new Bounds(transform.position, Vector3.zero)); } for (var i = 0; i < Nodes.Count - 1; i++) { var n = Nodes[i]; for (var j = 0; j < n.OutConnections.Count - 1; j++) { var sb = n.OutConnections[j].GetSplineBounds(); if (b == null) { b = sb; } else { b.Value.Encapsulate(sb); } } } return(b.Value); }
public SpeechBubble Attach(Transform target, Vector2?offset = null) { followTarget = target; if (offset == null) { Bounds?bounds = null; foreach (var collider in target.GetComponents <Collider2D>()) { if (bounds == null) { bounds = collider.bounds; } else { bounds.Value.Encapsulate(collider.bounds); } } var expectPos = followTarget.position + new Vector3(bounds.Value.extents.x, bounds.Value.extents.y, 0); followOffset = RectTransformUtility.WorldToScreenPoint(Camera.main, expectPos) - RectTransformUtility.WorldToScreenPoint(Camera.main, followTarget.position); } else { followOffset = offset.Value; } return(this); }
private void RecordProperties() { _startPosition = transform.position; _rigidbody.isKinematic = true; var attachedColliders = new List <Collider2D>(); _rigidbody.GetAttachedColliders(attachedColliders); Bounds?b = null; foreach (var collider in attachedColliders) { if (!b.HasValue) { b = collider.bounds; } else { var bounds = collider.bounds; bounds.Encapsulate(b.Value); b = bounds; } } if (b.HasValue) { var bounds = b.Value; bounds.center = transform.InverseTransformPoint(bounds.center); colliderLocalBounds = bounds; } else { colliderLocalBounds = new Bounds(); } }
/// <summary> /// Gets the detached child bounds. /// </summary> /// <returns>The detached child bounds.</returns> public Bounds?GetDetachedChildBounds() { Bounds?bounds = null; for (int i = 0; i < m_DetachChildren.Length; ++i) { Transform detached = m_DetachChildren[i]; if (detached != null) { foreach (Renderer rend in detached.GetComponentsInChildren <MeshRenderer>()) { if (rend.enabled && rend.gameObject.activeInHierarchy) { if (bounds.HasValue) { Bounds boundVal = bounds.Value; boundVal.Encapsulate(rend.bounds); bounds = boundVal; } else { bounds = rend.bounds; } } } } } return(bounds); }
/// <summary> /// Calculate the world space axis-aligned bounding box /// for a hierarchy of game objects containing zero or more meshes. /// If the hierarchy does not contain any meshes, then /// return value will be null (i.e. Bounds.HasValue == false). /// </summary> public static Bounds?GetRendererBoundsForHierarchy(GameObject o) { Bounds?bounds = null; // Note: Renderer.bounds returns the bounding box // in world space, whereas Mesh.bounds return the // bounding box in local space. Renderer renderer = o.GetComponent <Renderer>(); if (renderer != null) { bounds = renderer.bounds; } foreach (Transform child in o.transform) { Bounds?childBounds = GetRendererBoundsForHierarchy(child.gameObject); if (childBounds.HasValue) { if (!bounds.HasValue) { bounds = childBounds; } else { Bounds tmp = bounds.Value; tmp.Encapsulate(childBounds.Value); bounds = tmp; } } } return(bounds); }
public void AddVertex(ref VertexData vertexData) { if (this.channels == MeshBuilderChannels.INVALID) { throw new System.InvalidOperationException("Cannot add vertex data to meshbuilder without calling StartBuild first!"); } // Validate layout foreach (var channel in this.channels.AsEnumerable()) { if (!vertexData.HasDataForChannel(channel)) { throw new System.InvalidOperationException("Vertex data must contain the data required by the mesh builder! Missing channel: " + channel); } } // Write data this.positions.Add(vertexData.position); foreach (var channel in this.channels.AsEnumerable()) { switch (channel) { case MeshBuilderChannel.NORMALS: this.normals.Add(vertexData.normal.Value); break; case MeshBuilderChannel.TANGENTS: this.tangents.Add(vertexData.tangent.Value); break; case MeshBuilderChannel.COLORS: this.colors.Add(vertexData.color.Value); break; case MeshBuilderChannel.UV: this.uvs[0].Add(vertexData.uv.Value); break; case MeshBuilderChannel.UV2: this.uvs[1].Add(vertexData.uv2.Value); break; case MeshBuilderChannel.UV3: this.uvs[2].Add(vertexData.uv3.Value); break; case MeshBuilderChannel.UV4: this.uvs[3].Add(vertexData.uv4.Value); break; case MeshBuilderChannel.UV5: this.uvs[4].Add(vertexData.uv5.Value); break; case MeshBuilderChannel.UV6: this.uvs[5].Add(vertexData.uv6.Value); break; case MeshBuilderChannel.UV7: this.uvs[6].Add(vertexData.uv7.Value); break; case MeshBuilderChannel.UV8: this.uvs[7].Add(vertexData.uv8.Value); break; } } // Write index this.indices.Add(this.indices.Count); if (this.bounds.HasValue) { var b = this.bounds.Value; b.Encapsulate(vertexData.position); this.bounds = b; } else { this.bounds = new Bounds(vertexData.position, Vector3.zero); } }
internal void Purge(Texture2D reference, Bounds?sourceRectangle = null) { try { using (Lock.Shared) { lock (reference.Meta()) { var Map = reference.Meta().SpriteTable; if (Map.Count == 0) { return; } // TODO handle sourceRectangle meaningfully. using (Lock.Promote) { Debug.TraceLn($"Purging Texture {reference.SafeName()}"); foreach (var scaledTexture in Map.Values) { lock (scaledTexture) { if (scaledTexture.Texture != null) { scaledTexture.Texture.Dispose(); } scaledTexture.Texture = null; } } Map.Clear(); // TODO dispose sprites? } } } } catch { } }
Bounds GetBoundsForObject(GameObject prefab) { Bounds?bounds = null; if (prefab.GetComponent <Collider>() != null) { bounds = prefab.GetComponent <Collider>().bounds; } else { Renderer[] renderers = prefab.GetComponentsInChildren <Renderer>(); foreach (Renderer renderer in renderers) { if (bounds.HasValue) { bounds.Value.Encapsulate(renderer.bounds); } else { bounds = renderer.bounds; } } } return(new Bounds(bounds.HasValue ? Vector3.zero : bounds.Value.center, bounds.HasValue ? bounds.Value.size : Vector3.zero)); }
/// <summary> /// </summary> private void OnDrawGizmosSelected() { Bounds?bounds = null; foreach (var particle in particles) { if (!particle) { continue; } Bounds?particleBounds = particle.RenderBounds; if (!particleBounds.HasValue) { continue; } if (!bounds.HasValue) { bounds = particleBounds; } else { bounds.Value.Encapsulate(particleBounds.Value); } } if (bounds.HasValue) { bounds = transform.TransformBounds(bounds.Value); Gizmos.color = new Color(0.7f, 0.8f, 1, 0.5f); Gizmos.DrawWireCube(bounds.Value.center, bounds.Value.size); } }
public static Bounds?GetBounds(GameObject go) { Bounds?bounds = null; //bounds. Bounds ab; SongeUtil.forAllChildren(go, tar => { if (tar.GetComponent <Renderer>() != null) { Bounds b = tar.GetComponent <Renderer>().bounds; if (bounds == null) { bounds = b; } else { ab = bounds.Value;//对bounds.Value的改变不能作用到bounds上 需要中间变量 ab.Encapsulate(b); bounds = ab; } } }); return(bounds); }
Bounds?GetBoundingBox(GameObject root) { Bounds?prefabBounds1 = null; var sr = root.GetComponent <SpriteRenderer>(); if (sr != null) { prefabBounds1 = sr.bounds; } for (int i = 0; i < root.transform.childCount; ++i) { var b = GetBoundingBox(root.transform.GetChild(i).gameObject); if (prefabBounds1 == null) { prefabBounds1 = b; } else { if (b.HasValue) { var bb = prefabBounds1.Value; bb.Encapsulate(b.Value); prefabBounds1 = bb; } } } return(prefabBounds1); }
/// <summary> /// Adds all items belonging to sub-nodes (ignoring own items) to the provided list of items (<paramref name="items"/>). /// If boundaries (<paramref name="bounds"/>) are provided then only items intersecting with them will be added. /// </summary> /// /// <param name="items">Output list for found items</param> /// <param name="bounds">Boundaries to look for items within</param> protected internal void AddSubNodeItems(ref IList <TItem> items, Bounds?bounds = null) { foreach (var subNode in SubNodes) { subNode.AddItems(ref items, bounds); } }
public void SelectionCleared() { m_SelectionBounds_CS = null; gameObject.SetActive(false); m_xfOriginal_SS = TrTransform.identity; App.Scene.AsScene[transform] = TrTransform.identity; }
public static Bounds ComputeRelativeTotalBounds(GameObject gameObject) { Bounds?computedBounds = null; foreach (Renderer r in gameObject.GetComponentsInChildren <Renderer>()) { if (computedBounds == null) { computedBounds = r.bounds; } else { Bounds oldBounds = (Bounds)computedBounds; oldBounds.SetMinMax( Vector3.Min(oldBounds.min, r.bounds.min), Vector3.Max(oldBounds.max, r.bounds.max) ); computedBounds = oldBounds; } } Bounds computedBoundsValue = (Bounds)computedBounds; computedBoundsValue.center = computedBoundsValue.center - gameObject.transform.position; return(computedBoundsValue); }
public void UnsetTarget() { target = null; targetSize = defaultDistance; ResetPerspective(); SetCameraParameters(); }
/// <summary> /// Scale a hierarchy of meshes so that the longest /// dimension of its world-space axis-aligned bounding box /// is equal to `targetSize`. /// </summary> public static IEnumerable Resize(GameObject root, float targetSize) { // Scale model up/down to a standard size, so that the // largest dimension of its bounding box is equal to `DefaultModelSize`. Bounds?bounds = null; foreach (var result in GetRendererBoundsForHierarchyEnum(root)) { bounds = result; yield return(null); } // In the case that the hierarchy contains no meshes, the // return value from GetRendererBoundsForHierarchy will // be null. if (!bounds.HasValue) { yield break; } // avoid divide by zero var size = bounds.Value.extents.MaxComponent(); if (size < 0.000001f) { yield break; } // scale hierarchy to target size Vector3 scale = root.transform.localScale; float scaleFactor = targetSize / size; root.transform.localScale = scale * scaleFactor; }
private void RecalculateBoundingSphere() { var colliders = new List <Collider>(GetComponents <Collider>()); colliders.AddRange(GetComponentsInChildren <Collider>()); Bounds?bounds = null; foreach (var collider in colliders) { if (bounds == null) { bounds = collider.bounds; } else { bounds.Value.Encapsulate(collider.bounds); } } if (bounds == null) { offset = new Vector3(); radius = 0; } else { offset = bounds.Value.center - transform.position; radius = bounds.Value.extents.magnitude; } dirty = false; }
public void SetTarget(Bounds bounds) { target = bounds; targetSize = bounds.extents.magnitude * 2; ResetPerspective(); SetCameraParameters(); }
private static void DrawObjectBounds(GameObject go) { if (cacheTarget != go) { cacheTarget = go; if (cacheTarget != null) { #if UNITY_4_6 || UNITY_5 var rectTrans = cacheTarget.GetComponent <RectTransform>(); if (rectTrans != null) { selfBound = RectTransform2Bound(go.GetComponents <RectTransform>()); fullBound = RectTransform2Bound(go.GetComponentsInChildren <RectTransform>()); } else #endif { selfBound = Renderer2Bound(go.GetComponents <Renderer>()); fullBound = Renderer2Bound(go.GetComponentsInChildren <Renderer>()); } } else { selfBound = null; } } DrawBox(selfBound, null, Color.cyan); DrawBox(fullBound, go.transform, Color.yellow); }
private static void DrawBox(Bounds?bound, Transform t, Color c) { var oColor = Handles.color; Handles.color = CYAN_A50; if (bound != null) { var b = bound.Value; var v0 = b.min; var v7 = b.max; var v1 = new Vector3(v0.x, v0.y, v7.z); var v2 = new Vector3(v0.x, v7.y, v7.z); var v3 = new Vector3(v0.x, v7.y, v0.z); var v4 = new Vector3(v7.x, v0.y, v7.z); var v5 = new Vector3(v7.x, v0.y, v0.z); var v6 = new Vector3(v7.x, v7.y, v0.z); Handles.DrawPolyLine( v0, v1, v2, v3, v0, v5, v6, v7, v4, v5 ); Handles.DrawLine(v1, v4); Handles.DrawLine(v2, v7); Handles.DrawLine(v3, v6); } if (t != null) { //Handles.ArrowCap(0, t.position, t.rotation, 1f); if (bound != null) { Handles.DrawLine(t.position, bound.Value.center); } var sz = HandleUtility.GetHandleSize(t.position); Handles.color = GREEN_A50; Handles.ArrowCap(0, t.position, Quaternion.LookRotation(t.up), sz); Handles.color = BLUE_A50; Handles.ArrowCap(0, t.position, Quaternion.LookRotation(t.forward), sz); Handles.color = RED_A50; Handles.ArrowCap(0, t.position, Quaternion.LookRotation(t.right), sz); } Handles.color = oColor; }
public GetObjectsInSpaceItem(CastTypeEnum castType, Metadata.TypeInfo selectedTypeOnly, bool visibleOnly, Bounds bounds) { this.CastType = castType; this.SelectedTypeOnly = selectedTypeOnly; this.VisibleOnly = visibleOnly; this.Bounds = bounds; }
public GetObjectsItem(CastTypeEnum castType, Metadata.TypeInfo selectedTypeOnly, bool visibleOnly, Plane[] planes, Bounds bounds) { this.CastType = castType; this.SelectedTypeOnly = selectedTypeOnly; this.VisibleOnly = visibleOnly; this.Planes = planes; this.Bounds = bounds; }
public void SetSelectionBounds(Bounds bounds) { Debug.Assert(bounds.extents.magnitude > 0); m_SelectionBounds_CS = bounds; UpdateBoxCollider(); gameObject.SetActive(true); }
void UpdateBounds() { var camera = Camera.main; var height = camera.orthographicSize * 2; var width = height * camera.aspect; _lastBounds = new Bounds(Camera.main.transform.position.WithZ(0), new Vector2(width, height)); }
public Bounds GetBounds() { if (!this.m_Bounds.HasValue) { this.m_Bounds = new Bounds?(this.GetBounds(this.rangeStart, this.rangeEnd)); } return this.m_Bounds.Value; }