public bool InAnyCamera() { LightingManager2D manager = LightingManager2D.Get(); CameraSettings[] cameraSettings = manager.cameraSettings; for (int i = 0; i < cameraSettings.Length; i++) { Camera camera = manager.GetCamera(i); if (camera == null) { continue; } float distance = Vector2.Distance(transform.position, camera.transform.position); float cameraRadius = CameraTransform.GetRadius(camera); float radius = cameraRadius + 5; // 5 = Size if (distance < radius) { return(true); } } return(false); }
public void ResetPointOfView() { if (!isInPersonalCamera) { return; } // SetPointOfViewの時に記録した位置に戻す、CharacterControllerを再度有効化 if (!recordedPosition.HasValue || !recordedRotation.HasValue) { return; } if (enterDeviceType == EnterDeviceType.VR) { PlayerTransform.SetPositionAndRotation(recordedPosition.Value, recordedRotation.Value); } else { CameraTransform.SetPositionAndRotation(recordedPosition.Value, recordedRotation.Value); } playerController.ActivateCharacterController(true); isInPersonalCamera = false; }
public override void UpdateCamera() { // Apply target offset modifications Vector3 headbobOffset = Headbob.GetHeadbobModifier(_previousDistance); Target.AddWorldSpaceOffset(headbobOffset); Vector3 screenShakeOffset = ScreenShake.GetShaking(); Target.AddWorldSpaceOffset(screenShakeOffset); // Handle Cursor Cursor.SetCursorLock(); // Get target Vector3 target = Target.GetTarget(); float actualDistance = Target.GetDistanceFromTarget(); // -- Set camera position and rotation CameraTransform.Position = HoldingPosition.position; // First move it to the holding position CameraTransform.LookAt(target); // Look at the target from the perspective of the holding position. Now we have the proper rotation in the virtual transform. // Set Camera Position float desiredDistance = Vector3.Distance(target, HoldingPosition.position); // The distance between the hold position and the target float calculatedDistance = ViewCollision.CalculateMaximumDistanceFromTarget(target, Mathf.Max(desiredDistance, actualDistance)); // The maximum distance we calculated we can be based off collision and preference float zoom = Zoom.CalculateDistanceFromTarget(actualDistance, calculatedDistance, desiredDistance); // Where we want to be for the sake of zooming CameraTransform.Position = target - CameraTransform.Forward * zoom; // Set the position of the transform _previousDistance = Target.GetDistanceFromTarget(); Target.ClearAdditionalOffsets(); }
private void DrawGizmos() { if (isActiveAndEnabled == false) { return; } Gizmos.color = new Color(0, 1f, 1f); if (Lighting2D.ProjectSettings.editorView.drawGizmosBounds == EditorGizmosBounds.Rectangle) { for(int i = 0; i < cameraSettings.Length; i++) { CameraSettings cameraSetting = cameraSettings[i]; Camera camera = cameraSetting.GetCamera(); if (camera != null) { Rect cameraRect = CameraTransform.GetWorldRect(camera); GizmosHelper.DrawRect(transform.position, cameraRect); } } } for(int i = 0; i < Scriptable.LightSprite2D.List.Count; i++) { Scriptable.LightSprite2D light = Scriptable.LightSprite2D.List[i]; Rect rect = light.lightSpriteShape.GetWorldRect(); Gizmos.color = new Color(1f, 0.5f, 0.25f); GizmosHelper.DrawPolygon(light.lightSpriteShape.GetSpriteWorldPolygon(), transform.position); Gizmos.color = new Color(0, 1f, 1f); GizmosHelper.DrawRect(transform.position, rect); } }
public override void UpdateCamera() { Vector3 lockTarget = LockTarget.GetTarget(); Vector3 headbobOffset = Headbob.GetHeadbobModifier(_previousDistance); Target.AddWorldSpaceOffset(headbobOffset); Vector3 screenShakeOffset = ScreenShake.GetShaking(); Target.AddWorldSpaceOffset(screenShakeOffset); Vector3 target = Target.GetTarget(lockTarget); Vector3 direction = lockTarget - target; float desired = DesiredDistance; // Where we want the camera to be float actual = Vector3.Distance(CameraTransform.Position, target); // Where the camera physically is right now float calculated = ViewCollision.CalculateMaximumDistanceFromTarget(target, Mathf.Max(desired, actual)); // The maximum distance we calculated we can be based off collision and preference float zoom = Zoom.CalculateDistanceFromTarget(actual, calculated, desired); // Where we want to be for the sake of zooming CameraTransform.Position = target - direction.normalized * zoom; // Set the position of the transform CameraTransform.LookAt(target); _previousDistance = Vector3.Distance(CameraTransform.Position, target); Target.ClearAdditionalOffsets(); LockTarget.ClearAdditionalOffsets(); }
public static CameraTransform GetCamera(Camera camera) { if (camera == null) { Debug.LogError("Camera == Null"); } foreach (CameraTransform transform in list) { if (transform.camera == camera) { return(transform); } } CameraTransform cameraTransform = null; cameraTransform = new CameraTransform(); cameraTransform.camera = camera; list.Add(cameraTransform); return(cameraTransform); }
public bool InCamera(Camera camera) { float cameraRadius = CameraTransform.GetRadius(camera); float distance = Vector2.Distance(transform.position, camera.transform.position); float radius = cameraRadius + Mathf.Sqrt((size.x * size.x) * (size.y * size.y)); return(distance < radius); }
private void Start() { newCameraTransform = new CameraTransform(activeCamera); if (minPosTranform != null && maxPosTransform != null) { minPos = minPosTranform.localPosition; maxPos = maxPosTransform.localPosition; } }
public static void Draw(Camera camera, LightTilemapRoom2D id, Material material) { Vector2 cameraPosition = -camera.transform.position; float cameraRadius = CameraTransform.GetRadius(camera); LightTilemapCollider.Base tilemapCollider = id.GetCurrentTilemap(); material.mainTexture = null; Texture2D currentTexture = null; GL.Begin(GL.QUADS); int count = tilemapCollider.chunkManager.GetTiles(CameraTransform.GetWorldRect(camera)); for (int i = 0; i < count; i++) { LightTile tile = tilemapCollider.chunkManager.display[i]; if (tile.GetOriginalSprite() == null) { continue; } Vector2 tilePosition = tile.GetWorldPosition(tilemapCollider); tilePosition += cameraPosition; if (tile.NotInRange(tilePosition, cameraRadius)) { continue; } spriteRenderer.sprite = tile.GetOriginalSprite(); if (spriteRenderer.sprite.texture == null) { continue; } if (currentTexture != spriteRenderer.sprite.texture) { currentTexture = spriteRenderer.sprite.texture; material.mainTexture = currentTexture; material.SetPass(0); } Universal.Sprite.FullRect.Simple.DrawPass(tile.spriteMeshObject, spriteRenderer, tilePosition, tile.worldScale, tile.worldRotation); } GL.End(); material.mainTexture = null; }
public bool InCamera(Camera camera) { Rect cameraRect = CameraTransform.GetWorldRect(camera); if (cameraRect.Overlaps(lightSpriteShape.GetWorldRect())) { return(true); } return(false); }
/// <summary> /// Updates the rotation of the camera based on the target and /// </summary> public void UpdateRotation() { if (!Enabled) { return; } FixOffsets(); Quaternion targetRotation = GetCurrentRotation(); if (!DoesRotationNeedUpdating(targetRotation)) { return; } // The actual angle between the previous rotation and the current rotation. float angle = Quaternion.Angle(_previousTargetState.Rotation, targetRotation); // The t for lerping consistantly at the angles per second value. // If we're snapping, then we always do 1, otherwise, we do math. // We use mathf.abs because negative angles per second doesn't make sense. // I could force the AnglePerSecond value to change, but I decided to leave it incase people track angle per second values negatively here. float t = SnapRotation ? 1 : Mathf.Clamp01(Mathf.Abs(AnglePerSecond * Time.deltaTime) / angle); // We're going to be finished if t is equal to 1 (or greater, but because we're clamping that shouldn't be an issue.) _finishedAdjustment = t >= 1; if (t >= 1) { _forceAdjustment = false; } // Hit the t with the lerp transformer after we've done everything we have to with the real t value. // This honestly probably won't be used by many if any people, but the option is here if you want to mess with it. t = RotationLerpTransformer.Process(t); // Calculate the rotation we want for this update Quaternion rotation = Quaternion.Lerp(_previousTargetState.Rotation, targetRotation, t); // Actually rotate the camera CameraTransform.Rotation = rotation; CameraTransform.Rotate(CameraTransform.Right, YRotationOffset); CameraTransform.Rotate(_target.Target.up, -XRotationOffset); // Set the previous state information _previousTargetState.Rotation = rotation; _previousTargetState.Position = _target.Target.position; _previouslyDeterminedRotation = targetRotation; }
private void Start() { if (resetCameraButton == null) { throw new MissingReferenceException($"{nameof(resetCameraButton)} isn't set on ResetCameraTransform component."); } resetCameraButton.onClick.AddListener(Reset); _defaultCameraTransform = new CameraTransform { Position = transform.position, Rotation = transform.rotation, Scale = transform.localScale }; }
public static void DrawTiles(Camera camera, LightTilemapRoom2D id, Material material) { Vector2 cameraPosition = -camera.transform.position; float cameraRadius = CameraTransform.GetRadius(camera); if (id.superTilemapEditor.tilemap == null) { return; } if (id.superTilemapEditor.tilemap.Tileset != null) { material.mainTexture = id.superTilemapEditor.tilemap.Tileset.AtlasTexture; } material.color = id.color; LightTilemapCollider.Base tilemapCollider = id.GetCurrentTilemap(); material.SetPass(0); GL.Begin(GL.QUADS); int count = id.superTilemapEditor.chunkManager.GetTiles(CameraTransform.GetWorldRect(camera)); for (int i = 0; i < count; i++) { LightingTile tile = id.superTilemapEditor.chunkManager.display[i]; Vector2 tilePosition = tile.GetWorldPosition(tilemapCollider); tilePosition += cameraPosition; if (tile.NotInRange(tilePosition, cameraRadius)) { continue; } Vector2 scale = tile.worldScale * 0.5f * tile.scale; Rendering.Universal.Texture.DrawPassSTE(tilePosition, scale, tile.uv, tile.worldRotation, 0); } GL.End(); material.mainTexture = null; material.color = Color.white; }
private void UpdateTarget() { if (!m_target || m_target.IsDead) { ReleaseTarget(); return; } var pos = m_target.transform.position + (Vector3.up * 4f) + (m_target.transform.forward * -6f); FreeCamera.transform.position = pos; CameraTransform.position = pos; FreeCamera.transform.LookAt(m_target.transform); CameraTransform.LookAt(m_target.transform); }
/// <summary> /// If the Offsets for rotation are adjusted at run time, this will fix the rotation. /// </summary> private void FixOffsets() { if (_previousXRotationOffset != XRotationOffset) { float diff = XRotationOffset - _previousXRotationOffset; _previousXRotationOffset = XRotationOffset; CameraTransform.Rotate(_target.Target.up, -diff); } if (_previousYRotationOffset != YRotationOffset) { float diff = YRotationOffset - _previousYRotationOffset; _previousYRotationOffset = YRotationOffset; CameraTransform.Rotate(CameraTransform.Right, diff); } }
protected override void Awake() { base.Awake(); iniRot = transform.eulerAngles; charScript = FindObjectOfType <TombiCharacterController>(); collCapsule = charScript.GetComponent <CapsuleCollider>(); // Set initial rotation and distance Rotation.Rotate(InitialHorizontalRotation, InitialVerticalRotation); _previousDistance = DesiredDistance; // Then let update handle everything UpdateCamera(); CameraTransform.ApplyTo(Camera); Debug.Log("Test"); }
private static MeshObject GetMeshPixelPerfect(Light2D light) { if (pixelPerfectMeshObject == null) { Camera camera = Camera.main; Rect rect = CameraTransform.GetWorldRect(camera); CalculatePoints(); CalculateOffsets(rect.height * 1.1f / light.size); pixelPerfectMeshObject = GenerateMesh(); } return(pixelPerfectMeshObject); }
public void SetPointOfView(Transform targetPoint) { isInPersonalCamera = true; // 位置を記録した後PersonalCameraの位置に移動、CharacterControllerを無効化する if (enterDeviceType == EnterDeviceType.VR) { recordedPosition = PlayerTransform.position; recordedRotation = PlayerTransform.rotation; // OpenVRのカメラの高さがそのまま視点の高さになるので、 見せたい視点の高さ(y) - OpenVRによるカメラの高さ(local y)をしてやることで、視点の視線の高さにする var targetPosition = new Vector3(targetPoint.position.x, targetPoint.position.y - CameraTransform.localPosition.y, targetPoint.position.z); PlayerTransform.SetPositionAndRotation(targetPosition, targetPoint.rotation); } else { recordedPosition = CameraTransform.position; recordedRotation = CameraTransform.rotation; CameraTransform.SetPositionAndRotation(targetPoint.position, targetPoint.rotation); } playerController.ActivateCharacterController(false); }
private void Start() { activeCamera = Camera.main; cameraTransform = new CameraTransform(activeCamera); }
void Update() { UpdateCamera(); CameraTransform.ApplyTo(Camera); }
void Update() { UpdateCamera(); CameraTransform.ApplyTo(Camera); // Apply the virtual transform to the actual transform }
void Start() { CameraTransform.Position = HoldingPosition.position; CameraTransform.LookAt(Target.GetTarget()); _previousDistance = Target.GetDistanceFromTarget(); }
public static Rect GetWorldRect(Camera camera) { CameraTransform cameraTransform = GetCamera(camera); return(cameraTransform.WorldRect()); }