Ejemplo n.º 1
0
        /// <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);
            }
        }