예제 #1
0
        /// <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
        private void OnLeaveScene(GameEvent ge, EventParameter parameter)
        {
            MsgData_sSceneObjectLeaveNotify data = parameter.msgParameter as MsgData_sSceneObjectLeaveNotify;
            long serverID = (long)data.ObjectID;
            if (mObjRecord.ContainsKey(serverID))
            {
                mObjRecord.Remove(serverID);
                //Debug.LogError("怪物消失" + serverID);
            }
            if (mBackgroundPlayer.ContainsKey(serverID))
            {
                mBackgroundPlayer.Remove(serverID);
                return;
            }

            for (int i = 0; i < mSceneDataList.Count; i++)
            {
                if (mSceneDataList[i].ObjGuid == serverID)
                {
                    mSceneDataList.RemoveAt(i);

                    break;
                }
            }

            for(int i = 0;i < mDeathCache.Count;i++)
            {
                if(serverID == mDeathCache[i].ID)
                {
                    mDeathCache.RemoveAt(i);

                    break;
                }
            }

            for (int i = 0; i < mSceneCache.Count; i++)
            {
                if (mSceneCache[i].ObjGuid == serverID)
                {
                    mSceneCache.RemoveAt(i);

                    return;
                }
            }

            if (!bSceneLoaded)
            {
                return;
            }

            if (data.ObjectType == (sbyte)EnEntType.EnEntType_Item)
            {
                EventParameter param = EventParameter.Get();
                param.longParameter = serverID;
                CoreEntry.gEventMgr.TriggerEvent(GameEvent.GE_OBJ_ITEM_LEAVE, param);

                return;
            }
            else if (data.ObjectType == (sbyte)EnEntType.EnEntType_GatherObj)
            {
                CollectionObj collection = CoreEntry.gEntityMgr.GetCollectionByServerID(serverID) as CollectionObj;
                if (null != collection)
                {
                    CoreEntry.gEntityMgr.RemoveCollectionByServerID(serverID);
                    collection.RecycleObj();
                }

                return;
            }
            else if (data.ObjectType == (sbyte)EnEntType.EnEntType_StaticObj)
            {
                PortalObj portal = CoreEntry.gEntityMgr.GetPortalByServerID(serverID) as PortalObj;
                if (null != portal)
                {
                    CoreEntry.gEntityMgr.RemovePortalByServerID(serverID);
                    portal.RecycleObj();
                }

                return;
            }
            else if (data.ObjectType == (sbyte)EnEntType.EnEntType_Trap)
            {
                Trap trap = CoreEntry.gEntityMgr.GetTrapByServerID(serverID) as Trap;
                if (null != trap)
                {
                    CoreEntry.gEntityMgr.RemoveTrapByServerID(serverID);
                    trap.RecycleObj();
                }

                return;
            }

            ActorObj actor = CoreEntry.gActorMgr.GetActorByServerID(serverID);
            if (null != actor)
            {
                if (!actor.mActorState.IsDeathEnd())
                {
                    if (!mLeaveCache.Contains(actor))
                    {
                        mLeaveCache.Add(actor);
                    }

                    return;
                }

                CoreEntry.gActorMgr.RemoveActorByServerID(serverID);
                actor.RecycleObj();

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

                if (actor is OtherPlayer)
                {
                    param = EventParameter.Get();
                    param.longParameter = serverID;
                    CoreEntry.gEventMgr.TriggerEvent(GameEvent.GE_OTHERPLAYER_LEAVE, param);
                }

                //有后台玩家则切换进来
                if (mBackgroundPlayer.Count > 0)
                {
                    int num = CoreEntry.gActorMgr.GetAllPlayerActors().Count - 1 + GetCacheNumber(EnEntType.EnEntType_Player);
                    if (num < CreateMaxPlayer)
                    {
                        var e = mBackgroundPlayer.GetEnumerator();
                        if (e.MoveNext())
                        {
                            ScenePlayerData value = e.Current.Value;
                            SceneObj sceneobj = CacheSceneObj(EnEntType.EnEntType_Player, value.Guid, value.EnterData);
                            sceneobj.PlayerData = value;
                            mBackgroundPlayer.Remove(value.Guid);
                        }
                        e.Dispose();
                    }                    
                }
            }
        }