Refactor the settings to remove the old class

This commit is contained in:
Michal Pikulski
2025-09-24 08:05:37 +02:00
committed by AlexanderT
parent 404f6f4e5c
commit f07ce88331
19 changed files with 239 additions and 443 deletions

View File

@@ -31,28 +31,14 @@ public class GameManager : MonoBehaviour
}
}
[Header("Legacy Game Settings (Deprecated)")]
[Tooltip("This is only used for migration to the new settings system")]
public GameSettings legacyGameSettings;
[Header("Settings Status")]
[SerializeField] private bool _settingsLoaded = false;
public bool SettingsLoaded => _settingsLoaded;
// Use this for fallback values when settings aren't loaded yet
[Header("Fallback Settings")]
[SerializeField] private GameSettings fallbackSettings;
void Awake()
{
_instance = this;
// If no fallback settings assigned, try to load them
if (fallbackSettings == null)
{
fallbackSettings = Resources.Load<GameSettings>("DefaultSettings");
}
// Create settings provider if it doesn't exist
SettingsProvider.Instance.gameObject.name = "Settings Provider";
@@ -112,12 +98,6 @@ public class GameManager : MonoBehaviour
{
Debug.LogWarning("Some settings failed to load - check that all settings assets exist and are marked as Addressables");
}
// Migrate settings if needed
if (legacyGameSettings != null && !playerSettings && !interactionSettings && !minigameSettings)
{
Debug.LogWarning("Legacy settings detected but failed to load new settings. Consider running the migration tool.");
}
}
void OnApplicationQuit()
@@ -138,8 +118,8 @@ public class GameManager : MonoBehaviour
public float MoveSpeed => GetSettings<IPlayerFollowerSettings>()?.MoveSpeed ?? 5f;
public float StopDistance => GetSettings<IPlayerFollowerSettings>()?.StopDistance ?? 0.1f;
public bool UseRigidbody => GetSettings<IPlayerFollowerSettings>()?.UseRigidbody ?? true;
public GameSettings.HoldMovementMode DefaultHoldMovementMode =>
GetSettings<IPlayerFollowerSettings>()?.DefaultHoldMovementMode ?? GameSettings.HoldMovementMode.Pathfinding;
public HoldMovementMode DefaultHoldMovementMode =>
GetSettings<IPlayerFollowerSettings>()?.DefaultHoldMovementMode ?? HoldMovementMode.Pathfinding;
// Follower settings
public float FollowDistance => GetSettings<IPlayerFollowerSettings>()?.FollowDistance ?? 1.5f;
@@ -163,7 +143,7 @@ public class GameManager : MonoBehaviour
/// <summary>
/// Returns the combination rule for two items, if any.
/// </summary>
public GameSettings.CombinationRule GetCombinationRule(PickupItemData item1, PickupItemData item2)
public CombinationRule GetCombinationRule(PickupItemData item1, PickupItemData item2)
{
var settings = GetSettings<IInteractionSettings>();
if (settings == null || settings.CombinationRules == null) return null;
@@ -182,7 +162,7 @@ public class GameManager : MonoBehaviour
/// <summary>
/// Returns the slot item config for a given slot item.
/// </summary>
public GameSettings.SlotItemConfig GetSlotItemConfig(PickupItemData slotItem)
public SlotItemConfig GetSlotItemConfig(PickupItemData slotItem)
{
var settings = GetSettings<IInteractionSettings>();
if (settings == null || settings.SlotItemConfigs == null || slotItem == null) return null;

View File

@@ -1,73 +0,0 @@
using UnityEngine;
/// <summary>
/// ScriptableObject for storing and configuring all game settings, including player, follower, and item configuration.
/// </summary>
[CreateAssetMenu(fileName = "GameSettings", menuName = "AppleHills/GameSettings", order = 1)]
public class GameSettings : ScriptableObject
{
[Header("Interactions")]
public float playerStopDistance = 6.0f;
public float playerStopDistanceDirectInteraction = 2.0f;
public float followerPickupDelay = 0.2f;
[Header("Follower Settings")]
public float followDistance = 1.5f;
public float manualMoveSmooth = 8f;
public float thresholdFar = 2.5f;
public float thresholdNear = 0.5f;
public float stopThreshold = 0.1f;
[Header("Player Settings")]
public float moveSpeed = 5f;
public float stopDistance = 0.1f;
public bool useRigidbody = true;
public enum HoldMovementMode { Pathfinding, Direct }
public HoldMovementMode defaultHoldMovementMode = HoldMovementMode.Pathfinding;
[Header("Backend Settings")]
[Tooltip("Technical parameters, not for design tuning")]
public float followUpdateInterval = 0.1f;
public float followerSpeedMultiplier = 1.2f;
public float heldIconDisplayHeight = 2.0f;
[Header("Default Prefabs")]
public GameObject basePickupPrefab;
[Header("Endless Descender Settings")]
[Tooltip("How quickly the character follows the finger horizontally (higher = more responsive)")]
public float endlessDescenderLerpSpeed = 12f;
[Tooltip("Maximum horizontal offset allowed between character and finger position")]
public float endlessDescenderMaxOffset = 3f;
[Tooltip("Minimum allowed X position for endless descender movement")]
public float endlessDescenderClampXMin = -3.5f;
[Tooltip("Maximum allowed X position for endless descender movement")]
public float endlessDescenderClampXMax = 3.5f;
[Tooltip("Exponent for speed drop-off curve (higher = sharper drop near target)")]
public float endlessDescenderSpeedExponent = 2.5f;
[Header("InputManager Settings")]
[Tooltip("Layer(s) to use for interactable objects.")]
public LayerMask interactableLayerMask = -1; // Default to Everything
[Header("UI Prefabs")]
public GameObject levelSwitchMenuPrefab;
[System.Serializable]
public class CombinationRule {
public PickupItemData itemA;
public PickupItemData itemB;
public GameObject resultPrefab; // The prefab to spawn as the result
}
[System.Serializable]
public class SlotItemConfig {
public PickupItemData slotItem; // The slot object (SO reference)
public System.Collections.Generic.List<PickupItemData> allowedItems;
public System.Collections.Generic.List<PickupItemData> forbiddenItems;
}
[Header("Item Configuration")]
public System.Collections.Generic.List<CombinationRule> combinationRules;
public System.Collections.Generic.List<SlotItemConfig> slotItemConfigs;
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: e4ec438b455a4044957501c2c66a6f4b
timeCreated: 1756933137

View File

@@ -23,8 +23,8 @@ namespace AppleHills.Core.Settings
[SerializeField] private GameObject levelSwitchMenuPrefab;
[Header("Item Configuration")]
[SerializeField] private List<GameSettings.CombinationRule> combinationRules = new List<GameSettings.CombinationRule>();
[SerializeField] private List<GameSettings.SlotItemConfig> slotItemConfigs = new List<GameSettings.SlotItemConfig>();
[SerializeField] private List<CombinationRule> combinationRules = new List<CombinationRule>();
[SerializeField] private List<SlotItemConfig> slotItemConfigs = new List<SlotItemConfig>();
// IInteractionSettings implementation
public float PlayerStopDistance => playerStopDistance;
@@ -33,8 +33,8 @@ namespace AppleHills.Core.Settings
public LayerMask InteractableLayerMask => interactableLayerMask;
public GameObject BasePickupPrefab => basePickupPrefab;
public GameObject LevelSwitchMenuPrefab => levelSwitchMenuPrefab;
public List<GameSettings.CombinationRule> CombinationRules => combinationRules;
public List<GameSettings.SlotItemConfig> SlotItemConfigs => slotItemConfigs;
public List<CombinationRule> CombinationRules => combinationRules;
public List<SlotItemConfig> SlotItemConfigs => slotItemConfigs;
public override void OnValidate()
{

View File

@@ -0,0 +1,27 @@
using System.Collections.Generic;
using UnityEngine;
namespace AppleHills.Core.Settings
{
/// <summary>
/// Defines a rule for combining two items
/// </summary>
[System.Serializable]
public class CombinationRule
{
public PickupItemData itemA;
public PickupItemData itemB;
public GameObject resultPrefab; // The prefab to spawn as the result
}
/// <summary>
/// Configuration for items that can be placed in slots
/// </summary>
[System.Serializable]
public class SlotItemConfig
{
public PickupItemData slotItem; // The slot object (SO reference)
public List<PickupItemData> allowedItems;
public List<PickupItemData> forbiddenItems; // Items that cannot be placed in this slot
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9f9547445fd84c7db30533b7ee9d81dd
timeCreated: 1758699048

View File

@@ -0,0 +1,13 @@
using UnityEngine;
namespace AppleHills.Core.Settings
{
/// <summary>
/// Enum defining different movement modes for player movement
/// </summary>
public enum HoldMovementMode
{
Pathfinding,
Direct
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b6b1454235ab476dae09e99238d6c7ce
timeCreated: 1758699033

View File

@@ -12,7 +12,7 @@ namespace AppleHills.Core.Settings
[SerializeField] private float moveSpeed = 5f;
[SerializeField] private float stopDistance = 0.1f;
[SerializeField] private bool useRigidbody = true;
[SerializeField] private GameSettings.HoldMovementMode defaultHoldMovementMode = GameSettings.HoldMovementMode.Pathfinding;
[SerializeField] private HoldMovementMode defaultHoldMovementMode = HoldMovementMode.Pathfinding;
[Header("Follower Settings")]
[SerializeField] private float followDistance = 1.5f;
@@ -31,7 +31,7 @@ namespace AppleHills.Core.Settings
public float MoveSpeed => moveSpeed;
public float StopDistance => stopDistance;
public bool UseRigidbody => useRigidbody;
public GameSettings.HoldMovementMode DefaultHoldMovementMode => defaultHoldMovementMode;
public HoldMovementMode DefaultHoldMovementMode => defaultHoldMovementMode;
public float FollowDistance => followDistance;
public float ManualMoveSmooth => manualMoveSmooth;
public float ThresholdFar => thresholdFar;

View File

@@ -1,4 +1,5 @@
using UnityEngine;
using System.Collections.Generic;
namespace AppleHills.Core.Settings
{
@@ -11,7 +12,7 @@ namespace AppleHills.Core.Settings
float MoveSpeed { get; }
float StopDistance { get; }
bool UseRigidbody { get; }
GameSettings.HoldMovementMode DefaultHoldMovementMode { get; }
HoldMovementMode DefaultHoldMovementMode { get; }
// Follower settings
float FollowDistance { get; }
@@ -35,8 +36,8 @@ namespace AppleHills.Core.Settings
LayerMask InteractableLayerMask { get; }
GameObject BasePickupPrefab { get; }
GameObject LevelSwitchMenuPrefab { get; }
System.Collections.Generic.List<GameSettings.CombinationRule> CombinationRules { get; }
System.Collections.Generic.List<GameSettings.SlotItemConfig> SlotItemConfigs { get; }
List<CombinationRule> CombinationRules { get; }
List<SlotItemConfig> SlotItemConfigs { get; }
}
/// <summary>

View File

@@ -0,0 +1,57 @@
using UnityEngine;
namespace AppleHills
{
/// <summary>
/// Unified access to settings in both editor and play mode
/// </summary>
public static class SettingsAccess
{
// Delegate type for editor-only settings providers
public delegate float GetSettingsValueDelegate();
// Static delegates that will be set by editor code
private static GetSettingsValueDelegate getPlayerStopDistanceProvider;
private static GetSettingsValueDelegate getPlayerStopDistanceDirectInteractionProvider;
// Editor-only method to set up providers - will be called from editor code
public static void SetupEditorProviders(
GetSettingsValueDelegate playerStopDistanceProvider,
GetSettingsValueDelegate playerStopDistanceDirectInteractionProvider)
{
#if UNITY_EDITOR
if (!Application.isPlaying)
{
getPlayerStopDistanceProvider = playerStopDistanceProvider;
getPlayerStopDistanceDirectInteractionProvider = playerStopDistanceDirectInteractionProvider;
}
#endif
}
public static float GetPlayerStopDistance()
{
#if UNITY_EDITOR
if (!Application.isPlaying && getPlayerStopDistanceProvider != null)
{
return getPlayerStopDistanceProvider();
}
#endif
return GameManager.Instance.PlayerStopDistance;
}
public static float GetPlayerStopDistanceDirectInteraction()
{
#if UNITY_EDITOR
if (!Application.isPlaying && getPlayerStopDistanceDirectInteractionProvider != null)
{
return getPlayerStopDistanceDirectInteractionProvider();
}
#endif
return GameManager.Instance.PlayerStopDistanceDirectInteraction;
}
// Add more methods as needed for other settings
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a23d841c0e2047ff8dbe84820227bdea
timeCreated: 1758634274