UserPlayer.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using JCEngineCore;
  5. public class UserPlayer : JCEntity
  6. {
  7. public static UserPlayer ins;
  8. public UserPlayer() {
  9. ins = this;
  10. }
  11. public static void ConnectServer() {
  12. if (ins != null) return;
  13. if (HomeMgr.ins) HomeMgr.ins.ShowAuthLoginMask(true);
  14. JCEngine.boot(CommonConfig.businessServerWsURI, new UserPlayer());
  15. }
  16. public override void onLoad() {
  17. Debug.Log("UserPlayer onLoad()");
  18. authToken();
  19. }
  20. public override void onReload() {
  21. Debug.Log("UserPlayer onReload()");
  22. }
  23. public override void onDestroy() {
  24. Debug.Log("UserPlayer onDestroy()");
  25. }
  26. public override void onMiss() {
  27. Debug.Log("UserPlayer onMiss()");
  28. }
  29. //向服务端发送的请求
  30. public void authToken() {
  31. string p0 = PlayerPrefs.GetString("IdAndToken", "");
  32. #if UNITY_EDITOR
  33. if (string.IsNullOrEmpty(p0)) {
  34. p0 = "10&185fa8f92dfe4a55bf35e7ff604c519b";
  35. }
  36. #endif
  37. call("authToken", p0);
  38. }
  39. //被服务端调用的函数
  40. public void onAuthRes(bool res) {
  41. Debug.Log("onAuthRes," + res);
  42. if (res) {
  43. UserComp.ins.getUserInfo(delegate(UserInfo userInfo) {
  44. LoginMgr.myUserInfo = userInfo;
  45. if (HomeView.ins) {
  46. HomeView.ins.RenderMyAvatarSprite();
  47. HomeView.ins.RenderNameOrGender();
  48. HomeView.ins.RenderDeviceNames();
  49. }
  50. if (HomeMgr.ins) {
  51. HomeMgr.ins.ShowAuthLoginMask(false);
  52. }
  53. });
  54. }
  55. }
  56. }