Files
AppleHillsProduction/Assets/Scripts/Core/SettingsAccess.cs

125 lines
4.7 KiB
C#
Raw Normal View History

using Core;
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;
private static GetSettingsValueDelegate getPuzzlePromptRangeProvider;
2025-12-02 23:56:13 +01:00
private static GetSettingsValueDelegate getWeakPointExplosionRadiusProvider;
// Editor-only method to set up providers - will be called from editor code
public static void SetupEditorProviders(
GetSettingsValueDelegate playerStopDistanceProvider,
GetSettingsValueDelegate playerStopDistanceDirectInteractionProvider,
2025-12-02 23:56:13 +01:00
GetSettingsValueDelegate puzzlePromptRangeProvider,
GetSettingsValueDelegate weakPointExplosionRadiusProvider)
{
#if UNITY_EDITOR
if (!Application.isPlaying)
{
getPlayerStopDistanceProvider = playerStopDistanceProvider;
getPlayerStopDistanceDirectInteractionProvider = playerStopDistanceDirectInteractionProvider;
getPuzzlePromptRangeProvider = puzzlePromptRangeProvider;
2025-12-02 23:56:13 +01:00
getWeakPointExplosionRadiusProvider = weakPointExplosionRadiusProvider;
}
#endif
}
public static float GetPlayerStopDistance()
{
#if UNITY_EDITOR
if (getPlayerStopDistanceProvider == null)
{
return 0.0f;
}
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;
}
public static float GetPuzzlePromptRange()
{
#if UNITY_EDITOR
if (!Application.isPlaying && getPuzzlePromptRangeProvider != null)
{
return getPuzzlePromptRangeProvider();
}
#endif
return GameManager.Instance.DefaultPuzzlePromptRange;
}
2025-12-02 23:56:13 +01:00
// Fort Fight Settings
public static float GetWeakPointExplosionRadius()
{
#if UNITY_EDITOR
if (!Application.isPlaying && getWeakPointExplosionRadiusProvider != null)
{
return getWeakPointExplosionRadiusProvider();
}
#endif
return GameManager.Instance.WeakPointExplosionRadius;
}
// Add more methods as needed for other settings
2025-12-04 08:52:59 +01:00
/// <summary>
/// Get developer settings for editor-mode usage (OnDrawGizmos, etc.)
/// This handles both editor and play mode seamlessly.
/// </summary>
public static T GetDeveloperSettingsForEditor<T>() where T : AppleHills.Core.Settings.BaseDeveloperSettings
{
#if UNITY_EDITOR
if (!Application.isPlaying)
{
// In editor mode (not playing), use reflection to access EditorSettingsProvider
// This avoids direct reference to Editor assembly from runtime code
var editorProviderType = System.Type.GetType("AppleHills.Editor.EditorSettingsProvider, Assembly-CSharp-Editor");
if (editorProviderType != null)
{
var method = editorProviderType.GetMethod("GetDeveloperSettings",
System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
if (method != null)
{
var genericMethod = method.MakeGenericMethod(typeof(T));
return genericMethod.Invoke(null, null) as T;
}
}
return null;
}
#endif
// In play mode, use GameManager
return GameManager.GetDeveloperSettings<T>();
}
}
}