AccountManager.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using System.Collections.Generic;
  3. using Plugins.CxShine.Singleton;
  4. using UnityEngine;
  5. namespace Api
  6. {
  7. public class AccountManager : ScriptSingleton<AccountManager>
  8. {
  9. private string _session;
  10. public PlayerInfo selfInfo;
  11. public List<Cock> playerCocks = new List<Cock>();
  12. public void login(string phone, string code, bool isIndia, Action<ResponseSuccessData> success,
  13. Action<int, string> errAction)
  14. {
  15. ApiComp.Instance.NotSessionLoginVerifyCode(phone, code, isIndia, data =>
  16. {
  17. // Debug.LogError("sesssion>>>>"+data.session);
  18. selfInfo = data.selfInfo;
  19. _session = data.session;
  20. PlayerPrefs.SetString("session", data.session);
  21. success?.Invoke(data);
  22. }, errAction);
  23. }
  24. public bool isLogin()
  25. {
  26. return !String.IsNullOrEmpty(GetSession());
  27. }
  28. public void playerCocksEmpty()
  29. {
  30. playerCocks = new List<Cock>();
  31. }
  32. public void initPlayerCocks(List<Cock> dataPlayerCocks)
  33. {
  34. playerCocks = dataPlayerCocks;
  35. }
  36. public int GetCockTimes(int cockId)
  37. {
  38. foreach (var cock in playerCocks)
  39. {
  40. if (cock.cockId == cockId)
  41. {
  42. return cock.times;
  43. }
  44. }
  45. return 0;
  46. }
  47. public int GetDiamond()
  48. {
  49. return selfInfo.diamond;
  50. }
  51. public void requestSelfInfo(Action<ResponseSuccessData> action, Action<int, string> errAction)
  52. {
  53. ApiComp.Instance.QuerySelfInfo(data =>
  54. {
  55. _session = data.session;
  56. selfInfo = data.selfInfo;
  57. action.Invoke(data);
  58. }, errAction);
  59. }
  60. private const string PP_SESSION = "session";
  61. public bool HasSession()
  62. {
  63. return PlayerPrefs.HasKey(PP_SESSION);
  64. }
  65. public string GetSession()
  66. {
  67. if (String.IsNullOrEmpty(_session))
  68. {
  69. if (PlayerPrefs.HasKey(PP_SESSION))
  70. {
  71. _session = PlayerPrefs.GetString(PP_SESSION);
  72. }
  73. }
  74. // Debug.LogError(api+"获取Session"+_session);
  75. return _session;
  76. }
  77. }
  78. }