UserComp.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. /* Socket组件-用户 */
  3. public class UserComp : JCUnityLib.Singleton<UserComp>
  4. {
  5. public void getUserInfo(System.Action<UserInfo> cb) {
  6. UserPlayer.ins.call("userComp.getUserInfo", null, cb);
  7. }
  8. public void saveUserInfo(UserInfo userInfo) {
  9. UserPlayer.ins.call("userComp.saveUserInfo", userInfo);
  10. }
  11. private string _lastSaveMac;
  12. public void saveMac()
  13. {
  14. string mac = LoginMgr.myUserInfo.mac;
  15. if (string.IsNullOrEmpty(mac)) return;
  16. _lastSaveMac = mac;
  17. int type = AimHandler.ins.DeviceType;
  18. if (type > 0) {
  19. UserPlayer.ins.call("userComp.saveMac2", mac, type);
  20. } else {
  21. Action<Newtonsoft.Json.Linq.JToken> cb = (Newtonsoft.Json.Linq.JToken o) => {
  22. string gyrStr = o.Value<string>("gyr");
  23. string magStr = o.Value<string>("mag");
  24. AimHandler.ins.InitGyr(gyrStr);
  25. AimHandler.ins.InitMag(magStr);
  26. };
  27. UserPlayer.ins.call("userComp.saveMac", new object[]{mac}, cb);
  28. }
  29. }
  30. public void saveCalibrateRecord(string record) {
  31. string mac = BluetoothAim.ins.curMac;
  32. if (string.IsNullOrEmpty(mac)) {
  33. SideTipView.ShowTip("没有Mac无法上传九轴数据", UnityEngine.Color.yellow);
  34. throw new Exception("没有Mac无法上传九轴数据");
  35. }
  36. int type = AimHandler.ins.DeviceType;
  37. if (type > 0) {
  38. Axis9CalibrateRecord.CacheCalibrateRecord(mac, record);
  39. Axis9CalibrateRecord.SetCalibrateOkRecord(mac, true);
  40. UserPlayer.ins.call("userComp.saveCalibrateRecord2", type, record, mac);
  41. }
  42. }
  43. public void deleteAccount(Action<bool> callback)
  44. {
  45. if (UserPlayer.ins.isValid && UserPlayer.ins.loginAuthed)
  46. {
  47. UserPlayer.ins.call("userComp.deleteAccount", null, callback);
  48. }
  49. else
  50. {
  51. callback?.Invoke(false);
  52. }
  53. }
  54. #region 被服务端调用的函数
  55. public void onResumeCalibrateRecord(string record) {
  56. Axis9CalibrateRecord.CacheCalibrateRecord(_lastSaveMac, record);
  57. AimHandler.ins.ResumeCalibrateRecord(record);
  58. }
  59. #endregion
  60. }