123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Engine.Http;
- public class HttpMsgCallBack : MonoBehaviour {
-
- private void Start () {
-
- HttpManager.GetInstance().AddHttpMessageEvent(HandleHttpMessage);
- }
-
-
- private bool HandleHttpMessage(HttpResponse res)
- {
- if (res == null)
- {
- return false;
- }
- if(!res.isSuccess)
- {
-
- switch(res.ResponseStatu)
- {
- case -99999:
- MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_MSG_POP, res.ResponseMsg);
- break;
- case -8:
- MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_CODE_ERROR);
- MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_MSG_POP, "请填写验证码激活账号");
- break;
- default:
- if (res.Code != MsgConst.HTTP_MSG_AUTO_LOGIN)
- {
- MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_MSG_POP, res.ErrorString());
- }
- else
- {
- MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_MSG_POP, res.ErrorString());
-
- GamePlayerData.Instance.user_id = -1;
- }
- break;
- }
- return false;
- }
- switch (res.Code)
- {
-
- case MsgConst.HTTP_MSG_LOGIN:
- OnRefLogin(res);
- break;
-
- case MsgConst.HTTP_MSG_GET_QUESTION:
- OnRefGetQuestionData(res);
- break;
- case MsgConst.HTTP_MSG_AUTO_LOGIN:
- OnRefLogin(res);
- break;
- default: break;
- }
- return false;
- }
-
- private void OnRefLogin(HttpResponse res)
- {
- int last_uid = GamePlayerData.Instance.user_id;
- GamePlayerData.Instance.user_id = res.ReadInt("user_id");
- GamePlayerData.Instance.school_id = res.ReadInt("school_id");
- GamePlayerData.Instance.is_create = res.ReadBool("is_create");
- GamePlayerData.Instance.school_name = res.ReadString("school_name");
- GamePlayerData.Instance.user_name = res.ReadString("user_name");
- GamePlayerData.Instance.user_type = res.ReadInt("user_type");
- GamePlayerData.Instance.school_name = res.ReadString("school_name");
- GamePlayerData.Instance.max_ct = res.ReadInt("MaxCt");
- GetConfigData(res);
- LitJson.JsonData has_Subject = res.ReadJsonData("has_Subject");
- LitJson.JsonData has_Course = res.ReadJsonData("has_Course");
- GameConfigData.Instance.course_data.InitHasSubJect(has_Subject);
- GameConfigData.Instance.course_data.InitHasCourse(has_Course);
- GamePlayerData.Instance.url_image_str = res.ReadString("image_root");
- GamePlayerData.Instance.isDebugAccount = res.ReadBool("debug");
-
-
-
-
-
- GameServerInfo.Instance.InitServerInfo();
-
- GameServerInfo.Instance.AddServer(GamePlayerData.Instance.school_name, res.ReadString("sub_address"), res.ReadInt("sub_prot"), ServerType.Private);
-
- }
-
- private void GetConfigData(HttpResponse res)
- {
- LitJson.JsonData Subject_list_jsonData = res.ReadJsonData("Subject_list");
- GameConfigData.Instance.course_data.InitConfig(Subject_list_jsonData);
- LitJson.JsonData Course_list_jsonData = res.ReadJsonData("Course_list");
- GameConfigData.Instance.course_data.Init(Course_list_jsonData);
- }
-
- private void OnRefGetQuestionData(HttpResponse res)
- {
- GamePlayerData.Instance.eData = new ExperimentData();
- GamePlayerData.Instance.eData.MRAssetName = "MR_Game";
- LitJson.JsonData questionBasicList_jsonData = res.ReadJsonData("questionBasicList");
- LitJson.JsonData questionList_jsonData = res.ReadJsonData("questionList");
- LitJson.JsonData question_jsonData = res.ReadJsonData("question");
-
- GamePlayerData.Instance.eData.InitQuestionBank(question_jsonData);
- GamePlayerData.Instance.eData.InitCourseDesc(res.ReadString("course_desc"));
- GamePlayerData.Instance.eData.InitCourseMRDesc(res.ReadString("course_mr_desc"));
- GamePlayerData.Instance.eData.InitCourseResult(res.ReadString("course_summary"));
- GamePlayerData.Instance.eData.InitChapterItemConfig(res.ReadJsonData("chapterList"));
-
- StudentTaskReceiveManager.Instance.InitManager();
-
- MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_HTTP_COURSE_DATA_BACK);
- }
-
- }
|