Linking the octo localization system to the dialogue system
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using UnityEngine;
|
||||
using OctoCore.Localization;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Unheimlich.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple debug script to switch language at runtime.
|
||||
/// Attach to any GameObject and press keys to change language.
|
||||
/// </summary>
|
||||
public class LanguageSwitcher : MonoBehaviour
|
||||
{
|
||||
[Header("Info")]
|
||||
[Tooltip("Current language")]
|
||||
[SerializeField] private OctoLanguages _currentLanguage;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (OctoCore.OctoCore.Instance != null && OctoCore.OctoCore.Instance.Localization != null)
|
||||
{
|
||||
_currentLanguage = OctoCore.OctoCore.Instance.Localization.WrittenLanguage;
|
||||
UnityEngine.Debug.Log($"[LanguageSwitcher] Current language: {_currentLanguage}");
|
||||
UnityEngine.Debug.Log($"[LanguageSwitcher] Press F1 for English, F2 for French");
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (OctoCore.OctoCore.Instance == null || OctoCore.OctoCore.Instance.Localization == null)
|
||||
return;
|
||||
|
||||
if (Keyboard.current == null)
|
||||
return;
|
||||
|
||||
if (Keyboard.current.f1Key.wasPressedThisFrame)
|
||||
{
|
||||
SetLanguage(OctoLanguages.English);
|
||||
}
|
||||
else if (Keyboard.current.f2Key.wasPressedThisFrame)
|
||||
{
|
||||
SetLanguage(OctoLanguages.French);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetLanguage(OctoLanguages language)
|
||||
{
|
||||
OctoCore.OctoCore.Instance.Localization.SetLanguageWritten(language);
|
||||
_currentLanguage = language;
|
||||
|
||||
UnityEngine.Debug.Log($"<color=green>[LanguageSwitcher]</color> Language changed to: <color=yellow>{language}</color>");
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
// Display current language in top-left corner
|
||||
if (OctoCore.OctoCore.Instance != null && OctoCore.OctoCore.Instance.Localization != null)
|
||||
{
|
||||
GUI.color = Color.yellow;
|
||||
GUI.Label(new Rect(10, 10, 300, 30), $"Language: {_currentLanguage}");
|
||||
GUI.Label(new Rect(10, 30, 300, 30), $"[F1] EN | [F2] FR");
|
||||
GUI.color = Color.white;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user