Exemple #1
0
        void Awake()
        {
            _instance  = this;
            _transform = transform;

            // Get parent position
            if (_transform.parent != null)
            {
                _parentPosition = _transform.parent.position;
            }

            if (GameCamera == null)
            {
                GameCamera = GetComponent <Camera>();
            }
            if (GameCamera == null)
            {
                Debug.LogError("Unity Camera not set and not found on the GameObject: " + gameObject.name);
            }

            #if PC2D_TK2D_SUPPORT
            Tk2dCam = GetComponent <tk2dCamera>();
            #endif

            // Reset the axis functions
            ResetAxisFunctions();

            // Remove empty targets
            for (int i = 0; i < CameraTargets.Count; i++)
            {
                if (CameraTargets[i].TargetTransform == null)
                {
                    CameraTargets.RemoveAt(i);
                }
            }

            _screenSizeInWorldCoordinates = _startScreenSizeInWorldCoordinates = Utils.GetScreenSizeInWorldCoords(GameCamera, Mathf.Abs(Vector3D(_transform.localPosition)));

            _originalCameraDepthSign = Mathf.Sign(Vector3D(_transform.localPosition));
        }
        void OnDrawGizmosSelected()
        {
            if (ProCamera2D == null)
            {
                return;
            }

            var   gameCamera        = ProCamera2D.GetComponent <Camera>();
            float cameraDepthOffset = Vector3D(ProCamera2D.transform.localPosition) + Mathf.Abs(Vector3D(ProCamera2D.transform.localPosition)) * Vector3D(ProCamera2D.transform.forward);
            var   cameraDimensions  = Utils.GetScreenSizeInWorldCoords(gameCamera, Mathf.Abs(Vector3D(ProCamera2D.transform.localPosition)));

            // Draw cinematic path
            GUIStyle style = new GUIStyle();

            style.normal.textColor = Color.green;
            for (int i = 0; i < CinematicTargets.Count; i++)
            {
                var targetPos = VectorHVD(Vector3H(CinematicTargets[i].TargetTransform.position), Vector3V(CinematicTargets[i].TargetTransform.position), cameraDepthOffset);

                if (i > 0)
                {
                    UnityEditor.Handles.DrawLine(targetPos, VectorHVD(Vector3H(CinematicTargets[i - 1].TargetTransform.position), Vector3V(CinematicTargets[i - 1].TargetTransform.position), cameraDepthOffset));
                }

                UnityEditor.Handles.color = Color.blue;
                if (i < CinematicTargets.Count - 1)
                {
                    var nextTargetPos = VectorHVD(Vector3H(CinematicTargets[i + 1].TargetTransform.position), Vector3V(CinematicTargets[i + 1].TargetTransform.position), cameraDepthOffset);
                    var arrowSize     = cameraDimensions.x * .1f;
                    if ((nextTargetPos - targetPos).magnitude > arrowSize)
                    {
                        UnityEditor.Handles.ArrowCap(
                            i,
                            targetPos,
                            Quaternion.LookRotation(nextTargetPos - targetPos),
                            cameraDimensions.x * .1f);
                    }
                }
            }
        }
        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)));

            Gizmos.color = EditorPrefsX.GetColor(PrefsData.RailsColorKey, PrefsData.RailsColorValue);

            if (_tempCameraTargets.Count > 0)
            {
                Gizmos.color = Gizmos.color * .7f;
            }

            // Rails nodes
            for (int i = 0; i < RailNodes.Count; i++)
            {
                Gizmos.DrawWireCube(RailNodes[i], cameraDimensions * .01f);
            }

            // Rails path
            if (RailNodes.Count >= 2)
            {
                for (int i = 0; i < RailNodes.Count - 1; i++)
                {
                    Gizmos.DrawLine(RailNodes[i], RailNodes[i + 1]);
                }
            }
        }
        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);
        }
Exemple #6
0
        protected override void DrawGizmos()
        {
            base.DrawGizmos();

            var   gameCamera        = ProCamera2D.GetComponent <Camera>();
            var   cameraDimensions  = gameCamera.orthographic ? Utils.GetScreenSizeInWorldCoords(gameCamera) : Utils.GetScreenSizeInWorldCoords(gameCamera, Mathf.Abs(Vector3D(transform.position)));
            float cameraDepthOffset = Vector3D(ProCamera2D.transform.localPosition) + Mathf.Abs(Vector3D(transform.localPosition)) * Vector3D(ProCamera2D.transform.forward);

            // 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);
            }
        }
Exemple #7
0
        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);
        }
        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 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);

            // 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));
        }
        protected override void DrawGizmos()
        {
            base.DrawGizmos();

            Gizmos.color = EditorPrefsX.GetColor(PrefsData.PanEdgesColorKey, PrefsData.PanEdgesColorValue);
            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);

            if (UsePanByMoveToEdges)
            {
                Gizmos.DrawWireCube(
                    VectorHVD(Vector3H(ProCamera2D.transform.localPosition), Vector3V(ProCamera2D.transform.localPosition), cameraDepthOffset),
                    VectorHV(cameraDimensions.x * HorizontalPanEdges, cameraDimensions.y * VerticalPanEdges));
            }

            if (UsePanByDrag)
            {
                if (DraggableAreaRect.x != 0 ||
                    DraggableAreaRect.y != 0 ||
                    DraggableAreaRect.width != 1 ||
                    DraggableAreaRect.height != 1)
                {
                    Gizmos.DrawWireCube(
                        VectorHVD(ProCamera2D.transform.localPosition.x + DraggableAreaRect.x * cameraDimensions.x, ProCamera2D.transform.localPosition.y + DraggableAreaRect.y * cameraDimensions.y, cameraDepthOffset),
                        VectorHV(DraggableAreaRect.width * cameraDimensions.x, DraggableAreaRect.height * 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);
        }
Exemple #12
0
        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);
            }
        }
        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);

            // 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));
        }
        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);
            }
        }
Exemple #15
0
        override protected void DrawGizmos()
        {
            base.DrawGizmos();

            if (UseNumericBoundaries)
            {
                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);

                Gizmos.color = EditorPrefsX.GetColor(PrefsData.NumericBoundariesColorKey, PrefsData.NumericBoundariesColorValue);

                if (UseTopBoundary)
                {
                    Gizmos.DrawRay(VectorHVD(Vector3H(transform.localPosition) - cameraDimensions.x * .5f, TopBoundary, cameraDepthOffset), transform.right * cameraDimensions.x);
                }

                if (UseBottomBoundary)
                {
                    Gizmos.DrawRay(VectorHVD(Vector3H(transform.localPosition) - cameraDimensions.x * .5f, BottomBoundary, cameraDepthOffset), transform.right * cameraDimensions.x);
                }

                if (UseRightBoundary)
                {
                    Gizmos.DrawRay(VectorHVD(RightBoundary, Vector3V(transform.localPosition) - cameraDimensions.y * .5f, cameraDepthOffset), transform.up * cameraDimensions.y);
                }

                if (UseLeftBoundary)
                {
                    Gizmos.DrawRay(VectorHVD(LeftBoundary, Vector3V(transform.localPosition) - cameraDimensions.y * .5f, cameraDepthOffset), transform.up * cameraDimensions.y);
                }

                if (UseSoftBoundaries)
                {
                    Gizmos.color = new Color(Gizmos.color.r, Gizmos.color.g, Gizmos.color.b, Gizmos.color.a * .3f);

                    if (UseTopBoundary)
                    {
                        Gizmos.DrawRay(VectorHVD(Vector3H(transform.localPosition) - cameraDimensions.x * .5f, TopBoundary - cameraDimensions.y * SoftAreaSize, cameraDepthOffset), transform.right * cameraDimensions.x);
                    }

                    if (UseBottomBoundary)
                    {
                        Gizmos.DrawRay(VectorHVD(Vector3H(transform.localPosition) - cameraDimensions.x * .5f, BottomBoundary + cameraDimensions.y * SoftAreaSize, cameraDepthOffset), transform.right * cameraDimensions.x);
                    }

                    if (UseRightBoundary)
                    {
                        Gizmos.DrawRay(VectorHVD(RightBoundary - cameraDimensions.x * SoftAreaSize, Vector3V(transform.localPosition) - cameraDimensions.y * .5f, cameraDepthOffset), transform.up * cameraDimensions.y);
                    }

                    if (UseLeftBoundary)
                    {
                        Gizmos.DrawRay(VectorHVD(LeftBoundary + cameraDimensions.x * SoftAreaSize, Vector3V(transform.localPosition) - cameraDimensions.y * .5f, cameraDepthOffset), transform.up * cameraDimensions.y);
                    }
                }
            }
        }
Exemple #16
0
        void Awake()
        {
            _instance  = this;
            _transform = transform;

            if (GameCamera == null)
            {
                GameCamera = GetComponent <Camera>();
            }
            if (GameCamera == null)
            {
                Debug.LogError("Unity Camera not set and not found on the GameObject: " + gameObject.name);
            }

            #if PC2D_TK2D_SUPPORT
            Tk2dCam = GetComponent <tk2dCamera>();
            #endif

            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;
            }

            // Remove empty targets
            for (int i = 0; i < CameraTargets.Count; i++)
            {
                if (CameraTargets [i].TargetTransform == null)
                {
                    CameraTargets.RemoveAt(i);
                }
            }

            ScreenSizeInWorldCoordinates   = Utils.GetScreenSizeInWorldCoords(GameCamera, Mathf.Abs(Vector3D(_transform.localPosition)));
            _cameraWindowRectInWorldCoords = GetRectAroundTransf(CameraWindowRect, ScreenSizeInWorldCoordinates, _transform);

            _cameraMoveInColliderBoundaries = new MoveInColliderBoundaries(this);
            _cameraMoveInColliderBoundaries.CameraTransform     = _transform;
            _cameraMoveInColliderBoundaries.CameraSize          = ScreenSizeInWorldCoordinates;
            _cameraMoveInColliderBoundaries.CameraCollisionMask = BoundariesLayerMask;

            _originalCameraDepthSign = Mathf.Sign(Vector3D(_transform.localPosition));

            _transform.parent = new GameObject(gameObject.name + " Container").transform;

            // Center on target
            if (CenterTargetOnStart && CameraTargets.Count > 0)
            {
                var targetPos             = GetTargetsWeightedMidPoint(CameraTargets);
                var cameraTargetPositionX = FollowHorizontal ? Vector3H(targetPos) : Vector3H(_transform.localPosition);
                var cameraTargetPositionY = FollowVertical ? Vector3V(targetPos) : Vector3V(_transform.localPosition);
                targetPos  = VectorHV(cameraTargetPositionX, cameraTargetPositionY);
                targetPos += VectorHV(OverallOffset.x, OverallOffset.y);
                MoveCameraInstantlyToPosition(targetPos);
            }
            else
            {
                _cameraTargetPosition = _transform.localPosition;
                _cameraTargetHorizontalPositionSmoothed         = Vector3H(_cameraTargetPosition);
                _previousCameraTargetHorizontalPositionSmoothed = _cameraTargetHorizontalPositionSmoothed;
                _cameraTargetVerticalPositionSmoothed           = Vector3V(_cameraTargetPosition);
                _previousCameraTargetVerticalPositionSmoothed   = _cameraTargetVerticalPositionSmoothed;
            }
        }
Exemple #17
0
        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;
            }

            float cameraDepthOffset = Vector3D(ProCamera2D.transform.position) + 5f * Vector3D(ProCamera2D.transform.forward);
            var   cameraCenter      = VectorHVD(Vector3H(transform.position), Vector3V(transform.position), cameraDepthOffset);
            var   cameraDimensions  = Utils.GetScreenSizeInWorldCoords(ProCamera2D.GetComponent <Camera>());

            GetTargetBoundaries();

            Gizmos.DrawIcon(VectorHVD(Vector3H(transform.position), Vector3V(transform.position), cameraDepthOffset - .05f * Mathf.Sign(Vector3D(ProCamera2D.transform.position))), "ProCamera2D/gizmo_icon_bg.png", false);

            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)));

                Gizmos.DrawIcon(VectorHVD(Vector3H(transform.position), Vector3V(transform.position), cameraDepthOffset), "ProCamera2D/gizmo_icon_bound_top.png", false);
            }

            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)));

                Gizmos.DrawIcon(VectorHVD(Vector3H(transform.position), Vector3V(transform.position), cameraDepthOffset), "ProCamera2D/gizmo_icon_bound_bottom.png", false);
            }

            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));

                Gizmos.DrawIcon(VectorHVD(Vector3H(transform.position), Vector3V(transform.position), cameraDepthOffset), "ProCamera2D/gizmo_icon_bound_right.png", false);
            }

            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));

                Gizmos.DrawIcon(VectorHVD(Vector3H(transform.position), Vector3V(transform.position), cameraDepthOffset), "ProCamera2D/gizmo_icon_bound_left.png", false);
            }

            if (SetAsStartingBoundaries)
            {
                Gizmos.DrawIcon(VectorHVD(Vector3H(transform.position), Vector3V(transform.position), cameraDepthOffset), "ProCamera2D/gizmo_icon_start.png", false);
            }
        }
Exemple #18
0
        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);
            }
        }
        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);

            // 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);
                }
            }
        }
Exemple #20
0
        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));
        }