public static Obj_MainPlayer CreateMainPlayerObj() { Obj_MainPlayer mainPlayerObj; //所有的玩家都创建自固定的PlayerRoot的Prefab,具体模型在PlayerRoot下建立Model节点 GameObject mainPlayer = ResourceManager.InstantiateResource("Prefab/Model/PlayerRoot", "MainPlayer") as GameObject; if (null == mainPlayer) { return(null); } //先加载逻辑 mainPlayerObj = mainPlayer.AddComponent <Obj_MainPlayer>(); //赋值玩家guid和职业 mainPlayerObj.Profession = GameManager.gameManager.PlayerDataPool.EnterSceneCache.Profession; mainPlayerObj.GUID = GameManager.gameManager.PlayerDataPool.EnterSceneCache.Guid; ///临时代码 写死玩家 装备 if (GameManager.gameManager.RunningScene == (int)GameDefine_Globe.SCENE_DEFINE.SCENE_FB_CABALINTRO) { mainPlayerObj.InitYanMenGuanWaiVisual(); } else { mainPlayerObj.ModelVisualID = GameManager.gameManager.PlayerDataPool.EnterSceneCache.ModelVisualID; mainPlayerObj.CurWeaponDataID = GameManager.gameManager.PlayerDataPool.EnterSceneCache.WeaponDataID; mainPlayerObj.WeaponEffectGem = GameManager.gameManager.PlayerDataPool.EnterSceneCache.WeaponEffectGem; } Tab_ItemVisual tabItemVisual = TableManager.GetItemVisualByID(mainPlayerObj.ModelVisualID, 0); if (tabItemVisual == null) { tabItemVisual = TableManager.GetItemVisualByID(GlobeVar.DEFAULT_VISUAL_ID, 0); if (tabItemVisual == null) { return(null); } } int nCharmodelID = mainPlayerObj.GetCharModelID(tabItemVisual, mainPlayerObj.Profession); Tab_CharModel charModel = TableManager.GetCharModelByID(nCharmodelID, 0); if (charModel == null) { return(null); } //初始化动作资源路径 mainPlayerObj.AnimationFilePath = charModel.AnimPath; mainPlayerObj.ModelID = nCharmodelID; //进行进场经处理 mainPlayerObj.OnPlayerEnterScene(); mainPlayerObj.ChangeHeadPic(); ObjManager cachedManager = Singleton <ObjManager> .Instance; if (cachedManager == null) { return(null); } cachedManager.AddPoolObj(mainPlayerObj.ServerID.ToString(), mainPlayerObj); //ObjMainPlayer初始化完成 mainPlayerObj.CanLogic = true; mainPlayerObj.transform.localScale = Vector3.one; //朝向屏幕 mainPlayerObj.FaceToScreen(); //向服务器发送EnterSceneOK消息包 CG_ENTER_SCENE_OK packet = (CG_ENTER_SCENE_OK)PacketDistributed.CreatePacket(MessageID.PACKET_CG_ENTER_SCENE_OK); packet.IsOK = 1; packet.SendPacket(); //m_MainPlayer.MountID = GameManager.gameManager.PlayerDataPool.EnterSceneCache.EnterSceneMountID; if (mainPlayerObj.IsDie()) { mainPlayerObj.OnCorpse(); } mainPlayerObj.VipCost = GameManager.gameManager.PlayerDataPool.VipCost; mainPlayerObj.OtherCombatValue = GameManager.gameManager.PlayerDataPool.PoolCombatValue; mainPlayerObj.PaoShangState = GameManager.gameManager.PlayerDataPool.EnterSceneCache.PaoShangState; //如果主角已经创建,清理服务器数据,防止重复建立,并且准备下次切换场景使用 GameManager.gameManager.PlayerDataPool.EnterSceneCache.ClearEnterSceneInfo(); cachedManager.m_bBeginAsycCreateMainPlayer = true; mainPlayerObj.BindParent = GameManager.gameManager.PlayerDataPool.MainBindParent; mainPlayerObj.UpdateBindChildren(GameManager.gameManager.PlayerDataPool.MainBindChildren); LoadModelToRoot(nCharmodelID, EResourceType.CharacterModel, LoadModelComplete, mainPlayer, charModel, false); return(mainPlayerObj); }
/// <summary> /// 创建其他玩家 这里可以优化一下 代码里获取 ModelId 的部分 可能是重复的 等具体功能应用后 替换成obj.ModelId /// </summary> /// <param name="initData"></param> public static void CreateOtherPlayer(Obj_Init_Data initData) { if (null == initData) { return; } GameObject otherPlayer = ResourceManager.InstantiateResource("Prefab/Model/OtherPlayerRoot", initData.m_ServerID.ToString()) as GameObject; if (null != otherPlayer) { //加载逻辑体,同时异步加载渲染体 Obj_OtherPlayer objOtherPlayer = otherPlayer.AddComponent <Obj_OtherPlayer>(); ////////////////////////////////临时代码 写死玩家 装备 其他玩家跟主玩家相同 // // initData.m_ModelVisualID = 18; // initData.m_WeaponDataID = 52188; // initData.m_WeaponEffectGem = 8909; ////////////////////////////////临时代码 写死玩家 装备 if (objOtherPlayer.Init(initData)) { objOtherPlayer.CanLogic = true; } Tab_ItemVisual tabItemVisual = TableManager.GetItemVisualByID(objOtherPlayer.ModelVisualID, 0); if (tabItemVisual == null) { tabItemVisual = TableManager.GetItemVisualByID(GlobeVar.DEFAULT_VISUAL_ID, 0); if (tabItemVisual == null) { return; } } int nCharmodelID = objOtherPlayer.GetCharModelID(tabItemVisual, objOtherPlayer.Profession); //变身的特殊处理 int nChangeModelId = objOtherPlayer.GetCharModelIDByChangeState(objOtherPlayer.Profession, objOtherPlayer.CurChangeState); //如果在变身状态,就用变身状态的模型ID去创建 if (nChangeModelId != GlobeVar.INVALID_ID) { nCharmodelID = nChangeModelId; } Tab_CharModel charModel = TableManager.GetCharModelByID(nCharmodelID, 0); if (charModel == null) { return; } ObjManager cachedManager = Singleton <ObjManager> .Instance; if (cachedManager == null) { return; } cachedManager.AddPoolObj(objOtherPlayer.ServerID.ToString(), objOtherPlayer); if (!cachedManager.CheckOhterPlayerVisibleState(initData, charModel, objOtherPlayer)) { return; } cachedManager.TestOtherPlayerVisible(objOtherPlayer); objOtherPlayer.IsLoadingModel = true; LoadModelToRoot(nCharmodelID, EResourceType.CharacterModel, LoadModelComplete, otherPlayer, charModel, objOtherPlayer.CurChangeState == (int)GameDefine_Globe.ChangeModeState.CHANGE_2 || objOtherPlayer.CurChangeState == (int)GameDefine_Globe.ChangeModeState.CHANGE_1); } }