Working Developer Settings

This commit is contained in:
2025-09-24 13:31:15 +02:00
parent 8b96a5d0c3
commit 783541a776
24 changed files with 965 additions and 754 deletions

View File

@@ -17,11 +17,6 @@ namespace Minigames.DivingForPictures
[Tooltip("List of possible trench tile prefabs.")]
[SerializeField] private List<GameObject> tilePrefabs;
[Header("Object Pooling")]
[SerializeField] private bool useObjectPooling = true;
[SerializeField] private int maxPerPrefabPoolSize = 2;
[SerializeField] private int totalMaxPoolSize = 10;
[Header("Events")]
[FormerlySerializedAs("OnTileSpawned")]
public UnityEvent<GameObject> onTileSpawned;
@@ -29,8 +24,9 @@ namespace Minigames.DivingForPictures
[FormerlySerializedAs("OnTileDestroyed")]
public UnityEvent<GameObject> onTileDestroyed;
// Settings reference
// Settings references
private IDivingMinigameSettings _settings;
private DivingDeveloperSettings _devSettings;
// Private fields
private readonly Dictionary<GameObject, float> _tileHeights = new Dictionary<GameObject, float>();
@@ -67,11 +63,18 @@ namespace Minigames.DivingForPictures
// Get settings from GameManager
_settings = GameManager.GetSettingsObject<IDivingMinigameSettings>();
_devSettings = GameManager.GetDeveloperSettings<DivingDeveloperSettings>();
if (_settings == null)
{
Debug.LogError("[TrenchTileSpawner] Failed to load diving minigame settings!");
}
if (_devSettings == null)
{
Debug.LogError("[TrenchTileSpawner] Failed to load diving developer settings!");
}
_baseMoveSpeed = _settings?.EndlessDescenderMoveSpeed ?? 3f; // Store the original base speed
// Calculate tile heights for each prefab
@@ -80,7 +83,7 @@ namespace Minigames.DivingForPictures
// Ensure all prefabs have Tile components
ValidateTilePrefabs();
if (useObjectPooling)
if (_devSettings != null && _devSettings.TrenchTileUseObjectPooling)
{
InitializeObjectPool();
}
@@ -196,9 +199,9 @@ namespace Minigames.DivingForPictures
poolGO.transform.SetParent(transform);
_tilePool = poolGO.AddComponent<TrenchTilePool>();
// Set up the pool configuration
_tilePool.maxPerPrefabPoolSize = maxPerPrefabPoolSize;
_tilePool.totalMaxPoolSize = totalMaxPoolSize;
// Set up the pool configuration using developer settings
_tilePool.maxPerPrefabPoolSize = _devSettings.TrenchTileMaxPerPrefabPoolSize;
_tilePool.totalMaxPoolSize = _devSettings.TrenchTileTotalMaxPoolSize;
// Convert the GameObject list to a Tile list
List<Tile> prefabTiles = new List<Tile>(tilePrefabs.Count);
@@ -374,7 +377,7 @@ namespace Minigames.DivingForPictures
_activeTiles.RemoveAt(0);
onTileDestroyed?.Invoke(topTile);
if (useObjectPooling && _tilePool != null)
if (_devSettings != null && _devSettings.TrenchTileUseObjectPooling && _tilePool != null)
{
// Find the prefab index for this tile
int prefabIndex = GetPrefabIndex(topTile);
@@ -505,7 +508,7 @@ namespace Minigames.DivingForPictures
GameObject tile;
if (useObjectPooling && _tilePool != null)
if (_devSettings != null && _devSettings.TrenchTileUseObjectPooling && _tilePool != null)
{
tile = _tilePool.GetTile(prefabIndex);
if (tile == null)
@@ -537,7 +540,7 @@ namespace Minigames.DivingForPictures
{
int prefabCount = tilePrefabs.Count;
List<float> weights = new List<float>(prefabCount);
for (int i = 0; i < prefabCount; i++)
{
int lastUsed = _tileLastUsed.TryGetValue(i, out var value) ? value : -prefabCount;
@@ -545,13 +548,13 @@ namespace Minigames.DivingForPictures
float weight = Mathf.Clamp(age, 1, prefabCount * 2); // More unused = higher weight
weights.Add(weight);
}
float totalWeight = 0f;
foreach (var weight in weights)
{
totalWeight += weight;
}
float randomValue = Random.value * totalWeight;
for (int i = 0; i < prefabCount; i++)
{
@@ -561,10 +564,10 @@ namespace Minigames.DivingForPictures
}
randomValue -= weights[i];
}
return Random.Range(0, prefabCount); // fallback
}
/// <summary>
/// Gets the height of a tile based on its prefab or renderer bounds
/// </summary>
@@ -592,18 +595,18 @@ namespace Minigames.DivingForPictures
}
}
}
// If not found, calculate it from the renderer
Renderer renderer = tile.GetComponentInChildren<Renderer>();
if (renderer != null)
{
return renderer.bounds.size.y;
}
// Fallback
return DefaultTileHeight;
}
/// <summary>
/// Gets the index of the prefab that was used to create this tile
/// </summary>
@@ -619,7 +622,7 @@ namespace Minigames.DivingForPictures
for (int i = 0; i < tilePrefabs.Count; i++)
{
if (tilePrefabs[i] == null) continue;
if (tile.name.StartsWith(tilePrefabs[i].name))
{
return i;