109 lines
3.4 KiB
C#
109 lines
3.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Cysharp.Threading.Tasks;
|
|
using Framework;
|
|
using Framework.Wrapper;
|
|
using Gameplay;
|
|
using Gameplay.Level;
|
|
using Gameplay.Net;
|
|
using Gameplay.SubSystems;
|
|
using PhxhSDK;
|
|
using TGS;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
//防守方布阵
|
|
public partial class PVPManager
|
|
{
|
|
private enum ECurrState
|
|
{
|
|
None,
|
|
LoadingScene,
|
|
LoadingUI,
|
|
}
|
|
|
|
private ECurrState _currState;
|
|
private string _scenePath;
|
|
|
|
public async void EnterDefendPrepare()
|
|
{
|
|
var loadingExecutor = new LoadingExecutorWithUILoadingController
|
|
{
|
|
getProgress = GetEnterProgress,
|
|
};
|
|
UIManager.Instance.HideAllUI();
|
|
LoadingExecutorManager.Instance.ExecuteLoading(loadingExecutor);
|
|
_currState = ECurrState.None;
|
|
await LoadScene();
|
|
await LoadUI();
|
|
}
|
|
|
|
public async void ExitDefendPrepare(List<PVPUnitInfo> unitInfosAfterEdit)
|
|
{
|
|
SetPVPDefenderPrepareData(unitInfosAfterEdit);
|
|
PrepareTeamManager.Instance.Dispose();
|
|
UIManager.Instance.CloseWindow(UINameConst.UI_PVPDefendPrepare, UIWindowCloseType.HideAndDestroy);
|
|
UIManager.Instance.ShowAllUI();
|
|
await GameSceneManager.Instance.UnLoadSceneAsync(_scenePath);
|
|
CameraManager.Instance.SetMainCameraActive(true);
|
|
}
|
|
|
|
private async UniTask LoadScene()
|
|
{
|
|
_currState = ECurrState.LoadingScene;
|
|
_scenePath = _pvpLevelInfo.LevelScene;
|
|
var sceneHandle = await GameSceneManager.Instance.LoadSceneForUIView(_scenePath, LoadSceneMode.Additive);
|
|
if (sceneHandle != null)
|
|
{
|
|
CameraManager.Instance.SetMainCameraActive(false);
|
|
}
|
|
}
|
|
|
|
private async UniTask LoadUI()
|
|
{
|
|
if (_pvpLevelInfo == null)
|
|
return;
|
|
_currState = ECurrState.LoadingUI;
|
|
var tgs = UnityEngine.Object.FindObjectOfType<TerrainGridSystem>();
|
|
var mapData = await _pvpLevelInfo.GetMapData();
|
|
var levelData = await _pvpLevelInfo.GetLevelData();
|
|
PrepareTeamManager.Instance.Init(tgs, mapData, levelData.pvpDefendRegionId,
|
|
levelData.pvpDefendToward, NLDSceneManager.Instance.SceneCamera);
|
|
await UIManager.Instance.OpenWindow(UINameConst.UI_PVPDefendPrepare);
|
|
}
|
|
|
|
private float GetEnterProgress()
|
|
{
|
|
switch (_currState)
|
|
{
|
|
case ECurrState.None:
|
|
return 0;
|
|
break;
|
|
case ECurrState.LoadingScene:
|
|
return GameSceneManager.Instance.GetSceneLoadingProgress(_pvpLevelInfo.LevelScene) * 100;
|
|
break;
|
|
case ECurrState.LoadingUI:
|
|
return 100;
|
|
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
private void SetPVPDefenderPrepareData(List<PVPUnitInfo> unitInfos)
|
|
{
|
|
if (unitInfos.Count == 0)
|
|
return;
|
|
unitInfos.Sort((a, b) => a.type.CompareTo(b.type));
|
|
uint vehicleID = unitInfos[^1].type == Unit.UnitType.Vehicle ? unitInfos[^1].unitID : 0;
|
|
uint[] characterIDs = new uint[vehicleID == 0 ? unitInfos.Count : unitInfos.Count - 1];
|
|
for (int i = 0; i < characterIDs.Length; i++)
|
|
{
|
|
characterIDs[i] = unitInfos[i].unitID;
|
|
}
|
|
|
|
byte[] teamData = PVPUnitInfo.Serialize(unitInfos);
|
|
NetHelper.SetDefenceTeamForPvp(characterIDs, vehicleID, teamData);
|
|
}
|
|
} |