Merge branch 'master' of github.com:WillJeynes/Brackeys2026-2
This commit is contained in:
+343
-294
@@ -7,350 +7,399 @@ using System.Collections;
|
||||
|
||||
public class CameraController : MonoBehaviour
|
||||
{
|
||||
[Header("Cinemachine 3 Setup")]
|
||||
public CinemachineCamera focusCameraA;
|
||||
public CinemachineCamera focusCameraB;
|
||||
public CinemachineCamera explorationCamera;
|
||||
|
||||
public int activePriority = 20;
|
||||
public int inactivePriority = 10;
|
||||
[Header("Cinemachine 3 Setup")]
|
||||
public CinemachineCamera focusCameraA;
|
||||
public CinemachineCamera focusCameraB;
|
||||
public CinemachineCamera explorationCamera;
|
||||
|
||||
public int activePriority = 20;
|
||||
public int inactivePriority = 10;
|
||||
|
||||
[Header("Raycast Setup")]
|
||||
public Camera mainUnityCamera;
|
||||
public LayerMask interactableLayer;
|
||||
[Header("Intro Sequence Setup")]
|
||||
[Tooltip("The camera placed high up to show the whole room.")]
|
||||
public CinemachineCamera introCamera;
|
||||
public CinemachineSplineDolly introSplineDolly;
|
||||
|
||||
public float introHoldTime = 2f;
|
||||
[Tooltip("How long the Cinemachine blend takes to sweep down to the player.")]
|
||||
public float blendDuration = 2f;
|
||||
|
||||
[Header("UI Setup")]
|
||||
public Button talkButton;
|
||||
public Button doorButton;
|
||||
private GuardManager currentGuardManager;
|
||||
private DoorManager currentDoorManager;
|
||||
[Header("Raycast Setup")]
|
||||
public Camera mainUnityCamera;
|
||||
public LayerMask interactableLayer;
|
||||
|
||||
[Header("Hover Highlight Settings")]
|
||||
public Color highlightColour = Color.yellow;
|
||||
private Renderer currentlyHoveredRenderer;
|
||||
private Color originalColour;
|
||||
[Header("UI Setup")]
|
||||
public Button talkButton;
|
||||
public Button doorButton;
|
||||
private GuardManager currentGuardManager;
|
||||
private DoorManager currentDoorManager;
|
||||
|
||||
[Header("Exploration Nudge Settings")]
|
||||
public float nudgeSpeed = 15f;
|
||||
public float maxNudgeAngle = 8f;
|
||||
public float edgeThickness = 50f;
|
||||
[Header("Hover Highlight Settings")]
|
||||
public Color highlightColour = Color.yellow;
|
||||
private Renderer currentlyHoveredRenderer;
|
||||
private Color originalColour;
|
||||
|
||||
[Header("Focus Nudge Settings")]
|
||||
public float focusNudgeSpeed = 5f;
|
||||
public float maxFocusOffset = 2f;
|
||||
[Header("Exploration Nudge Settings")]
|
||||
public float nudgeSpeed = 15f;
|
||||
public float maxNudgeAngle = 8f;
|
||||
public float edgeThickness = 50f;
|
||||
|
||||
private Quaternion startingRotation;
|
||||
private float currentYaw = 0f;
|
||||
[Header("Focus Nudge Settings")]
|
||||
public float focusNudgeSpeed = 5f;
|
||||
public float maxFocusOffset = 2f;
|
||||
|
||||
private bool useCameraA = true;
|
||||
private Transform dynamicFocusTargetA;
|
||||
private Transform dynamicFocusTargetB;
|
||||
private Transform activeDynamicTarget;
|
||||
private Transform currentInteractableTransform;
|
||||
|
||||
private float currentFocusOffsetX = 0f;
|
||||
private bool isSequencePlaying = false;
|
||||
private Quaternion startingRotation;
|
||||
private float currentYaw = 0f;
|
||||
|
||||
void Start()
|
||||
private bool useCameraA = true;
|
||||
private Transform dynamicFocusTargetA;
|
||||
private Transform dynamicFocusTargetB;
|
||||
private Transform activeDynamicTarget;
|
||||
private Transform currentInteractableTransform;
|
||||
|
||||
private float currentFocusOffsetX = 0f;
|
||||
private bool isSequencePlaying = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (explorationCamera != null)
|
||||
{
|
||||
startingRotation = explorationCamera.transform.rotation;
|
||||
}
|
||||
|
||||
dynamicFocusTargetA = new GameObject("DynamicFocusTarget_A").transform;
|
||||
dynamicFocusTargetB = new GameObject("DynamicFocusTarget_B").transform;
|
||||
|
||||
if (talkButton != null)
|
||||
{
|
||||
talkButton.gameObject.SetActive(false);
|
||||
talkButton.onClick.AddListener(OnTalkButtonClicked);
|
||||
}
|
||||
|
||||
if (doorButton != null)
|
||||
{
|
||||
doorButton.gameObject.SetActive(false);
|
||||
doorButton.onClick.AddListener(OnDoorButtonClicked);
|
||||
}
|
||||
|
||||
// Play the intro sweep straight away when the game first loads!
|
||||
if (introCamera != null)
|
||||
{
|
||||
StartCoroutine(IntroSequenceRoutine());
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Allow the Escape key to skip intro sequences or drop interactions at any time
|
||||
if (Keyboard.current != null && Keyboard.current.escapeKey.wasPressedThisFrame)
|
||||
{
|
||||
StopAllCoroutines();
|
||||
isSequencePlaying = false;
|
||||
ResetCameraPositions();
|
||||
}
|
||||
|
||||
if (Mouse.current == null || isSequencePlaying) return;
|
||||
|
||||
HandleHover();
|
||||
HandleEdgeNudge();
|
||||
|
||||
if (Mouse.current.leftButton.wasPressedThisFrame)
|
||||
{
|
||||
if (EventSystem.current != null && EventSystem.current.IsPointerOverGameObject())
|
||||
{
|
||||
return;
|
||||
}
|
||||
HandleInteractionClick();
|
||||
}
|
||||
|
||||
if (Mouse.current.rightButton.wasPressedThisFrame)
|
||||
{
|
||||
ReturnToMainCamera();
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator IntroSequenceRoutine()
|
||||
{
|
||||
if (explorationCamera != null)
|
||||
{
|
||||
startingRotation = explorationCamera.transform.rotation;
|
||||
}
|
||||
// If you haven't assigned an intro camera yet, just skip this
|
||||
if (introCamera == null) yield break;
|
||||
|
||||
dynamicFocusTargetA = new GameObject("DynamicFocusTarget_A").transform;
|
||||
dynamicFocusTargetB = new GameObject("DynamicFocusTarget_B").transform;
|
||||
|
||||
if (talkButton != null)
|
||||
{
|
||||
talkButton.gameObject.SetActive(false);
|
||||
talkButton.onClick.AddListener(OnTalkButtonClicked);
|
||||
}
|
||||
|
||||
if (doorButton != null)
|
||||
{
|
||||
doorButton.gameObject.SetActive(false);
|
||||
doorButton.onClick.AddListener(OnDoorButtonClicked);
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Mouse.current == null || isSequencePlaying) return;
|
||||
|
||||
HandleHover();
|
||||
HandleEdgeNudge();
|
||||
|
||||
if (Mouse.current.leftButton.wasPressedThisFrame)
|
||||
{
|
||||
if (EventSystem.current != null && EventSystem.current.IsPointerOverGameObject())
|
||||
{
|
||||
return;
|
||||
}
|
||||
HandleInteractionClick();
|
||||
}
|
||||
// Lock controls
|
||||
isSequencePlaying = true;
|
||||
RemoveHighlight();
|
||||
|
||||
if (Mouse.current.rightButton.wasPressedThisFrame)
|
||||
// If we have a track, reset the camera to the very start of it
|
||||
if (introSplineDolly != null)
|
||||
{
|
||||
ReturnToMainCamera();
|
||||
introSplineDolly.CameraPosition = 0f;
|
||||
}
|
||||
|
||||
if (Keyboard.current != null && Keyboard.current.escapeKey.wasPressedThisFrame)
|
||||
// Snap to the intro camera
|
||||
introCamera.Priority = 30;
|
||||
|
||||
// If we have a track, push the camera along it smoothly!
|
||||
if (introSplineDolly != null)
|
||||
{
|
||||
ResetCameraPositions();
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleEdgeNudge()
|
||||
{
|
||||
Vector2 mousePos = Mouse.current.position.ReadValue();
|
||||
float yawInput = 0f;
|
||||
|
||||
if (mousePos.x < edgeThickness) yawInput = -1f;
|
||||
else if (mousePos.x > Screen.width - edgeThickness) yawInput = 1f;
|
||||
|
||||
bool isFocused = focusCameraA.Priority >= activePriority || focusCameraB.Priority >= activePriority;
|
||||
|
||||
if (yawInput != 0f)
|
||||
{
|
||||
if (isFocused && currentInteractableTransform != null && activeDynamicTarget != null)
|
||||
float elapsedTime = 0f;
|
||||
while (elapsedTime < introHoldTime)
|
||||
{
|
||||
currentFocusOffsetX += yawInput * focusNudgeSpeed * Time.deltaTime;
|
||||
currentFocusOffsetX = Mathf.Clamp(currentFocusOffsetX, -maxFocusOffset, maxFocusOffset);
|
||||
|
||||
activeDynamicTarget.position = currentInteractableTransform.position
|
||||
+ (mainUnityCamera.transform.right * currentFocusOffsetX);
|
||||
elapsedTime += Time.deltaTime;
|
||||
// This maths magically moves it from 0 to 1 perfectly timed to your introHoldTime
|
||||
introSplineDolly.CameraPosition = Mathf.Lerp(0f, 1f, elapsedTime / introHoldTime);
|
||||
yield return null;
|
||||
}
|
||||
else if (!isFocused && explorationCamera != null)
|
||||
{
|
||||
currentYaw += yawInput * nudgeSpeed * Time.deltaTime;
|
||||
currentYaw = Mathf.Clamp(currentYaw, -maxNudgeAngle, maxNudgeAngle);
|
||||
|
||||
Quaternion yawRotation = Quaternion.AngleAxis(currentYaw, Vector3.up);
|
||||
explorationCamera.transform.rotation = startingRotation * yawRotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleHover()
|
||||
{
|
||||
Vector2 mousePos = Mouse.current.position.ReadValue();
|
||||
Ray ray = mainUnityCamera.ScreenPointToRay(mousePos);
|
||||
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, 100f, interactableLayer))
|
||||
{
|
||||
Renderer hitRenderer = hit.transform.GetComponentInChildren<Renderer>();
|
||||
|
||||
if (hitRenderer != null && hitRenderer != currentlyHoveredRenderer)
|
||||
{
|
||||
RemoveHighlight();
|
||||
currentlyHoveredRenderer = hitRenderer;
|
||||
|
||||
if (
|
||||
currentlyHoveredRenderer.gameObject.GetComponentInParent<DoorManager>() != null &&
|
||||
currentlyHoveredRenderer.gameObject.GetComponentInParent<DoorManager>() != currentDoorManager
|
||||
)
|
||||
{
|
||||
currentlyHoveredRenderer.gameObject.GetComponentInParent<DoorManager>().isfocussed = 1;
|
||||
}
|
||||
|
||||
if (
|
||||
currentlyHoveredRenderer.gameObject.GetComponentInParent<GuardManager>() != null &&
|
||||
currentlyHoveredRenderer.gameObject.GetComponentInParent<GuardManager>() != currentGuardManager
|
||||
)
|
||||
{
|
||||
currentlyHoveredRenderer.gameObject.GetComponentInParent<GuardManager>().isfocussed = 1;
|
||||
}
|
||||
}
|
||||
// Make sure it snaps perfectly to the end (1.0)
|
||||
introSplineDolly.CameraPosition = 1f;
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveHighlight();
|
||||
// If you didn't plug in a spline, just wait normally
|
||||
yield return new WaitForSeconds(introHoldTime);
|
||||
}
|
||||
|
||||
// Drop priority so Cinemachine blends down to the exploration camera
|
||||
introCamera.Priority = inactivePriority;
|
||||
|
||||
// Wait whilst the camera physically travels downwards
|
||||
yield return new WaitForSeconds(blendDuration);
|
||||
|
||||
// Unlock controls
|
||||
isSequencePlaying = false;
|
||||
}
|
||||
|
||||
private void RemoveHighlight()
|
||||
{
|
||||
if (currentlyHoveredRenderer != null)
|
||||
{
|
||||
if (
|
||||
currentlyHoveredRenderer.gameObject.GetComponentInParent<DoorManager>() != null &&
|
||||
currentlyHoveredRenderer.gameObject.GetComponentInParent<DoorManager>() != currentDoorManager
|
||||
)
|
||||
{
|
||||
currentlyHoveredRenderer.gameObject.GetComponentInParent<DoorManager>().isfocussed = 0;
|
||||
}
|
||||
|
||||
if (
|
||||
currentlyHoveredRenderer.gameObject.GetComponentInParent<GuardManager>() != null &&
|
||||
currentlyHoveredRenderer.gameObject.GetComponentInParent<GuardManager>() != currentGuardManager
|
||||
)
|
||||
{
|
||||
currentlyHoveredRenderer.gameObject.GetComponentInParent<GuardManager>().isfocussed = 0;
|
||||
}
|
||||
|
||||
currentlyHoveredRenderer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleInteractionClick()
|
||||
{
|
||||
Vector2 mousePos = Mouse.current.position.ReadValue();
|
||||
Ray ray = mainUnityCamera.ScreenPointToRay(mousePos);
|
||||
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, 100f, interactableLayer))
|
||||
{
|
||||
currentInteractableTransform = hit.transform;
|
||||
currentFocusOffsetX = 0f;
|
||||
|
||||
CinemachineCamera nextCam = useCameraA ? focusCameraA : focusCameraB;
|
||||
CinemachineCamera oldCam = useCameraA ? focusCameraB : focusCameraA;
|
||||
Transform nextTarget = useCameraA ? dynamicFocusTargetA : dynamicFocusTargetB;
|
||||
|
||||
nextTarget.position = currentInteractableTransform.position;
|
||||
nextCam.Follow = currentInteractableTransform;
|
||||
nextCam.LookAt = nextTarget;
|
||||
|
||||
nextCam.Priority = activePriority;
|
||||
oldCam.Priority = inactivePriority;
|
||||
|
||||
activeDynamicTarget = nextTarget;
|
||||
useCameraA = !useCameraA;
|
||||
|
||||
GuardManager guard = hit.transform.GetComponent<GuardManager>();
|
||||
DoorManager door = hit.transform.GetComponent<DoorManager>();
|
||||
|
||||
if (talkButton != null) talkButton.gameObject.SetActive(false);
|
||||
if (doorButton != null) doorButton.gameObject.SetActive(false);
|
||||
|
||||
UnsetAll();
|
||||
|
||||
if (guard != null)
|
||||
{
|
||||
TutorialManager.Instance.LogAction("TAP");
|
||||
currentGuardManager = guard;
|
||||
guard.isfocussed = 2;
|
||||
if (talkButton != null) talkButton.gameObject.SetActive(true);
|
||||
}
|
||||
else if (door != null)
|
||||
{
|
||||
TutorialManager.Instance.LogAction("TAP");
|
||||
currentDoorManager = door;
|
||||
door.isfocussed = 2;
|
||||
if (doorButton != null) doorButton.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ReturnToMainCamera();
|
||||
UnsetAll();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTalkButtonClicked()
|
||||
{
|
||||
if (currentGuardManager != null)
|
||||
{
|
||||
DialogManager.Instance.StartDialog(currentGuardManager);
|
||||
// talkButton.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDoorButtonClicked()
|
||||
{
|
||||
if (currentDoorManager != null && currentDoorManager.doorCamera != null && currentDoorManager.doorSplineDolly != null)
|
||||
{
|
||||
doorButton.gameObject.SetActive(false);
|
||||
StartCoroutine(DoorSequenceRoutine(currentDoorManager));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("The DoorManager is missing its Camera or Spline Dolly references!");
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator DoorSequenceRoutine(DoorManager activeDoor)
|
||||
private IEnumerator DoorSequenceRoutine(DoorManager activeDoor)
|
||||
{
|
||||
isSequencePlaying = true;
|
||||
RemoveHighlight();
|
||||
|
||||
activeDoor.doorSplineDolly.CameraPosition = 0f;
|
||||
activeDoor.doorCamera.Priority = 30;
|
||||
// 1. Determine which camera and track to use based on the door type
|
||||
bool isDeathDoor = activeDoor.type == "DEATH" && activeDoor.deathCamera != null;
|
||||
|
||||
CinemachineCamera activeCam = isDeathDoor ? activeDoor.deathCamera : activeDoor.doorCamera;
|
||||
CinemachineSplineDolly activeDolly = isDeathDoor ? activeDoor.deathSplineDolly : activeDoor.doorSplineDolly;
|
||||
|
||||
// 2. Reset the chosen track and boost its priority
|
||||
activeDolly.CameraPosition = 0f;
|
||||
activeCam.Priority = 30;
|
||||
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
|
||||
// 3. Push the camera (You might want to speed this up for the death drop!)
|
||||
float pushSpeed = 0.5f;
|
||||
|
||||
// Push the camera through the doorway
|
||||
while (activeDoor.doorSplineDolly.CameraPosition < 1f)
|
||||
while (activeDoor != null && activeDolly != null && activeDolly.CameraPosition < 1f)
|
||||
{
|
||||
activeDoor.doorSplineDolly.CameraPosition += pushSpeed * Time.deltaTime;
|
||||
activeDolly.CameraPosition += pushSpeed * Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
activeDoor.doorSplineDolly.CameraPosition = 1f;
|
||||
string doorType = activeDoor != null ? activeDoor.type : "";
|
||||
|
||||
yield return new WaitForSeconds(2.0f);
|
||||
// 4. Safely drop the camera's priority
|
||||
if (activeCam != null)
|
||||
{
|
||||
activeCam.Priority = inactivePriority;
|
||||
}
|
||||
|
||||
// The camera is now inside the room. Let's check what kind of door it was!
|
||||
if (activeDoor.type == "LIFE")
|
||||
// 5. Trigger the appropriate level logic
|
||||
if (doorType == "LIFE")
|
||||
{
|
||||
Debug.Log("Safe door chosen! Advancing to the next level.");
|
||||
GlobalStateManager.Instance.SetLevelCompleted();
|
||||
}
|
||||
else if (activeDoor.type == "DEATH")
|
||||
else if (doorType == "DEATH")
|
||||
{
|
||||
Debug.Log("Wrong door! The player has met a grim fate.");
|
||||
|
||||
// Add your death screen or level restart logic here!
|
||||
// For example: GlobalStateManager.Instance.TriggerGameOver();
|
||||
Debug.Log("Wrong door! Teleporting back to start.");
|
||||
// Insert your death/teleport logic here
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"Door type '{activeDoor.type}' is not recognised for level transitions.");
|
||||
}
|
||||
}
|
||||
|
||||
private void ReturnToMainCamera()
|
||||
{
|
||||
focusCameraA.Priority = inactivePriority;
|
||||
focusCameraB.Priority = inactivePriority;
|
||||
|
||||
focusCameraA.Follow = null; focusCameraA.LookAt = null;
|
||||
focusCameraB.Follow = null; focusCameraB.LookAt = null;
|
||||
|
||||
currentInteractableTransform = null;
|
||||
activeDynamicTarget = null;
|
||||
currentGuardManager = null;
|
||||
currentDoorManager = null;
|
||||
|
||||
if (talkButton != null) talkButton.gameObject.SetActive(false);
|
||||
if (doorButton != null) doorButton.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void UnsetAll()
|
||||
{
|
||||
foreach (var doorManager in LevelLoader.Instance.Doors)
|
||||
{
|
||||
doorManager.isfocussed = 0;
|
||||
}
|
||||
foreach (var doorManager in LevelLoader.Instance.Guards)
|
||||
{
|
||||
doorManager.isfocussed = 0;
|
||||
Debug.LogWarning($"Door type '{doorType}' is not recognised.");
|
||||
}
|
||||
|
||||
// 6. Play the intro sweep for the newly generated room or restart
|
||||
yield return StartCoroutine(IntroSequenceRoutine());
|
||||
}
|
||||
|
||||
private void ResetCameraPositions()
|
||||
{
|
||||
ReturnToMainCamera();
|
||||
private void HandleEdgeNudge()
|
||||
{
|
||||
Vector2 mousePos = Mouse.current.position.ReadValue();
|
||||
float yawInput = 0f;
|
||||
|
||||
currentFocusOffsetX = 0f;
|
||||
currentYaw = 0f;
|
||||
|
||||
if (explorationCamera != null)
|
||||
{
|
||||
explorationCamera.transform.rotation = startingRotation;
|
||||
}
|
||||
}
|
||||
if (mousePos.x < edgeThickness) yawInput = -1f;
|
||||
else if (mousePos.x > Screen.width - edgeThickness) yawInput = 1f;
|
||||
|
||||
bool isFocused = focusCameraA.Priority >= activePriority || focusCameraB.Priority >= activePriority;
|
||||
|
||||
if (yawInput != 0f)
|
||||
{
|
||||
if (isFocused && currentInteractableTransform != null && activeDynamicTarget != null)
|
||||
{
|
||||
currentFocusOffsetX += yawInput * focusNudgeSpeed * Time.deltaTime;
|
||||
currentFocusOffsetX = Mathf.Clamp(currentFocusOffsetX, -maxFocusOffset, maxFocusOffset);
|
||||
|
||||
activeDynamicTarget.position = currentInteractableTransform.position
|
||||
+ (mainUnityCamera.transform.right * currentFocusOffsetX);
|
||||
}
|
||||
else if (!isFocused && explorationCamera != null)
|
||||
{
|
||||
currentYaw += yawInput * nudgeSpeed * Time.deltaTime;
|
||||
currentYaw = Mathf.Clamp(currentYaw, -maxNudgeAngle, maxNudgeAngle);
|
||||
|
||||
Quaternion yawRotation = Quaternion.AngleAxis(currentYaw, Vector3.up);
|
||||
explorationCamera.transform.rotation = startingRotation * yawRotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleHover()
|
||||
{
|
||||
Vector2 mousePos = Mouse.current.position.ReadValue();
|
||||
Ray ray = mainUnityCamera.ScreenPointToRay(mousePos);
|
||||
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, 100f, interactableLayer))
|
||||
{
|
||||
Renderer hitRenderer = hit.transform.GetComponentInChildren<Renderer>();
|
||||
|
||||
if (hitRenderer != null && hitRenderer != currentlyHoveredRenderer)
|
||||
{
|
||||
RemoveHighlight();
|
||||
currentlyHoveredRenderer = hitRenderer;
|
||||
|
||||
if (currentlyHoveredRenderer is SpriteRenderer sprite)
|
||||
{
|
||||
originalColour = sprite.color;
|
||||
sprite.color = highlightColour;
|
||||
}
|
||||
else
|
||||
{
|
||||
originalColour = currentlyHoveredRenderer.material.color;
|
||||
currentlyHoveredRenderer.material.color = highlightColour;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveHighlight();
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveHighlight()
|
||||
{
|
||||
if (currentlyHoveredRenderer != null)
|
||||
{
|
||||
if (currentlyHoveredRenderer is SpriteRenderer sprite)
|
||||
{
|
||||
sprite.color = originalColour;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentlyHoveredRenderer.material.color = originalColour;
|
||||
}
|
||||
currentlyHoveredRenderer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleInteractionClick()
|
||||
{
|
||||
Vector2 mousePos = Mouse.current.position.ReadValue();
|
||||
Ray ray = mainUnityCamera.ScreenPointToRay(mousePos);
|
||||
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, 100f, interactableLayer))
|
||||
{
|
||||
currentInteractableTransform = hit.transform;
|
||||
currentFocusOffsetX = 0f;
|
||||
|
||||
CinemachineCamera nextCam = useCameraA ? focusCameraA : focusCameraB;
|
||||
CinemachineCamera oldCam = useCameraA ? focusCameraB : focusCameraA;
|
||||
Transform nextTarget = useCameraA ? dynamicFocusTargetA : dynamicFocusTargetB;
|
||||
|
||||
nextTarget.position = currentInteractableTransform.position;
|
||||
nextCam.Follow = currentInteractableTransform;
|
||||
nextCam.LookAt = nextTarget;
|
||||
|
||||
nextCam.Priority = activePriority;
|
||||
oldCam.Priority = inactivePriority;
|
||||
|
||||
activeDynamicTarget = nextTarget;
|
||||
useCameraA = !useCameraA;
|
||||
|
||||
GuardManager guard = hit.transform.GetComponent<GuardManager>();
|
||||
DoorManager door = hit.transform.GetComponent<DoorManager>();
|
||||
|
||||
if (talkButton != null) talkButton.gameObject.SetActive(false);
|
||||
if (doorButton != null) doorButton.gameObject.SetActive(false);
|
||||
|
||||
if (guard != null)
|
||||
{
|
||||
TutorialManager.Instance.LogAction("TAP");
|
||||
currentGuardManager = guard;
|
||||
if (talkButton != null) talkButton.gameObject.SetActive(true);
|
||||
}
|
||||
else if (door != null)
|
||||
{
|
||||
TutorialManager.Instance.LogAction("TAP");
|
||||
currentDoorManager = door;
|
||||
if (doorButton != null) doorButton.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ReturnToMainCamera();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTalkButtonClicked()
|
||||
{
|
||||
if (currentGuardManager != null)
|
||||
{
|
||||
DialogManager.Instance.StartDialog(currentGuardManager);
|
||||
talkButton.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDoorButtonClicked()
|
||||
{
|
||||
if (currentDoorManager != null && currentDoorManager.doorCamera != null && currentDoorManager.doorSplineDolly != null)
|
||||
{
|
||||
doorButton.gameObject.SetActive(false);
|
||||
StartCoroutine(DoorSequenceRoutine(currentDoorManager));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("The DoorManager is missing its Camera or Spline Dolly references!");
|
||||
}
|
||||
}
|
||||
|
||||
private void ReturnToMainCamera()
|
||||
{
|
||||
focusCameraA.Priority = inactivePriority;
|
||||
focusCameraB.Priority = inactivePriority;
|
||||
if (introCamera != null) introCamera.Priority = inactivePriority;
|
||||
|
||||
focusCameraA.Follow = null; focusCameraA.LookAt = null;
|
||||
focusCameraB.Follow = null; focusCameraB.LookAt = null;
|
||||
|
||||
currentInteractableTransform = null;
|
||||
activeDynamicTarget = null;
|
||||
currentGuardManager = null;
|
||||
currentDoorManager = null;
|
||||
|
||||
if (talkButton != null) talkButton.gameObject.SetActive(false);
|
||||
if (doorButton != null) doorButton.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void ResetCameraPositions()
|
||||
{
|
||||
ReturnToMainCamera();
|
||||
|
||||
currentFocusOffsetX = 0f;
|
||||
currentYaw = 0f;
|
||||
|
||||
if (explorationCamera != null)
|
||||
{
|
||||
explorationCamera.transform.rotation = startingRotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,9 @@ public class DoorManager : MonoBehaviour, IDescribable
|
||||
|
||||
public CinemachineCamera doorCamera;
|
||||
public CinemachineSplineDolly doorSplineDolly;
|
||||
|
||||
public CinemachineCamera deathCamera;
|
||||
public CinemachineSplineDolly deathSplineDolly;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
|
||||
Reference in New Issue
Block a user