SecureIntValue.cs 543 B

123456789101112131415161718192021222324252627282930313233
  1. using UnityEngine;
  2. using System.Collections;
  3. public class SecureIntValue
  4. {
  5. string name;
  6. int salt;
  7. int multiplier;
  8. public SecureIntValue(string name, int salt, int multiplier, int defaultValue)
  9. {
  10. this.name = name;
  11. this.salt = salt;
  12. this.multiplier = multiplier;
  13. if (!PlayerPrefs.HasKey(name))
  14. {
  15. Value = defaultValue;
  16. }
  17. }
  18. public int Value
  19. {
  20. get
  21. {
  22. return (PlayerPrefs.GetInt(name, salt) - salt)/multiplier;
  23. }
  24. set
  25. {
  26. PlayerPrefs.SetInt(name, (value * multiplier) + salt);
  27. PlayerPrefs.Save();
  28. }
  29. }
  30. }