You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
941 B

  1. using UnityEngine;
  2. using TMPro;
  3. public class PreFilledText : MonoBehaviour
  4. {
  5. [System.Serializable]
  6. private enum Action {String, Int, Float};
  7. [SerializeField]
  8. private TMP_InputField text;
  9. [Header("Player Prefs")]
  10. [SerializeField]
  11. private Action Type;
  12. [SerializeField]
  13. private string Key;
  14. [SerializeField]
  15. private string DefaultValue;
  16. private void Awake()
  17. {
  18. SetText();
  19. }
  20. private void SetText()
  21. {
  22. switch (Type)
  23. {
  24. case Action.String:
  25. text.text = PlayerPrefs.GetString(Key, DefaultValue);
  26. break;
  27. case Action.Int:
  28. text.text = PlayerPrefs.GetFloat(Key, int.Parse(DefaultValue)).ToString();
  29. break;
  30. case Action.Float:
  31. text.text = PlayerPrefs.GetFloat(Key, float.Parse(DefaultValue)).ToString();
  32. break;
  33. }
  34. }
  35. }