地图初步
This commit is contained in:
90
Assets/Scripts/MainGame/GameRun/Map/MapManager.cs
Normal file
90
Assets/Scripts/MainGame/GameRun/Map/MapManager.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Cielonos.Core.UI;
|
||||
using Cielonos.MainGame.Map;
|
||||
using DG.Tweening;
|
||||
using SLSUtilities.General;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Cielonos.MainGame
|
||||
{
|
||||
public partial class MapManager : Singleton<MapManager>
|
||||
{
|
||||
public MapBaseCollection baseCollection;
|
||||
|
||||
public ZoneData currentZoneData;
|
||||
public ZoneManager currentZoneManager;
|
||||
public int zoneIndex;
|
||||
public List<ZoneData> zoneDataList;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
zoneIndex = 0;
|
||||
StartCoroutine(SwitchRoomRoutine(zoneDataList[zoneIndex++]));
|
||||
}
|
||||
|
||||
public void GoToNextZone()
|
||||
{
|
||||
if (zoneIndex >= zoneDataList.Count)
|
||||
{
|
||||
Debug.Log("No more zones to load.");
|
||||
return;
|
||||
}
|
||||
|
||||
ScreenFader.Instance.FadeToBlack(onComplete : () => StartCoroutine(SwitchRoomRoutine(zoneDataList[zoneIndex++]))).Play();
|
||||
}
|
||||
}
|
||||
|
||||
public partial class MapManager
|
||||
{
|
||||
public static MapBaseCollection BaseCollection => Instance.baseCollection;
|
||||
}
|
||||
|
||||
public partial class MapManager
|
||||
{
|
||||
public IEnumerator SwitchRoomRoutine(ZoneData nextZoneData) {
|
||||
// 1. 发送转场开始事件 (UI显示遮挡,特效触发)
|
||||
//EventManager.Trigger("OnTeleportStart");
|
||||
|
||||
// 2. 异步卸载旧场景
|
||||
if (currentZoneData != null) {
|
||||
yield return SceneManager.UnloadSceneAsync(currentZoneData.sceneName);
|
||||
}
|
||||
|
||||
currentZoneData = nextZoneData;
|
||||
|
||||
// 3. 异步加载新场景
|
||||
string nextSceneName = nextZoneData.sceneName;
|
||||
AsyncOperation op = SceneManager.LoadSceneAsync(nextSceneName, LoadSceneMode.Additive);
|
||||
op.allowSceneActivation = false; // 先不激活,等加载到90%
|
||||
|
||||
while (op.progress < 0.9f) {
|
||||
yield return null;
|
||||
}
|
||||
|
||||
op.allowSceneActivation = true; // 允许激活
|
||||
yield return op; // 等待激活完成
|
||||
|
||||
// 4. 设置为活跃场景 (非常重要!)
|
||||
Scene nextScene = SceneManager.GetSceneByName(nextSceneName);
|
||||
SceneManager.SetActiveScene(nextScene);
|
||||
|
||||
// 5. 将玩家放到出生点
|
||||
//Player.Instance.TeleportTo(FindObjectOfType<SpawnPoint>().transform.position);
|
||||
|
||||
yield return new WaitForEndOfFrame();
|
||||
|
||||
BattleManager.AttackAreaSm.Reset();
|
||||
BattleManager.EnemySm.Reset();
|
||||
MainGameManager.Player.transform.position = Vector3.zero;
|
||||
ZoneManager.instance.SetupZone(currentZoneData);
|
||||
// 6. 发送转场结束事件 (特效消失,UI关闭)
|
||||
//EventManager.Trigger("OnTeleportEnd");
|
||||
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
ScreenFader.Instance.FadeToClear().Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user