Untitled
unknown
csharp
2 years ago
2.9 kB
7
Indexable
using UnityEngine;
using UnityEngine.UI;
public class LanguageAPI : MonoBehaviour
{
[SerializeField] private Text langText;
[SerializeField] private Text debugText;
[SerializeField] private Text debugText2;
[SerializeField] private Text urlText;
private void Start()
{
#if UNITY_WEBGL
Application.deepLinkActivated += OnDeepLinkActivated;
string url = GetURL();
if (!string.IsNullOrEmpty(url))
{
OnDeepLinkActivated(url);
}
else
{
Debug.LogError("Error: URL not found.");
debugText2.text = "URL bulunamadı.";
}
#else
Debug.LogError("Error: This script is intended to run on WebGL platform.");
debugText.text = "Bu script WebGL platformunda çalışması bekleniyor.";
#endif
}
private string GetURL()
{
string url = "";
url = Application.absoluteURL;
return url;
}
private void OnDeepLinkActivated(string url)
{
if (!string.IsNullOrEmpty(url))
{
urlText.text = "URL: " + url;
string language = GetQueryStringValue(url, "language");
if (!string.IsNullOrEmpty(language))
{
CheckLanguageAndPrintMessage(language.ToLower());
}
else
{
Debug.LogError("Error: 'language' parameter not found or invalid.");
debugText2.text = "Dil parametresi bulunamadı veya geçersiz.";
}
}
else
{
Debug.LogError("Error: URL not found.");
debugText2.text = "URL bulunamadı.";
}
}
private string GetQueryStringValue(string url, string key)
{
if (url.Contains("?"))
{
string queryString = url.Split('?')[1];
string[] queryParams = queryString.Split('&');
foreach (string param in queryParams)
{
string[] keyValue = param.Split('=');
if (keyValue.Length == 2 && keyValue[0].Trim().ToLower() == key.ToLower())
{
return keyValue[1];
}
}
}
return null;
}
private void CheckLanguageAndPrintMessage(string language)
{
if (language.Trim() == "tr")
{
Debug.Log("Türkçe: İstek başarılı");
langText.text = "TR AKTİF";
}
else if (language.Trim() == "en")
{
Debug.Log("English: Request successful");
langText.text = "EN AKTİF";
}
else
{
Debug.Log("Language not supported or not provided: " + language);
langText.text = "İKİSİ DE AKTİF DEĞİL";
}
}
}
Editor is loading...
Leave a Comment