Fix up eagle eye's weirdness, add option to auto clear saves

This commit is contained in:
Michal Pikulski
2025-11-24 10:37:40 +01:00
parent 3f847508be
commit ff28bd23cb
10 changed files with 235 additions and 84 deletions

View File

@@ -63,18 +63,6 @@ MonoBehaviour:
m_SerializedLabels:
- BlokkemonCard
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: 4f4ec75013bc276429c2f4fa52d165e0
m_Address: Assets/Data/Cards/Card_KalkUlation 3.asset
m_ReadOnly: 0
m_SerializedLabels:
- BlokkemonCard
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: 53996921ed2094948aa317efe4ca6630
m_Address: Assets/Data/Cards/Card_MormorMarmor 3.asset
m_ReadOnly: 0
m_SerializedLabels:
- BlokkemonCard
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: 73d54071304571647b3238a799d9781f
m_Address: Assets/Data/Cards/Card_New Card.asset
m_ReadOnly: 0

View File

@@ -0,0 +1,95 @@
using System.IO;
using UnityEditor;
using UnityEngine;
using AppleHills.Core.Settings;
namespace Editor.Tools
{
/// <summary>
/// Editor script that automatically clears saves before entering play mode
/// if the autoClearSaves setting is enabled in DebugSettings
/// </summary>
[InitializeOnLoad]
public static class AutoClearSavesOnPlay
{
static AutoClearSavesOnPlay()
{
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
}
private static void OnPlayModeStateChanged(PlayModeStateChange state)
{
// Only act when entering play mode (before the scene starts playing)
if (state != PlayModeStateChange.ExitingEditMode)
return;
// Try to load the debug settings
DebugSettings debugSettings = LoadDebugSettings();
if (debugSettings == null)
{
Debug.LogWarning("[AutoClearSaves] Could not find DebugSettings asset. Auto-clear saves disabled.");
return;
}
// Check if auto-clear is enabled
if (!debugSettings.AutoClearSaves)
{
return;
}
// Execute the clear saves logic
ClearSavesFolder();
}
private static DebugSettings LoadDebugSettings()
{
// Try to find the DebugSettings asset in the project
string[] guids = AssetDatabase.FindAssets("t:DebugSettings");
if (guids.Length == 0)
{
return null;
}
// Load the first found DebugSettings asset
string path = AssetDatabase.GUIDToAssetPath(guids[0]);
return AssetDatabase.LoadAssetAtPath<DebugSettings>(path);
}
private static void ClearSavesFolder()
{
// Construct the save folder path (matches SaveLoadManager.DefaultSaveFolder)
string saveFolder = Path.Combine(Application.persistentDataPath, "GameSaves");
if (!Directory.Exists(saveFolder))
{
Debug.Log("[AutoClearSaves] Save folder does not exist, nothing to clear.");
return;
}
try
{
// Delete all files in the save folder
string[] files = Directory.GetFiles(saveFolder);
int deletedCount = 0;
foreach (string file in files)
{
File.Delete(file);
deletedCount++;
}
if (deletedCount > 0)
{
Debug.Log($"[AutoClearSaves] Automatically deleted {deletedCount} save file(s) before entering play mode");
}
}
catch (System.Exception ex)
{
Debug.LogError($"[AutoClearSaves] Failed to auto-clear saves: {ex}");
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c3ba01f7bb704c17bc4f22fd726f7fee
timeCreated: 1763974355

View File

@@ -802,7 +802,7 @@ MonoBehaviour:
m_SelectedTrigger: Selected
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 0}
m_TargetGraphic: {fileID: 4189849640380816173}
m_OnClick:
m_PersistentCalls:
m_Calls:
@@ -1459,6 +1459,10 @@ PrefabInstance:
serializedVersion: 3
m_TransformParent: {fileID: 2474710976069581060}
m_Modifications:
- target: {fileID: 823686888810001266, guid: 428a0feafda9d6d4e87ecf43ad41dc20, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_CallState
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5445689290567702089, guid: 428a0feafda9d6d4e87ecf43ad41dc20, type: 3}
propertyPath: m_Pivot.x
value: 1

View File

@@ -450296,7 +450296,7 @@ GameObject:
- component: {fileID: 1137411215}
m_Layer: 0
m_Name: CinemachineCamera
m_TagString: Untagged
m_TagString: MainCinemachineCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0

View File

@@ -31,6 +31,8 @@ namespace AppleHills.Core.Settings
[Header("Save Load Options")]
[Tooltip("Should use save laod system?")]
[SerializeField] public bool useSaveLoadSystem = true;
[Tooltip("Automatically clear all saves before entering play mode in editor")]
[SerializeField] public bool autoClearSaves = false;
[Header("Logging Options")]
[Tooltip("Logging level for bootstrap services")]
@@ -49,6 +51,7 @@ namespace AppleHills.Core.Settings
// Property getters
public bool ShowDebugUiMessages => showDebugUiMessages;
public bool PauseTimeOnPauseGame => pauseTimeOnPauseGame;
public bool AutoClearSaves => autoClearSaves;
public override void OnValidate()
{

View File

@@ -1,84 +1,131 @@
using System.Collections;
using Unity.Cinemachine;
using UnityEngine;
using System.Collections;
public class EagleEyeBehaviour : MonoBehaviour
namespace DamianExperiments
{
[SerializeField] private CinemachineCamera virtualCamera;
[SerializeField] private CinemachineConfiner2D confiner2D;
[SerializeField] private float zoomOutOrthoSize = 30f;
[SerializeField] private float normalOrthoSize = 15f;
private float currentOrthoSize;
[SerializeField] private float transitionDuration = 0.5f; // Duration of the transition
[SerializeField] private float eagleEyeDuration = 3f; // Duration to stay zoomed out
[SerializeField] private bool disablePlayerInputDuringEagleEye = true; // Gate input disable
[SerializeField] private UnityEngine.UI.Button eagleEyeButton; // Reference to the UI button
private Coroutine zoomCoroutine;
public void ActivateEagleEye()
public class EagleEyeBehaviour : MonoBehaviour
{
//Assigns the Virtual Camera and Confiner if not already assigned
if (virtualCamera == null)
{
virtualCamera = FindAnyObjectByType<CinemachineCamera>();
}
if (confiner2D == null)
{
confiner2D = virtualCamera.GetComponent<CinemachineConfiner2D>();
}
// Serialized backing fields allow manual assignment in the inspector
private GameObject _cinecameraObject;
private CinemachineCamera _virtualCamera;
private CinemachineConfiner2D _confiner2D;
// Implementation for activating eagle eye behaviour
if (disablePlayerInputDuringEagleEye)
// Lazy-fetched properties: if null, try to find the GameObject tagged "MainCinemachineCamera"
private CinemachineCamera VirtualCamera
{
currentOrthoSize = virtualCamera.Lens.OrthographicSize;
}
if (eagleEyeButton != null)
{
eagleEyeButton.interactable = false;
}
if (zoomCoroutine != null) StopCoroutine(zoomCoroutine);
zoomCoroutine = StartCoroutine(EagleEyeSequence());
}
private IEnumerator EagleEyeSequence()
{
if (disablePlayerInputDuringEagleEye)
{
Core.GameManager.Instance.RequestPause(this); // Disable player input
}
yield return StartCoroutine(SmoothOrthoSize(virtualCamera, zoomOutOrthoSize, transitionDuration));
yield return new WaitForSeconds(eagleEyeDuration);
float zoomInTarget = disablePlayerInputDuringEagleEye ? currentOrthoSize : normalOrthoSize;
yield return StartCoroutine(SmoothOrthoSize(virtualCamera, zoomInTarget, transitionDuration));
if (disablePlayerInputDuringEagleEye)
{
Core.GameManager.Instance.ReleasePause(this); // Re-enable player input
}
if (eagleEyeButton != null)
{
eagleEyeButton.interactable = true;
}
}
private IEnumerator SmoothOrthoSize(CinemachineCamera cam, float targetSize, float duration)
{
float startSize = cam.Lens.OrthographicSize;
float elapsed = 0f;
while (elapsed < duration)
{
elapsed += Time.deltaTime;
cam.Lens.OrthographicSize = Mathf.Lerp(startSize, targetSize, elapsed / duration);
if (confiner2D != null)
get
{
confiner2D.InvalidateBoundingShapeCache();
if (_virtualCamera == null)
{
if (_cinecameraObject == null)
_cinecameraObject = GameObject.FindWithTag("MainCinemachineCamera");
if (_cinecameraObject != null)
{
_virtualCamera = _cinecameraObject.GetComponent<CinemachineCamera>();
if (_virtualCamera == null)
Debug.LogWarning("EagleEyeBehaviour: Found object with tag 'MainCinemachineCamera' " +
"but couldn't find a CinemachineCamera component.");
}
else
{
Debug.LogWarning("EagleEyeBehaviour: No GameObject found with tag 'MainCinemachineCamera'.");
}
}
return _virtualCamera;
}
yield return null;
set => _virtualCamera = value;
}
cam.Lens.OrthographicSize = targetSize;
if (confiner2D != null)
private CinemachineConfiner2D Confiner2D
{
confiner2D.InvalidateBoundingShapeCache();
get
{
if (_confiner2D == null)
{
// If a virtual camera exists, try to pull the confiner from it
if (VirtualCamera != null)
{
_confiner2D = VirtualCamera.GetComponent<CinemachineConfiner2D>();
}
if (_confiner2D == null)
{
Debug.LogWarning("EagleEyeBehaviour: CinemachineConfiner2D not found on the MainCinemachineCamera object.");
}
}
return _confiner2D;
}
set => _confiner2D = value;
}
[SerializeField] private float zoomOutOrthoSize = 30f;
[SerializeField] private float normalOrthoSize = 15f;
[SerializeField] private float transitionDuration = 0.5f; // Duration of the transition
[SerializeField] private float eagleEyeDuration = 3f; // Duration to stay zoomed out
[SerializeField] private UnityEngine.UI.Button eagleEyeButton; // Reference to the UI button
private Coroutine _zoomCoroutine;
private Coroutine _smoothOrthoCoroutine;
private float _currentOrthoSize;
public void ResetEagleEye()
{
if (_zoomCoroutine != null)
StopCoroutine(_zoomCoroutine);
if (_smoothOrthoCoroutine != null)
StopCoroutine(_smoothOrthoCoroutine);
if (eagleEyeButton != null)
eagleEyeButton.interactable = true;
}
public void ActivateEagleEye()
{
if (eagleEyeButton != null)
{
eagleEyeButton.interactable = false;
}
if (_zoomCoroutine != null) StopCoroutine(_zoomCoroutine);
_zoomCoroutine = StartCoroutine(EagleEyeSequence());
}
private IEnumerator EagleEyeSequence()
{
_smoothOrthoCoroutine = StartCoroutine(SmoothOrthoSize(VirtualCamera, zoomOutOrthoSize, transitionDuration));
yield return _smoothOrthoCoroutine;
yield return new WaitForSeconds(eagleEyeDuration);
float zoomInTarget = normalOrthoSize;
_smoothOrthoCoroutine = StartCoroutine(SmoothOrthoSize(VirtualCamera, zoomInTarget, transitionDuration));;
yield return _smoothOrthoCoroutine;
if (eagleEyeButton != null)
{
eagleEyeButton.interactable = true;
}
}
private IEnumerator SmoothOrthoSize(CinemachineCamera cam, float targetSize, float duration)
{
float startSize = cam.Lens.OrthographicSize;
float elapsed = 0f;
while (elapsed < duration)
{
elapsed += Time.deltaTime;
cam.Lens.OrthographicSize = Mathf.Lerp(startSize, targetSize, elapsed / duration);
if (Confiner2D != null)
{
Confiner2D.InvalidateBoundingShapeCache();
}
yield return null;
}
cam.Lens.OrthographicSize = targetSize;
if (Confiner2D != null)
{
Confiner2D.InvalidateBoundingShapeCache();
}
}
}
}

View File

@@ -8,6 +8,7 @@ using UnityEngine.UI;
using System.Linq;
using System.Collections.Generic;
using System;
using DamianExperiments;
namespace UI
{
@@ -308,6 +309,9 @@ namespace UI
/// </summary>
private void ApplyUIModeOverrides(bool visible)
{
// First, reset state to neutral
ResetStateBeforeLevelLoad();
switch (currentUIMode)
{
case UIMode.Overworld:
@@ -336,6 +340,11 @@ namespace UI
}
}
protected void ResetStateBeforeLevelLoad()
{
eagleEye.GetComponent<EagleEyeBehaviour>()?.ResetEagleEye();
}
/// <summary>
/// Automatically manages HUD visibility based on page stack state
/// </summary>

View File

@@ -15,6 +15,7 @@ MonoBehaviour:
showDebugUiMessages: 1
pauseTimeOnPauseGame: 0
useSaveLoadSystem: 1
autoClearSaves: 0
bootstrapLogVerbosity: 0
settingsLogVerbosity: 0
gameManagerLogVerbosity: 0

View File

@@ -10,6 +10,7 @@ TagManager:
- Obstacle
- Projectile
- Target
- MainCinemachineCamera
layers:
- Default
- TransparentFX