UserPlayer.cs 1.9 KB

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