Snapshot of the existing Unity 6 language-learning word game before any refactoring. Adds Unity .gitignore and .gitattributes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
86 lines
No EOL
2.4 KiB
C#
86 lines
No EOL
2.4 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using UnityEngine.SceneManagement;
|
|
using System.Collections.Generic;
|
|
|
|
public class LanguageSettingsController : MonoBehaviour
|
|
{
|
|
[Header("━━━ DROPDOWNLAR ━━━━━━━━━━━━━━━━━━━━━━━")]
|
|
public TMP_Dropdown questionDropdown;
|
|
public TMP_Dropdown answerDropdown;
|
|
|
|
[Header("━━━ BUTONLAR ━━━━━━━━━━━━━━━━━━━━━━━━━━")]
|
|
public Button saveAndBackButton;
|
|
|
|
[Header("━━━ AUDIO ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")]
|
|
public AudioClip clickSound;
|
|
public AudioSource sfxSource;
|
|
|
|
void Start()
|
|
{
|
|
PopulateDropdowns();
|
|
|
|
questionDropdown.value = PlayerPrefs.GetInt("QuestionLangID", 1);
|
|
answerDropdown.value = PlayerPrefs.GetInt("AnswerLangID", 0);
|
|
|
|
questionDropdown.RefreshShownValue();
|
|
answerDropdown.RefreshShownValue();
|
|
|
|
saveAndBackButton.onClick.AddListener(() => { PlayClick(); SaveAndBack(); });
|
|
}
|
|
|
|
void PopulateDropdowns()
|
|
{
|
|
List<string> languageNames = new List<string>
|
|
{
|
|
"Türkçe", // 0
|
|
"English", // 1
|
|
"Español", // 2
|
|
"Deutsch", // 3
|
|
"Français", // 4
|
|
"Português" // 5
|
|
};
|
|
|
|
questionDropdown.ClearOptions();
|
|
answerDropdown.ClearOptions();
|
|
|
|
questionDropdown.AddOptions(languageNames);
|
|
answerDropdown.AddOptions(languageNames);
|
|
}
|
|
|
|
void SaveAndBack()
|
|
{
|
|
int qID = questionDropdown.value;
|
|
int aID = answerDropdown.value;
|
|
|
|
PlayerPrefs.SetInt("QuestionLangID", qID);
|
|
PlayerPrefs.SetInt("AnswerLangID", aID);
|
|
PlayerPrefs.SetString("QuestionLangCode", ToCode(qID));
|
|
PlayerPrefs.SetString("AnswerLangCode", ToCode(aID));
|
|
PlayerPrefs.SetString("AppLanguage", ToCode(qID));
|
|
PlayerPrefs.Save();
|
|
|
|
SceneManager.LoadScene("Anamen");
|
|
}
|
|
|
|
void PlayClick()
|
|
{
|
|
if (sfxSource != null && clickSound != null)
|
|
sfxSource.PlayOneShot(clickSound);
|
|
}
|
|
|
|
string ToCode(int id)
|
|
{
|
|
return id switch
|
|
{
|
|
0 => "tr",
|
|
1 => "en",
|
|
2 => "es",
|
|
3 => "de",
|
|
4 => "fr",
|
|
5 => "pt",
|
|
_ => "en"
|
|
};
|
|
}
|
|
} |