コード例 #1
0
ファイル: SceneLoader.cs プロジェクト: midgithub/notes
        /// <summary>
        /// 静态物体,传送门加载
        /// </summary>
        /// <param name="staticStruct"></param>
        /// <returns></returns>
        public GameObject LoadStaticObj(MsgData_sSceneObjectEnterStaticObj staticStruct)
        {
            if (null != CoreEntry.gEntityMgr.GetPortalByServerID(staticStruct.Guid))
            {
                return(null);
            }

            LuaTable portalCfg = ConfigManager.Instance.Map.GetPortalConfig(staticStruct.ConfigID);

            if (null == portalCfg)
            {
                return(null);
            }

            Vector3    position   = CommonTools.ServerPosToClient(staticStruct.PosX, staticStruct.PosY);
            Vector3    eulerAngle = CommonTools.ServerDirToClient(staticStruct.Dir);
            GameObject obj        = CreateGameObject(portalCfg.Get <int>("modelId"), position, eulerAngle);

            if (obj == null)
            {
                obj = CoreEntry.gObjPoolMgr.ObtainObject(portalCfg.Get <int>("modelId"));
                if (null == obj)
                {
                    obj = new GameObject("Portal");
                }

                position.y                = CommonTools.GetTerrainHeight(new Vector2(position.x, position.z));
                obj.transform.position    = position;
                obj.transform.eulerAngles = eulerAngle;
            }

            Entity actorObject = null;

            actorObject = obj.GetComponent <Entity>();
            if (null != actorObject)
            {
                Object.DestroyImmediate(actorObject);
            }

            PortalObj portal = obj.AddComponent <PortalObj>();

            portal.Init(portalCfg.Get <int>("modelId"), staticStruct.ConfigID, staticStruct.Guid);
            portal.ConfigID = staticStruct.ConfigID;

            CoreEntry.gEntityMgr.AddPortal(portal);

            return(obj);
        }
コード例 #2
0
        void Update()
        {
            if (!bSceneLoaded)
            {
                return;
            }

            float time = 0.0f;
            float lastTime = Time.realtimeSinceStartup;
            while (mSceneCache.Count > 0)
            {
                if (time > mMaxPrcessingTime)
                {
                    return;
                }

                SceneObj sceneObj = mSceneCache[0];
                switch (sceneObj.ObjType)
                {
                    case EnEntType.EnEntType_Player:
                        MsgData_sSceneObjectEnterHuman humanStruct = sceneObj.ObjData as MsgData_sSceneObjectEnterHuman;
                        CoreEntry.gSceneLoader.LoadOtherPlayer(humanStruct);
                        if (sceneObj.PlayerData != null)
                        {
                            sceneObj.PlayerData = null;
                        }
                        break;
                    case EnEntType.EnEntType_Monster:
                        MsgData_sSceneObjectEnterMonster monsterStruct = sceneObj.ObjData as MsgData_sSceneObjectEnterMonster;
                        //Debug.LogError("创建怪物:" + monsterStruct.Guid);
                        if (!mObjRecord.ContainsKey(monsterStruct.Guid))
                        {
                            CoreEntry.gSceneLoader.LoadMonster(monsterStruct);
                            mObjRecord.Add(monsterStruct.Guid, CoreEntry.gActorMgr.GetActorByServerID(monsterStruct.Guid));
                        }
                        else
                        {
                            //Debug.LogError("重复怪物:" + monsterStruct.Guid);
                        }
                        break;
                    case EnEntType.EnEntType_NPC:
                        MsgData_sSceneObjectEnterNPC npcStruct = sceneObj.ObjData as MsgData_sSceneObjectEnterNPC;
                        CoreEntry.gSceneLoader.LoadNPC(npcStruct);
                        break;
                    case EnEntType.EnEntType_StaticObj:
                        MsgData_sSceneObjectEnterStaticObj sstaticStruct = sceneObj.ObjData as MsgData_sSceneObjectEnterStaticObj;
                        CoreEntry.gSceneLoader.LoadStaticObj(sstaticStruct);
                        break;
                    case EnEntType.EnEntType_Item:
                        MsgData_sSceneObjectEnterItem itemStruct = sceneObj.ObjData as MsgData_sSceneObjectEnterItem;
                        EventParameter param = EventParameter.Get();
                        param.objParameter = itemStruct;
                        CoreEntry.gEventMgr.TriggerEvent(GameEvent.GE_OBJ_ITEM_ENTER, param);
                        break;
                    case EnEntType.EnEntType_GatherObj:
                        MsgData_sSceneObjectEnterCollection collectionStruct = sceneObj.ObjData as MsgData_sSceneObjectEnterCollection;
                        CoreEntry.gSceneLoader.LoadCollection(collectionStruct);
                        break;
                    case EnEntType.EnEntType_Pet:
                        MsgData_sSceneObjectEnterPet petStruct = sceneObj.ObjData as MsgData_sSceneObjectEnterPet;
                        CoreEntry.gSceneLoader.LoadPet(petStruct);
                        break;
                    case EnEntType.EnEntType_BiaoChe:
                        MsgData_sSceneObjectEnterBiaoChe cheStruct = sceneObj.ObjData as MsgData_sSceneObjectEnterBiaoChe;
                        CoreEntry.gSceneLoader.LoadBiaoChe(cheStruct);
                        break;
                    case EnEntType.EnEntType_Trap:
                        MsgData_sSceneObjectEnterTrap trapStruct = sceneObj.ObjData as MsgData_sSceneObjectEnterTrap;
                        CoreEntry.gSceneLoader.LoadTrap(trapStruct);
                        break;
                    case EnEntType.EntType_VirtualPlayer:
                        MsgData_sSceneObjectEnterVirtualPlayer vpStruct = sceneObj.ObjData as MsgData_sSceneObjectEnterVirtualPlayer;
                        CoreEntry.gSceneLoader.LoadVirtualPlayer(vpStruct);
                        break;
                    default:
                        break;
                }
                
                mSceneCache.RemoveAt(0);

                time += Time.realtimeSinceStartup - lastTime;
            }

            for (int i = 0; i < mDeathCache.Count; i++)
            {
                MsgData_sObjDeadInfo msg = mDeathCache[i];
                ActorObj behitActor = CoreEntry.gActorMgr.GetActorByServerID(msg.ID);
                if (null == behitActor)
                {
                    continue;
                }

                ActorObj attackActor = CoreEntry.gActorMgr.GetActorByServerID(msg.KillerID);

                BehitParam behitParam = new BehitParam();
                DamageParam damageParam = new DamageParam();
                damageParam.attackActor = attackActor;
                damageParam.behitActor = behitActor;
                damageParam.skillID = msg.KillerSkillID;

                behitParam.damgageInfo = damageParam;
                behitActor.OnDead(msg.KillerSkillID, attackActor, behitParam, EventParameter.Get());

                mDeathCache.RemoveAt(i);
                i--;
            }

            for (int i = 0; i < mLeaveCache.Count; i++)
            {
                ActorObj actor = mLeaveCache[i];
                if (null != actor)
                {
                    if (actor.mActorState.IsDeathEnd())
                    {
                        CoreEntry.gActorMgr.RemoveActorByServerID(actor.ServerID);
                        actor.RecycleObj();

                        EventParameter param = EventParameter.Get();
                        param.longParameter = actor.ServerID;
                        CoreEntry.gEventMgr.TriggerEvent(GameEvent.GE_ACTOR_REMOVE, param);

                        if (actor is OtherPlayer)
                        {
                            param = EventParameter.Get();
                            param.longParameter = actor.ServerID;
                            CoreEntry.gEventMgr.TriggerEvent(GameEvent.GE_OTHERPLAYER_LEAVE, param);
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                mLeaveCache.RemoveAt(i);
                i--;
            }
        }
コード例 #3
0
        private void OnEnterScene(GameEvent ge, EventParameter parameter)
        {
            NetReadBuffer buffer = parameter.objParameter as NetReadBuffer;
            CacheEnterHead.unpack(buffer);
            buffer.pos = 0;     //重新给具体类型的消息读取
            if (CacheEnterHead.ObjType == (sbyte)EnEntType.EnEntType_Player)//其它玩家
            {
                MsgData_sSceneObjectEnterHuman humanStruct = new MsgData_sSceneObjectEnterHuman();
                humanStruct.unpack(buffer);

                //队友一定创建
                bool inteam = PlayerData.Instance.TeamData.IsInTeam(humanStruct.Guid);
                int num = inteam ? 0 : (CoreEntry.gActorMgr.GetAllPlayerActors().Count - 1 + GetCacheNumber(EnEntType.EnEntType_Player));
                if (num < CreateMaxPlayer)
                {
                    CacheSceneObj(EnEntType.EnEntType_Player, humanStruct.Guid, humanStruct);
                }
                else
                {
                    ScenePlayerData playerdata = new ScenePlayerData();
                    playerdata.EnterData = humanStruct;
                    if (!mBackgroundPlayer.ContainsKey(playerdata.Guid))
                    {
                        mBackgroundPlayer.Add(playerdata.Guid, playerdata);
                    }
                    else
                    {
                        LogMgr.LogError("玩家已经在缓存中 guid:{0}", playerdata.Guid);
                    }                    
                }                
            }
            else if (CacheEnterHead.ObjType == (sbyte)EnEntType.EnEntType_Monster)//怪物
            {
                MsgData_sSceneObjectEnterMonster monsterStruct = new MsgData_sSceneObjectEnterMonster();
                monsterStruct.unpack(buffer);
                if (CoreEntry.gCurrentMapDesc.Get<int>("type") == 31)   //幻灵副本 ,延时刷怪
                {
                    DungeonMgr.Instance.AddMonster(monsterStruct);
                }
                else
                {
                    CacheSceneObj(EnEntType.EnEntType_Monster, monsterStruct.Guid, monsterStruct);
                }
            }
            else if (CacheEnterHead.ObjType == (sbyte)EnEntType.EnEntType_NPC)//NPC
            {
                MsgData_sSceneObjectEnterNPC npcStruct = new MsgData_sSceneObjectEnterNPC();
                npcStruct.unpack(buffer);
                CacheSceneObj(EnEntType.EnEntType_NPC, npcStruct.Guid, npcStruct);
            }
            else if (CacheEnterHead.ObjType == (sbyte)EnEntType.EnEntType_Item)//物品
            {
                MsgData_sSceneObjectEnterItem itemStruct = new MsgData_sSceneObjectEnterItem();
                itemStruct.unpack(buffer);

                if (itemStruct.Owner == PlayerData.Instance.RoleID)
                {
                    CacheSceneObj(EnEntType.EnEntType_Item, itemStruct.Guid, itemStruct);

                    EventParameter ep = EventParameter.Get();
                    ep.intParameter = itemStruct.ConfigID;
                    ep.intParameter1 = itemStruct.Count;
                    ep.longParameter = itemStruct.Source;
                    CoreEntry.gEventMgr.TriggerEvent(GameEvent.GE_ITEM_DROP, ep);
                }                
            }
            else if (CacheEnterHead.ObjType == (sbyte)EnEntType.EnEntType_GatherObj)
            {
                MsgData_sSceneObjectEnterCollection collectionStruct = new MsgData_sSceneObjectEnterCollection();
                collectionStruct.unpack(buffer);
                CacheSceneObj(EnEntType.EnEntType_GatherObj, collectionStruct.Guid, collectionStruct);
            }
            else if (CacheEnterHead.ObjType == (sbyte)EnEntType.EnEntType_Trap)//陷阱
            {
                MsgData_sSceneObjectEnterTrap trapStruct = new MsgData_sSceneObjectEnterTrap();
                trapStruct.unpack(buffer);
                CacheSceneObj(EnEntType.EnEntType_Trap, trapStruct.Guid, trapStruct);
            }
            else if (CacheEnterHead.ObjType == (sbyte)EnEntType.EnEntType_Pet)
            {
                MsgData_sSceneObjectEnterPet petStruct = new MsgData_sSceneObjectEnterPet();
                petStruct.unpack(buffer);
                CacheSceneObj(EnEntType.EnEntType_Pet, petStruct.Guid, petStruct);
            }
            else if (CacheEnterHead.ObjType == (sbyte)EnEntType.EnEntType_BiaoChe)
            {
                MsgData_sSceneObjectEnterBiaoChe cheStruct = new MsgData_sSceneObjectEnterBiaoChe();
                cheStruct.unpack(buffer);
                CacheSceneObj(EnEntType.EnEntType_BiaoChe, cheStruct.Guid, cheStruct);
            }
            else if (CacheEnterHead.ObjType == (sbyte)EnEntType.EnEntType_StaticObj)//Portal
            {
                MsgData_sSceneObjectEnterStaticObj sstaticStruct = new MsgData_sSceneObjectEnterStaticObj();
                sstaticStruct.unpack(buffer);
                CacheSceneObj(EnEntType.EnEntType_StaticObj, sstaticStruct.Guid, sstaticStruct);
            }
            else if (CacheEnterHead.ObjType == (sbyte)EnEntType.EntType_VirtualPlayer)//EntType_VirtualPlayer
            {
                MsgData_sSceneObjectEnterVirtualPlayer sstaticStruct = new MsgData_sSceneObjectEnterVirtualPlayer();
                sstaticStruct.unpack(buffer);
                //Debug.LogError(sstaticStruct.Guid+"   " + sstaticStruct.HP+"  " +sstaticStruct.Level + "  "+sstaticStruct.Power+"  " +sstaticStruct.Wing);
                CacheSceneObj(EnEntType.EntType_VirtualPlayer, sstaticStruct.Guid, sstaticStruct);
            }


            //下方的游戏中还没用到,就不改了,减少被没必要的GC,以后需要可参照上方定义协议数据后使用
            //else if (baseStruct.ObjType == (sbyte)EnEntType.EnEntType_Patrol)
            //{
            //    PatrolEnterStruct patrolStruct = new PatrolEnterStruct();
            //    PacketUtil.Unpack<PatrolEnterStruct>(data.Data, out patrolStruct);
            //}
            //else if (baseStruct.ObjType == (sbyte)EnEntType.EnEntType_Duke)
            //{
            //    DukeEnterStruct dukeStruct = new DukeEnterStruct();
            //    PacketUtil.Unpack<DukeEnterStruct>(data.Data, out dukeStruct);
            //}

            //else if (baseStruct.ObjType == (sbyte)EnEntType.EnEntType_BiaoChe)
            //{
            //    BiaoCheEnterStruct biaocheStruct = new BiaoCheEnterStruct();
            //    PacketUtil.Unpack<BiaoCheEnterStruct>(data.Data, out biaocheStruct);
            //}
        }