public static Box GetModelSpaceBox(this SpriteRenderer spriteRenderer) { Sprite sprite = spriteRenderer.sprite; if (sprite == null) { return(Box.GetInvalid()); } List <Vector2> spriteVerts = new List <Vector2>(sprite.vertices); return(Vector2Extensions.GetBoxFromPointCloud(spriteVerts)); }
public static Box GetModelSpaceBox(this SpriteRenderer spriteRenderer) { Sprite sprite = spriteRenderer.sprite; if (sprite == null) { return(Box.GetInvalid()); } #if !UNITY_5 Vector3 modelSpaceCenter = spriteRenderer.transform.InverseTransformPoint(spriteRenderer.bounds.center); modelSpaceCenter.z = 0.0f; return(new Box(modelSpaceCenter, sprite.rect.size / sprite.pixelsPerUnit)); #else List <Vector2> spriteVerts = new List <Vector2>(sprite.vertices); return(Vector2Extensions.GetBoxFromPointCloud(spriteVerts)); #endif }
public void UpdateForMouseMovement() { if (_state == State.Inactive) { return; } if (MouseButtonStates.Instance.IsMouseButtonDown(MouseButton.Left)) { _state = State.Snap; } else { _state = State.SelectPivot; } if (_state == State.SelectPivot && _selectedParents.Count != 0) { Camera camera = SceneViewCamera.Camera; Vector2 mousePos = Event.current.InvMousePos(camera); _isPivotAvailable = false; float minDistanceSq = float.MaxValue; foreach (var parent in _selectedParents) { if (parent == null) { continue; } OrientedBox worldOOBB = parent.GetHierarchyWorldOrientedBox(); if (worldOOBB.IsValid()) { List <Vector3> centerAndCorners = worldOOBB.GetCenterAndCornerPoints(); List <Vector2> oobbScreenPts = Vector2Extensions.GetScreenPoints(centerAndCorners, camera); for (int ptIndex = 0; ptIndex < centerAndCorners.Count; ++ptIndex) { Vector3 worldPt = centerAndCorners[ptIndex]; Vector2 screenPt = oobbScreenPts[ptIndex]; float distSq = (mousePos - screenPt).sqrMagnitude; if (distSq < minDistanceSq) { minDistanceSq = distSq; _pivot = worldPt; _isPivotAvailable = true; } } } } } else if (_state == State.Snap && _isPivotAvailable) { GameObjectExtensions.RecordObjectTransformsForUndo(_selectedParents); MouseCursorRayHit cursorHit = MouseCursor.Instance.GetCursorRayHitForGridCell(); if (cursorHit.WasACellHit) { Camera camera = SceneViewCamera.Camera; Vector2 mousePos = Event.current.InvMousePos(camera); GridCellRayHit cellRayHit = cursorHit.GridCellRayHit; Vector3 snapDestination = Vector3Extensions.GetClosestPointToPoint(cellRayHit.HitCell.Quad.GetCenterAndCornerPoints(), cellRayHit.HitPoint); Vector3 moveVector = snapDestination - _pivot; foreach (var parent in _selectedParents) { if (parent != null) { parent.transform.position += moveVector; } } _pivot = snapDestination; ObjectSelection.Get().ObjectSelectionTransformGizmoSystem.OnObjectSelectionUpdated(); } } }
public List <Vector3> GetWorldExtentPointsInFrontOfCamera(Camera camera, float distanceFromCamNearPlane) { List <Vector2> extentPoints = GetExtentsPoints(); return(Vector2Extensions.GetWorldPointsInFrontOfCamera(extentPoints, camera, distanceFromCamNearPlane)); }
public static List <Vector3> GetWorldCornerPointsInFrontOfCamera(this Rect rectangle, Camera camera, float distanceFromCamNearPlane) { List <Vector2> cornerPoints = rectangle.GetCornerPoints(); return(Vector2Extensions.GetWorldPointsInFrontOfCamera(cornerPoints, camera, distanceFromCamNearPlane)); }
public List <Vector2> GetScreenCenterAndCornerPoints(Camera camera) { return(Vector2Extensions.GetScreenPoints(GetCenterAndCornerPoints(), camera)); }