1
This commit is contained in:
@@ -2,6 +2,7 @@ using Assets.MyGame.Scripts.Net.API;
|
||||
using Assets.MyGame.Scripts.Net.WebResponses;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -116,12 +117,10 @@ namespace Assets.MyGame.Scripts.Net
|
||||
}
|
||||
if (UIManager.Instance.Get<GameMainPanel_Base>(uIPanel)==null)
|
||||
{
|
||||
UIManager.Instance.ShowAsync(uIPanel, UIPanel.HomeMainPanel, msg);
|
||||
// 卸载所有已加载的游戏地图场景(保证场景唯一性)
|
||||
// ① 先卸载其他已加载的游戏地图场景(保证场景唯一性),不卸载即将加载的目标场景
|
||||
string[] gameScenes = { "FLZY", "YYSC", "XJMH", "HHWK" };
|
||||
foreach (var sn in gameScenes)
|
||||
{
|
||||
// 不卸载即将加载的目标场景
|
||||
if (sn == sceneName) continue;
|
||||
var s = SceneManager.GetSceneByName(sn);
|
||||
if (s.IsValid() && s.isLoaded)
|
||||
@@ -130,16 +129,15 @@ namespace Assets.MyGame.Scripts.Net
|
||||
_loadedGameScenes.Remove(sn);
|
||||
}
|
||||
}
|
||||
// 目标场景仅加载一次:标记已加载后不再重复 LoadSceneAsync(防止人机通知触发重复加载)
|
||||
if (!string.IsNullOrEmpty(sceneName) && !_loadedGameScenes.Contains(sceneName))
|
||||
{
|
||||
_loadedGameScenes.Add(sceneName);
|
||||
var targetScene = SceneManager.GetSceneByName(sceneName);
|
||||
if (!targetScene.IsValid() || !targetScene.isLoaded)
|
||||
SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
|
||||
}
|
||||
|
||||
UIManager.Instance.Close(UIPanel.HomeMainPanel);
|
||||
// ② 先显示游戏面板(加载页面,含进度条):ShowAsync 的 onShown 回调在面板实例化并显示后触发,
|
||||
// 用它保证"面板先显示 → 再加载场景 → 再加载资源"的严格先后顺序。
|
||||
// 全程为协程异步,不做 WaitForCompletion 之类的同步等待,不阻塞主线程。
|
||||
UIManager.Instance.ShowAsync(uIPanel, UIPanel.HomeMainPanel, msg, (panel) =>
|
||||
{
|
||||
UIManager.Instance.StartCoroutine(LoadSceneThenResources(panel, sceneName));
|
||||
});
|
||||
|
||||
WebSocketManager.Instance.isGame = true;
|
||||
}
|
||||
else
|
||||
@@ -165,6 +163,30 @@ namespace Assets.MyGame.Scripts.Net
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ③ 加载游戏场景(异步等待完成)→ ④ 场景就绪后再让面板加载资源(鱼/音频/路线等)。
|
||||
/// 全程逐帧 yield 等待,不做同步等待,不阻塞主线程。
|
||||
/// </summary>
|
||||
private static IEnumerator LoadSceneThenResources(UIBase panel, string sceneName)
|
||||
{
|
||||
// ③ 目标场景仅加载一次:标记已加载后不再重复 LoadSceneAsync(防止人机通知触发重复加载)
|
||||
if (!string.IsNullOrEmpty(sceneName) && !_loadedGameScenes.Contains(sceneName))
|
||||
{
|
||||
_loadedGameScenes.Add(sceneName);
|
||||
var targetScene = SceneManager.GetSceneByName(sceneName);
|
||||
if (!targetScene.IsValid() || !targetScene.isLoaded)
|
||||
{
|
||||
var op = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
|
||||
while (op != null && !op.isDone) yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
// ④ 场景就绪后再加载面板资源
|
||||
if (panel is GameMainPanel_FishBase fishPanel)
|
||||
fishPanel.BeginLoadResources();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 把 RoomJoinNotice 玩家数据写入 currRoomData.players(存在则更新,不存在则添加)。
|
||||
/// JoinGame 里 SetUserInfo 按 userId 从 currRoomData.players 查显示信息
|
||||
|
||||
Reference in New Issue
Block a user