IMplement basic Developer Settings
This commit is contained in:
@@ -4,6 +4,7 @@ using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.Serialization;
|
||||
using Pooling;
|
||||
using AppleHills.Core.Settings;
|
||||
|
||||
namespace Minigames.DivingForPictures
|
||||
{
|
||||
@@ -16,16 +17,6 @@ namespace Minigames.DivingForPictures
|
||||
[Tooltip("List of possible trench tile prefabs.")]
|
||||
[SerializeField] private List<GameObject> tilePrefabs;
|
||||
|
||||
[Header("Tile Settings")]
|
||||
[SerializeField] private int initialTileCount = 3;
|
||||
[SerializeField] private float tileSpawnBuffer = 1f;
|
||||
|
||||
[Header("Movement Settings")]
|
||||
[SerializeField] private float moveSpeed = 3f;
|
||||
[SerializeField] private float speedUpFactor = 0.2f;
|
||||
[SerializeField] private float speedUpInterval = 10f;
|
||||
[SerializeField] private float maxMoveSpeed = 12f;
|
||||
|
||||
[Header("Object Pooling")]
|
||||
[SerializeField] private bool useObjectPooling = true;
|
||||
[SerializeField] private int maxPerPrefabPoolSize = 2;
|
||||
@@ -38,6 +29,9 @@ namespace Minigames.DivingForPictures
|
||||
[FormerlySerializedAs("OnTileDestroyed")]
|
||||
public UnityEvent<GameObject> onTileDestroyed;
|
||||
|
||||
// Settings reference
|
||||
private IDivingMinigameSettings _settings;
|
||||
|
||||
// Private fields
|
||||
private readonly Dictionary<GameObject, float> _tileHeights = new Dictionary<GameObject, float>();
|
||||
private readonly List<GameObject> _activeTiles = new List<GameObject>();
|
||||
@@ -52,9 +46,6 @@ namespace Minigames.DivingForPictures
|
||||
|
||||
// Current velocity for tile movement
|
||||
private float _currentVelocity;
|
||||
|
||||
// Interval for velocity calculations (seconds)
|
||||
[SerializeField] private float velocityCalculationInterval = 0.5f;
|
||||
|
||||
private const float TileSpawnZ = -1f;
|
||||
private const float DefaultTileHeight = 5f;
|
||||
@@ -73,7 +64,15 @@ namespace Minigames.DivingForPictures
|
||||
private void Awake()
|
||||
{
|
||||
_mainCamera = Camera.main;
|
||||
_baseMoveSpeed = moveSpeed; // Store the original base speed
|
||||
|
||||
// Get settings from GameManager
|
||||
_settings = GameManager.GetSettingsObject<IDivingMinigameSettings>();
|
||||
if (_settings == null)
|
||||
{
|
||||
Debug.LogError("[TrenchTileSpawner] Failed to load diving minigame settings!");
|
||||
}
|
||||
|
||||
_baseMoveSpeed = _settings?.EndlessDescenderMoveSpeed ?? 3f; // Store the original base speed
|
||||
|
||||
// Calculate tile heights for each prefab
|
||||
CalculateTileHeights();
|
||||
@@ -110,7 +109,7 @@ namespace Minigames.DivingForPictures
|
||||
SpawnInitialTiles();
|
||||
|
||||
// Initialize velocity and start the velocity calculation coroutine
|
||||
_currentVelocity = moveSpeed * Time.fixedDeltaTime;
|
||||
_currentVelocity = _baseMoveSpeed * Time.fixedDeltaTime;
|
||||
StartCoroutine(VelocityCalculationRoutine());
|
||||
}
|
||||
|
||||
@@ -148,7 +147,7 @@ namespace Minigames.DivingForPictures
|
||||
while (true)
|
||||
{
|
||||
CalculateVelocity();
|
||||
yield return new WaitForSeconds(velocityCalculationInterval);
|
||||
yield return new WaitForSeconds(_settings.EndlessDescenderVelocityCalculationInterval);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +156,7 @@ namespace Minigames.DivingForPictures
|
||||
/// </summary>
|
||||
private void CalculateVelocity()
|
||||
{
|
||||
_currentVelocity = moveSpeed * Time.fixedDeltaTime;
|
||||
_currentVelocity = _baseMoveSpeed * Time.fixedDeltaTime;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -247,7 +246,7 @@ namespace Minigames.DivingForPictures
|
||||
// Move starting position up by 2 tile heights
|
||||
startingY += tileHeightEstimate * 2;
|
||||
|
||||
for (int i = 0; i < initialTileCount; i++)
|
||||
for (int i = 0; i < _settings.EndlessDescenderInitialTileCount; i++)
|
||||
{
|
||||
float y = startingY;
|
||||
// Calculate proper Y position based on previous tiles
|
||||
@@ -291,12 +290,12 @@ namespace Minigames.DivingForPictures
|
||||
|
||||
// Update the actual move speed based on the velocity factor
|
||||
// This keeps the original move speed intact for game logic
|
||||
moveSpeed = _baseMoveSpeed * Mathf.Abs(_velocityFactor);
|
||||
_baseMoveSpeed = _settings.EndlessDescenderMoveSpeed * Mathf.Abs(_velocityFactor);
|
||||
|
||||
// Recalculate velocity immediately
|
||||
CalculateVelocity();
|
||||
|
||||
Debug.Log($"[TrenchTileSpawner] Velocity factor updated to {_velocityFactor:F2}, moveSpeed: {moveSpeed:F2}");
|
||||
Debug.Log($"[TrenchTileSpawner] Velocity factor updated to {_velocityFactor:F2}, moveSpeed: {_baseMoveSpeed:F2}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -362,12 +361,12 @@ namespace Minigames.DivingForPictures
|
||||
if (_isSurfacing)
|
||||
{
|
||||
// When surfacing, destroy tiles at the bottom
|
||||
shouldDestroy = topTile.transform.position.y + tileHeight / 2 < _screenBottom - tileSpawnBuffer;
|
||||
shouldDestroy = topTile.transform.position.y + tileHeight / 2 < _screenBottom - _settings.EndlessDescenderTileSpawnBuffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
// When descending, destroy tiles at the top
|
||||
shouldDestroy = topTile.transform.position.y - tileHeight / 2 > _screenTop + tileSpawnBuffer;
|
||||
shouldDestroy = topTile.transform.position.y - tileHeight / 2 > _screenTop + _settings.EndlessDescenderTileSpawnBuffer;
|
||||
}
|
||||
|
||||
if (shouldDestroy)
|
||||
@@ -431,12 +430,12 @@ namespace Minigames.DivingForPictures
|
||||
if (_isSurfacing)
|
||||
{
|
||||
// When surfacing, check if the bottom of the tile is above the top of the screen
|
||||
isLastTileLeaving = bottomTile.transform.position.y - tileHeight / 2 > _screenTop + tileSpawnBuffer;
|
||||
isLastTileLeaving = bottomTile.transform.position.y - tileHeight / 2 > _screenTop + _settings.EndlessDescenderTileSpawnBuffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
// When descending, check if the top of the tile is below the bottom of the screen
|
||||
isLastTileLeaving = bottomTile.transform.position.y + tileHeight / 2 < _screenBottom - tileSpawnBuffer;
|
||||
isLastTileLeaving = bottomTile.transform.position.y + tileHeight / 2 < _screenBottom - _settings.EndlessDescenderTileSpawnBuffer;
|
||||
}
|
||||
|
||||
if (isLastTileLeaving)
|
||||
@@ -454,14 +453,14 @@ namespace Minigames.DivingForPictures
|
||||
{
|
||||
// When surfacing, spawn new tiles at the top
|
||||
float topEdge = bottomTile.transform.position.y + tileHeight / 2;
|
||||
shouldSpawn = topEdge < _screenTop + tileSpawnBuffer;
|
||||
shouldSpawn = topEdge < _screenTop + _settings.EndlessDescenderTileSpawnBuffer;
|
||||
newY = bottomTile.transform.position.y + tileHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
// When descending, spawn new tiles at the bottom
|
||||
float bottomEdge = bottomTile.transform.position.y - tileHeight / 2;
|
||||
shouldSpawn = bottomEdge > _screenBottom - tileSpawnBuffer;
|
||||
shouldSpawn = bottomEdge > _screenBottom - _settings.EndlessDescenderTileSpawnBuffer;
|
||||
newY = bottomTile.transform.position.y - tileHeight;
|
||||
}
|
||||
|
||||
@@ -477,9 +476,9 @@ namespace Minigames.DivingForPictures
|
||||
private void HandleSpeedRamping()
|
||||
{
|
||||
_speedUpTimer += Time.deltaTime;
|
||||
if (_speedUpTimer >= speedUpInterval)
|
||||
if (_speedUpTimer >= _settings.EndlessDescenderSpeedUpInterval)
|
||||
{
|
||||
moveSpeed = Mathf.Min(moveSpeed + speedUpFactor, maxMoveSpeed);
|
||||
_baseMoveSpeed = Mathf.Min(_baseMoveSpeed + _settings.EndlessDescenderSpeedUpFactor, _settings.EndlessDescenderMaxMoveSpeed);
|
||||
_speedUpTimer = 0f;
|
||||
}
|
||||
}
|
||||
@@ -656,16 +655,19 @@ namespace Minigames.DivingForPictures
|
||||
|
||||
// Draw tile bounds for debugging
|
||||
Gizmos.color = Color.cyan;
|
||||
for (int i = 0; i < initialTileCount; i++)
|
||||
if (_settings != null)
|
||||
{
|
||||
float height = DefaultTileHeight;
|
||||
if (tilePrefabs != null && tilePrefabs.Count > 0 && tilePrefabs[0] != null &&
|
||||
_tileHeights.TryGetValue(tilePrefabs[0], out float h))
|
||||
for (int i = 0; i < _settings.EndlessDescenderInitialTileCount; i++)
|
||||
{
|
||||
height = h;
|
||||
float height = DefaultTileHeight;
|
||||
if (tilePrefabs != null && tilePrefabs.Count > 0 && tilePrefabs[0] != null &&
|
||||
_tileHeights.TryGetValue(tilePrefabs[0], out float h))
|
||||
{
|
||||
height = h;
|
||||
}
|
||||
Vector3 center = new Vector3(0f, _screenBottom + i * height, 0f);
|
||||
Gizmos.DrawWireCube(center, new Vector3(10f, height, 1f));
|
||||
}
|
||||
Vector3 center = new Vector3(0f, _screenBottom + i * height, 0f);
|
||||
Gizmos.DrawWireCube(center, new Vector3(10f, height, 1f));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user