void LoadScene(int sceneid, string name) { if (m_GameScene != null) { CleanScene(); } GComponent loading = UIPackage.CreateObject("GameUI", "Loading").asCom; GRoot.inst.AddChild(loading); Vector2 screenPos = new Vector2(Screen.width / 2, Screen.height / 2); Vector2 logicScreenPos = GRoot.inst.GlobalToLocal(screenPos); loading.xy = logicScreenPos; ResourceLoadAsync.Instance.AddLoad(name, (re) => { Debug.Log("--ResourceLoadAsync:" + re.isDone + " :" + re.progress + " time:" + Tool.GetTime()); loading.GetChild("loadingbar").asProgress.value = re.progress * 100; if (re.isDone) { m_GameScene = (GameObject)Instantiate(re.asset); //System.Threading.Thread.Sleep(5000); //ab //ABManager.LoadAB(); var pos = new Vector3(m_GameScene.transform.position.x, 0, m_GameScene.transform.position.z); m_PlaneScene.SetNormalAndPosition(m_GameScene.transform.up, pos); loading.Dispose(); //SceneManager.LoadScene(0); //通知服务器加载完成 Protomsg.CS_LodingScene msg1 = new Protomsg.CS_LodingScene(); msg1.SceneID = sceneid; MyKcp.Instance.SendMsg(m_ServerName, "CS_LodingScene", msg1); } }); //m_GameScene = (GameObject)Instantiate(Resources.Load(name)); //var pos = new Vector3(m_GameScene.transform.position.x, 0, m_GameScene.transform.position.z); //m_PlaneScene.SetNormalAndPosition(m_GameScene.transform.up, pos); Debug.Log("SC_NewScene:" + name); }
//进入新场景 public bool SC_NewScene(Protomsg.MsgBase d1) { Debug.Log("SC_NewScene:"); IMessage IMperson = new Protomsg.SC_NewScene(); Protomsg.SC_NewScene p1 = (Protomsg.SC_NewScene)IMperson.Descriptor.Parser.ParseFrom(d1.Datas); bool needNewScene = false; if (m_ScenePath != p1.Name) { needNewScene = true; } //p1.Name m_CurFrame = p1.CurFrame; m_LogicFps = p1.LogicFps; m_ServerName = p1.ServerName; m_DataShowType = p1.DataShowType; m_SceneID = p1.SceneID; m_ScenePath = p1.Name; m_GameServerStartTime = Tool.GetTime() - 1.0f / p1.LogicFps * p1.CurFrame; Debug.Log("starttime:" + m_GameServerStartTime + " LogicFps: " + p1.LogicFps + " curframe:" + m_CurFrame + " time:" + Time.realtimeSinceStartup); //显示服务器时间差值 var timenow = DateTime.Now; Debug.Log("111:" + p1.TimeHour + " :" + timenow.Hour); TimeHourDiffer = p1.TimeHour - timenow.Hour; TimeMinuteDiffer = p1.TimeMinute - timenow.Minute; TimeSecondDiffer = p1.TimeSecond - timenow.Second; CleanScene(); if (needNewScene) { LoadScene(p1.SceneID, p1.Name); } else { //通知服务器加载完成 Protomsg.CS_LodingScene msg1 = new Protomsg.CS_LodingScene(); msg1.SceneID = m_SceneID; MyKcp.Instance.SendMsg(m_ServerName, "CS_LodingScene", msg1); } return(true); }