UnityHelper.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using UnityEngine;
  2. public class UnityHelper
  3. {
  4. /// <summary>
  5. /// 玩家本地数据存储目录.
  6. /// </summary>
  7. /// <returns></returns>
  8. static public string GetUserDataPath()
  9. {
  10. string filepath = Application.persistentDataPath + "\\";
  11. switch (Application.platform)
  12. {
  13. case RuntimePlatform.WindowsPlayer:
  14. filepath = Application.persistentDataPath + "\\" + System.IO.Path.AltDirectorySeparatorChar;
  15. break;
  16. case RuntimePlatform.IPhonePlayer:
  17. filepath = Application.persistentDataPath + "/";
  18. break;
  19. case RuntimePlatform.OSXEditor:
  20. filepath = Application.persistentDataPath + "/";
  21. //filepath = Application.dataPath + "/"; // fixed 开发环境时直接放到asset目录下
  22. break;
  23. case RuntimePlatform.WindowsEditor:
  24. filepath = Application.persistentDataPath + "/";
  25. //filepath = Application.dataPath + "/";
  26. break;
  27. case RuntimePlatform.Android:
  28. filepath = Application.persistentDataPath + "/";
  29. break;
  30. default:
  31. filepath = Application.persistentDataPath + "\\";
  32. break;
  33. }
  34. return filepath;
  35. }
  36. }