Unity - A计划 3.0(三年有效期) 已关闭

Unity - A计划 3.0(三年有效期) 扫二维码继续学习 二维码时效为半小时

(4评价)
价格: 1666.00元
丛林战争以及接入第三方sdk时候遇到的问题
李大狗发起了问答2018-03-15
7
回复
521
浏览

微博登录时,本地校已验授权成功,我下一步没有选择加载新场景,而是push一个新的面板,在安卓测试时上会闪退

 

结合丛林战争的框架模式,想把登录变成接入第三方sdk即微博登录,具体流程如下点击

1.点击微博登录,弹出网上授权那个页面,授权成功后,

把platform type 以及在该平台上的id(即platformid)打包发送到服务器端

   在数据库里查找是否有username(usename需要自己在游戏里注册),

   如果username有的话直接弹出主界面

    如果username没有的话,platformtype和platformid就不写入,弹出注册界面

 

2.弹出注册界面时,闪退(即此界面弹不出来)

所有回复
  • 李大狗 2018-03-15

    public class LoginPanel : BasePanel
    {
        private Button sinaButton;
        private Button mobButton;
        private Button weiXinButton;
        private Button backButton;
        private LoginSinaRequest loginSinaRequest;
        private string platform;
        private string platformid;
        public string Platform
        {
            get { return platform; }
        }
        public string Platformid
        {
            get { return platformid; }
        }

        
        ShareSDK ssdk;//


        private void Start()
        {
            loginSinaRequest = GetComponent<LoginSinaRequest>();
            ssdk = ShareSDKManager.Instance.ssdk;
            ssdk.authHandler = OnSinaAuthResultHandler;//指定授权结果的回调函数

            sinaButton = transform.Find("SinaButton").GetComponent<Button>();
            mobButton = transform.Find("MobButton").GetComponent<Button>();
            weiXinButton = transform.Find("WeiXinButton").GetComponent<Button>();
            backButton = transform.Find("BackButton").GetComponent<Button>();

            sinaButton.onClick.AddListener(OnSinaClick);
            mobButton.onClick.AddListener(OnMobClick);
            weiXinButton.onClick.AddListener(OnWeiXinClick);
          backButton.onClick.AddListener(OnBackClick);
        }

        public override void OnEnter()
        {
            EnterAnimation();
         
        }
        public override void OnPause()
        {
            HideAnimaton();   
        }
        public override void OnResume()
        {
            EnterAnimation();
        }
        public override void OnExit()
        {
            HideAnimaton();
        }
        private void EnterAnimation()
        {
            gameObject.SetActive(true);
            transform.localScale = Vector3.zero;
            transform.DOScale(1, 0.2f);
            transform.localPosition = new Vector3(400, 0, 0);
            transform.DOLocalMove(Vector3.zero,0.2f);
        }
        private void HideAnimaton()
        {
            transform.DOScale(0, 0.3f);
            transform.DOLocalMoveX(1000, 0.3f).OnComplete(() => gameObject.SetActive(false));
        }
        private void OnSinaClick()
        {
            platform = "sina";
            //校验是否授权过
            if (ssdk.IsAuthorized(PlatformType.SinaWeibo))
            {
                Utility.WriteFile(Application.persistentDataPath, "AuthInfo.dat", ssdk.GetAuthInfo(PlatformType.SinaWeibo).toJson());
                //todo
                Hashtable authInfo = Utility.ReadFile(Application.persistentDataPath, "AuthInfo.dat").hashtableFromJson();
                platformid = authInfo["userID"].ToString();

                loginSinaRequest.SendRequest(platform, platformid);
                //1.授权成功就检查授权成功后本地缓存的文件中的用户id是否在数据库注册过,注册过说明是通过register面板注册的,即有用户名
                //uiMng.PushPanel(UIPanelType.Main);
                //2.如果没有在数据库注册过,就弹出register面板进行注册入数据库
            }
            else
            {//失败的话继续授权
                ssdk.Authorize(PlatformType.SinaWeibo);
            }//
            
           
        }
        void OnSinaAuthResultHandler(int reqID, ResponseState state, PlatformType type, Hashtable data)
        {
            if (state == ResponseState.Success)//
            {   //todo
                //1.授权成功就检查授权成功后本地缓存的文件中的用户id是否在数据库注册过,注册过说明是通过register面板注册的,即有用户名
                //  然后uiMng.PushPanel(UIPanelType.Main);
                //2.如果没有在数据库注册过,就弹出register面板进行注册入数据库


                // Utility.WriteFile(Application.persistentDataPath, "AuthResult.dat", data.toJson());

                //写入授权成功的信息
                //uiMng.ShowMessageSync("授权成功!");
                Utility.WriteFile(Application.persistentDataPath, "AuthInfo.dat", ssdk.GetAuthInfo(PlatformType.SinaWeibo).toJson());
                //读取写入本地缓存的授权成功信息
                Hashtable authInfo = Utility.ReadFile(Application.persistentDataPath, "AuthInfo.dat").hashtableFromJson();
                platformid = authInfo["userID"].ToString();
                uiMng.ShowMessageSync("正在向数据库发起平台信息和本地缓存的平台id!");
                loginSinaRequest.SendRequest(platform, platformid);
            }//
            else if (state == ResponseState.Fail)//
            {//
                ssdk.CancelAuthorize(type);//
                uiMng.ShowMessageSync("登录失败!");
            }//
            else if (state == ResponseState.Cancel)//
            {//
                ssdk.CancelAuthorize(type);//
                uiMng.ShowMessageSync("登录失败!");
            }//
            //
        }//
        private void OnMobClick()
        {

        }
        private void OnWeiXinClick()
        {

        }
        private void OnBackClick()
        {
            uiMng.PopPanel();
        }
       
        

        public void OnLoginResopnse(ReturnCode returnCode)
        {
            if (returnCode == ReturnCode.Success)
            {
                //登陆成功进入房间列表
                uiMng.ShowMessageSync("登录成功!");
               // uiMng.PopPanel();
              //  uiMng.PushPanel(UIPanelType.Main);
                //todo
            }
            else
            {
                uiMng.ShowMessageSync("请填写昵称");
               
             uiMng.PushPanel(UIPanelType.Register);
            }
        }
       
        


    }

    还有-5条回复,点击查看
    你还没有登录,请先登录注册
  • 李大狗 2018-03-15

    最后showmessageSync有显示 请填写昵称,但是push新面板时候随即就会闪退

    而切换场景就不会闪退

    还有-5条回复,点击查看
    你还没有登录,请先登录注册
  • 李大狗 2018-03-15

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using Common;
    using UnityEngine.UI;
    using DG.Tweening;

    public class RegisterPanel : BasePanel {

        //private InputField usernameIF;
        private string username;
        
        private Button okButton;
        private Button closeButton;
        private RegisterRequest registerRequest;
        private string platform;
        private string platformid;
        

        public void OnRegisterResponse(ReturnCode returnCode)
        {
            if (returnCode == ReturnCode.Success)
            {
                uiMng.ShowMessage("注册成功");
                uiMng.PushPanel(UIPanelType.Main);
            }
            else
            {
                uiMng.ShowMessage("用户名重复");
            }

        }
        private void Start()
        {
           // usernameIF = transform.Find("RegisterUsernameInputField").GetComponent<InputField>();
           // username = usernameIF.text;
            
            okButton = transform.Find("OkButton").GetComponent<Button>();
            closeButton = transform.Find("CloseButton").GetComponent<Button>();
            platform = uiMng.GetPlatform();
            platformid = uiMng.GetPlatformid();
            okButton.onClick.AddListener(OnOkButtonClick);
            closeButton.onClick.AddListener(OnCloseButtonClick);
        }

        public override void OnEnter()
        {
            gameObject.SetActive(true);
            transform.localScale = Vector3.zero;
            transform.DOScale(1, 0.2f);
            transform.localPosition = new Vector3(400, 0, 0);
            transform.DOLocalMove(Vector3.zero, 0.2f);

        }
        
        
           public override void OnExit()
        {
            base.OnExit();
            gameObject.SetActive(false);
        }

        public override void OnPause()
        {
            gameObject.SetActive(false);
        }
        private void OnOkButtonClick()
        {
            registerRequest.SendRequest(platform,platformid,username);
        }
        private void OnCloseButtonClick()
        {
            transform.DOScale(0, 0.4f);
            Tweener tweener = transform.DOLocalMove(new Vector3(1000, 0, 0), 0.4f);
            tweener.OnComplete(() => uiMng.PopPanel());
        }

    }

    还有-5条回复,点击查看
    你还没有登录,请先登录注册
  • 李大狗 2018-03-15

    这个bug,已经卡着我两天了sad,救命啊crying

    还有-5条回复,点击查看
    你还没有登录,请先登录注册
  • siki 2018-03-17

    老师这边也没搞过微博登录,这个问题要自己解决了哦

    还有-3条回复,点击查看
    你还没有登录,请先登录注册
发表回复
你还没有登录,请先 登录或 注册!