UserComp.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. public void saveMac()
  12. {
  13. string mac = LoginMgr.myUserInfo.mac;
  14. if (string.IsNullOrEmpty(mac)) return;
  15. int type = AimHandler.ins.DeviceType;
  16. if (type > 0) {
  17. UserPlayer.ins.call("userComp.saveMac2", mac, type);
  18. } else {
  19. Action<Newtonsoft.Json.Linq.JToken> cb = (Newtonsoft.Json.Linq.JToken o) => {
  20. string gyrStr = o.Value<string>("gyr");
  21. string magStr = o.Value<string>("mag");
  22. AimHandler.ins.InitGyr(gyrStr);
  23. AimHandler.ins.InitMag(magStr);
  24. };
  25. UserPlayer.ins.call("userComp.saveMac", new object[]{mac}, cb);
  26. }
  27. }
  28. public void saveCalibrateRecord(string record) {
  29. string mac = BluetoothAim.ins.curMac;
  30. if (string.IsNullOrEmpty(mac)) {
  31. SideTipView.ShowTip("没有Mac无法上传九轴数据", UnityEngine.Color.yellow);
  32. throw new Exception("没有Mac无法上传九轴数据");
  33. }
  34. int type = AimHandler.ins.DeviceType;
  35. if (type > 0) {
  36. UserPlayer.ins.call("userComp.saveCalibrateRecord2", type, record, mac);
  37. }
  38. }
  39. public void deleteAccount(Action<bool> callback)
  40. {
  41. if (UserPlayer.ins.isValid && UserPlayer.ins.loginAuthed)
  42. {
  43. UserPlayer.ins.call("userComp.deleteAccount", null, callback);
  44. }
  45. else
  46. {
  47. callback?.Invoke(false);
  48. }
  49. }
  50. #region 被服务端调用的函数
  51. public void onResumeCalibrateRecord(string record) {
  52. AimHandler.ins.ResumeCalibrateRecord(record);
  53. }
  54. #endregion
  55. }