| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using JCEngineCore;
- using UnityEngine.SceneManagement;
- public class UserPlayer : JCEntity
- {
- public static UserPlayer ins;
- public UserPlayer() {
- ins = this;
- }
- public static void ConnectServer() {
- if (ins != null) return;
- if (HomeMgr.ins) HomeMgr.ins.ShowAuthLoginMask(true);
- JCEngine.boot(CommonConfig.businessServerWsURI, new UserPlayer());
- }
- bool canReconnnect = true;
- public override void onLoad() {
- Debug.Log("UserPlayer onLoad()");
- authToken();
- }
- public override void onReload() {
- Debug.Log("UserPlayer onReload()");
- authToken();
- }
- public override void onDestroy() {
- Debug.Log("UserPlayer onDestroy()");
- if (canReconnnect) {
- JCEngine.reboot(this);
- }
- }
- public override void onMiss() {
- Debug.Log("UserPlayer onMiss()");
- if (canReconnnect) {
- JCEngine.reboot(this);
- }
- }
- public void Close() {
- if (ins == this) ins = null;
- this.canReconnnect = false;
- this.channel.close();
- Debug.Log("user player close");
- }
- //向服务端发送的请求
- public void authToken() {
- string p0 = PlayerPrefs.GetString("IdAndToken", "");
- #if UNITY_EDITOR
- if (string.IsNullOrEmpty(p0)) {
- p0 = "12&f29f72fcba4b4a63aa4f965b5d603a4e";
- }
- #endif
- call("authToken", p0);
- }
- //被服务端调用的函数
- public void onAuthRes(bool res) {
- Debug.Log("onAuthRes," + res);
- if (res) {
- UserComp.ins.getUserInfo(delegate(UserInfo userInfo) {
- LoginMgr.myUserInfo = userInfo;
- if (HomeView.ins) {
- HomeView.ins.RenderMyAvatarSprite();
- HomeView.ins.RenderNameOrGender();
- HomeView.ins.RenderDeviceNames();
- }
- if (HomeMgr.ins) {
- HomeMgr.ins.ShowAuthLoginMask(false);
- }
- });
- } else {
- PlayerPrefs.DeleteKey("IdAndToken");
- SceneManager.LoadScene("Login", LoadSceneMode.Single);
- Close();
- }
- }
- public void onInvitePK(int avatarID, string nickname, int roomID, int roomType) {
- string tip = "";
- if (roomType == 0) {
- tip = "好友邀请你参加静止靶PK";
- }
- System.Action cb = delegate() {
- if (SceneManager.GetActiveScene().name == "Home") {
- PKMatchingView view = PKMatchingView.Create();
- view.isFriendPKInvitee = true;
- view.targetJoinRoomID = roomID;
- GlobalData.pkMatchType = PKMatchType.OnlinePK;
- GlobalData.matchRoomType = roomType;
- }
- };
- PopupMgr.ins.ShowPKInviteNotice(avatarID, nickname, tip, cb);
- }
- }
|