Starting to integrate the new art

This commit is contained in:
WillJeynes
2026-08-29 22:29:12 +01:00
parent b1705cd041
commit ecb078809b
13 changed files with 1637 additions and 279 deletions
+277 -271
View File
@@ -3,123 +3,119 @@ using Unity.Cinemachine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections;
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("Intro Sequence Setup")] [Tooltip("The camera placed high up to show the whole room.")]
public CinemachineCamera introCamera;
    [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("Raycast Setup")]
    public Camera mainUnityCamera;
    public LayerMask interactableLayer;
public float introHoldTime = 2f;
    [Header("UI Setup")]
    public Button talkButton;
    public Button doorButton;
    private GuardManager currentGuardManager;
    private DoorManager currentDoorManager;
[Tooltip("How long the Cinemachine blend takes to sweep down to the player.")]
public float blendDuration = 2f;
    [Header("Hover Highlight Settings")]
    public Color highlightColour = Color.yellow;
    private Renderer currentlyHoveredRenderer;
    private Color originalColour;
[Header("Raycast Setup")] public Camera mainUnityCamera;
public LayerMask interactableLayer;
    [Header("Exploration Nudge Settings")]
    public float nudgeSpeed = 15f;
    public float maxNudgeAngle = 8f;
    public float edgeThickness = 50f;
[Header("UI Setup")] public Button talkButton;
public Button doorButton;
private GuardManager currentGuardManager;
private DoorManager currentDoorManager;
    [Header("Focus Nudge Settings")]
    public float focusNudgeSpeed = 5f;
    public float maxFocusOffset = 2f;
[Header("Hover Highlight Settings")] public Color highlightColour = Color.yellow;
private Renderer currentlyHoveredRenderer;
private Color originalColour;
    private Quaternion startingRotation;
    private float currentYaw = 0f;
[Header("Exploration Nudge Settings")] public float nudgeSpeed = 15f;
public float maxNudgeAngle = 8f;
public float edgeThickness = 50f;
    private bool useCameraA = true;
    private Transform dynamicFocusTargetA;
    private Transform dynamicFocusTargetB;
    private Transform activeDynamicTarget;
    private Transform currentInteractableTransform;
   
    private float currentFocusOffsetX = 0f;
    private bool isSequencePlaying = false;
[Header("Focus Nudge Settings")] public float focusNudgeSpeed = 5f;
public float maxFocusOffset = 2f;
    void Start()
    {
        if (explorationCamera != null)
        {
            startingRotation = explorationCamera.transform.rotation;
        }
private Quaternion startingRotation;
private float currentYaw = 0f;
        dynamicFocusTargetA = new GameObject("DynamicFocusTarget_A").transform;
        dynamicFocusTargetB = new GameObject("DynamicFocusTarget_B").transform;
private bool useCameraA = true;
private Transform dynamicFocusTargetA;
private Transform dynamicFocusTargetB;
private Transform activeDynamicTarget;
private Transform currentInteractableTransform;
        if (talkButton != null)
        {
            talkButton.gameObject.SetActive(false);
            talkButton.onClick.AddListener(OnTalkButtonClicked);
        }
private float currentFocusOffsetX = 0f;
private bool isSequencePlaying = false;
        if (doorButton != null)
        {
            doorButton.gameObject.SetActive(false);
            doorButton.onClick.AddListener(OnDoorButtonClicked);
        }
void Start()
{
if (explorationCamera != null)
{
startingRotation = explorationCamera.transform.rotation;
}
        // Play the intro sweep straight away when the game first loads!
        if (introCamera != null)
        {
            StartCoroutine(IntroSequenceRoutine());
        }
    }
dynamicFocusTargetA = new GameObject("DynamicFocusTarget_A").transform;
dynamicFocusTargetB = new GameObject("DynamicFocusTarget_B").transform;
    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 (talkButton != null)
{
talkButton.gameObject.SetActive(false);
talkButton.onClick.AddListener(OnTalkButtonClicked);
}
        if (Mouse.current == null || isSequencePlaying) return;
if (doorButton != null)
{
doorButton.gameObject.SetActive(false);
doorButton.onClick.AddListener(OnDoorButtonClicked);
}
        HandleHover();
        HandleEdgeNudge();
// Play the intro sweep straight away when the game first loads!
if (introCamera != null)
{
StartCoroutine(IntroSequenceRoutine());
}
}
        if (Mouse.current.leftButton.wasPressedThisFrame)
        {
            if (EventSystem.current != null && EventSystem.current.IsPointerOverGameObject())
            {
                return;
            }
            HandleInteractionClick();
        }
       
        if (Mouse.current.rightButton.wasPressedThisFrame)
        {
            ReturnToMainCamera();
        }
    }
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();
}
    private IEnumerator IntroSequenceRoutine()
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 you haven't assigned an intro camera yet, just skip this
if (introCamera == null) yield break;
@@ -127,7 +123,7 @@ public class CameraController : MonoBehaviour
// Lock controls
isSequencePlaying = true;
RemoveHighlight();
// If we have a track, reset the camera to the very start of it
if (introSplineDolly != null)
{
@@ -148,7 +144,7 @@ public class CameraController : MonoBehaviour
introSplineDolly.CameraPosition = Mathf.Lerp(0f, 1f, elapsedTime / introHoldTime);
yield return null;
}
// Make sure it snaps perfectly to the end (1.0)
introSplineDolly.CameraPosition = 1f;
}
@@ -168,7 +164,7 @@ public class CameraController : MonoBehaviour
isSequencePlaying = false;
}
    private IEnumerator DoorSequenceRoutine(DoorManager activeDoor)
private IEnumerator DoorSequenceRoutine(DoorManager activeDoor)
{
isSequencePlaying = true;
RemoveHighlight();
@@ -176,34 +172,40 @@ public class CameraController : MonoBehaviour
// 1. TRIPWIRE: Check if the slots are empty!
if (activeDoor.type == "DEATH")
{
if (activeDoor.deathCamera == null) Debug.LogError("🚨 ERROR: This is a DEATH door, but the Death Camera slot is empty in the Prefab Inspector!");
if (activeDoor.deathSplineDolly == null) Debug.LogError("🚨 ERROR: This is a DEATH door, but the Death Spline Dolly slot is empty in the Prefab Inspector!");
if (activeDoor.deathCamera == null)
Debug.LogError(
"🚨 ERROR: This is a DEATH door, but the Death Camera slot is empty in the Prefab Inspector!");
if (activeDoor.deathSplineDolly == null)
Debug.LogError(
"🚨 ERROR: This is a DEATH door, but the Death Spline Dolly slot is empty in the Prefab Inspector!");
}
// 2. Determine which camera to use
bool isDeathDoor = activeDoor.type == "DEATH" && activeDoor.deathCamera != null && activeDoor.deathSplineDolly != null;
bool isDeathDoor = activeDoor.type == "DEATH" && activeDoor.deathCamera != null &&
activeDoor.deathSplineDolly != null;
CinemachineCamera activeCam = isDeathDoor ? activeDoor.deathCamera : activeDoor.doorCamera;
CinemachineSplineDolly activeDolly = isDeathDoor ? activeDoor.deathSplineDolly : activeDoor.doorSplineDolly;
// 3. TRIPWIRE: Tell us which camera was actually chosen
Debug.Log($"🎯 Door clicked! Type is: '{activeDoor.type}'. Script is using track: '{activeCam.gameObject.name}'");
Debug.Log(
$"🎯 Door clicked! Type is: '{activeDoor.type}'. Script is using track: '{activeCam.gameObject.name}'");
activeDolly.CameraPosition = 0f;
activeCam.Priority = 30;
yield return new WaitForSeconds(0.5f);
yield return new WaitForSeconds(1f);
// --- DISTANCE MOVEMENT FIX ---
// Using real metres now! 5f means 5 metres per second. Adjust this if it falls too slowly!
float pushSpeed = 5f;
float pushSpeed = 5f;
float previousPosition = -1f;
while (activeDoor != null && activeDolly != null && activeDolly.CameraPosition > previousPosition)
{
previousPosition = activeDolly.CameraPosition;
activeDolly.CameraPosition += pushSpeed * Time.deltaTime;
yield return null;
yield return null;
}
// ------------------------------
@@ -222,10 +224,10 @@ public class CameraController : MonoBehaviour
else if (doorType == "DEATH")
{
Debug.Log("Wrong door! Player died.");
// We intentionally DO NOT drop the priority here.
// The camera stays locked at Priority 30, trapping the player's view at the bottom of the pit!
isSequencePlaying = false;
isSequencePlaying = false;
}
else
{
@@ -236,184 +238,188 @@ public class CameraController : MonoBehaviour
}
}
    private void HandleEdgeNudge()
    {
        Vector2 mousePos = Mouse.current.position.ReadValue();
        float yawInput = 0f;
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;
if (mousePos.x < edgeThickness) yawInput = -1f;
else if (mousePos.x > Screen.width - edgeThickness) yawInput = 1f;
        bool isFocused = focusCameraA.Priority >= activePriority || focusCameraB.Priority >= activePriority;
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);
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;
            }
        }
    }
activeDynamicTarget.position = currentInteractableTransform.position
+ (mainUnityCamera.transform.right * currentFocusOffsetX);
}
else if (!isFocused && explorationCamera != null)
{
currentYaw += yawInput * nudgeSpeed * Time.deltaTime;
currentYaw = Mathf.Clamp(currentYaw, -maxNudgeAngle, maxNudgeAngle);
    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;
Quaternion yawRotation = Quaternion.AngleAxis(currentYaw, Vector3.up);
explorationCamera.transform.rotation = startingRotation * yawRotation;
}
}
}
                if (currentlyHoveredRenderer is SpriteRenderer sprite)
                {
                    originalColour = sprite.color;
                    sprite.color = highlightColour;
                }
                else
                {
                    originalColour = currentlyHoveredRenderer.material.color;
                    currentlyHoveredRenderer.material.color = highlightColour;
                }
            }
        }
        else
        {
            RemoveHighlight();
        }
    }
private void HandleHover()
{
Vector2 mousePos = Mouse.current.position.ReadValue();
Ray ray = mainUnityCamera.ScreenPointToRay(mousePos);
    private void RemoveHighlight()
    {
        if (currentlyHoveredRenderer != null)
        {
            if (currentlyHoveredRenderer is SpriteRenderer sprite)
            {
                sprite.color = originalColour;
            }
            else
            {
                currentlyHoveredRenderer.material.color = originalColour;
            }
            currentlyHoveredRenderer = null;
        }
    }
if (Physics.Raycast(ray, out RaycastHit hit, 100f, interactableLayer))
{
Renderer hitRenderer = hit.transform.GetComponentInChildren<Renderer>();
    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;
if (hitRenderer != null && hitRenderer != currentlyHoveredRenderer)
{
RemoveHighlight();
currentlyHoveredRenderer = hitRenderer;
            GuardManager guard = hit.transform.GetComponent<GuardManager>();
            DoorManager door = hit.transform.GetComponent<DoorManager>();
if (currentlyHoveredRenderer is SpriteRenderer sprite)
{
originalColour = sprite.color;
sprite.color = highlightColour;
}
else
{
originalColour = currentlyHoveredRenderer.material.color;
currentlyHoveredRenderer.material.color = highlightColour;
}
}
}
else
{
RemoveHighlight();
}
}
            if (talkButton != null) talkButton.gameObject.SetActive(false);
            if (doorButton != null) doorButton.gameObject.SetActive(false);
private void RemoveHighlight()
{
if (currentlyHoveredRenderer != null)
{
if (currentlyHoveredRenderer is SpriteRenderer sprite)
{
sprite.color = originalColour;
}
else
{
currentlyHoveredRenderer.material.color = originalColour;
}
            if (guard != null)
            {
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)
            {
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();
        }
    }
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 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 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;
private void ReturnToMainCamera()
{
focusCameraA.Priority = inactivePriority;
focusCameraB.Priority = inactivePriority;
if (introCamera != null) introCamera.Priority = inactivePriority;
        if (talkButton != null) talkButton.gameObject.SetActive(false);
        if (doorButton != null) doorButton.gameObject.SetActive(false);
    }
focusCameraA.Follow = null;
focusCameraA.LookAt = null;
focusCameraB.Follow = null;
focusCameraB.LookAt = null;
    private void ResetCameraPositions()
    {
        ReturnToMainCamera();
currentInteractableTransform = null;
activeDynamicTarget = null;
currentGuardManager = null;
currentDoorManager = null;
        currentFocusOffsetX = 0f;
        currentYaw = 0f;
       
        if (explorationCamera != null)
        {
            explorationCamera.transform.rotation = startingRotation;
        }
    }
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;
}
}
}
+1 -1
View File
@@ -139,7 +139,7 @@ public class LevelLoader : Singleton<LevelLoader>
IEnumerator DoSomethingAfterOneSecond()
{
yield return new WaitForSeconds(0.1f);
yield return new WaitForSeconds(1.5f);
var responder = "GUARD";
if (introchar != null)
+8
View File
@@ -1,3 +1,4 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Utils;
@@ -37,6 +38,13 @@ public class TutorialManager : Singleton<TutorialManager>
return;
}
StartCoroutine(DoSomethingAfterOneSecond());
}
IEnumerator DoSomethingAfterOneSecond()
{
yield return new WaitForSeconds(1.5f);
var tutorial = LevelLoader.Instance.GlobalModifier == "TUT1" ? tutorialOne : tutorialTwo;
tutorial[index].value.SetActive(true);
}