Update the photo taking mode to automatic and hone in visual feedback
This commit is contained in:
@@ -1,23 +1,24 @@
|
||||
using AudioSourceEvents;
|
||||
using Core;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using AudioSourceEvents;
|
||||
using Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
|
||||
namespace Minigames.DivingForPictures
|
||||
namespace Minigames.DivingForPictures.Monster
|
||||
{
|
||||
public class Monster : MonoBehaviour
|
||||
{
|
||||
[Header("References")]
|
||||
[SerializeField] private CircleCollider2D detectionCollider;
|
||||
[SerializeField] private GameObject proximityIndicator; // Visual sprite showing detection range
|
||||
|
||||
private bool pictureAlreadyTaken = false;
|
||||
private bool photoSequenceInProgress = false;
|
||||
private UnityEngine.Camera mainCamera;
|
||||
private bool _pictureAlreadyTaken = false;
|
||||
private bool _photoSequenceInProgress = false;
|
||||
private Camera _mainCamera;
|
||||
|
||||
// Track if player is in detection range
|
||||
private bool playerInDetectionRange = false;
|
||||
private bool _playerInDetectionRange = false;
|
||||
|
||||
// Events
|
||||
public event Action<Monster> OnMonsterDespawned;
|
||||
@@ -26,18 +27,18 @@ namespace Minigames.DivingForPictures
|
||||
|
||||
// Properties
|
||||
public float PictureRadius => detectionCollider != null ? detectionCollider.radius : 0f;
|
||||
public bool IsPhotoSequenceInProgress => photoSequenceInProgress;
|
||||
public bool IsPlayerInDetectionRange => playerInDetectionRange;
|
||||
public bool IsPictureTaken => pictureAlreadyTaken;
|
||||
public bool IsPhotoSequenceInProgress => _photoSequenceInProgress;
|
||||
public bool IsPlayerInDetectionRange => _playerInDetectionRange;
|
||||
public bool IsPictureTaken => _pictureAlreadyTaken;
|
||||
|
||||
public enum MonsterSounds
|
||||
{Hello, RareBeast, Pooping,Smile,Whatsup1, Whatsup2}
|
||||
private AudioSource _audioSource;
|
||||
public AudioResource[] monsterClips;
|
||||
private AudioSource playerAudioSource;
|
||||
private AudioSource _playerAudioSource;
|
||||
public AudioResource monsterSpottedAudio;
|
||||
private IAudioEventSource _eventSource;
|
||||
private GameObject playerObject;
|
||||
private GameObject _playerObject;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -46,37 +47,37 @@ namespace Minigames.DivingForPictures
|
||||
if (detectionCollider == null)
|
||||
detectionCollider = GetComponent<CircleCollider2D>();
|
||||
|
||||
mainCamera = UnityEngine.Camera.main;
|
||||
_mainCamera = UnityEngine.Camera.main;
|
||||
_audioSource = GetComponent<AudioSource>();
|
||||
|
||||
|
||||
playerObject = GameObject.FindGameObjectsWithTag("Player")[0];
|
||||
playerAudioSource = playerObject.GetComponent<AudioSource>();
|
||||
_eventSource = playerAudioSource.RequestEventHandlers();
|
||||
_eventSource.AudioStopped += playerAudioDone;
|
||||
_playerObject = GameObject.FindGameObjectsWithTag("Player")[0];
|
||||
_playerAudioSource = _playerObject.GetComponent<AudioSource>();
|
||||
_eventSource = _playerAudioSource.RequestEventHandlers();
|
||||
_eventSource.AudioStopped += PlayerAudioDone;
|
||||
|
||||
|
||||
// Start checking if monster is off-screen
|
||||
StartCoroutine(CheckIfOffScreen());
|
||||
}
|
||||
|
||||
private void playerAudioDone(object sender, EventArgs e)
|
||||
private void PlayerAudioDone(object sender, EventArgs e)
|
||||
{
|
||||
_audioSource.Play();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
playerAudioSource.resource = monsterSpottedAudio;
|
||||
playerAudioSource.Play();
|
||||
pictureAlreadyTaken = false;
|
||||
photoSequenceInProgress = false;
|
||||
_playerAudioSource.resource = monsterSpottedAudio;
|
||||
_playerAudioSource.Play();
|
||||
_pictureAlreadyTaken = false;
|
||||
_photoSequenceInProgress = false;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
Logging.Debug("Monster destroyed: " + gameObject.name);
|
||||
_eventSource.AudioStopped -= playerAudioDone;
|
||||
_eventSource.AudioStopped -= PlayerAudioDone;
|
||||
}
|
||||
|
||||
private IEnumerator CheckIfOffScreen()
|
||||
@@ -97,15 +98,15 @@ namespace Minigames.DivingForPictures
|
||||
|
||||
private bool IsVisibleToCamera()
|
||||
{
|
||||
if (mainCamera == null)
|
||||
mainCamera = UnityEngine.Camera.main;
|
||||
if (_mainCamera == null)
|
||||
_mainCamera = UnityEngine.Camera.main;
|
||||
|
||||
if (mainCamera == null)
|
||||
if (_mainCamera == null)
|
||||
return false;
|
||||
|
||||
// Get the world position (will account for parent movement)
|
||||
Vector3 worldPosition = transform.position;
|
||||
Vector3 viewportPoint = mainCamera.WorldToViewportPoint(worldPosition);
|
||||
Vector3 viewportPoint = _mainCamera.WorldToViewportPoint(worldPosition);
|
||||
|
||||
// If z is negative, the object is behind the camera
|
||||
if (viewportPoint.z < 0)
|
||||
@@ -129,10 +130,14 @@ namespace Minigames.DivingForPictures
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
// Don't trigger if picture already taken - prevents re-triggering photo sequence
|
||||
if (_pictureAlreadyTaken)
|
||||
return;
|
||||
|
||||
// Check if it's the player
|
||||
if (other.CompareTag("Player") && !pictureAlreadyTaken)
|
||||
if (other.CompareTag("Player"))
|
||||
{
|
||||
playerInDetectionRange = true;
|
||||
_playerInDetectionRange = true;
|
||||
// Fire the event so the game manager can display the viewfinder without pausing
|
||||
OnPlayerEnterDetectionRange?.Invoke(this);
|
||||
}
|
||||
@@ -140,10 +145,14 @@ namespace Minigames.DivingForPictures
|
||||
|
||||
private void OnTriggerExit2D(Collider2D other)
|
||||
{
|
||||
// Don't trigger if picture already taken
|
||||
if (_pictureAlreadyTaken)
|
||||
return;
|
||||
|
||||
// Check if it's the player
|
||||
if (other.CompareTag("Player"))
|
||||
{
|
||||
playerInDetectionRange = false;
|
||||
_playerInDetectionRange = false;
|
||||
// Fire the event so the game manager can hide the viewfinder
|
||||
OnPlayerExitDetectionRange?.Invoke(this);
|
||||
}
|
||||
@@ -154,8 +163,8 @@ namespace Minigames.DivingForPictures
|
||||
/// </summary>
|
||||
public void SetPhotoSequenceInProgress(bool inProgress = true)
|
||||
{
|
||||
if (pictureAlreadyTaken) return;
|
||||
photoSequenceInProgress = inProgress;
|
||||
if (_pictureAlreadyTaken) return;
|
||||
_photoSequenceInProgress = inProgress;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -164,10 +173,19 @@ namespace Minigames.DivingForPictures
|
||||
/// </summary>
|
||||
public void NotifyPictureTaken()
|
||||
{
|
||||
if (pictureAlreadyTaken) return;
|
||||
if (_pictureAlreadyTaken) return;
|
||||
|
||||
pictureAlreadyTaken = true;
|
||||
photoSequenceInProgress = false;
|
||||
_pictureAlreadyTaken = true;
|
||||
_photoSequenceInProgress = false;
|
||||
|
||||
// Destroy the proximity indicator visual
|
||||
if (proximityIndicator != null)
|
||||
{
|
||||
Destroy(proximityIndicator);
|
||||
proximityIndicator = null;
|
||||
}
|
||||
|
||||
Logging.Debug($"[Monster] {gameObject.name} picture taken, collider still enabled for debugging");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user