/// <summary>Sets the screen size used for calculating Offset and Bound values</summary> private void SetScreenSize() { Transform currentTarget; if (_currentRail != null && _currentRail.Target != null) { currentTarget = _currentRail.Target; } else { currentTarget = Target; } var zDisplacementToTarget = 0f; if (currentTarget != null) { zDisplacementToTarget = Mathf.Abs(transform.position.z - currentTarget.position.z); } _screenSizeInWorldUnits = Utilities.GetScreenSizeInWorldUnits(_camera, zDisplacementToTarget); }
private void OnDrawGizmosSelected() { if (Target == null && (_currentRail == null || _currentRail.Target == null)) { return; } var camera = GetComponent <Camera>(); var gizmoZPos = transform.position.z + Mathf.Abs(transform.position.z) * transform.forward.z; Gizmos.color = EditorPreferences.GetColor32(EditorPreferences.CameraTargetColorKey, EditorPreferences.CameraTargetColorValue); // Current camera position var screenSizeY = Utilities.GetScreenSizeInWorldUnits(camera, Mathf.Abs(transform.position.z)).y; var cameraPos = new Vector3(transform.position.x, transform.position.y, gizmoZPos); Utilities.GizmosDrawWireDisc(cameraPos, screenSizeY * 0.02f); Utilities.GizmosDrawWireDisc(cameraPos, screenSizeY * 0.015f); Gizmos.DrawRay(cameraPos - new Vector3(screenSizeY * 0.02f, 0f, 0f), new Vector2(screenSizeY * 0.04f, 0f)); Gizmos.DrawRay(cameraPos - new Vector3(0f, screenSizeY * 0.02f, 0f), new Vector2(0f, screenSizeY * 0.04f)); // Intended Position var intendedPos = new Vector3(_intendedPosition.x, _intendedPosition.y, gizmoZPos); Utilities.GizmosDrawWireDisc(intendedPos, screenSizeY * 0.01f); Gizmos.DrawRay(intendedPos - new Vector3(screenSizeY * 0.01f, 0f, 0f), new Vector2(screenSizeY * 0.02f, 0f)); Gizmos.DrawRay(intendedPos - new Vector3(0f, screenSizeY * 0.01f, 0f), new Vector2(0f, screenSizeY * 0.02f)); Gizmos.DrawLine(cameraPos, intendedPos); // Offset if (OffsetX > 0f || OffsetY > 0f) { var intendedPosWithoutOffset = new Vector3(_intendedPositionWithoutOffset.x, _intendedPositionWithoutOffset.y, gizmoZPos); Gizmos.DrawWireSphere(intendedPosWithoutOffset, screenSizeY * 0.0125f); Gizmos.DrawLine(intendedPosWithoutOffset, intendedPos); } // Smoothing Bounds if (SmoothX > 0f && BoundX > 0f) { Gizmos.color = EditorPreferences.GetColor32(EditorPreferences.CameraBoundColorKey, EditorPreferences.CameraBoundColorValue); if (SmoothX > 0f && BoundY > 0f) { Gizmos.DrawWireCube(cameraPos, new Vector3(BoundX * _screenSizeInWorldUnits.x, BoundY * _screenSizeInWorldUnits.y, 0f)); } else { var bottomLeft = cameraPos - new Vector3(_screenSizeInWorldUnits.x * 0.5f * BoundX, _screenSizeInWorldUnits.y * 0.5f, 0f); var bottomRight = cameraPos - new Vector3(-_screenSizeInWorldUnits.x * 0.5f * BoundX, _screenSizeInWorldUnits.y * 0.5f, 0f); Gizmos.DrawRay(bottomLeft, new Vector3(0f, _screenSizeInWorldUnits.y * 0.5f * 2f, 0f)); Gizmos.DrawRay(bottomRight, new Vector3(0f, _screenSizeInWorldUnits.y * 0.5f * 2f, 0f)); } } else if (SmoothY > 0f && BoundY > 0f) { Gizmos.color = EditorPreferences.GetColor32(EditorPreferences.CameraBoundColorKey, EditorPreferences.CameraBoundColorValue); var bottomLeft = cameraPos - new Vector3(_screenSizeInWorldUnits.x * 0.5f, _screenSizeInWorldUnits.y * 0.5f * BoundY, 0f); var topLeft = cameraPos - new Vector3(_screenSizeInWorldUnits.x * 0.5f, -_screenSizeInWorldUnits.y * 0.5f * BoundY, 0f); Gizmos.DrawRay(bottomLeft, new Vector3(_screenSizeInWorldUnits.x, 0f, 0f)); Gizmos.DrawRay(topLeft, new Vector3(_screenSizeInWorldUnits.x, 0f, 0f)); } }