Files
Ultimate-Fishing-Simulator-…/Assets/Scripts/Assembly-CSharp/UI_NewGame.cs
2026-03-04 09:37:33 +08:00

56 lines
1.3 KiB
C#

using System.Text.RegularExpressions;
using Michsky.UI.Heat;
using Obvious.Soap;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
public class UI_NewGame : MonoBehaviour
{
public PlayerProfile PlayerProfile;
[SerializeField]
private TMP_InputField _NameText;
private static Regex validNameRegex = new Regex("^[\\p{L}\\p{Nd}]+$", RegexOptions.Compiled);
public ScriptableEventNoParam invalidCharacters;
public UnityEvent onLoadData = new UnityEvent();
private void Start()
{
if (!PlayerPrefs.HasKey("PlayerLastProfileLoaded"))
{
Debug.Log("No player last profile loaded, should be first game played if not check why it's does");
}
string text = PlayerPrefs.GetString("PlayerLastProfileLoaded", "Angler");
if (!PlayerProfile.LoadData(text))
{
onLoadData.Invoke();
}
else
{
GetComponent<ModalWindowManager>().CloseWindow();
}
}
public void TryAcceptNewProfile()
{
string text = _NameText.text;
if (!validNameRegex.IsMatch(text))
{
Debug.Log("The name contains invalid characters. Use only letters! " + text);
invalidCharacters.Raise();
}
else if (PlayerProfile.TryCreateProfile(text))
{
GetComponent<ModalWindowManager>().CloseWindow();
}
else
{
Debug.Log("Failed to accept new profile: " + text);
}
}
}