//public ObjectCachePool(CacheReleaser _releaser, int _max_cache_count, int _cache_limit_count, float _worn_time, GameObject _root_node); private void Awake() { mInstance = this; //init gameobj pool root mPoolRoot = new GameObject("PoolRoot"); mPoolRoot.SetActive(false); DontDestroyOnLoad(mPoolRoot); Transform root_trans = mPoolRoot.transform; mPoolRootActor = new GameObject("PoolActor"); mPoolRootActor.transform.parent = root_trans; mPoolRootSmallPrefab = new GameObject("PoolSmallPrefab"); //mPoolRootSmallPrefab.SetActive(false); mPoolRootSmallPrefab.transform.parent = root_trans; mPoolRootSFX = new GameObject("PoolSFX"); //mPoolRootSFX.SetActive(false); mPoolRootSFX.transform.parent = root_trans; mPoolRootUIPrefab = new GameObject("PoolUIPrefab"); //mPoolRootUIPrefab.SetActive(false); mPoolRootUIPrefab.transform.parent = root_trans; mPoolRootDropPrefab = new GameObject("PoolDropPrefab"); //mPoolRootDropPrefab.SetActive(false); mPoolRootDropPrefab.transform.parent = root_trans; CacheReleaser cacheReleaserUnityObj = new CacheReleaser(); cacheReleaserUnityObj.register_release(new CacheReleaser.ReleaseCacheHandle(CacheReleaseHandlerUnityObj)); CacheReleaser cacheReleaserGameObject = new CacheReleaser(); cacheReleaserGameObject.register_release(new CacheReleaser.ReleaseCacheHandle(CacheReleaseHandlerPrefab)); mDicObjPools.Add(ObjCachePoolType.JSON, new ObjectCachePool(cacheReleaserUnityObj, 16, 32, 10, null)); mDicObjPools.Add(ObjCachePoolType.AIJSON, new ObjectCachePool(cacheReleaserUnityObj, 16, 32, 120, null)); mDicObjPools.Add(ObjCachePoolType.AI, new ObjectCachePool(null, 128, 256, 120, null)); mDicObjPools.Add(ObjCachePoolType.MACHINE, new ObjectCachePool(null, 256, 512, 60, null)); mDicObjPools.Add(ObjCachePoolType.STATE, new ObjectCachePool(null, 1024, 2048, 60, null)); mDicObjPools.Add(ObjCachePoolType.SMALL_PREFAB, new ObjectCachePool(cacheReleaserGameObject, 128, 256, 10, mPoolRootSmallPrefab)); mDicObjPools.Add(ObjCachePoolType.UI_PREFAB, new ObjectCachePool(cacheReleaserGameObject, 50, 100, 60, mPoolRootUIPrefab)); mDicObjPools.Add(ObjCachePoolType.DROP_PREFAB, new ObjectCachePool(cacheReleaserGameObject, 50, 100, 180, mPoolRootDropPrefab)); if (QualitySetting.IsVeryLowIPhone()) { mDicObjPools.Add(ObjCachePoolType.ACTOR, new ObjectCachePool(cacheReleaserGameObject, 15, 30, 30, mPoolRootActor)); mDicObjPools.Add(ObjCachePoolType.SFX, new ObjectCachePool(cacheReleaserGameObject, 25, 50, 30, mPoolRootSFX)); } else { mDicObjPools.Add(ObjCachePoolType.ACTOR, new ObjectCachePool(cacheReleaserGameObject, 25, 50, 60, mPoolRootActor)); mDicObjPools.Add(ObjCachePoolType.SFX, new ObjectCachePool(cacheReleaserGameObject, 50, 100, 60, mPoolRootSFX)); } //timers InvokeRepeating("UpdateCachePool", 5f, 5f); ClientEventMgr.Instance.SubscribeClientEvent((int)ClientEvent.CE_START_SWITCHSCENE, OnStartSwitchScene); }
public static IEnumerator EnterGame() { // 预加载资源 ControlServerLogHelper.Instance.PostPlayerFollowRecord(PlayerFollowRecordSceneId.PreloadResStart, "", false); #if UNITY_EDITOR MikuLuaProfiler.HookLuaSetup.OnStartGame(); #endif // 创建Core物体 mCoreObject = new GameObject("Core"); GameObject.DontDestroyOnLoad(mCoreObject); // 实例化Game Game mGame = Game.GetInstance(); mHeartBehavior = mCoreObject.AddComponent <Heart>(); AssemblyBridge.Instance.TimelinePlayableEmployee = new TimelinePlayableEmployee(); ClientEventMgr.GetInstance(); // 增加各种Component var resource_loader = mCoreObject.AddComponent <ResourceLoader>(); resource_loader.BundleVersion = NewInitSceneLoader.Instance.BundleVersion; resource_loader.ServerBundleInfo = NewInitSceneLoader.Instance.g_server_bundle_info; mCoreObject.AddComponent <ResourceUtilEx> (); ResourceLoader.Instance.init(); mCoreObject.AddComponent <ObjCachePoolMgr>(); // 因为部分表格资源放在bundle资源中,因此要尽早进行加载 yield return(GlobalMono.StartCoroutine(DBTableManager.Instance.Preload())); mCoreObject.AddComponent <ActorManager>(); HttpRequest.Instance = mCoreObject.AddComponent <HttpRequest>(); mCoreObject.AddComponent <QuadTreeSceneManager>(); mCoreObject.AddComponent <PushManager>(); xc.RedPointDataMgr.GetInstance(); //小红点实例化 xc.LockIconDataMgr.GetInstance(); xc.NewMarkerDataMgr.GetInstance(); //New标记 #if !DISABLE_LUA //mCoreObject.AddComponent<LuaClient>().Init(); LuaClient luaClient = mCoreObject.AddComponent <LuaClient>(); yield return(GlobalMono.StartCoroutine(luaClient.InitRoutine())); #endif #if (TEST_HOST && !PERFORMANCE_TEST) || HD_RESOURCE //mCoreObject.AddComponent<DebugFPS>();// 因为gc的问题暂时屏蔽 mDebugUI = mCoreObject.AddComponent <DebugUI>(); mDebugUI.UnsubscribeAllProcessCmd(); mDebugUI.SubscribeProcessCmd(DebugCommand.OnProcessCmd); //测试环境打开DebugWindow,取消仅在编辑器打开的判断 //#if UNITY_EDITOR var window = GameObject.Instantiate(Resources.Load <GameObject>("Debug/DebugWindow")); GameObject.DontDestroyOnLoad(window); debugWindow = window.AddComponent <DebugWindow>(); //#endif #endif CullManager.Instance.Factor = 1.0f; QualitySetting.DeviceAdaptation(); AssetResource ar = new AssetResource(); // 加载混音设置 yield return(GetGlobalMono().StartCoroutine(ResourceLoader.Instance.load_asset("Assets/Res/Sound/AudioMixer.mixer", typeof(UnityEngine.Object), ar))); AudioManager.Instance.InitMixer(ar.asset_ as AudioMixer); AudioSource audio = mCoreObject.AddComponent <AudioSource>(); audio.playOnAwake = true; audio.loop = true; audio.outputAudioMixerGroup = AudioManager.Instance.GetAudioMixerGroup("Music"); BackGroundAudio backAudio = mCoreObject.AddComponent <BackGroundAudio>(); backAudio.Init(); if (Const.Language != LanguageType.SIMPLE_CHINESE) { string localizeData = LocalizeManager.Instance.GetLocalizationDataPath(Const.Language); yield return(GetGlobalMono().StartCoroutine(GameLocalizeHelper.CoLoadLocalizeFile(localizeData))); } // 加载Font ar = new AssetResource(); yield return(GetGlobalMono().StartCoroutine(ResourceLoader.Instance.load_asset("Assets/Res/UI/Textures/Emoji/Output/emoji.txt", typeof(UnityEngine.Object), ar))); mEmojiTxt = ar.asset_; if (mEmojiTxt == null) { Debug.LogError("emmoji.txt load failed."); } ar = new AssetResource(); yield return(GetGlobalMono().StartCoroutine(ResourceLoader.Instance.load_asset(EmojiText.GetEmojiTextName(EmojiText.EmojiMaterialType.EquipTips), typeof(UnityEngine.Object), ar))); mEmojiTxt_equipTips = ar.asset_; if (mEmojiTxt_equipTips == null) { Debug.LogError("emoji_equipTips.txt load failed."); } // 加载UIMain,程序中只加载一次 PrefabResource pr = new PrefabResource(); yield return(GetGlobalMono().StartCoroutine(ResourceLoader.Instance.load_prefab("Assets/Res/UI/Widget/Preset/UIRoot.prefab", pr, false))); pr.obj_.transform.position = new Vector3(0, 1000.0f, 0); GameObject.DontDestroyOnLoad(pr.obj_); mGame.Init(); // 加载Start场景 if (Game.Instance.IsSkillEditorScene) { var scene_asset_path = string.Format("Assets/Res/Map/scenes/{0}.unity", GlobalConst.DefaultTestScene); yield return(GetGlobalMono().StartCoroutine(ResourceLoader.Instance.load_scene(scene_asset_path, GlobalConst.DefaultTestScene, null))); } // destroy initscenloader GameObject.DestroyImmediate(NewInitSceneLoader.Instance.gameObject, true); // 初始化Game的状态机 mGame.InitFSM(); mGame.mIsInited = true; Application.targetFrameRate = Const.G_FPS; var fps_respond = mCoreObject.AddComponent <FPSRespond>(); fps_respond.FPSUpdateWaitTime = 15.0f; var fps_notice = mCoreObject.AddComponent <FPSNotice>(); // 预加载资源 ControlServerLogHelper.Instance.PostPlayerFollowRecord(PlayerFollowRecordSceneId.PreloadResEnd); ControlServerLogHelper.Instance.PostCloudLadderEventAction(CloudLadderMarkEnum.load_res); // 向后台请求渠道信息列表和服务器列表 #if !UNITY_IPHONE ControlServerLogHelper.Instance.GetChannelList(); #endif ControlServerLogHelper.Instance.GetServerList(); }
/// <summary> /// 是否已经达到了可显示玩家的最大数量 /// </summary> /// <returns></returns> public bool IsPlayerReachLimit() { return(mAppearWildPlayersInfo.Count >= QualitySetting.GetMaxPlayerProcessCount() * 1.2f); }
/// <summary> /// 加载场景完成的检查 /// </summary> void SceneLoadingUpdate() { // 场景的Scene文件加载完毕 if (mLoadASyncOp != null && mLoadASyncOp.isDone) { // 通过IsSwitchingScene变量确保场景初始化的逻辑只执行一次 if (SceneHelp.Instance.IsSwitchingScene) { QualitySetting.SetSceneGL((EGraphLevel)QualitySetting.GraphicLevel); // 设置相机layer裁剪距离 Camera cur_camera = Game.Instance.MainCamera; if (cur_camera != null) { // 尝试从CameraCull组件中获取裁剪的距离 float cull_distance = 18; var camera_cull = cur_camera.GetComponent <CameraCull>(); if (camera_cull != null) { cull_distance = camera_cull.CullDistance; } for (int i = 0; i < 32; ++i) { distances[i] = 0; } distances[23] = cull_distance; // Tree distances[26] = cull_distance; // SplitScene cur_camera.layerCullDistances = distances; cur_camera.layerCullSpherical = false; int invisible_mask = (1 << LayerMask.NameToLayer("UI")) | (1 << LayerMask.NameToLayer("UI2")) | (1 << LayerMask.NameToLayer("Hide")); cur_camera.cullingMask = ~invisible_mask & cur_camera.cullingMask; //cur_camera.gameObject.AddComponent<CameraScale>(); } SceneHelp.Instance.IsSwitchingScene = false; SceneHelp.Instance.IsLoadingQuadTreeScene = SceneHelp.LoadQuadTreeSceneState.Loading; // 目前不自动隐藏loading界面的场景都未进行切割(登录\创角\选角) if (SceneHelp.Instance.AutoHideLoadingUI) { QuadTreeSceneManager.Instance.StartLoadListener(); } else { Application.targetFrameRate = Const.G_FPS;// 恢复帧率限制 } ScenePostProcess.Instance.Do(); } // 处理自动隐藏loading界面的逻辑 if (SceneHelp.Instance.AutoHideLoadingUI) { // 非野外和副本的时候,可以直接隐藏loading界面 if (SceneHelp.Instance.IsInWildInstance() || SceneHelp.Instance.IsInInstance) { if (MainCamera == null) { return; } var local_player = Game.Instance.GetLocalPlayer(); if (local_player != null) { // 本地玩家创建之后才设置SplitScene可见, 以防止加载额外的动态场景 if ((MainCamera.cullingMask & mSplitSceneLayer) == 0) { MainCamera.cullingMask = MainCamera.cullingMask | mSplitSceneLayer; } // 加载完毕后再隐藏loading界面 if (QuadTreeSceneManager.Instance.LoadFinish) { SceneHelp.Instance.IsLoadingQuadTreeScene = SceneHelp.LoadQuadTreeSceneState.LoadFinished; } if (SceneHelp.Instance.IsLoadingQuadTreeScene == SceneHelp.LoadQuadTreeSceneState.LoadFinished) { if (UIManager.Instance.LoadingBKIsShow == true) { // 新手剧情prefab加载完毕后再隐藏loading界面 if (SceneHelp.Instance.CurSceneID == GameConstHelper.GetUint("GAME_BORN_DUNGEON") && TimelineManager.Instance.ShouldPlayOpenningTimeline() == true) { if (TimelineManager.Instance.OpenningTimelineHavePlayed() == true && TimelineManager.Instance.IsLoading() == false && TimelineManager.Instance.IsPreloading() == false) { if (UIManager.Instance.LoadingBKIsShow == true) { UIManager.Instance.ShowLoadingBK(false); ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_FINISH_LOAD_SCENE, null); } } } else // 没有新手剧情,直接隐藏loading界面 { UIManager.Instance.ShowLoadingBK(false); ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_FINISH_LOAD_SCENE, null); } } } } else { // 没有localplayer的时候,SplitScene设置为不可见 if ((MainCamera.cullingMask & mSplitSceneLayer) != 0) { MainCamera.cullingMask = MainCamera.cullingMask & ~mSplitSceneLayer; } } } else { UIManager.Instance.ShowLoadingBK(false); } } } }
/// <summary> /// 预加载资源 /// </summary> /// <param name="id"></param> /// <returns></returns> public bool Preload(uint id, System.Action finishCallback = null) { TimelineConfig timelineConfig = null; if (GetTimelineConfig(id, out timelineConfig) == false) { if (finishCallback != null) { finishCallback(); finishCallback = null; } GameDebug.LogError("Preload timeline error, can not find timeline id: " + id); return(false); } if (QualitySetting.SkipTimeline(timelineConfig.MinMemory) == true) { if (finishCallback != null) { finishCallback(); finishCallback = null; } return(false); } string prefabPath = timelineConfig.PrefabPath; bool needCameraFollowInterpolationWhenFinished = timelineConfig.NeedCameraFollowInterpolationWhenFinished; // 是否已经预加载过 if (mPreloadedTimelineReses.ContainsKey(id) == true) { if (finishCallback != null) { finishCallback(); finishCallback = null; } //GameDebug.LogError("Preload timeline error, this timeline have been preloaded, id:" + id); return(false); } // 加载前放一个空值进去,防止多次预加载 mPreloadedTimelineReses.Add(id, null); if (mPreloadingTimelines.Contains(id) == false) { mPreloadingTimelines.Add(id); } SGameEngine.ResourceLoader.Instance.LoadAssetAsync(string.Format("Assets/Res{0}.prefab", prefabPath), (ar) => { if (ar != null) { mPreloadedTimelineReses[id] = ar; if (mPreloadingTimelines.Contains(id) == true) { mPreloadingTimelines.Remove(id); } } if (finishCallback != null) { finishCallback(); finishCallback = null; } }); return(true); }
/// <summary> /// 播放Timeline动画 /// </summary> /// <param name="id">剧情配置表里面的id</param> /// <param name="finishCallback">播放结束回调</param> public void Play(uint id, System.Action finishCallback = null, AvatarProperty avatarProperty = null) { //GameDebug.LogError("TimelineManager.Play: " + id); //GameDebug.Log("TimelineManager.Play: " + id); TimelineConfig timelineConfig = null; if (GetTimelineConfig(id, out timelineConfig) == false) { if (finishCallback != null) { finishCallback(); } GameDebug.LogError("Play timeline error, can not find timeline id: " + id); return; } if (QualitySetting.SkipTimeline(timelineConfig.MinMemory) == true) { // 野外场景中记住正在寻路的任务 uint navigatingTaskId = 0; if (SceneHelp.Instance.IsInWildInstance() == true) { Task navigatingTask = TaskManager.Instance.NavigatingTask; if (navigatingTask != null) { navigatingTaskId = navigatingTask.Define.Id; } } bool isAutoFighting = InstanceManager.Instance.IsAutoFighting; if (finishCallback != null) { finishCallback(); } // 恢复自动战斗和任务寻路 InstanceManager.Instance.IsAutoFighting = isAutoFighting; if (navigatingTaskId > 0) { TaskHelper.TaskGuide(navigatingTaskId); } return; } mPlayedTimelineIds.Add(id); if (mLoadingTimelineIdList.Contains(id) == false) { mLoadingTimelineIdList.Add(id); } // 停止并禁止玩家操作 if (timelineConfig.NoStopLocalPlayer == false) { Actor localPlayer = Game.Instance.GetLocalPlayer(); if (localPlayer != null) { localPlayer.Stop(); localPlayer.MoveCtrl.TryWalkAlongStop(); } } GameInput.Instance.EnableInput(false, true); Coroutine coroutine = SGameEngine.ResourceLoader.Instance.StartCoroutine(LoadPrefabCoroutine(timelineConfig, finishCallback, avatarProperty)); mLoadPrefabCoroutines.Add(coroutine); }