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.

48 lines
1005 B

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