override protected void DrawGizmos() { base.DrawGizmos(); var gameCamera = ProCamera2D.GetComponent <Camera>(); var cameraDimensions = gameCamera.orthographic ? Utils.GetScreenSizeInWorldCoords(gameCamera) : Utils.GetScreenSizeInWorldCoords(gameCamera, Mathf.Abs(Vector3D(transform.localPosition))); float cameraDepthOffset = Vector3D(ProCamera2D.transform.localPosition) + Mathf.Abs(Vector3D(transform.localPosition)) * Vector3D(ProCamera2D.transform.forward); var cameraCenter = VectorHVD(Vector3H(transform.position), Vector3V(transform.position), cameraDepthOffset); Gizmos.color = EditorPrefsX.GetColor(PrefsData.ForwardFocusColorKey, PrefsData.ForwardFocusColorValue); if (LeftFocus > EPSILON) { Gizmos.DrawRay(VectorHVD(Vector3H(transform.position) + cameraDimensions.x * LeftFocus, Vector3V(transform.position) - cameraDimensions.y / 2, cameraDepthOffset), transform.up * cameraDimensions.y); Utils.DrawArrowForGizmo(cameraCenter + VectorHV(cameraDimensions.x * LeftFocus, 0), -transform.right * .3f); } if (RightFocus > EPSILON) { Gizmos.DrawRay(VectorHVD(Vector3H(transform.position) - cameraDimensions.x * RightFocus, Vector3V(transform.position) - cameraDimensions.y / 2, cameraDepthOffset), transform.up * cameraDimensions.y); Utils.DrawArrowForGizmo(cameraCenter - VectorHV(cameraDimensions.x * RightFocus, 0), transform.right * .3f); } if (TopFocus > EPSILON) { Gizmos.DrawRay(VectorHVD(Vector3H(transform.position) - cameraDimensions.x / 2, Vector3V(transform.position) - cameraDimensions.y * TopFocus, cameraDepthOffset), transform.right * cameraDimensions.x); Utils.DrawArrowForGizmo(cameraCenter - VectorHV(0, cameraDimensions.y * TopFocus), transform.up * .3f); } if (BottomFocus > EPSILON) { Gizmos.DrawRay(VectorHVD(Vector3H(transform.position) - cameraDimensions.x / 2, Vector3V(transform.position) + cameraDimensions.y * BottomFocus, cameraDepthOffset), transform.right * cameraDimensions.x); Utils.DrawArrowForGizmo(cameraCenter + VectorHV(0, cameraDimensions.y * BottomFocus), -transform.up * .3f); } }
void OnDrawGizmosSelected() { if (Application.isPlaying) { return; } // Don't draw gizmos on other cameras if (Camera.current != CameraToUse && ((UnityEditor.SceneView.lastActiveSceneView != null && Camera.current != UnityEditor.SceneView.lastActiveSceneView.camera) || (UnityEditor.SceneView.lastActiveSceneView == null))) { return; } Gizmos.color = Color.red; // Draw object size and origin if (ObjectToRepeat != null && ObjectOnStage) { var origin = ObjectToRepeat.position + VectorHV(ObjectBottomLeft.x, ObjectBottomLeft.y); if (_repeatHorizontal) { Gizmos.DrawLine(origin, origin + VectorHV(ObjectSize.x, 0)); Utils.DrawArrowForGizmo(origin + VectorHV(ObjectSize.x - ObjectSize.x * .25f, 0), ObjectToRepeat.right * ObjectSize.x * .25f, ObjectSize.x * .25f); } if (_repeatVertical) { Gizmos.DrawLine(origin, origin + VectorHV(0, ObjectSize.y)); Utils.DrawArrowForGizmo(origin + VectorHV(0, ObjectSize.y - ObjectSize.y * .25f), ObjectToRepeat.up * ObjectSize.y * .25f, ObjectSize.y * .25f); } } }
override protected void OnDrawGizmos() { // HACK to prevent Unity bug on startup: http://forum.unity3d.com/threads/screen-position-out-of-view-frustum.9918/ _drawGizmosCounter++; if (_drawGizmosCounter < 5 && UnityEditor.EditorApplication.timeSinceStartup < 60f) { return; } base.OnDrawGizmos(); if (_gizmosDrawingFailed) { return; } var cameraDimensions = Utils.GetScreenSizeInWorldCoords(ProCamera2D.GameCamera, Mathf.Abs(Vector3D(transform.localPosition))); // Shake influence if (_shakePositionSmoothed != Vector3.zero) { Gizmos.color = EditorPrefsX.GetColor(PrefsData.ShakeInfluenceColorKey, PrefsData.ShakeInfluenceColorValue); Utils.DrawArrowForGizmo(ProCamera2D.TargetsMidPoint, _shakePositionSmoothed, .04f * cameraDimensions.y); } }
override protected void DrawGizmos() { base.DrawGizmos(); var cameraDimensions = Utils.GetScreenSizeInWorldCoords(ProCamera2D.GameCamera, Mathf.Abs(Vector3D(transform.localPosition))); if (Application.isPlaying && _shakeParent.localPosition != Vector3.zero) { Gizmos.color = EditorPrefsX.GetColor(PrefsData.ShakeInfluenceColorKey, PrefsData.ShakeInfluenceColorValue); Utils.DrawArrowForGizmo(ProCamera2D.TargetsMidPoint, _shakeParent.localPosition, .04f * cameraDimensions.y); } }
override protected void DrawGizmos() { base.DrawGizmos(); var gameCamera = ProCamera2D.GetComponent <Camera>(); var cameraDimensions = gameCamera.orthographic ? Utils.GetScreenSizeInWorldCoords(gameCamera) : Utils.GetScreenSizeInWorldCoords(gameCamera, Mathf.Abs(Vector3D(transform.localPosition))); float cameraDepthOffset = Vector3D(ProCamera2D.transform.localPosition) + Mathf.Abs(Vector3D(transform.localPosition)) * Vector3D(ProCamera2D.transform.forward); var cameraCenter = Application.isPlaying ? ProCamera2D.TargetsMidPoint : VectorHVD(Vector3H(transform.position), Vector3V(transform.position), cameraDepthOffset); var bordersColor = DisableWhenOneTarget && ProCamera2D.CameraTargets.Count <= 1 ? EditorPrefsX.GetColor(PrefsData.ZoomToFitColorKey, Color.white) * .75f : EditorPrefsX.GetColor(PrefsData.ZoomToFitColorKey, Color.white); // Targets bounding box if (Application.isPlaying && ProCamera2D.CameraTargets.Count > 1) { float maxX = Mathf.NegativeInfinity; float minX = Mathf.Infinity; float maxY = Mathf.NegativeInfinity; float minY = Mathf.Infinity; for (int i = 0; i < ProCamera2D.CameraTargets.Count; i++) { var targetPos = new Vector2(Vector3H(ProCamera2D.CameraTargets[i].TargetPosition) + ProCamera2D.CameraTargets[i].TargetOffset.x, Vector3V(ProCamera2D.CameraTargets[i].TargetPosition) + ProCamera2D.CameraTargets[i].TargetOffset.y); maxX = targetPos.x > maxX ? targetPos.x : maxX; minX = targetPos.x < minX ? targetPos.x : minX; maxY = targetPos.y > maxY ? targetPos.y : maxY; minY = targetPos.y < minY ? targetPos.y : minY; } Gizmos.color = EditorPrefsX.GetColor(PrefsData.ZoomToFitColorKey, Color.white) * .25f; Gizmos.DrawWireCube(cameraCenter, VectorHV(maxX - minX, maxY - minY)); } if (CompensateForCameraPosition) { cameraCenter = VectorHVD(Vector3H(ProCamera2D.transform.localPosition), Vector3V(ProCamera2D.transform.localPosition), cameraDepthOffset); } // Zoom out border Gizmos.color = Math.Abs(_targetCamSizeSmoothed - _maxCameraSize) < .01f ? bordersColor * .5f : bordersColor; Gizmos.DrawWireCube(cameraCenter, VectorHV(cameraDimensions.x, cameraDimensions.y) * ZoomOutBorder); Utils.DrawArrowForGizmo(cameraCenter + VectorHV(cameraDimensions.x / 2 * ZoomOutBorder, cameraDimensions.y / 2 * ZoomOutBorder), VectorHV(.05f * cameraDimensions.y, .05f * cameraDimensions.y), .04f * cameraDimensions.y); Utils.DrawArrowForGizmo(cameraCenter - VectorHV(cameraDimensions.x / 2 * ZoomOutBorder, cameraDimensions.y / 2 * ZoomOutBorder), VectorHV(-.05f * cameraDimensions.y, -.05f * cameraDimensions.y), .04f * cameraDimensions.y); // Zoom in border Gizmos.color = Math.Abs(_targetCamSizeSmoothed - _minCameraSize) < .01f ? bordersColor * .75f : bordersColor; Gizmos.DrawWireCube(cameraCenter, VectorHV(cameraDimensions.x, cameraDimensions.y) * ZoomInBorder); Utils.DrawArrowForGizmo(cameraCenter + VectorHV(cameraDimensions.x / 2 * ZoomInBorder, cameraDimensions.y / 2 * ZoomInBorder), VectorHV(-.05f * cameraDimensions.y, -.05f * cameraDimensions.y), .04f * cameraDimensions.y); Utils.DrawArrowForGizmo(cameraCenter - VectorHV(cameraDimensions.x / 2 * ZoomInBorder, cameraDimensions.y / 2 * ZoomInBorder), VectorHV(.05f * cameraDimensions.y, .05f * cameraDimensions.y), .04f * cameraDimensions.y); }
override protected void OnDrawGizmos() { // HACK to prevent Unity bug on startup: http://forum.unity3d.com/threads/screen-position-out-of-view-frustum.9918/ _drawGizmosCounter++; if (_drawGizmosCounter < 5 && UnityEditor.EditorApplication.timeSinceStartup < 60f) { return; } base.OnDrawGizmos(); if (_gizmosDrawingFailed) { return; } var gameCamera = ProCamera2D.GetComponent <Camera>(); var cameraDimensions = gameCamera.orthographic ? Utils.GetScreenSizeInWorldCoords(gameCamera) : Utils.GetScreenSizeInWorldCoords(gameCamera, Mathf.Abs(Vector3D(transform.localPosition))); float cameraDepthOffset = Vector3D(ProCamera2D.transform.localPosition) + Mathf.Abs(Vector3D(transform.localPosition)) * Vector3D(ProCamera2D.transform.forward); var cameraCenter = VectorHVD(Vector3H(transform.position), Vector3V(transform.position), cameraDepthOffset); Gizmos.color = EditorPrefsX.GetColor(PrefsData.ForwardFocusColorKey, PrefsData.ForwardFocusColorValue); if (LeftFocus > EPSILON) { Gizmos.DrawRay(VectorHVD(Vector3H(transform.position) + cameraDimensions.x * LeftFocus, Vector3V(transform.position) - cameraDimensions.y / 2, cameraDepthOffset), transform.up * cameraDimensions.y); Utils.DrawArrowForGizmo(cameraCenter + VectorHV(cameraDimensions.x * LeftFocus, 0), -transform.right * .3f); } if (RightFocus > EPSILON) { Gizmos.DrawRay(VectorHVD(Vector3H(transform.position) - cameraDimensions.x * RightFocus, Vector3V(transform.position) - cameraDimensions.y / 2, cameraDepthOffset), transform.up * cameraDimensions.y); Utils.DrawArrowForGizmo(cameraCenter - VectorHV(cameraDimensions.x * RightFocus, 0), transform.right * .3f); } if (TopFocus > EPSILON) { Gizmos.DrawRay(VectorHVD(Vector3H(transform.position) - cameraDimensions.x / 2, Vector3V(transform.position) - cameraDimensions.y * TopFocus, cameraDepthOffset), transform.right * cameraDimensions.x); Utils.DrawArrowForGizmo(cameraCenter - VectorHV(0, cameraDimensions.y * TopFocus), transform.up * .3f); } if (BottomFocus > EPSILON) { Gizmos.DrawRay(VectorHVD(Vector3H(transform.position) - cameraDimensions.x / 2, Vector3V(transform.position) + cameraDimensions.y * BottomFocus, cameraDepthOffset), transform.right * cameraDimensions.x); Utils.DrawArrowForGizmo(cameraCenter + VectorHV(0, cameraDimensions.y * BottomFocus), -transform.up * .3f); } }
void OnDrawGizmosSelected() { // HACK to prevent Unity bug on startup: http://forum.unity3d.com/threads/screen-position-out-of-view-frustum.9918/ _drawGizmosCounter++; if (_drawGizmosCounter < 5 && UnityEditor.EditorApplication.timeSinceStartup < 60f) { return; } if (_gizmosDrawingFailed) { return; } float cameraDepthOffset = Vector3D(ProCamera2D.transform.localPosition) + Mathf.Abs(Vector3D(ProCamera2D.transform.localPosition)) * Vector3D(ProCamera2D.transform.forward); var cameraCenter = VectorHVD(Vector3H(transform.position), Vector3V(transform.position), cameraDepthOffset); var cameraDimensions = Utils.GetScreenSizeInWorldCoords(ProCamera2D.GetComponent <Camera>(), Mathf.Abs(Vector3D(ProCamera2D.transform.localPosition))); GetTargetBoundaries(); Gizmos.color = EditorPrefsX.GetColor(PrefsData.BoundariesTriggerColorKey, PrefsData.BoundariesTriggerColorValue); if (UseTopBoundary) { Gizmos.DrawRay(VectorHVD(Vector3H(transform.position) - cameraDimensions.x / 2, _targetTopBoundary, cameraDepthOffset), ProCamera2D.transform.right * cameraDimensions.x); Utils.DrawArrowForGizmo(cameraCenter, VectorHV(0, _targetTopBoundary - Vector3V(transform.position))); } if (UseBottomBoundary) { Gizmos.DrawRay(VectorHVD(Vector3H(transform.position) - cameraDimensions.x / 2, _targetBottomBoundary, cameraDepthOffset), ProCamera2D.transform.right * cameraDimensions.x); Utils.DrawArrowForGizmo(cameraCenter, VectorHV(0, _targetBottomBoundary - Vector3V(transform.position))); } if (UseRightBoundary) { Gizmos.DrawRay(VectorHVD(_targetRightBoundary, Vector3V(transform.position) - cameraDimensions.y / 2, cameraDepthOffset), ProCamera2D.transform.up * cameraDimensions.y); Utils.DrawArrowForGizmo(cameraCenter, VectorHV(_targetRightBoundary - Vector3H(transform.position), 0)); } if (UseLeftBoundary) { Gizmos.DrawRay(VectorHVD(_targetLeftBoundary, Vector3V(transform.position) - cameraDimensions.y / 2, cameraDepthOffset), ProCamera2D.transform.up * cameraDimensions.y); Utils.DrawArrowForGizmo(cameraCenter, VectorHV(_targetLeftBoundary - Vector3H(transform.position), 0)); } }
void OnDrawGizmosSelected() { if (ProCamera2D == null) { return; } float cameraDepthOffset = Vector3D(ProCamera2D.transform.localPosition) + Mathf.Abs(Vector3D(ProCamera2D.transform.localPosition)) * Vector3D(ProCamera2D.transform.forward); var cameraCenter = VectorHVD(Vector3H(transform.position), Vector3V(transform.position), cameraDepthOffset); var cameraDimensions = Utils.GetScreenSizeInWorldCoords(ProCamera2D.GetComponent <Camera>(), Mathf.Abs(Vector3D(ProCamera2D.transform.localPosition))); GetTargetBoundaries(); Gizmos.color = EditorPrefsX.GetColor(PrefsData.BoundariesTriggerColorKey, PrefsData.BoundariesTriggerColorValue); if (UseTopBoundary) { Gizmos.DrawRay(VectorHVD(Vector3H(transform.position) - cameraDimensions.x / 2, _targetTopBoundary, cameraDepthOffset), ProCamera2D.transform.right * cameraDimensions.x); Utils.DrawArrowForGizmo(cameraCenter, VectorHV(0, _targetTopBoundary - Vector3V(transform.position))); } if (UseBottomBoundary) { Gizmos.DrawRay(VectorHVD(Vector3H(transform.position) - cameraDimensions.x / 2, _targetBottomBoundary, cameraDepthOffset), ProCamera2D.transform.right * cameraDimensions.x); Utils.DrawArrowForGizmo(cameraCenter, VectorHV(0, _targetBottomBoundary - Vector3V(transform.position))); } if (UseRightBoundary) { Gizmos.DrawRay(VectorHVD(_targetRightBoundary, Vector3V(transform.position) - cameraDimensions.y / 2, cameraDepthOffset), ProCamera2D.transform.up * cameraDimensions.y); Utils.DrawArrowForGizmo(cameraCenter, VectorHV(_targetRightBoundary - Vector3H(transform.position), 0)); } if (UseLeftBoundary) { Gizmos.DrawRay(VectorHVD(_targetLeftBoundary, Vector3V(transform.position) - cameraDimensions.y / 2, cameraDepthOffset), ProCamera2D.transform.up * cameraDimensions.y); Utils.DrawArrowForGizmo(cameraCenter, VectorHV(_targetLeftBoundary - Vector3H(transform.position), 0)); } }
override protected void DrawGizmos() { base.DrawGizmos(); var gameCamera = ProCamera2D.GetComponent <Camera>(); var cameraDimensions = gameCamera.orthographic ? Utils.GetScreenSizeInWorldCoords(gameCamera) : Utils.GetScreenSizeInWorldCoords(gameCamera, Mathf.Abs(Vector3D(transform.localPosition))); float cameraDepthOffset = Vector3D(ProCamera2D.transform.localPosition) + Mathf.Abs(Vector3D(transform.localPosition)) * Vector3D(ProCamera2D.transform.forward); var cameraCenter = VectorHVD(Vector3H(transform.position), Vector3V(transform.position), cameraDepthOffset); var bordersColor = DisableWhenOneTarget && ProCamera2D.CameraTargets.Count <= 1 ? EditorPrefsX.GetColor(PrefsData.ZoomToFitColorKey, Color.white) * .75f : EditorPrefsX.GetColor(PrefsData.ZoomToFitColorKey, Color.white); // Zoom out border Gizmos.color = Math.Abs(_targetCamSizeSmoothed - _maxCameraSize) < .01f ? bordersColor * .5f : bordersColor; Gizmos.DrawWireCube(cameraCenter, VectorHV(cameraDimensions.x, cameraDimensions.y) * ZoomOutBorder); Utils.DrawArrowForGizmo(cameraCenter + VectorHV(cameraDimensions.x / 2 * ZoomOutBorder, cameraDimensions.y / 2 * ZoomOutBorder), VectorHV(.05f * cameraDimensions.y, .05f * cameraDimensions.y), .04f * cameraDimensions.y); Utils.DrawArrowForGizmo(cameraCenter - VectorHV(cameraDimensions.x / 2 * ZoomOutBorder, cameraDimensions.y / 2 * ZoomOutBorder), VectorHV(-.05f * cameraDimensions.y, -.05f * cameraDimensions.y), .04f * cameraDimensions.y); // Zoom in border Gizmos.color = Math.Abs(_targetCamSizeSmoothed - _minCameraSize) < .01f ? bordersColor * .75f : bordersColor; Gizmos.DrawWireCube(cameraCenter, VectorHV(cameraDimensions.x, cameraDimensions.y) * ZoomInBorder); Utils.DrawArrowForGizmo(cameraCenter + VectorHV(cameraDimensions.x / 2 * ZoomInBorder, cameraDimensions.y / 2 * ZoomInBorder), VectorHV(-.05f * cameraDimensions.y, -.05f * cameraDimensions.y), .04f * cameraDimensions.y); Utils.DrawArrowForGizmo(cameraCenter - VectorHV(cameraDimensions.x / 2 * ZoomInBorder, cameraDimensions.y / 2 * ZoomInBorder), VectorHV(.05f * cameraDimensions.y, .05f * cameraDimensions.y), .04f * cameraDimensions.y); }
override protected void OnDrawGizmos() { // HACK to prevent Unity bug on startup: http://forum.unity3d.com/threads/screen-position-out-of-view-frustum.9918/ _drawGizmosCounter++; if (_drawGizmosCounter < 5 && UnityEditor.EditorApplication.timeSinceStartup < 60f) { return; } base.OnDrawGizmos(); if (_gizmosDrawingFailed) { return; } var gameCamera = ProCamera2D.GetComponent <Camera>(); var cameraDimensions = gameCamera.orthographic ? Utils.GetScreenSizeInWorldCoords(gameCamera) : Utils.GetScreenSizeInWorldCoords(gameCamera, Mathf.Abs(Vector3D(transform.localPosition))); float cameraDepthOffset = Vector3D(ProCamera2D.transform.localPosition) + Mathf.Abs(Vector3D(transform.localPosition)) * Vector3D(ProCamera2D.transform.forward); var cameraCenter = VectorHVD(Vector3H(transform.position), Vector3V(transform.position), cameraDepthOffset); var bordersColor = DisableWhenOneTarget && ProCamera2D.CameraTargets.Count <= 1 ? PrefsData.ZoomToFitColorValue * .75f : PrefsData.ZoomToFitColorValue; // Zoom out border Gizmos.color = Math.Abs(_targetCamSizeSmoothed - _maxCameraSize) < .01f ? Color.red : EditorPrefsX.GetColor(PrefsData.ZoomToFitColorKey, bordersColor); Gizmos.DrawWireCube(cameraCenter, VectorHV(cameraDimensions.x, cameraDimensions.y) * ZoomOutBorder); Utils.DrawArrowForGizmo(cameraCenter + VectorHV(cameraDimensions.x / 2 * ZoomOutBorder, cameraDimensions.y / 2 * ZoomOutBorder), VectorHV(.05f * cameraDimensions.y, .05f * cameraDimensions.y), .04f * cameraDimensions.y); Utils.DrawArrowForGizmo(cameraCenter - VectorHV(cameraDimensions.x / 2 * ZoomOutBorder, cameraDimensions.y / 2 * ZoomOutBorder), VectorHV(-.05f * cameraDimensions.y, -.05f * cameraDimensions.y), .04f * cameraDimensions.y); // Zoom in border Gizmos.color = Math.Abs(_targetCamSizeSmoothed - _minCameraSize) < .01f ? Color.red : EditorPrefsX.GetColor(PrefsData.ZoomToFitColorKey, bordersColor); Gizmos.DrawWireCube(cameraCenter, VectorHV(cameraDimensions.x, cameraDimensions.y) * ZoomInBorder); Utils.DrawArrowForGizmo(cameraCenter + VectorHV(cameraDimensions.x / 2 * ZoomInBorder, cameraDimensions.y / 2 * ZoomInBorder), VectorHV(-.05f * cameraDimensions.y, -.05f * cameraDimensions.y), .04f * cameraDimensions.y); Utils.DrawArrowForGizmo(cameraCenter - VectorHV(cameraDimensions.x / 2 * ZoomInBorder, cameraDimensions.y / 2 * ZoomInBorder), VectorHV(.05f * cameraDimensions.y, .05f * cameraDimensions.y), .04f * cameraDimensions.y); }
void OnDrawGizmos() { // HACK to prevent Unity bug on startup: http://forum.unity3d.com/threads/screen-position-out-of-view-frustum.9918/ _drawGizmosCounter++; if (_drawGizmosCounter < 5 && UnityEditor.EditorApplication.timeSinceStartup < 60f) { return; } if (Vector3H == null) { ResetAxisFunctions(); } var gameCamera = GetComponent <Camera>(); // Don't draw gizmos on other cameras if (Camera.current != gameCamera && ((UnityEditor.SceneView.lastActiveSceneView != null && Camera.current != UnityEditor.SceneView.lastActiveSceneView.camera) || (UnityEditor.SceneView.lastActiveSceneView == null))) { return; } var cameraDimensions = Utils.GetScreenSizeInWorldCoords(gameCamera, Mathf.Abs(Vector3D(transform.position))); float cameraDepthOffset = Vector3D(transform.position) + Mathf.Abs(Vector3D(transform.position)) * Vector3D(transform.forward); // Targets mid point Gizmos.color = EditorPrefsX.GetColor(PrefsData.TargetsMidPointColorKey, PrefsData.TargetsMidPointColorValue); var targetsMidPoint = GetTargetsWeightedMidPoint(ref CameraTargets); targetsMidPoint = VectorHVD(Vector3H(targetsMidPoint), Vector3V(targetsMidPoint), cameraDepthOffset); Gizmos.DrawWireSphere(targetsMidPoint, .01f * cameraDimensions.y); // Influences sum Gizmos.color = EditorPrefsX.GetColor(PrefsData.InfluencesColorKey, PrefsData.InfluencesColorValue); if (_influencesSum != Vector3.zero) { Utils.DrawArrowForGizmo(targetsMidPoint, _influencesSum, .04f * cameraDimensions.y); } // Overall offset line Gizmos.color = EditorPrefsX.GetColor(PrefsData.OverallOffsetColorKey, PrefsData.OverallOffsetColorValue); if (OffsetX != 0 || OffsetY != 0) { if (IsRelativeOffset) { Utils.DrawArrowForGizmo(targetsMidPoint, VectorHV((OffsetX * cameraDimensions.x * .5f), (OffsetY * cameraDimensions.y * .5f)), .04f * cameraDimensions.y); } else { Utils.DrawArrowForGizmo(targetsMidPoint, VectorHV(OffsetX, OffsetY), .04f * cameraDimensions.y); } } // Camera target position Gizmos.color = EditorPrefsX.GetColor(PrefsData.CamTargetPositionColorKey, PrefsData.CamTargetPositionColorValue); var cameraTargetPosition = targetsMidPoint + _influencesSum + VectorHV((OffsetX * cameraDimensions.x * .5f), (OffsetY * cameraDimensions.y * .5f)); if (!IsRelativeOffset) { cameraTargetPosition = targetsMidPoint + _influencesSum + VectorHV(OffsetX, OffsetY); } var cameraTargetPos = VectorHVD(Vector3H(cameraTargetPosition), Vector3V(cameraTargetPosition), cameraDepthOffset); Gizmos.DrawWireSphere(cameraTargetPos, .015f * cameraDimensions.y); // Camera target position smoothed if (Application.isPlaying) { Gizmos.color = EditorPrefsX.GetColor(PrefsData.CamTargetPositionSmoothedColorKey, PrefsData.CamTargetPositionSmoothedColorValue); var cameraTargetPosSmoothed = VectorHVD(_cameraTargetHorizontalPositionSmoothed + Vector3H(ParentPosition), _cameraTargetVerticalPositionSmoothed + Vector3V(ParentPosition), cameraDepthOffset); Gizmos.DrawWireSphere(cameraTargetPosSmoothed, .02f * cameraDimensions.y); Gizmos.DrawLine(cameraTargetPos, cameraTargetPosSmoothed); } // Current camera position Gizmos.color = EditorPrefsX.GetColor(PrefsData.CurrentCameraPositionColorKey, PrefsData.CurrentCameraPositionColorValue); var currentCameraPos = VectorHVD(Vector3H(transform.position), Vector3V(transform.position), cameraDepthOffset); Gizmos.DrawWireSphere(currentCameraPos, .025f * cameraDimensions.y); }
protected override void DrawGizmosSelected() { base.DrawGizmosSelected(); var fillColor = EditorPrefsX.GetColor(PrefsData.FitterFillColorKey, PrefsData.FitterFillColorValue); var lineColor = EditorPrefsX.GetColor(PrefsData.FitterLineColorKey, PrefsData.FitterFillColorValue); Gizmos.color = lineColor; var camSize = Utils.GetScreenSizeInWorldCoords(ProCamera2D.GameCamera, Mathf.Abs(Vector3D(transform.localPosition))); var camPos = VectorHVD(Vector3H(ProCamera2D.transform.position), Vector3V(ProCamera2D.transform.position), 0); var rectCorners = DrawGizmoRectangle( Vector3H(ProCamera2D.transform.position), Vector3V(ProCamera2D.transform.position), ContentFitterMode != ContentFitterMode.FixedHeight ? TargetWidth : camSize.x, ContentFitterMode != ContentFitterMode.FixedWidth ? TargetHeight : camSize.y, fillColor, lineColor); if (_contentFitterMode == ContentFitterMode.AspectRatio) { if (TargetHeight * .5f > TargetWidth * .5f / ProCamera2D.GameCamera.aspect) { DrawGizmoRectangle( Vector3H(ProCamera2D.transform.position) - HorizontalAlignment * (TargetHeight * ProCamera2D.GameCamera.aspect - TargetWidth) / 2f, Vector3V(ProCamera2D.transform.position), TargetHeight * ProCamera2D.GameCamera.aspect, TargetHeight, fillColor, lineColor); } else { DrawGizmoRectangle( Vector3H(ProCamera2D.transform.position), Vector3V(ProCamera2D.transform.position) - VerticalAlignment * (TargetWidth / ProCamera2D.GameCamera.aspect - TargetHeight) / 2f, TargetWidth, TargetWidth / ProCamera2D.GameCamera.aspect, fillColor, lineColor); } Utils.DrawArrowForGizmo(camPos, camPos - rectCorners[0], camSize.y * .03f); Utils.DrawArrowForGizmo(camPos, camPos - rectCorners[2], camSize.y * .03f); } else if (_contentFitterMode == ContentFitterMode.FixedWidth) { DrawGizmoRectangle( Vector3H(ProCamera2D.transform.position), Vector3V(ProCamera2D.transform.position), TargetWidth, TargetWidth / ProCamera2D.GameCamera.aspect, fillColor, lineColor); Utils.DrawArrowForGizmo(camPos, ProCamera2D.transform.right * TargetWidth * .5f, camSize.y * .03f); Utils.DrawArrowForGizmo(camPos, -ProCamera2D.transform.right * TargetWidth * .5f, camSize.y * .03f); } else { DrawGizmoRectangle( Vector3H(ProCamera2D.transform.position), Vector3V(ProCamera2D.transform.position), TargetHeight * ProCamera2D.GameCamera.aspect, TargetHeight, fillColor, lineColor); Utils.DrawArrowForGizmo(camPos, ProCamera2D.transform.up * TargetHeight * .5f, camSize.y * .03f); Utils.DrawArrowForGizmo(camPos, -ProCamera2D.transform.up * TargetHeight * .5f, camSize.y * .03f); } }
void OnDrawGizmos() { // HACK to prevent Unity bug on startup: http://forum.unity3d.com/threads/screen-position-out-of-view-frustum.9918/ _drawGizmosCounter++; if (_drawGizmosCounter < 5 && UnityEditor.EditorApplication.timeSinceStartup < 60f) { return; } switch (Axis) { case MovementAxis.XY: Vector3H = vector => vector.x; Vector3V = vector => vector.y; Vector3D = vector => vector.z; VectorHV = (h, v) => new Vector3(h, v, 0); VectorHVD = (h, v, d) => new Vector3(h, v, d); break; case MovementAxis.XZ: Vector3H = vector => vector.x; Vector3V = vector => vector.z; Vector3D = vector => vector.y; VectorHV = (h, v) => new Vector3(h, 0, v); VectorHVD = (h, v, d) => new Vector3(h, d, v); break; case MovementAxis.YZ: Vector3H = vector => vector.z; Vector3V = vector => vector.y; Vector3D = vector => vector.x; VectorHV = (h, v) => new Vector3(0, v, h); VectorHVD = (h, v, d) => new Vector3(d, v, h); break; } var gameCamera = GetComponent <Camera>(); // Don't draw gizmos on other cameras if (Camera.current != gameCamera && ((UnityEditor.SceneView.lastActiveSceneView != null && Camera.current != UnityEditor.SceneView.lastActiveSceneView.camera) || (UnityEditor.SceneView.lastActiveSceneView == null))) { return; } var cameraDimensions = Utils.GetScreenSizeInWorldCoords(gameCamera, Mathf.Abs(Vector3D(transform.localPosition))); float cameraDepthOffset = Vector3D(transform.localPosition) + Mathf.Abs(Vector3D(transform.localPosition)) * Vector3D(transform.forward); // Numeric boundaries Gizmos.color = EditorPrefsX.GetColor(PrefsData.NumericBoundariesColorKey, PrefsData.NumericBoundariesColorValue); if (UseNumericBoundaries) { if (UseTopBoundary) { Gizmos.DrawRay(VectorHVD(Vector3H(transform.localPosition) - cameraDimensions.x / 2, TopBoundary, cameraDepthOffset), transform.right * cameraDimensions.x); } if (UseBottomBoundary) { Gizmos.DrawRay(VectorHVD(Vector3H(transform.localPosition) - cameraDimensions.x / 2, BottomBoundary, cameraDepthOffset), transform.right * cameraDimensions.x); } if (UseRightBoundary) { Gizmos.DrawRay(VectorHVD(RightBoundary, Vector3V(transform.localPosition) - cameraDimensions.y / 2, cameraDepthOffset), transform.up * cameraDimensions.y); } if (UseLeftBoundary) { Gizmos.DrawRay(VectorHVD(LeftBoundary, Vector3V(transform.localPosition) - cameraDimensions.y / 2, cameraDepthOffset), transform.up * cameraDimensions.y); } } // Targets mid point Gizmos.color = EditorPrefsX.GetColor(PrefsData.TargetsMidPointColorKey, PrefsData.TargetsMidPointColorValue); var targetsMidPoint = GetTargetsWeightedMidPoint(CameraTargets); targetsMidPoint = VectorHVD(Vector3H(targetsMidPoint), Vector3V(targetsMidPoint), cameraDepthOffset); Gizmos.DrawWireSphere(targetsMidPoint, .01f * cameraDimensions.y); // Influences sum Gizmos.color = EditorPrefsX.GetColor(PrefsData.InfluencesColorKey, PrefsData.InfluencesColorValue); if (_influencesSum != Vector3.zero) { Utils.DrawArrowForGizmo(targetsMidPoint, _influencesSum, .04f * cameraDimensions.y); } // Overall offset line Gizmos.color = EditorPrefsX.GetColor(PrefsData.OverallOffsetColorKey, PrefsData.OverallOffsetColorValue); if (OverallOffset != Vector2.zero) { Utils.DrawArrowForGizmo(targetsMidPoint, VectorHV(OverallOffset.x, OverallOffset.y), .04f * cameraDimensions.y); } // Limit cam distance if (LimitHorizontalCameraDistance) { Gizmos.color = EditorPrefsX.GetColor(PrefsData.CamDistanceColorKey, PrefsData.CamDistanceColorValue); Gizmos.DrawRay(VectorHVD(Vector3H(transform.position) + (cameraDimensions.x / 2) * MaxHorizontalTargetDistance, Vector3V(transform.position) - cameraDimensions.y / 2, cameraDepthOffset), transform.up * cameraDimensions.y); Gizmos.DrawRay(VectorHVD(Vector3H(transform.position) - (cameraDimensions.x / 2) * MaxHorizontalTargetDistance, Vector3V(transform.position) - cameraDimensions.y / 2, cameraDepthOffset), transform.up * cameraDimensions.y); } if (LimitVerticalCameraDistance) { Gizmos.color = EditorPrefsX.GetColor(PrefsData.CamDistanceColorKey, PrefsData.CamDistanceColorValue); Gizmos.DrawRay(VectorHVD(Vector3H(transform.position) - cameraDimensions.x / 2, Vector3V(transform.position) - (cameraDimensions.y / 2) * MaxVerticalTargetDistance, cameraDepthOffset), transform.right * cameraDimensions.x); Gizmos.DrawRay(VectorHVD(Vector3H(transform.position) - cameraDimensions.x / 2, Vector3V(transform.position) + (cameraDimensions.y / 2) * MaxVerticalTargetDistance, cameraDepthOffset), transform.right * cameraDimensions.x); } // Camera target position Gizmos.color = EditorPrefsX.GetColor(PrefsData.CamTargetPositionColorKey, PrefsData.CamTargetPositionColorValue); var cameraTargetPosition = targetsMidPoint + _influencesSum + VectorHV(OverallOffset.x, OverallOffset.y); var cameraTargetPos = VectorHVD(Vector3H(cameraTargetPosition), Vector3V(cameraTargetPosition), cameraDepthOffset); Gizmos.DrawWireSphere(cameraTargetPos, .015f * cameraDimensions.y); // Camera target position smoothed if (Application.isPlaying) { Gizmos.color = EditorPrefsX.GetColor(PrefsData.CamTargetPositionSmoothedColorKey, PrefsData.CamTargetPositionSmoothedColorValue); var cameraTargetPosSmoothed = VectorHVD(_cameraTargetHorizontalPositionSmoothed, _cameraTargetVerticalPositionSmoothed, cameraDepthOffset); Gizmos.DrawWireSphere(cameraTargetPosSmoothed, .02f * cameraDimensions.y); Gizmos.DrawLine(cameraTargetPos, cameraTargetPosSmoothed); } // Current camera position Gizmos.color = EditorPrefsX.GetColor(PrefsData.CurrentCameraPositionColorKey, PrefsData.CurrentCameraPositionColorValue); var currentCameraPos = VectorHVD(Vector3H(transform.localPosition), Vector3V(transform.localPosition), cameraDepthOffset); Gizmos.DrawWireSphere(currentCameraPos, .025f * cameraDimensions.y); // Draw camera window Gizmos.color = EditorPrefsX.GetColor(PrefsData.CameraWindowColorKey, PrefsData.CameraWindowColorValue); var cameraRect = GetRectAroundTransf(CameraWindowRect, cameraDimensions, transform); Gizmos.DrawWireCube(VectorHVD(cameraRect.x + cameraRect.width / 2, cameraRect.y + cameraRect.height / 2, cameraDepthOffset), VectorHV(cameraRect.width, cameraRect.height)); }