void Start() { if (DelegateDefine.Instance.OnSceneLoadOk != null) { DelegateDefine.Instance.OnSceneLoadOk(); } if (GlobalInit.Instance == null) { return; } RoleMgr.Instance.InitMainPlayer(m_PlayerBornPos); if (GlobalInit.Instance.CurrPlayer != null) { worldMapEntity = WorldMapDBModel.GetInstance.GetEntityById(SceneMgr.Instance.CurrWorldMapId); if (worldMapEntity != null) { GlobalInit.Instance.CurrPlayer.gameObject.transform.position = worldMapEntity.RoleBirthPosition; GlobalInit.Instance.CurrPlayer.gameObject.transform.eulerAngles = new Vector3(0, worldMapEntity.RoleBirthY, 0); } else { //没有得到表格中的坐标就用临时的 GlobalInit.Instance.CurrPlayer.gameObject.transform.position = m_PlayerBornPos.position; } } StartCoroutine(InitNPC()); }
protected override void OnMainCityUILoadComplete() { base.OnMainCityUILoadComplete(); if (DelegateDefine.Instance.OnSceneLoadOk != null) { DelegateDefine.Instance.OnSceneLoadOk(); } RoleManager.Instance.InitMainPlayer(); PlayerCtrl.Instance.SetMainCityRoleInfo(); UpdateMainMenuIcon(); if (GlobalInit.Instance == null) { return; } if (GlobalInit.Instance.CurrPlayer != null) { //GlobalInit.Instance.CurrPlayer.gameObject.transform.position = m_PlayerBornPos.position; WorldMapEntity entity = WorldMapDBModel.Instance.Get(SceneMgr.Instance.CurrentWorldMapId); if (entity.RoleBirthPos != null && entity.RoleBirthPos.Length > 3) { GlobalInit.Instance.CurrPlayer.SetBornPoint(new Vector3(entity.RoleBirthPos[0], entity.RoleBirthPos[1], entity.RoleBirthPos[2])); GlobalInit.Instance.CurrPlayer.gameObject.transform.eulerAngles = new Vector3(0, entity.RoleBirthPos[3], 0); } else { GlobalInit.Instance.CurrPlayer.SetBornPoint(m_PlayerBornPos.position); } } StartCoroutine(RoleManager.Instance.InitNPC(SceneMgr.Instance.CurrentWorldMapId)); }
/// <summary> 去世界地图场景(主城 + 野外场景) </summary> /// <param name="worldMapId"> 场景编号(世界地图.xls/WorldMap表) </param> public void LoadToWorldMap(int worldMapId) { m_CurrWorldMapId = worldMapId; WorldMapEntity entity = WorldMapDBModel.Instance.Get(worldMapId); CurrentSceneName = entity.SceneName; CurrSceneType = entity.SceneType; SceneManager.LoadScene("Scene_Loading"); }
private IEnumerator LoadingScene() { string strSceneName = string.Empty; switch (SceneMgr.Instance.CurrentSceneType) { case SceneType.LogOn: strSceneName = "Scene_LogOn"; break; case SceneType.SelectRole: strSceneName = "Scene_SelectRole"; break; case SceneType.WorldMap: //现在需要根据当前服务器返回的最后登录的世界地图id拿到地图相关实体数据 WorldMapEntity worldMapEntity = WorldMapDBModel.GetInstance.GetEntityById(SceneMgr.Instance.CurrWorldMapId); if (worldMapEntity != null) { //现在我们从地图实体类中找到我们地图编号对应的场景名字 strSceneName = worldMapEntity.SceneName; } else { AppDebug.Log(GetType() + "/LoadingScene()/当前世界地图id没有得到对应的实体数据,请检查。id = " + SceneMgr.Instance.CurrWorldMapId); strSceneName = string.Empty; } break; } //说明有错误需要调整 if (strSceneName == string.Empty) { //直接退出携程 yield break; } if (SceneMgr.Instance.CurrentSceneType == SceneType.SelectRole || SceneMgr.Instance.CurrentSceneType == SceneType.WorldMap) { AssetBundleMgr.Instance.LoadAssetAsync(string.Format("Scene/{0}.unity3d", strSceneName), strSceneName, OnLoadABCompleted: (UnityEngine.GameObject obj) => { m_Async = SceneManager.LoadSceneAsync(strSceneName, LoadSceneMode.Additive); m_Async.allowSceneActivation = false; }); } else { m_Async = SceneManager.LoadSceneAsync(strSceneName, LoadSceneMode.Additive); m_Async.allowSceneActivation = false; yield return(m_Async); } }
/// <summary> /// 初始化传送点 /// </summary> private void InitTrans() { m_TransPosDic = new Dictionary <int, Transform>(); //传送点(坐标_y轴旋转_传送点编号_要传送的场景Id_目标场景出生传送点id) WorldMapEntity entity = WorldMapDBModel.Instance.Get(SceneMgr.Instance.CurWorldMapSceneId); if (string.IsNullOrEmpty(entity.TransPos)) { return; } string[] transArr = entity.TransPos.Split('|'); for (int i = 0; i < transArr.Length; i++) { string[] transEntity = transArr[i].Split('_'); if (transEntity.Length != 7) { continue; } Vector3 pos = new Vector3(); float f = 0; float.TryParse(transArr[0], out f); pos.x = f; float.TryParse(transArr[1], out f); pos.y = f; float.TryParse(transArr[2], out f); pos.z = f; float rotateY = 0; float.TryParse(transArr[3], out rotateY); int transId = 0; int.TryParse(transArr[4], out transId); int targetSceneId = 0; int.TryParse(transArr[5], out targetSceneId); int targetTransId = 0; int.TryParse(transArr[6], out targetTransId); GameObject go = ResourcesMrg.Instance.Load(ResourcesMrg.ResourceType.Effect, "EffectTrans", isCache: true, isClone: true); if (go != null) { go.transform.position = pos; go.transform.eulerAngles = new Vector3(0, rotateY, 0); WroldMapTransCtrl transCtrl = go.GetComponent <WroldMapTransCtrl>(); if (transCtrl != null) { transCtrl.SetParameter(transId, targetSceneId, targetTransId); } if (!m_TransPosDic.ContainsKey(transId)) { m_TransPosDic[transId] = go.transform; } } } }
/// <summary> 获取指定世界地图中的所有NPC列表 </summary> /// <param name="id">世界地图WorldMap表中的id</param> /// <returns></returns> public List <NPCDataEntity> GetWorldMapEntityList(int id) { WorldMapEntity entity = WorldMapDBModel.Instance.Get(id); if (entity == null) { Debuger.Log("该场景没有NPC 场景在WorldMap表中的id = " + id); return(null); } else { return(GetWorldMapEntityList(entity.NPCExcel)); } }
/// <summary> 加载NPC并实例化 </summary> /// <param name="npcExcelId">NPCId</param> /// <returns></returns> public IEnumerator InitNPC(int npcExcelId) { List <NPCDataEntity> entityList = NPCManager.Instance.GetWorldMapEntityList(npcExcelId); WorldMapEntity worldMapEntity = WorldMapDBModel.Instance.Get(npcExcelId); if (entityList != null && entityList.Count > 0) { for (int i = 0; i < entityList.Count; i++) { yield return(new WaitForEndOfFrame()); GameObject obj = AssetBundleManager.Instance.Load(string.Format("Download/Model/Npc/{0}/{1}.assetbundle", worldMapEntity.NPCFloader, entityList[i].PrefabName), entityList[i].PrefabName); GameObject npcObj = Object.Instantiate(obj); npcObj.GetComponent <NPCCtrl>().Init(entityList[i]); } } }
/// <summary> /// 初始化世界地图场景控制器 /// </summary> private void InitWorldMapScene() { List <WorldMapEntity> lst = DataTableManager.Instance.WorldMapDBModel.GetList(); if (lst == null) { return; } m_WorldMapSceneControllerDic = new Dictionary <int, WorldMapSceneController>(); for (int i = 0; i < lst.Count; i++) { WorldMapEntity entity = lst[i]; Console.WriteLine("世界地图{0}初始化完毕", entity.Name); WorldMapSceneController ctrl = new WorldMapSceneController(entity.Id); m_WorldMapSceneControllerDic[entity.Id] = ctrl; } }
/// <summary> /// 服务器返回角色进入世界地图场景消息 /// </summary> /// <param name="buffer"></param> private void OnWorldMapRoleEnterReturn(byte[] buffer) { WorldMap_RoleEnterReturnProto proto = WorldMap_RoleEnterReturnProto.GetProto(buffer); if (proto.IsSuccess) { m_CurrWorldMapId = m_WillToWorldMapId; CurrSceneType = SceneType.WorldMap; CurrPlayType = PlayType.PVP; WorldMapEntity entity = WorldMapDBModel.Instance.Get(m_CurrWorldMapId); if (entity != null) { //不是主城 就可以战斗 IsFightingScene = entity.IsCity == 0; } SceneManager.LoadScene("Scene_Loading"); } }